Bug 564991. Part 8: Hoist GetLayerType out of individual layer manager types and make it available for all layers. r=jrmuizel,sr=vlad
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 01 Jul 2010 20:01:09 -0500
changeset 47104 7f4929f934c0e269c675b6013817dd875a6df18d
parent 47103 da4eaba07c92f7019b09318186a20026693b089a
child 47105 fd533e44a4e0aae37cf182419504c2545b3781ff
push id14230
push usercjones@mozilla.com
push dateFri, 02 Jul 2010 01:01:22 +0000
treeherdermozilla-central@7f4929f934c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, vlad
bugs564991
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 564991. Part 8: Hoist GetLayerType out of individual layer manager types and make it available for all layers. r=jrmuizel,sr=vlad
gfx/layers/ImageLayers.h
gfx/layers/Layers.h
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/d3d9/CanvasLayerD3D9.h
gfx/layers/d3d9/ColorLayerD3D9.cpp
gfx/layers/d3d9/ColorLayerD3D9.h
gfx/layers/d3d9/ContainerLayerD3D9.cpp
gfx/layers/d3d9/ContainerLayerD3D9.h
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/d3d9/ImageLayerD3D9.h
gfx/layers/d3d9/LayerManagerD3D9.h
gfx/layers/d3d9/ThebesLayerD3D9.cpp
gfx/layers/d3d9/ThebesLayerD3D9.h
gfx/layers/opengl/CanvasLayerOGL.h
gfx/layers/opengl/ColorLayerOGL.cpp
gfx/layers/opengl/ColorLayerOGL.h
gfx/layers/opengl/ContainerLayerOGL.cpp
gfx/layers/opengl/ContainerLayerOGL.h
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/layers/opengl/ImageLayerOGL.h
gfx/layers/opengl/LayerManagerOGL.cpp
gfx/layers/opengl/LayerManagerOGL.h
gfx/layers/opengl/ThebesLayerOGL.cpp
gfx/layers/opengl/ThebesLayerOGL.h
--- a/gfx/layers/ImageLayers.h
+++ b/gfx/layers/ImageLayers.h
@@ -193,16 +193,18 @@ public:
    * CONSTRUCTION PHASE ONLY
    * Set the filter used to resample this image if necessary.
    */
   void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
 
   ImageContainer* GetContainer() { return mContainer; }
   gfxPattern::GraphicsFilter GetFilter() { return mFilter; }
 
+  NS_LAYER_DECL_NAME("ImageLayer", TYPE_IMAGE)
+
 protected:
   ImageLayer(LayerManager* aManager, void* aImplData)
     : Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD) {}
 
   nsRefPtr<ImageContainer> mContainer;
   gfxPattern::GraphicsFilter mFilter;
 };
 
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -62,16 +62,25 @@ namespace layers {
 class Layer;
 class ThebesLayer;
 class ContainerLayer;
 class ImageLayer;
 class ColorLayer;
 class ImageContainer;
 class CanvasLayer;
 
+#if defined(DEBUG) || defined(PR_LOGGING)
+#define NS_LAYER_DECL_NAME(n, e) \
+  virtual const char* Name() { return n; } \
+  virtual LayerType GetType() { return e; }
+#else
+#define NS_LAYER_DECL_NAME(n, e) \
+  virtual LayerType GetType() { return e; }
+#endif
+
 /*
  * Motivation: For truly smooth animation and video playback, we need to
  * be able to compose frames and render them on a dedicated thread (i.e.
  * off the main thread where DOM manipulation, script execution and layout
  * induce difficult-to-bound latency). This requires Gecko to construct
  * some kind of persistent scene structure (graph or tree) that can be
  * safely transmitted across threads. We have other scenarios (e.g. mobile 
  * browsing) where retaining some rendered data between paints is desired
@@ -232,16 +241,24 @@ class ThebesLayer;
 /**
  * A Layer represents anything that can be rendered onto a destination
  * surface.
  */
 class THEBES_API Layer {
   NS_INLINE_DECL_REFCOUNTING(Layer)  
 
 public:
+  enum LayerType {
+    TYPE_THEBES,
+    TYPE_CONTAINER,
+    TYPE_IMAGE,
+    TYPE_COLOR,
+    TYPE_CANVAS
+  };
+
   virtual ~Layer() {}
 
   /**
    * Returns the LayoutManager this Layer belongs to. Cannot be null.
    */
   LayerManager* Manager() { return mManager; }
 
   /**
@@ -331,17 +348,22 @@ public:
   void SetUserData(void* aData) { mUserData = aData; }
   void* GetUserData() { return mUserData; }
 
   /**
    * Dynamic downcast to a Thebes layer. Returns null if this is not
    * a ThebesLayer.
    */
   virtual ThebesLayer* AsThebesLayer() { return nsnull; }
-  
+
+#ifdef DEBUG
+  virtual const char* Name() = 0;
+#endif
+  virtual LayerType GetType() = 0;
+
   /**
    * Only the implementation should call this. This is per-implementation
    * private data. Normally, all layers with a given layer manager
    * use the same type of ImplData.
    */
   void* ImplData() { return mImplData; }
 
   /**
@@ -401,16 +423,18 @@ public:
 
   /**
    * Can be used anytime
    */
   const nsIntRegion& GetValidRegion() { return mValidRegion; }
 
   virtual ThebesLayer* AsThebesLayer() { return this; }
 
+  NS_LAYER_DECL_NAME("ThebesLayer", TYPE_THEBES)
+
 protected:
   ThebesLayer(LayerManager* aManager, void* aImplData)
     : Layer(aManager, aImplData) {}
 
   nsIntRegion mValidRegion;
 };
 
 /**
@@ -432,16 +456,18 @@ public:
    * Remove aChild from the child list of this container. aChild must
    * be a child of this container.
    */
   virtual void RemoveChild(Layer* aChild) = 0;
 
   // This getter can be used anytime.
   virtual Layer* GetFirstChild() { return mFirstChild; }
 
+  NS_LAYER_DECL_NAME("ContainerLayer", TYPE_CONTAINER)
+
 protected:
   ContainerLayer(LayerManager* aManager, void* aImplData)
     : Layer(aManager, aImplData),
       mFirstChild(nsnull)
   {}
 
   Layer* mFirstChild;
 };
