Bug 1321275 - Confirm VRLayerChild is not destroyed before sending destroy message to the parent side; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 03 May 2017 18:43:39 +0800
changeset 571863 da952c056235af5eec32f964bc4b17c03bfe0560
parent 569138 0b77ed3f26c5335503bc16e85b8c067382e7bb1e
child 626893 70eb1f0ab6b683fa073a58de1ca5a2786a4e9ecd
push id56932
push userbmo:dmu@mozilla.com
push dateWed, 03 May 2017 10:44:31 +0000
reviewerskip
bugs1321275
milestone55.0a1
Bug 1321275 - Confirm VRLayerChild is not destroyed before sending destroy message to the parent side; r?kip MozReview-Commit-ID: v0awwplOQv
gfx/vr/VRDisplayPresentation.cpp
gfx/vr/ipc/VRLayerChild.cpp
gfx/vr/ipc/VRLayerChild.h
--- a/gfx/vr/VRDisplayPresentation.cpp
+++ b/gfx/vr/VRDisplayPresentation.cpp
@@ -91,17 +91,19 @@ VRDisplayPresentation::CreateLayers()
     mLayers.AppendElement(vrLayer);
   }
 }
 
 void
 VRDisplayPresentation::DestroyLayers()
 {
   for (VRLayerChild* layer : mLayers) {
-    Unused << layer->SendDestroy();
+    if (layer->IsIPCOpen()) {
+      Unused << layer->SendDestroy();
+    }
   }
   mLayers.Clear();
 }
 
 void
 VRDisplayPresentation::GetDOMLayers(nsTArray<dom::VRLayer>& result)
 {
   result = mDOMLayers;
--- a/gfx/vr/ipc/VRLayerChild.cpp
+++ b/gfx/vr/ipc/VRLayerChild.cpp
@@ -15,16 +15,17 @@
 namespace mozilla {
 namespace gfx {
 
 VRLayerChild::VRLayerChild(uint32_t aVRDisplayID, VRManagerChild* aVRManagerChild)
   : mVRDisplayID(aVRDisplayID)
   , mCanvasElement(nullptr)
   , mShSurfClient(nullptr)
   , mFront(nullptr)
+  , mIPCOpen(true)
 {
 }
 
 VRLayerChild::~VRLayerChild()
 {
   if (mCanvasElement) {
     mCanvasElement->StopVRPresentation();
   }
@@ -69,17 +70,29 @@ VRLayerChild::SubmitFrame()
   mFront->SetAddedToCompositableClient();
   VRManagerChild* vrmc = VRManagerChild::Get();
   mFront->SyncWithObject(vrmc->GetSyncObject());
   MOZ_ALWAYS_TRUE(mFront->InitIPDLActor(vrmc));
 
   SendSubmitFrame(mFront->GetIPDLActor());
 }
 
+bool
+VRLayerChild::IsIPCOpen()
+{
+  return mIPCOpen;
+}
+
 void
 VRLayerChild::ClearSurfaces()
 {
   mFront = nullptr;
   mShSurfClient = nullptr;
 }
 
+void
+VRLayerChild::ActorDestroy(ActorDestroyReason aWhy)
+{
+  mIPCOpen = false;
+}
+
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/vr/ipc/VRLayerChild.h
+++ b/gfx/vr/ipc/VRLayerChild.h
@@ -30,24 +30,27 @@ namespace gfx {
 
 class VRLayerChild : public PVRLayerChild {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRLayerChild)
 
 public:
   VRLayerChild(uint32_t aVRDisplayID, VRManagerChild* aVRManagerChild);
   void Initialize(dom::HTMLCanvasElement* aCanvasElement);
   void SubmitFrame();
+  bool IsIPCOpen();
 
 protected:
   virtual ~VRLayerChild();
   void ClearSurfaces();
+  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   uint32_t mVRDisplayID;
 
   RefPtr<dom::HTMLCanvasElement> mCanvasElement;
   RefPtr<layers::SharedSurfaceTextureClient> mShSurfClient;
   RefPtr<layers::TextureClient> mFront;
+  bool mIPCOpen;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif