Bug 648484, part 2: Add various helpers, refactor ContainerLayer::SetSpecificAttributes. r=roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 13 Jul 2011 22:43:43 -0700
changeset 72803 b8e675ff425d9612aa9fb1ce5c4eb551a2100cc8
parent 72802 f7b376eb263d18be439d5de730e25db3761a30ff
child 72804 6b041c05b2cbc725e3192223a60bf6ab4b06c6bf
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs648484
milestone8.0a1
Bug 648484, part 2: Add various helpers, refactor ContainerLayer::SetSpecificAttributes. r=roc
gfx/layers/Layers.cpp
gfx/layers/Layers.h
gfx/layers/basic/BasicLayers.cpp
gfx/layers/basic/BasicLayers.h
gfx/layers/ipc/ShadowLayers.h
gfx/layers/opengl/LayerManagerOGL.h
ipc/glue/IPCMessageUtils.h
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -33,16 +33,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/layers/PLayers.h"
 #include "mozilla/layers/ShadowLayers.h"
 
 #include "ImageLayers.h"
 #include "Layers.h"
 #include "gfxPlatform.h"
 #include "ReadbackLayer.h"
 #include "gfxUtils.h"
 #include "mozilla/Util.h"
@@ -384,16 +385,22 @@ Layer::GetEffectiveOpacity()
   float opacity = GetOpacity();
   for (ContainerLayer* c = GetParent(); c && !c->UseIntermediateSurface();
        c = c->GetParent()) {
     opacity *= c->GetOpacity();
   }
   return opacity;
 }
 