@@ -460,16 +486,18 @@ public:
   virtual void SetColor(const gfxRGBA& aColor)
   {
     mColor = aColor;
   }
 
   // This getter can be used anytime.
   virtual const gfxRGBA& GetColor() { return mColor; }
 
+  NS_LAYER_DECL_NAME("ColorLayer", TYPE_COLOR)
+
 protected:
   ColorLayer(LayerManager* aManager, void* aImplData)
     : Layer(aManager, aImplData),
       mColor(0.0, 0.0, 0.0, 0.0)
   {}
 
   gfxRGBA mColor;
 };
@@ -526,16 +554,18 @@ public:
 
   /**
    * CONSTRUCTION PHASE ONLY
    * Set the filter used to resample this image (if necessary).
    */
   void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
   gfxPattern::GraphicsFilter GetFilter() const { return mFilter; }
 
+  NS_LAYER_DECL_NAME("CanvasLayer", TYPE_CANVAS)
+
 protected:
   CanvasLayer(LayerManager* aManager, void* aImplData)
     : Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD) {}
 
   gfxPattern::GraphicsFilter mFilter;
 };
 
 }
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -161,22 +161,16 @@ CanvasLayerD3D9::Updated(const nsIntRect
              startBits + sourceStride * y,
              aRect.width * 4);
     }
 
     mTexture->UnlockRect(0);
   }
 }
 
-LayerD3D9::LayerType
-CanvasLayerD3D9::GetType()
-{
-  return TYPE_CANVAS;
-}
-
 Layer*
 CanvasLayerD3D9::GetLayer()
 {
   return this;
 }
 
 void
 CanvasLayerD3D9::RenderLayer()
--- a/gfx/layers/d3d9/CanvasLayerD3D9.h
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.h
@@ -63,17 +63,16 @@ public:
 
   ~CanvasLayerD3D9();
 
   // CanvasLayer implementation
   virtual void Initialize(const Data& aData);
   virtual void Updated(const nsIntRect& aRect);
 
   // LayerD3D9 implementation
-  virtual LayerType GetType();
   virtual Layer* GetLayer();
   virtual void RenderLayer();
 
 protected:
   typedef mozilla::gl::GLContext GLContext;
 
   nsRefPtr<gfxASurface> mSurface;
   nsRefPtr<GLContext> mGLContext;
