Bug 570620, part g: Fix bone-headed bugs with shadowable layers, remove unnecessary MOZ_LAYER_DECL_NAME()s, and have the "shadow layer manager" side keep a "shadow root" rather than setting the "real" root. r=vlad
authorChris Jones <jones.chris.g@gmail.com>
Fri, 20 Aug 2010 18:24:41 -0500
changeset 54011 4b1b6833bd5a60682ebda1c717c25c05992c6e55
parent 54010 0e941af684aba87f165e4912707ca21cd12c42bc
child 54012 1a2663f57705337fe0ae80e5893519a7348ba17f
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs570620
milestone2.0b5pre
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 570620, part g: Fix bone-headed bugs with shadowable layers, remove unnecessary MOZ_LAYER_DECL_NAME()s, and have the "shadow layer manager" side keep a "shadow root" rather than setting the "real" root. r=vlad
gfx/layers/basic/BasicLayers.cpp
gfx/layers/basic/BasicLayers.h
gfx/layers/ipc/ShadowLayers.h
gfx/layers/ipc/ShadowLayersParent.cpp
gfx/layers/ipc/ShadowLayersParent.h
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -1293,51 +1293,54 @@ private:
  
 void
 BasicShadowableThebesLayer::PaintBuffer(gfxContext* aContext,
                                         const nsIntRegion& aRegionToDraw,
                                         const nsIntRegion& aRegionToInvalidate,
                                         LayerManager::DrawThebesLayerCallback aCallback,
                                         void* aCallbackData)
 {
-  NS_ABORT_IF_FALSE(!!mBackBuffer, "should have a back buffer by now");
-
   Base::PaintBuffer(aContext, aRegionToDraw, aRegionToInvalidate,
                     aCallback, aCallbackData);
 
-  nsRefPtr<gfxContext> tmpCtx = new gfxContext(mBackBuffer);
-  tmpCtx->DrawSurface(aContext->OriginalSurface(),
-                      gfxIntSize(mBufferSize.width, mBufferSize.height));
+  if (HasShadow()) {
+    NS_ABORT_IF_FALSE(!!mBackBuffer, "should have a back buffer by now");
 
-  BasicManager()->PaintedThebesBuffer(BasicManager()->Hold(this),
-                                      mBuffer.BufferRect(),
-                                      mBuffer.BufferRotation(),
-                                      mBackBuffer);
+    nsRefPtr<gfxContext> tmpCtx = new gfxContext(mBackBuffer);
+    tmpCtx->DrawSurface(aContext->OriginalSurface(),
+                        gfxIntSize(mBufferSize.width, mBufferSize.height));
+
+    BasicManager()->PaintedThebesBuffer(BasicManager()->Hold(this),
+                                        mBuffer.BufferRect(),
+                                        mBuffer.BufferRotation(),
+                                        mBackBuffer);
+  }
 }
 
 already_AddRefed<gfxASurface>
 BasicShadowableThebesLayer::CreateBuffer(Buffer::ContentType aType,
                                          const nsIntSize& aSize)
 {
-  nsRefPtr<gfxSharedImageSurface> tmpFront;
-  // XXX error handling
-  if (!BasicManager()->AllocDoubleBuffer(gfxIntSize(aSize.width, aSize.height),
-                                         gfxASurface::ImageFormatARGB32,
-                                         getter_AddRefs(tmpFront),
-                                         getter_AddRefs(mBackBuffer)))
-    NS_RUNTIMEABORT("creating ThebesLayer 'back buffer' failed!");
-  mBufferSize = aSize;
+  if (HasShadow()) {
+    nsRefPtr<gfxSharedImageSurface> tmpFront;
+    // XXX error handling
+    if (!BasicManager()->AllocDoubleBuffer(gfxIntSize(aSize.width, aSize.height),
+                                           gfxASurface::ImageFormatARGB32,
+                                           getter_AddRefs(tmpFront),
+                                           getter_AddRefs(mBackBuffer)))
+      NS_RUNTIMEABORT("creating ThebesLayer 'back buffer' failed!");
+    mBufferSize = aSize;
 
-  BasicManager()->CreatedThebesBuffer(BasicManager()->Hold(this),
-                                      // only |aSize| really matters
-                                      // here, since Painted() soon
-                                      // follows
-                                      nsIntRect(nsIntPoint(0, 0), aSize),
-                                      tmpFront);
-
+    BasicManager()->CreatedThebesBuffer(BasicManager()->Hold(this),
+                                        // only |aSize| really matters
+                                        // here, since Painted() soon
+                                        // follows
+                                        nsIntRect(nsIntPoint(0, 0), aSize),
+                                        tmpFront);
+  }
   return Base::CreateBuffer(aType, aSize);
 }
 
 
 class BasicShadowableImageLayer : public BasicImageLayer,
                                   public BasicShadowableLayer
 {
 public:
@@ -1574,18 +1577,16 @@ public:
     return mFrontBuffer.Swap(aNewFront, aBufferRect, aRotation);
   }
 
   virtual void Paint(gfxContext* aContext,
                      LayerManager::DrawThebesLayerCallback aCallback,
                      void* aCallbackData,
                      float aOpacity);
 
-  MOZ_LAYER_DECL_NAME("BasicShadowThebesLayer", TYPE_SHADOW)
-
 private:
   BasicShadowLayerManager* BasicManager()
   {
     return static_cast<BasicShadowLayerManager*>(mManager);
   }
 
   ShadowThebesLayerBuffer mFrontBuffer;
 };
@@ -1645,18 +1646,16 @@ public:
   virtual already_AddRefed<gfxSharedImageSurface>
   Swap(gfxSharedImageSurface* newFront);
 
   virtual void Paint(gfxContext* aContext,
                      LayerManager::DrawThebesLayerCallback aCallback,
                      void* aCallbackData,
                      float aOpacity);
 
-  MOZ_LAYER_DECL_NAME("BasicShadowImageLayer", TYPE_SHADOW)
-
 protected:
   BasicShadowLayerManager* BasicManager()
   {
     return static_cast<BasicShadowLayerManager*>(mManager);
   }
 
   // XXX ShmemImage?
   nsRefPtr<gfxSharedImageSurface> mFrontSurface;
@@ -1716,18 +1715,16 @@ public:
   virtual already_AddRefed<gfxSharedImageSurface>
   Swap(gfxSharedImageSurface* newFront);
 
   virtual void Paint(gfxContext* aContext,
                      LayerManager::DrawThebesLayerCallback aCallback,
                      void* aCallbackData,
                      float aOpacity);
 
-  MOZ_LAYER_DECL_NAME("BasicShadowCanvasLayer", TYPE_SHADOW)
-
 private:
   BasicShadowLayerManager* BasicManager()
   {
     return static_cast<BasicShadowLayerManager*>(mManager);
   }
 
   nsRefPtr<gfxSharedImageSurface> mFrontSurface;
   nsIntRect mBounds;
@@ -1874,21 +1871,16 @@ BasicShadowLayerManager::CreateShadowCan
 BasicShadowLayerManager::BasicShadowLayerManager(nsIWidget* aWidget) :
   BasicLayerManager(aWidget)
 {
   MOZ_COUNT_CTOR(BasicShadowLayerManager);
 }
 
 BasicShadowLayerManager::~BasicShadowLayerManager()
 {
-  // FIXME/bug 570294: shadow forwarders don't have __delete__ until
-  // they have manager protocols
-  //
-  //if (HasShadowManager())
-  //  PLayersChild::Send__delete__(mShadow);
   MOZ_COUNT_DTOR(BasicShadowLayerManager);
 }
 
 void
 BasicShadowLayerManager::SetRoot(Layer* aLayer)
 {
   if (mRoot != aLayer) {
     if (HasShadowManager()) {
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -221,19 +221,24 @@ public:
   virtual already_AddRefed<ContainerLayer> CreateContainerLayer();
   virtual already_AddRefed<ImageLayer> CreateImageLayer();
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
   virtual already_AddRefed<ColorLayer> CreateColorLayer();
   virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer();
   virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer();
   virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer();
 
-  virtual const char* Name() const { return "BasicShadowLayerManager"; }
+  ShadowableLayer* Hold(Layer* aLayer);
+
+  PLayersChild* GetShadowManager() const { return mShadowManager; }
 
-  ShadowableLayer* Hold(Layer* aLayer);
+  void SetShadowManager(PLayersChild* aShadowManager)
+  {
+    mShadowManager = aShadowManager;
+  }
 
 private:
   LayerRefArray mKeepAlive;
 };
 #endif  // MOZ_IPC
 
 }
 }
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -209,17 +209,17 @@ public:
    * |aReplies| are directions from the ShadowLayerManager to the
    * caller of EndTransaction().
    */
   PRBool EndTransaction(nsTArray<EditReply>* aReplies);
 
   /**
    * True if this is forwarding to a ShadowLayerManager.
    */
