Bug 967824 - Make SetCompositableHost gracefully handle errors instead of just aborting - r=nical
authorBenoit Jacob <bjacob@mozilla.com>
Thu, 20 Feb 2014 08:05:30 -0500
changeset 170022 73949afadd3fcdf0d92579aa184cc0bb5a53516f
parent 170021 03598731cb2abc11911f14bb5c9153475b410d30
child 170023 88950b3366602a1ed2d4024265e49d7ac8238ded
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersnical
bugs967824
milestone30.0a1
Bug 967824 - Make SetCompositableHost gracefully handle errors instead of just aborting - r=nical
gfx/layers/composite/CanvasLayerComposite.cpp
gfx/layers/composite/CanvasLayerComposite.h
gfx/layers/composite/ImageLayerComposite.cpp
gfx/layers/composite/ImageLayerComposite.h
gfx/layers/composite/LayerManagerComposite.h
gfx/layers/composite/ThebesLayerComposite.cpp
gfx/layers/composite/ThebesLayerComposite.h
gfx/layers/ipc/LayerTransactionParent.cpp
--- a/gfx/layers/composite/CanvasLayerComposite.cpp
+++ b/gfx/layers/composite/CanvasLayerComposite.cpp
@@ -35,19 +35,21 @@ CanvasLayerComposite::CanvasLayerComposi
 
 CanvasLayerComposite::~CanvasLayerComposite()
 {
   MOZ_COUNT_DTOR(CanvasLayerComposite);
 
   CleanupResources();
 }
 
-void
-CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) {
+bool
+CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost)
+{
   mImageHost = aHost;
+  return true;
 }
 
 Layer*
 CanvasLayerComposite::GetLayer()
 {
   return this;
 }
 
--- a/gfx/layers/composite/CanvasLayerComposite.h
+++ b/gfx/layers/composite/CanvasLayerComposite.h
@@ -35,17 +35,17 @@ public:
   // CanvasLayer impl
   virtual void Initialize(const Data& aData) MOZ_OVERRIDE
   {
     NS_RUNTIMEABORT("Incompatibe surface type");
   }
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
 
-  virtual void SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
+  virtual bool SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
 
   virtual void Disconnect() MOZ_OVERRIDE
   {
     Destroy();
   }
 
   virtual Layer* GetLayer() MOZ_OVERRIDE;
   virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
--- a/gfx/layers/composite/ImageLayerComposite.cpp
+++ b/gfx/layers/composite/ImageLayerComposite.cpp
@@ -42,20 +42,21 @@ ImageLayerComposite::ImageLayerComposite
 ImageLayerComposite::~ImageLayerComposite()
 {
   MOZ_COUNT_DTOR(ImageLayerComposite);
   MOZ_ASSERT(mDestroyed);
 
   CleanupResources();
 }
 
-void
+bool
 ImageLayerComposite::SetCompositableHost(CompositableHost* aHost)
 {
   mImageHost = aHost;
+  return true;
 }
 
 void
 ImageLayerComposite::Disconnect()
 {
   Destroy();
 }
 
--- a/gfx/layers/composite/ImageLayerComposite.h
+++ b/gfx/layers/composite/ImageLayerComposite.h
@@ -34,17 +34,17 @@ public:
   ImageLayerComposite(LayerManagerComposite* aManager);
 
   virtual ~ImageLayerComposite();
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
 
   virtual void Disconnect() MOZ_OVERRIDE;
 
-  virtual void SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
+  virtual bool SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
 
   virtual Layer* GetLayer() MOZ_OVERRIDE;
 
   virtual void RenderLayer(const nsIntRect& aClipRect);
 
   virtual void ComputeEffectiveTransforms(const mozilla::gfx::Matrix4x4& aTransformToSurface) MOZ_OVERRIDE;
 
   virtual void CleanupResources() MOZ_OVERRIDE;
--- a/gfx/layers/composite/LayerManagerComposite.h
+++ b/gfx/layers/composite/LayerManagerComposite.h
@@ -304,19 +304,21 @@ public:
    * concrete class destructor
    */
   virtual void Destroy();
 
   virtual Layer* GetLayer() = 0;
 
   virtual void RenderLayer(const nsIntRect& aClipRect) = 0;
 
-  virtual void SetCompositableHost(CompositableHost* aHost)
+  virtual bool SetCompositableHost(CompositableHost*)
   {
-    MOZ_ASSERT(false, "called SetCompositableHost for a layer without a compositable host");
+    // We must handle this gracefully, see bug 967824
+    NS_WARNING("called SetCompositableHost for a layer type not accepting a compositable");
+    return false;
   }
   virtual CompositableHost* GetCompositableHost() = 0;
 
   virtual void CleanupResources() = 0;
 
   virtual TiledLayerComposer* GetTiledLayerComposer() { return nullptr; }
 
 
--- a/gfx/layers/composite/ThebesLayerComposite.cpp
+++ b/gfx/layers/composite/ThebesLayerComposite.cpp
@@ -44,20 +44,21 @@ ThebesLayerComposite::ThebesLayerComposi
 }
 
 ThebesLayerComposite::~ThebesLayerComposite()
 {
   MOZ_COUNT_DTOR(ThebesLayerComposite);
   CleanupResources();
 }
 
-void
+bool
 ThebesLayerComposite::SetCompositableHost(CompositableHost* aHost)
 {
   mBuffer = static_cast<ContentHost*>(aHost);
+  return true;
 }
 
 void
 ThebesLayerComposite::Disconnect()
 {
   Destroy();
 }
 
--- a/gfx/layers/composite/ThebesLayerComposite.h
+++ b/gfx/layers/composite/ThebesLayerComposite.h
@@ -51,17 +51,17 @@ public:
   virtual Layer* GetLayer() MOZ_OVERRIDE;
 
   virtual TiledLayerComposer* GetTiledLayerComposer() MOZ_OVERRIDE;
 
   virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
 
   virtual void CleanupResources() MOZ_OVERRIDE;
 
-  virtual void SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
+  virtual bool SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
 
   virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
 
   void EnsureTiled() { mRequiresTiledProperties = true; }
 
   virtual void InvalidateRegion(const nsIntRegion& aRegion)
   {
     NS_RUNTIMEABORT("ThebesLayerComposites can't fill invalidated regions");
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -531,17 +531,20 @@ LayerTransactionParent::Attach(ShadowLay
   LayerComposite* layer = aLayerParent->AsLayer()->AsLayerComposite();
   MOZ_ASSERT(layer);
 
   Compositor* compositor
     = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor();
 
   CompositableHost* compositable = aCompositable->GetCompositableHost();
   MOZ_ASSERT(compositable);
-  layer->SetCompositableHost(compositable);
+  if (!layer->SetCompositableHost(compositable)) {
+    // not all layer types accept a compositable, see bug 967824
+    return;
+  }
   compositable->Attach(aLayerParent->AsLayer(),
                        compositor,
                        aIsAsyncVideo
                          ? CompositableHost::ALLOW_REATTACH
                            | CompositableHost::KEEP_ATTACHED
                          : CompositableHost::NO_FLAGS);
 }