Don't attach shadowable layers if IPDL fails to construct an actor. (bug 1314349, r=mattwoodrow)
authorDavid Anderson <danderson@mozilla.com>
Sun, 06 Nov 2016 18:50:15 -0800
changeset 351413 9438fd24fd96114d9513f49f88f48b4c694efa99
parent 351412 48942d5a145affedf326c9f6a34066615f422405
child 351414 a4b855274882da6fb53e9ba618b403d6cfa11264
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1314349
milestone52.0a1
Don't attach shadowable layers if IPDL fails to construct an actor. (bug 1314349, r=mattwoodrow)
gfx/layers/ipc/ShadowLayerChild.cpp
gfx/layers/ipc/ShadowLayerChild.h
gfx/layers/ipc/ShadowLayers.cpp
--- a/gfx/layers/ipc/ShadowLayerChild.cpp
+++ b/gfx/layers/ipc/ShadowLayerChild.cpp
@@ -7,30 +7,37 @@
 
 #include "ShadowLayerChild.h"
 #include "Layers.h"                     // for Layer
 #include "ShadowLayers.h"               // for ShadowableLayer
 
 namespace mozilla {
 namespace layers {
 
-ShadowLayerChild::ShadowLayerChild(ShadowableLayer* aLayer)
-  : mLayer(aLayer)
+ShadowLayerChild::ShadowLayerChild()
+  : mLayer(nullptr)
 { }
 
 ShadowLayerChild::~ShadowLayerChild()
 { }
 
 void
+ShadowLayerChild::SetShadowableLayer(ShadowableLayer* aLayer)
+{
+  MOZ_ASSERT(!mLayer);
+  mLayer = aLayer;
+}
+
+void
 ShadowLayerChild::ActorDestroy(ActorDestroyReason why)
 {
   MOZ_ASSERT(AncestorDeletion != why,
              "shadowable layer should have been cleaned up by now");
 
-  if (AbnormalShutdown == why) {
+  if (AbnormalShutdown == why && mLayer) {
     // This is last-ditch emergency shutdown.  Just have the layer
     // forget its IPDL resources; IPDL-generated code will clean up
     // automatically in this case.
     mLayer->AsLayer()->Disconnect();
     mLayer = nullptr;
   }
 }
 
--- a/gfx/layers/ipc/ShadowLayerChild.h
+++ b/gfx/layers/ipc/ShadowLayerChild.h
@@ -15,19 +15,20 @@
 namespace mozilla {
 namespace layers {
 
 class ShadowableLayer;
 
 class ShadowLayerChild : public PLayerChild
 {
 public:
-  explicit ShadowLayerChild(ShadowableLayer* aLayer);
+  ShadowLayerChild();
   virtual ~ShadowLayerChild();
 
+  void SetShadowableLayer(ShadowableLayer* aLayer);
   ShadowableLayer* layer() const { return mLayer; }
 
 protected:
   virtual void ActorDestroy(ActorDestroyReason why) override;
 
 private:
   ShadowableLayer* mLayer;
 };
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -744,17 +744,24 @@ ShadowLayerForwarder::IPCOpen() const
   */
 PLayerChild*
 ShadowLayerForwarder::ConstructShadowFor(ShadowableLayer* aLayer)
 {
   MOZ_ASSERT(IPCOpen(), "no manager to forward to");
   if (!IPCOpen()) {
     return nullptr;
   }
-  return mShadowManager->SendPLayerConstructor(new ShadowLayerChild(aLayer));
+
+  ShadowLayerChild* child = new ShadowLayerChild();
+  if (!mShadowManager->SendPLayerConstructor(child)) {
+    return nullptr;
+  }
+
+  child->SetShadowableLayer(aLayer);
+  return child;
 }
 
 #if !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
 
 /*static*/ void
 ShadowLayerForwarder::PlatformSyncBeforeUpdate()
 {
 }