Bug 627273, part 1: API for tiling Layers. r=Bas sr=roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 26 Jan 2011 00:26:37 -0600
changeset 61309 656ed06c9a100e29d7b5814c471cb3d7745a20b6
parent 61308 5a0f46c26d12b1b915ba7003308cbf978757f058
child 61310 3bdbbd75eb04786b2560dcf762c4da9172983aea
push idunknown
push userunknown
push dateunknown
reviewersBas, roc
bugs627273
milestone2.0b11pre
Bug 627273, part 1: API for tiling Layers. r=Bas sr=roc
gfx/layers/Layers.cpp
gfx/layers/Layers.h
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -451,16 +451,19 @@ Layer::PrintInfo(nsACString& aTo, const 
     AppendToString(aTo, mTransform, " [transform=", "]");
   }
   if (!mVisibleRegion.IsEmpty()) {
     AppendToString(aTo, mVisibleRegion, " [visible=", "]");
   }
   if (1.0 != mOpacity) {
     aTo.AppendPrintf(" [opacity=%g]", mOpacity);
   }
+  if (const nsIntRect* tileSourceRect = GetTileSourceRect()) {
+    AppendToString(aTo, *tileSourceRect, " [tileSrc=", "]");
+  }
   if (GetContentFlags() & CONTENT_OPAQUE) {
     aTo += " [opaqueContent]";
   }
   if (GetContentFlags() & CONTENT_COMPONENT_ALPHA) {
     aTo += " [componentAlpha]";
   }
 
   return aTo;
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -617,27 +617,57 @@ public:
    * are supported.
    */
   void SetTransform(const gfx3DMatrix& aMatrix)
   {
     mTransform = aMatrix;
     Mutated();
   }
 
+  /**
+   * CONSTRUCTION PHASE ONLY
+   *
+   * Define a subrect of this layer that will be used as the source
+   * image for tiling this layer's visible region.  The coordinates
+   * are in the un-transformed space of this layer (i.e. the visible
+   * region of this this layer is tiled before being transformed).
+   * The visible region is tiled "outwards" from the source rect; that
+   * is, the source rect is drawn "in place", then repeated to cover
+   * the layer's visible region.
+   *
+   * The interpretation of the source rect varies depending on
+   * underlying layer type.  For ImageLayers and CanvasLayers, it
+   * doesn't make sense to set a source rect not fully contained by
+   * the bounds of their underlying images.  For ThebesLayers, thebes
+   * content may need to be rendered to fill the source rect.  For
+   * ColorLayers, a source rect for tiling doesn't make sense at all.
+   *
+   * If aRect is null no tiling will be performed. 
+   */
+  void SetTileSourceRect(const nsIntRect* aRect)
+  {
+    mUseTileSourceRect = aRect != nsnull;
+    if (aRect) {
+      mTileSourceRect = *aRect;
+    }
+    Mutated();
+  }
+
   // These getters can be used anytime.
   float GetOpacity() { return mOpacity; }
   const nsIntRect* GetClipRect() { return mUseClipRect ? &mClipRect : nsnull; }
   PRUint32 GetContentFlags() { return mContentFlags; }
   const nsIntRegion& GetVisibleRegion() { return mVisibleRegion; }
   ContainerLayer* GetParent() { return mParent; }
   Layer* GetNextSibling() { return mNextSibling; }
   Layer* GetPrevSibling() { return mPrevSibling; }
   virtual Layer* GetFirstChild() { return nsnull; }
   virtual Layer* GetLastChild() { return nsnull; }
   const gfx3DMatrix& GetTransform() { return mTransform; }
+  const nsIntRect* GetTileSourceRect() { return mUseTileSourceRect ? &mTileSourceRect : nsnull; }
 
   /**
    * DRAWING PHASE ONLY
    *
    * Write layer-subtype-specific attributes into aAttrs.  Used to
    * synchronize layer attributes to their shadows'.
    */
   virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) { }
@@ -787,17 +817,18 @@ protected:
   Layer(LayerManager* aManager, void* aImplData) :
     mManager(aManager),
     mParent(nsnull),
     mNextSibling(nsnull),
     mPrevSibling(nsnull),
     mImplData(aImplData),
     mOpacity(1.0),
     mContentFlags(0),
-    mUseClipRect(PR_FALSE)
+    mUseClipRect(PR_FALSE),
+    mUseTileSourceRect(PR_FALSE)
     {}
 
   void Mutated() { mManager->Mutated(this); }
 
   // Print interesting information about this into aTo.  Internally
   // used to implement Dump*() and Log*().  If subclasses have
   // additional interesting properties, they should override this with
   // an implementation that first calls the base implementation then
@@ -831,18 +862,20 @@ protected:
   Layer* mPrevSibling;
   void* mImplData;
   LayerUserDataSet mUserData;
   nsIntRegion mVisibleRegion;
   gfx3DMatrix mTransform;
   gfx3DMatrix mEffectiveTransform;
   float mOpacity;
   nsIntRect mClipRect;
+  nsIntRect mTileSourceRect;
   PRUint32 mContentFlags;
   PRPackedBool mUseClipRect;
+  PRPackedBool mUseTileSourceRect;
 };
 
 /**
  * A Layer which we can draw into using Thebes. It is a conceptually
  * infinite surface, but each ThebesLayer has an associated "valid region"
  * of contents that it is currently storing, which is finite. ThebesLayer
  * implementations can store content between paints.
  *