+void
+ContainerLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
+{
+  aAttrs = ContainerLayerAttributes(GetFrameMetrics());
+}
+
 PRBool
 ContainerLayer::HasMultipleChildren()
 {
   PRUint32 count = 0;
   for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
     const nsIntRect *clipRect = child->GetEffectiveClipRect();
     if (clipRect && clipRect->IsEmpty())
       continue;
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -74,19 +74,21 @@ namespace layers {
 
 class Layer;
 class ThebesLayer;
 class ContainerLayer;
 class ImageLayer;
 class ColorLayer;
 class ImageContainer;
 class CanvasLayer;
-class ShadowLayer;
 class ReadbackLayer;
 class ReadbackProcessor;
+class ShadowLayer;
+class ShadowLayerForwarder;
+class ShadowLayerManager;
 class SpecificLayerAttributes;
 
 /**
  * The viewport and displayport metrics for the painted frame at the
  * time of a layer-tree transaction.  These metrics are especially
  * useful for shadow layers, because the metrics values are updated
  * atomically with new pixels.
  */
@@ -110,16 +112,20 @@ public:
 
   PRBool operator==(const FrameMetrics& aOther) const
   {
     return (mViewport.IsEqualEdges(aOther.mViewport) &&
             mViewportScrollOffset == aOther.mViewportScrollOffset &&
             mDisplayPort.IsEqualEdges(aOther.mDisplayPort) &&
             mScrollId == aOther.mScrollId);
   }
+  PRBool operator!=(const FrameMetrics& aOther) const
+  { 
+    return !operator==(aOther);
+  }
 
   PRBool IsDefault() const
   {
     return (FrameMetrics() == *this);
   }
 
   PRBool IsRootScrollable() const
   {
@@ -278,16 +284,22 @@ public:
    * Release layers and resources held by this layer manager, and mark
    * it as destroyed.  Should do any cleanup necessary in preparation
    * for its widget going away.  After this call, only user data calls
    * are valid on the layer manager.
    */
   virtual void Destroy() { mDestroyed = PR_TRUE; mUserData.Clear(); }
   PRBool IsDestroyed() { return mDestroyed; }
 
+  virtual ShadowLayerForwarder* AsShadowForwarder()
+  { return nsnull; }
+
+  virtual ShadowLayerManager* AsShadowManager()
+  { return nsnull; }
+
   /**
    * Start a new transaction. Nested transactions are not allowed so
    * there must be no transaction currently in progress.
    * This transaction will update the state of the window from which
    * this LayerManager was obtained.
    */
   virtual void BeginTransaction() = 0;
   /**
@@ -1066,18 +1078,21 @@ public:
   /**
    * CONSTRUCTION PHASE ONLY
    * Set the (sub)document metrics used to render the Layer subtree
    * rooted at this.
    */
   void SetFrameMetrics(const FrameMetrics& aFrameMetrics)
   {
     mFrameMetrics = aFrameMetrics;
+    Mutated();
   }
 
+  virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs);
+
   // These getters can be used anytime.
 
   virtual ContainerLayer* AsContainerLayer() { return this; }
 
   virtual Layer* GetFirstChild() { return mFirstChild; }
   virtual Layer* GetLastChild() { return mLastChild; }
   const FrameMetrics& GetFrameMetrics() { return mFrameMetrics; }
 
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -1866,21 +1866,16 @@ public:
   virtual ~BasicShadowableContainerLayer()
   {
     MOZ_COUNT_DTOR(BasicShadowableContainerLayer);
   }
 
   virtual void InsertAfter(Layer* aChild, Layer* aAfter);
   virtual void RemoveChild(Layer* aChild);
 
-  virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
-  {
-    aAttrs = ContainerLayerAttributes(GetFrameMetrics());
-  }
-
   virtual Layer* AsLayer() { return this; }
   virtual ShadowableLayer* AsShadowableLayer() { return this; }
 
   virtual void Disconnect()
   {
     BasicShadowableLayer::Disconnect();
   }
 
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -219,16 +219,25 @@ class BasicShadowLayerManager : public B
                                 public ShadowLayerForwarder
 {
   typedef nsTArray<nsRefPtr<Layer> > LayerRefArray;
 
 public:
   BasicShadowLayerManager(nsIWidget* aWidget);
   virtual ~BasicShadowLayerManager();
 
+  virtual ShadowLayerForwarder* AsShadowForwarder()
+  {
+    return this;
+  }
+  virtual ShadowLayerManager* AsShadowManager()
+  {
+    return this;
+  }
+
   virtual void BeginTransactionWithTarget(gfxContext* aTarget);
   virtual bool EndEmptyTransaction();
   virtual void EndTransaction(DrawThebesLayerCallback aCallback,
                               void* aCallbackData);
 
   virtual void SetRoot(Layer* aLayer);
 
   virtual void Mutated(Layer* aLayer);
@@ -242,22 +251,16 @@ public:
   virtual already_AddRefed<ShadowContainerLayer> CreateShadowContainerLayer();
   virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer();
   virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer();
   virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer();
 
   ShadowableLayer* Hold(Layer* aLayer);
 
   bool HasShadowManager() const { return ShadowLayerForwarder::HasShadowManager(); }
-  PLayersChild* GetShadowManager() const { return mShadowManager; }
-
-  void SetShadowManager(PLayersChild* aShadowManager)
-  {
-    mShadowManager = aShadowManager;
-  }
 
   virtual PRBool IsCompositingCheap();
   virtual bool HasShadowManagerInternal() const { return HasShadowManager(); }
 
 private:
   /**
    * Forward transaction results to the parent context.
    */
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -233,19 +233,28 @@ public:
   /**
    * End the current transaction and forward it to ShadowLayerManager.
    * |aReplies| are directions from the ShadowLayerManager to the
    * caller of EndTransaction().
    */
   PRBool EndTransaction(InfallibleTArray<EditReply>* aReplies);
 
   /**
+   * Set an actor through which layer updates will be pushed.
+   */
+  void SetShadowManager(PLayersChild* aShadowManager)
+  {
+    mShadowManager = aShadowManager;
+  }
+
+  /**
    * True if this is forwarding to a ShadowLayerManager.
    */
   PRBool HasShadowManager() const { return !!mShadowManager; }
+  PLayersChild* GetShadowManager() const { return mShadowManager; }
 
   /**
    * The following Alloc/Open/Destroy interfaces abstract over the
    * details of working with surfaces that are shared across
    * processes.  They provide the glue between C++ Layers and the
    * ShadowLayer IPC system.
    *
    * The basic lifecycle is
--- a/gfx/layers/opengl/LayerManagerOGL.h
+++ b/gfx/layers/opengl/LayerManagerOGL.h
@@ -121,16 +121,21 @@ public:
    * \param aClippingRegion Region to clip to. Setting an empty region
    * will disable clipping.
    */
   void SetClippingRegion(const nsIntRegion& aClippingRegion);
 
   /**
    * LayerManager implementation.
    */
+  virtual ShadowLayerManager* AsShadowManager()
+  {
+    return this;
+  }
+
   void BeginTransaction();
 
   void BeginTransactionWithTarget(gfxContext* aTarget);
 
   void EndConstruction();
 
   virtual bool EndEmptyTransaction();
   virtual void EndTransaction(DrawThebesLayerCallback aCallback,
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -70,16 +70,20 @@ namespace base { class FileDescriptor { 
 
 using mozilla::layers::LayerManager;
 
 namespace mozilla {
 
 typedef gfxPattern::GraphicsFilter GraphicsFilterType;
 typedef gfxASurface::gfxSurfaceType gfxSurfaceType;
 typedef LayerManager::LayersBackend LayersBackend;
+typedef gfxASurface::gfxImageFormat PixelFormat;
+// This is a cross-platform approximation to HANDLE, which we expect
+// to be typedef'd to void* or thereabouts.
+typedef uintptr_t WindowsHandle;
 
 // XXX there are out of place and might be generally useful.  Could
 // move to nscore.h or something.
 struct void_t {
   bool operator==(const void_t&) const { return true; }
 };
 struct null_t {
   bool operator==(const null_t&) const { return true; }
@@ -499,17 +503,17 @@ struct ParamTraits<mozilla::gfxSurfaceTy
         filter < gfxASurface::SurfaceTypeMax) {
       *result = paramType(filter);
       return true;
     }
     return false;
   }
 };
 
- template<>
+template<>
 struct ParamTraits<mozilla::LayersBackend>
 {
   typedef mozilla::LayersBackend paramType;
 
   static void Write(Message* msg, const paramType& param)
   {
     if (LayerManager::LAYERS_NONE < param &&
         param < LayerManager::LAYERS_LAST) {
@@ -530,16 +534,48 @@ struct ParamTraits<mozilla::LayersBacken
       *result = paramType(type);
       return true;
     }
     return false;
   }
 };
 
 template<>
+struct ParamTraits<mozilla::PixelFormat>
+{
+  typedef mozilla::PixelFormat paramType;
+
+  static bool IsLegalPixelFormat(const paramType& format)
+  {
+    return (gfxASurface::ImageFormatARGB32 <= format &&
+            format < gfxASurface::ImageFormatUnknown);
+  }
+
+  static void Write(Message* msg, const paramType& param)
+  {
+    if (!IsLegalPixelFormat(param)) {
+      NS_RUNTIMEABORT("Unknown pixel format");
+    }
+    WriteParam(msg, int32(param));
+    return;
+  }
+
+  static bool Read(const Message* msg, void** iter, paramType* result)
+  {
+    int32 format;
+    if (!ReadParam(msg, iter, &format) ||
+        !IsLegalPixelFormat(paramType(format))) {
+      return false;
+    }
+    *result = paramType(format);
+    return true;
+  }
+};
+
+template<>
 struct ParamTraits<gfxRGBA>
 {
   typedef gfxRGBA paramType;
 
   static void Write(Message* msg, const paramType& param)
   {
     WriteParam(msg, param.r);
     WriteParam(msg, param.g);