--- a/gfx/layers/d3d9/ColorLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ColorLayerD3D9.cpp
@@ -36,22 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "ColorLayerD3D9.h"
 
 namespace mozilla {
 namespace layers {
 
-LayerD3D9::LayerType
-ColorLayerD3D9::GetType()
-{
-  return TYPE_COLOR;
-}
-
 Layer*
 ColorLayerD3D9::GetLayer()
 {
   return this;
 }
 
 void
 ColorLayerD3D9::RenderLayer()
--- a/gfx/layers/d3d9/ColorLayerD3D9.h
+++ b/gfx/layers/d3d9/ColorLayerD3D9.h
@@ -51,18 +51,16 @@ public:
   ColorLayerD3D9(LayerManagerD3D9 *aManager)
     : ColorLayer(aManager, NULL)
     , LayerD3D9(aManager)
   {
     mImplData = static_cast<LayerD3D9*>(this);
   }
 
   // LayerD3D9 Implementation
-  virtual LayerType GetType();
-
   virtual Layer* GetLayer();
 
   virtual void RenderLayer();
 };
 
 } /* layers */
 } /* mozilla */
 
--- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp
@@ -114,22 +114,16 @@ ContainerLayerD3D9::RemoveChild(Layer *a
       child->SetParent(nsnull);
       NS_RELEASE(aChild);
       return;
     }
     lastChild = child;
   }
 }
 
-LayerD3D9::LayerType
-ContainerLayerD3D9::GetType()
-{
-  return TYPE_CONTAINER;
-}
-
 Layer*
 ContainerLayerD3D9::GetLayer()
 {
   return this;
 }
 
 LayerD3D9*
 ContainerLayerD3D9::GetFirstChildD3D9()
--- a/gfx/layers/d3d9/ContainerLayerD3D9.h
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.h
@@ -54,18 +54,16 @@ public:
   nsIntRect GetVisibleRect() { return mVisibleRegion.GetBounds(); }
 
   /* ContainerLayer implementation */
   virtual void InsertAfter(Layer* aChild, Layer* aAfter);
 
   virtual void RemoveChild(Layer* aChild);
 
   /* LayerD3D9 implementation */
-  LayerType GetType();
-
   Layer* GetLayer();
 
   LayerD3D9* GetFirstChildD3D9();
 
   PRBool IsEmpty();
 
   void RenderLayer();
 };
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -125,22 +125,16 @@ ImageContainerD3D9::GetCurrentSize()
     CairoImageD3D9 *cairoImage =
       static_cast<CairoImageD3D9*>(mActiveImage.get());
     return cairoImage->mSize;
   }
 
   return gfxIntSize(0,0);
 }
 
-LayerD3D9::LayerType
-ImageLayerD3D9::GetType()
-{
-  return TYPE_IMAGE;
-}
-
 Layer*
 ImageLayerD3D9::GetLayer()
 {
   return this;
 }
 
 void
 ImageLayerD3D9::RenderLayer()
--- a/gfx/layers/d3d9/ImageLayerD3D9.h
+++ b/gfx/layers/d3d9/ImageLayerD3D9.h
@@ -77,18 +77,16 @@ public:
   ImageLayerD3D9(LayerManagerD3D9 *aManager)
     : ImageLayer(aManager, NULL)
     , LayerD3D9(aManager)
   {
     mImplData = static_cast<LayerD3D9*>(this);
   }
 
   // LayerD3D9 Implementation
