Bug 695845 - Part 2: Add ShadowImplData. r=cjones
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 19 Dec 2011 14:49:45 -0500
changeset 84701 86e91202ef5153177d4f38b0b7f174799819ee03
parent 84700 f9a5736cd6bcb8f6773862cfc713dfa0eeac30f6
child 84702 d8004eb222525f6ac7f0429d5a898ad3dac02637
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs695845
milestone11.0a1
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 695845 - Part 2: Add ShadowImplData. r=cjones
gfx/layers/basic/BasicImages.cpp
gfx/layers/basic/BasicLayers.cpp
gfx/layers/basic/BasicLayers.h
--- a/gfx/layers/basic/BasicImages.cpp
+++ b/gfx/layers/basic/BasicImages.cpp
@@ -226,37 +226,48 @@ BasicPlanarYCbCrImage::GetAsSurface()
   return result.forget();
 }
 
 /**
  * Our image container is very simple. It's really just a factory
  * for the image objects. We use a ReentrantMonitor to synchronize access to
  * mImage.
  */
-class BasicImageContainer : public ImageContainer {
+class BasicImageContainer : public ImageContainer,
+                            public ShadowImplData
+{
 public:
   typedef gfxASurface::gfxImageFormat gfxImageFormat;
 
   BasicImageContainer() :
-    ImageContainer(nsnull),
+    ImageContainer(nsnull, static_cast<ShadowImplData*>(this)),
     mScaleHint(-1, -1),
     mOffscreenFormat(gfxASurface::ImageFormatUnknown),
     mDelayed(false)
   {}
+  BasicImageContainer(LayerManager* aManager) :
+    ImageContainer(aManager, static_cast<ShadowImplData*>(this)),
+    mScaleHint(-1, -1),
+    mOffscreenFormat(gfxASurface::ImageFormatUnknown),
+    mDelayed(false)
+  {}
+
   virtual already_AddRefed<Image> CreateImage(const Image::Format* aFormats,
                                               PRUint32 aNumFormats);
   virtual void SetDelayedConversion(bool aDelayed) { mDelayed = aDelayed; }
   virtual void SetCurrentImage(Image* aImage);
   virtual already_AddRefed<Image> GetCurrentImage();
   virtual already_AddRefed<gfxASurface> GetCurrentAsSurface(gfxIntSize* aSize);
   virtual gfxIntSize GetCurrentSize();
   virtual bool SetLayerManager(LayerManager *aManager);
   virtual void SetScaleHint(const gfxIntSize& aScaleHint);
   void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
   virtual LayerManager::LayersBackend GetBackendType() { return LayerManager::LAYERS_BASIC; }
+  
+  virtual ShadowableLayer* AsShadowableLayer() { return NULL; }
 
 protected:
   nsRefPtr<Image> mImage;
   gfxIntSize mScaleHint;
   gfxImageFormat mOffscreenFormat;
   bool mDelayed;
 };
 
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -92,17 +92,17 @@ class ShadowableLayer;
  *  +-> ThebesLayer                     |   |
  *  |    |                              |   |
  *  |    +-> BasicThebesLayer <---------+   |
  *  |                                       |
  *  +-> ImageLayer                          |
  *       |                                  |
  *       +-> BasicImageLayer <--------------+
  */
-class BasicImplData {
+class BasicImplData : public ShadowImplData {
 public:
   BasicImplData() : mHidden(false),
     mClipToVisibleRegion(false), mOperator(gfxContext::OPERATOR_OVER)
   {
     MOZ_COUNT_CTOR(BasicImplData);
   }
   virtual ~BasicImplData()
   {
@@ -192,16 +192,23 @@ private:
 };
 
 static BasicImplData*
 ToData(Layer* aLayer)
 {
   return static_cast<BasicImplData*>(aLayer->ImplData());
 }
 
+template <typename T>
+static ShadowImplData*
+ToShadowData(T* aLayer)
+{
+  return static_cast<ShadowImplData*>(aLayer->ImplData());
+}
+
 template<class Container>
 static void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
 template<class Container>
 static void ContainerRemoveChild(Layer* aChild, Container* aContainer);
 
 class BasicContainerLayer : public ContainerLayer, public BasicImplData {
   template<class Container>
   friend void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
@@ -2073,20 +2080,21 @@ public:
     // free them here (it's hard to get that right on emergency
     // shutdown anyway).
     mShadow = nsnull;
   }
 
   virtual BasicShadowableThebesLayer* AsThebes() { return nsnull; }
 };
 
+template <typename T>
 static ShadowableLayer*
-ToShadowable(Layer* aLayer)
+ToShadowable(T* aLayer)
 {
-  return ToData(aLayer)->AsShadowableLayer();
+  return ToShadowData(aLayer)->AsShadowableLayer();
 }
 
 // Some layers, like ReadbackLayers, can't be shadowed and shadowing
 // them doesn't make sense anyway
 static bool
 ShouldShadow(Layer* aLayer)
 {
   if (!ToShadowable(aLayer)) {
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -267,16 +267,22 @@ private:
   /**
    * Forward transaction results to the parent context.
    */
   void ForwardTransaction();
 
   LayerRefArray mKeepAlive;
 };
 
+class ShadowImplData
+{
+public:
+  virtual ShadowableLayer* AsShadowableLayer() = 0;
+};
+
 }
 }
 
 /**
  * We need to be able to hold a reference to a gfxASurface from Image
  * subclasses. This is potentially a problem since Images can be addrefed
  * or released off the main thread. We can ensure that we never AddRef
  * a gfxASurface off the main thread, but we might want to Release due