-  PRBool HasShadowManager() { return !!mShadowManager; }
+  PRBool HasShadowManager() const { return !!mShadowManager; }
 
   PRBool AllocDoubleBuffer(const gfxIntSize& aSize,
                            gfxASurface::gfxImageFormat aFormat,
                            gfxSharedImageSurface** aFrontBuffer,
                            gfxSharedImageSurface** aBackBuffer);
 
   void DestroySharedSurface(gfxSharedImageSurface* aSurface);
 
@@ -243,17 +243,17 @@ class ShadowLayerManager : public LayerM
 {
 public:
   virtual ~ShadowLayerManager() {}
 
   PRBool HasForwarder() { return !!mForwarder; }
 
   void SetForwarder(PLayersParent* aForwarder)
   {
-    NS_ASSERTION(!HasForwarder(), "setting forwarder twice?");
+    NS_ASSERTION(!aForwarder || !HasForwarder(), "stomping live forwarder?");
     mForwarder = aForwarder;
   }
 
   void DestroySharedSurface(gfxSharedImageSurface* aSurface);
 
   /** CONSTRUCTION PHASE ONLY */
   virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer() = 0;
   /** CONSTRUCTION PHASE ONLY */
--- a/gfx/layers/ipc/ShadowLayersParent.cpp
+++ b/gfx/layers/ipc/ShadowLayersParent.cpp
@@ -273,17 +273,17 @@ ShadowLayersParent::RecvUpdate(const nsT
       }
       break;
     }
 
       // Tree ops
     case Edit::TOpSetRoot: {
       MOZ_LAYERS_LOG(("[ParentSide] SetRoot"));
 
-      layer_manager()->SetRoot(AsShadowLayer(edit.get_OpSetRoot())->AsLayer());
+      mRoot = AsShadowLayer(edit.get_OpSetRoot())->AsLayer();
       break;
     }
     case Edit::TOpInsertAfter: {
       MOZ_LAYERS_LOG(("[ParentSide] InsertAfter"));
 
       const OpInsertAfter& oia = edit.get_OpInsertAfter();
       ShadowContainer(oia)->AsContainer()->InsertAfter(
         ShadowChild(oia)->AsLayer(), ShadowAfter(oia)->AsLayer());
@@ -369,10 +369,23 @@ ShadowLayersParent::RecvUpdate(const nsT
   reply->SetCapacity(replyv.size());
   if (replyv.size() > 0) {
     reply->AppendElements(&replyv.front(), replyv.size());
   }
 
   return true;
 }
 
+PLayerParent*
+ShadowLayersParent::AllocPLayer()
+{
+  return new ShadowLayerParent();
+}
+
+bool
+ShadowLayersParent::DeallocPLayer(PLayerParent* actor)
+{
+  delete actor;
+  return true;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/ipc/ShadowLayersParent.h
+++ b/gfx/layers/ipc/ShadowLayersParent.h
@@ -37,47 +37,46 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_layers_ShadowLayersParent_h
 #define mozilla_layers_ShadowLayersParent_h
 
 #include "mozilla/layers/PLayersParent.h"
-#include "ShadowLayerParent.h"
 
 namespace mozilla {
 namespace layers {
 
+class Layer;
 class ShadowLayerManager;
 
 class ShadowLayersParent : public PLayersParent
 {
   typedef nsTArray<Edit> EditArray;
   typedef nsTArray<EditReply> EditReplyArray;
 
 public:
   ShadowLayersParent(ShadowLayerManager* aManager);
   ~ShadowLayersParent();
 
   ShadowLayerManager* layer_manager() const { return mLayerManager; }
 
+  Layer* GetRoot() const { return mRoot; }
+
 protected:
   NS_OVERRIDE virtual bool RecvUpdate(const EditArray& cset,
                                       EditReplyArray* reply);
 
-  NS_OVERRIDE virtual PLayerParent* AllocPLayer() {
-    return new ShadowLayerParent();
-  }
-
-  NS_OVERRIDE virtual bool DeallocPLayer(PLayerParent* actor) {
-    delete actor;
-    return true;
-  }
+  NS_OVERRIDE virtual PLayerParent* AllocPLayer();
+  NS_OVERRIDE virtual bool DeallocPLayer(PLayerParent* actor);
 
 private:
   nsRefPtr<ShadowLayerManager> mLayerManager;
+  // Hold the root because it might be grafted under various
+  // containers in the "real" layer tree
+  nsRefPtr<Layer> mRoot;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // ifndef mozilla_layers_ShadowLayersParent_h