-  virtual LayerType GetType();
-
   virtual Layer* GetLayer();
 
   virtual void RenderLayer();
 };
 
 class THEBES_API ImageD3D9
 {
 public:
--- a/gfx/layers/d3d9/LayerManagerD3D9.h
+++ b/gfx/layers/d3d9/LayerManagerD3D9.h
@@ -207,21 +207,16 @@ private:
 /*
  * General information and tree management for OGL layers.
  */
 class LayerD3D9
 {
 public:
   LayerD3D9(LayerManagerD3D9 *aManager);
 
-  enum LayerType { TYPE_THEBES, TYPE_CONTAINER, TYPE_IMAGE, TYPE_COLOR,
-                   TYPE_CANVAS };
-
-  virtual LayerType GetType() = 0;
-
   virtual LayerD3D9 *GetFirstChildD3D9() { return nsnull; }
 
   void SetFirstChild(LayerD3D9 *aParent);
 
   virtual Layer* GetLayer() = 0;
 
   virtual void RenderLayer() = 0;
 
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -74,22 +74,16 @@ void
 ThebesLayerD3D9::InvalidateRegion(const nsIntRegion &aRegion)
 {
   nsIntRegion invalidatedRegion;
   invalidatedRegion.Or(aRegion, mInvalidatedRect);
   invalidatedRegion.And(invalidatedRegion, mVisibleRegion);
   mInvalidatedRect = invalidatedRegion.GetBounds();
 }
 
-LayerD3D9::LayerType
-ThebesLayerD3D9::GetType()
-{
-  return TYPE_THEBES;
-}
-
 void
 ThebesLayerD3D9::RenderLayer()
 {
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
   if (!mTexture) {
     device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
                             D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
--- a/gfx/layers/d3d9/ThebesLayerD3D9.h
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.h
@@ -55,17 +55,16 @@ public:
 
   /* Layer implementation */
   void SetVisibleRegion(const nsIntRegion& aRegion);
 
   /* ThebesLayer implementation */
   void InvalidateRegion(const nsIntRegion& aRegion);
 
   /* LayerD3D9 implementation */
-  LayerType GetType();
   Layer* GetLayer();
   virtual PRBool IsEmpty();
   virtual void RenderLayer();
   virtual void CleanResources();
 
   /* ThebesLayerD3D9 */
   nsIntRect GetVisibleRect() { return mVisibleRegion.GetBounds(); }
   const nsIntRect &GetInvalidatedRect();
--- a/gfx/layers/opengl/CanvasLayerOGL.h
+++ b/gfx/layers/opengl/CanvasLayerOGL.h
@@ -59,17 +59,16 @@ public:
 
   ~CanvasLayerOGL();
 
   // CanvasLayer implementation
   virtual void Initialize(const Data& aData);
   virtual void Updated(const nsIntRect& aRect);
 
   // LayerOGL implementation
-  virtual LayerType GetType() { return TYPE_CANVAS; }
   virtual Layer* GetLayer() { return this; }
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset);
 
 protected:
   nsRefPtr<gfxASurface> mCanvasSurface;
   nsRefPtr<GLContext> mCanvasGLContext;
 
--- a/gfx/layers/opengl/ColorLayerOGL.cpp
+++ b/gfx/layers/opengl/ColorLayerOGL.cpp
@@ -36,22 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "ColorLayerOGL.h"
 
 namespace mozilla {
 namespace layers {
 
-LayerOGL::LayerType
-ColorLayerOGL::GetType()
-{
-  return TYPE_COLOR;
-}
-
 Layer*
 ColorLayerOGL::GetLayer()
 {
   return this;
 }
 
 void
 ColorLayerOGL::RenderLayer(int,
--- a/gfx/layers/opengl/ColorLayerOGL.h
+++ b/gfx/layers/opengl/ColorLayerOGL.h
@@ -50,18 +50,16 @@ public:
   ColorLayerOGL(LayerManagerOGL *aManager)
     : ColorLayer(aManager, NULL)
     , LayerOGL(aManager)
   { 
     mImplData = static_cast<LayerOGL*>(this);
   }
 
   // LayerOGL Implementation
-  virtual LayerType GetType();
-
   virtual Layer* GetLayer();
 
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset);
 };
 
 } /* layers */
 } /* mozilla */
--- a/gfx/layers/opengl/ContainerLayerOGL.cpp
+++ b/gfx/layers/opengl/ContainerLayerOGL.cpp
@@ -114,22 +114,16 @@ ContainerLayerOGL::RemoveChild(Layer *aC
       child->SetParent(nsnull);
       NS_RELEASE(aChild);
       return;
     }
     lastChild = child;
   }
 }
 
-LayerOGL::LayerType
-ContainerLayerOGL::GetType()
-{
-  return TYPE_CONTAINER;
-}
-
 Layer*
 ContainerLayerOGL::GetLayer()
 {
   return this;
 }
 
 LayerOGL*
 ContainerLayerOGL::GetFirstChildOGL()
--- a/gfx/layers/opengl/ContainerLayerOGL.h
+++ b/gfx/layers/opengl/ContainerLayerOGL.h
@@ -53,18 +53,16 @@ public:
 
   nsIntRect GetVisibleRect() { return mVisibleRegion.GetBounds(); }
 
   void InsertAfter(Layer* aChild, Layer* aAfter);
 
   void RemoveChild(Layer* aChild);
 
   /** LayerOGL implementation */
-  LayerType GetType();
-
   Layer* GetLayer();
 
   LayerOGL* GetFirstChildOGL();
 
   PRBool IsEmpty();
 
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset);
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -250,22 +250,16 @@ ImageContainerOGL::GetCurrentSize()
     CairoImageOGL *cairoImage =
       static_cast<CairoImageOGL*>(mActiveImage.get());
     return cairoImage->mSize;
   }
 
   return gfxIntSize(0,0);
 }
 
-LayerOGL::LayerType
-ImageLayerOGL::GetType()
-{
-  return TYPE_IMAGE;
-}
-
 Layer*
 ImageLayerOGL::GetLayer()
 {
   return this;
 }
 
 void
 ImageLayerOGL::RenderLayer(int,
--- a/gfx/layers/opengl/ImageLayerOGL.h
+++ b/gfx/layers/opengl/ImageLayerOGL.h
@@ -166,18 +166,16 @@ public:
   ImageLayerOGL(LayerManagerOGL *aManager)
     : ImageLayer(aManager, NULL)
     , LayerOGL(aManager)
   { 
     mImplData = static_cast<LayerOGL*>(this);
   }
 
   // LayerOGL Implementation
-  virtual LayerType GetType();
-
   virtual Layer* GetLayer();
 
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset);
 };
 
 class THEBES_API PlanarYCbCrImageOGL : public PlanarYCbCrImage
 {
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -57,32 +57,16 @@
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gl;
 
 int LayerManagerOGLProgram::sCurrentProgramKey = 0;
 
-static void
-DumpLayerAndChildren(LayerOGL *l, int advance = 0)
-{
-  for (int i = 0; i < advance; i++)
-    fprintf(stderr, "  ");
-
-  fprintf(stderr, "%p: Layer type %d\n", l, l->GetType());
-
-  l = l->GetFirstChildOGL();
-  while (l) {
-    DumpLayerAndChildren(l, advance+1);
-    Layer *genl =  l->GetLayer()->GetNextSibling();
-    l = genl ? static_cast<LayerOGL*>(genl->ImplData()) : nsnull;
-  }
-}
-
 /**
  * LayerManagerOGL
  */
 LayerManagerOGL::LayerManagerOGL(nsIWidget *aWidget)
   : mWidget(aWidget)
   , mBackBufferFBO(0)
   , mBackBufferTexture(0)
   , mBackBufferSize(-1, -1)
--- a/gfx/layers/opengl/LayerManagerOGL.h
+++ b/gfx/layers/opengl/LayerManagerOGL.h
@@ -353,26 +353,16 @@ private:
  */
 class LayerOGL
 {
 public:
   LayerOGL(LayerManagerOGL *aManager)
     : mOGLManager(aManager)
   { }
 
-  enum LayerType {
-    TYPE_THEBES,
-    TYPE_CONTAINER,
-    TYPE_IMAGE,
-    TYPE_COLOR,
-    TYPE_CANVAS
-  };
-  
-  virtual LayerType GetType() = 0;
-
   virtual LayerOGL *GetFirstChildOGL() {
     return nsnull;
   }
 
   virtual Layer* GetLayer() = 0;
 
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset) = 0;
--- a/gfx/layers/opengl/ThebesLayerOGL.cpp
+++ b/gfx/layers/opengl/ThebesLayerOGL.cpp
@@ -124,22 +124,16 @@ ThebesLayerOGL::SetVisibleRegion(const n
 }
 
 void
 ThebesLayerOGL::InvalidateRegion(const nsIntRegion &aRegion)
 {
   mValidRegion.Sub(mValidRegion, aRegion);
 }
 
-LayerOGL::LayerType
-ThebesLayerOGL::GetType()
-{
-  return TYPE_THEBES;
-}
-
 void
 ThebesLayerOGL::RenderLayer(int aPreviousFrameBuffer,
                             const nsIntPoint& aOffset)
 {
   if (!EnsureSurface())
     return;
 
   mOGLManager->MakeCurrent();
--- a/gfx/layers/opengl/ThebesLayerOGL.h
+++ b/gfx/layers/opengl/ThebesLayerOGL.h
@@ -59,17 +59,16 @@ public:
 
   /** Layer implementation */
   void SetVisibleRegion(const nsIntRegion& aRegion);
 
   /** ThebesLayer implementation */
   void InvalidateRegion(const nsIntRegion& aRegion);
 
   /** LayerOGL implementation */
-  LayerType GetType();
   Layer* GetLayer();
   virtual PRBool IsEmpty();
   virtual void RenderLayer(int aPreviousFrameBuffer,
                            const nsIntPoint& aOffset);
 
 private:
   PRBool EnsureSurface();