Move ImageContainerChild to its own file. (bug 1299621 part 1, r=nical)
authorDavid Anderson <danderson@mozilla.com>
Tue, 06 Sep 2016 15:19:35 -0700
changeset 312920 3972080f18990d102f1c74319dc5b2c89fabb541
parent 312919 94befb88aee28153afdd35ef8a46761cd1a07bc6
child 312921 9d2271c836ce127fbc343cbf253e0caf78ccca07
push id30665
push usercbook@mozilla.com
push dateWed, 07 Sep 2016 15:20:43 +0000
treeherdermozilla-central@95acb9299faf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1299621
milestone51.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
Move ImageContainerChild to its own file. (bug 1299621 part 1, r=nical)
gfx/layers/ImageContainer.cpp
gfx/layers/ImageContainer.h
gfx/layers/ipc/ImageBridgeChild.cpp
gfx/layers/ipc/ImageContainerChild.cpp
gfx/layers/ipc/ImageContainerChild.h
gfx/layers/moz.build
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -10,18 +10,18 @@
 #include "gfx2DGlue.h"
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "gfxUtils.h"                   // for gfxUtils
 #include "libyuv.h"
 #include "mozilla/RefPtr.h"             // for already_AddRefed
 #include "mozilla/ipc/CrossProcessMutex.h"  // for CrossProcessMutex, etc
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/ImageBridgeChild.h"  // for ImageBridgeChild
-#include "mozilla/layers/PImageContainerChild.h"
 #include "mozilla/layers/ImageClient.h"  // for ImageClient
+#include "mozilla/layers/ImageContainerChild.h"
 #include "mozilla/layers/LayersMessages.h"
 #include "mozilla/layers/SharedPlanarYCbCrImage.h"
 #include "mozilla/layers/SharedRGBImage.h"
 #include "mozilla/layers/TextureClientRecycleAllocator.h"
 #include "nsISupportsUtils.h"           // for NS_IF_ADDREF
 #include "YCbCrUtils.h"                 // for YCbCr conversions
 #ifdef MOZ_WIDGET_GONK
 #include "GrallocImages.h"
@@ -98,57 +98,16 @@ BufferRecycleBin::ClearRecycledBuffers()
 {
   MutexAutoLock lock(mLock);
   if (!mRecycledBuffers.IsEmpty()) {
     mRecycledBuffers.Clear();
   }
   mRecycledBufferSize = 0;
 }
 
-/**
- * The child side of PImageContainer. It's best to avoid ImageContainer filling
- * this role since IPDL objects should be associated with a single thread and
- * ImageContainer definitely isn't. This object belongs to (and is always
- * destroyed on) the ImageBridge thread, except when we need to destroy it
- * during shutdown.
- * An ImageContainer owns one of these; we have a weak reference to our
- * ImageContainer.
- */
-class ImageContainerChild : public PImageContainerChild {
-public:
-  explicit ImageContainerChild(ImageContainer* aImageContainer)
-    : mLock("ImageContainerChild")
-    , mImageContainer(aImageContainer)
-    , mImageContainerReleased(false)
-    , mIPCOpen(true)
-  {}
-
-  void ForgetImageContainer()
-  {
-    MutexAutoLock lock(mLock);
-    mImageContainer = nullptr;
-  }
-
-  // This protects mImageContainer. This is always taken before the
-  // mImageContainer's monitor (when both need to be held).
-  Mutex mLock;
-  ImageContainer* mImageContainer;
-  // If mImageContainerReleased is false when we try to deallocate this actor,
-  // it means the ImageContainer is still holding a pointer to this.
-  // mImageContainerReleased must not be accessed off the ImageBridgeChild thread.
-  bool mImageContainerReleased;
-  // If mIPCOpen is false, it means the IPDL code tried to deallocate the actor
-  // before the ImageContainer released it. When this happens we don't actually
-  // delete the actor right away because the ImageContainer has a reference to
-  // it. In this case the actor will be deleted when the ImageContainer lets go
-  // of it.
-  // mIPCOpen must not be accessed off the ImageBridgeChild thread.
-  bool mIPCOpen;
-};
-
 // static
 void
 ImageContainer::DeallocActor(PImageContainerChild* aActor)
 {
   MOZ_ASSERT(aActor);
   MOZ_ASSERT(InImageBridgeChildThread());
 
   auto actor = static_cast<ImageContainerChild*>(aActor);
@@ -855,29 +814,16 @@ SourceSurfaceImage::GetTextureClient(Com
 }
 
 PImageContainerChild*
 ImageContainer::GetPImageContainerChild()
 {
   return mIPDLChild;
 }
 
-/* static */ void
-ImageContainer::NotifyComposite(const ImageCompositeNotification& aNotification)
-{
-  ImageContainerChild* child =
-      static_cast<ImageContainerChild*>(aNotification.imageContainerChild());
-  if (child) {
-    MutexAutoLock lock(child->mLock);
-    if (child->mImageContainer) {
-      child->mImageContainer->NotifyCompositeInternal(aNotification);
-    }
-  }
-}
-
 ImageContainer::ProducerID
 ImageContainer::AllocateProducerID()
 {
   // Callable on all threads.
   static Atomic<ImageContainer::ProducerID> sProducerID(0u);
   return ++sProducerID;
 }
 
--- a/gfx/layers/ImageContainer.h
+++ b/gfx/layers/ImageContainer.h
@@ -349,18 +349,22 @@ protected:
  * SetCurrentImages sends a message through the ImageBridge to the compositor
  * thread to update the image, without going through the main thread or
  * a layer transaction.
  * The ImageContainer uses a shared memory block containing a cross-process mutex
  * to communicate with the compositor thread. SetCurrentImage synchronously
  * updates the shared state to point to the new image and the old image
  * is immediately released (not true in Normal or Asynchronous modes).
  */
-class ImageContainer final : public SupportsWeakPtr<ImageContainer> {
+class ImageContainer final : public SupportsWeakPtr<ImageContainer>
+{
+  friend class ImageContainerChild;
+
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer)
+
 public:
   MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ImageContainer)
 
   enum Mode { SYNCHRONOUS = 0x0, ASYNCHRONOUS = 0x01 };
 
   static const uint64_t sInvalidAsyncContainerId = 0;
 
   explicit ImageContainer(ImageContainer::Mode flag = SYNCHRONOUS);
@@ -566,17 +570,16 @@ public:
    */
   uint32_t GetDroppedImageCount()
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     return mDroppedImageCount;
   }
 
   PImageContainerChild* GetPImageContainerChild();
-  static void NotifyComposite(const ImageCompositeNotification& aNotification);
 
   /**
    * Main thread only.
    */
   static ProducerID AllocateProducerID();
 
   /// ImageBridgeChild thread only.
   static void AsyncDestroyActor(PImageContainerChild* aActor);
--- a/gfx/layers/ipc/ImageBridgeChild.cpp
+++ b/gfx/layers/ipc/ImageBridgeChild.cpp
@@ -23,19 +23,19 @@
 #include "mozilla/layers/AsyncCanvasRenderer.h"
 #include "mozilla/media/MediaSystemResourceManager.h" // for MediaSystemResourceManager
 #include "mozilla/media/MediaSystemResourceManagerChild.h" // for MediaSystemResourceManagerChild
 #include "mozilla/layers/CompositableChild.h"
 #include "mozilla/layers/CompositableClient.h"  // for CompositableChild, etc
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/ImageClient.h"  // for ImageClient
+#include "mozilla/layers/ImageContainerChild.h"
 #include "mozilla/layers/LayersMessages.h"  // for CompositableOperation
 #include "mozilla/layers/PCompositableChild.h"  // for PCompositableChild
-#include "mozilla/layers/PImageContainerChild.h"
 #include "mozilla/layers/TextureClient.h"  // for TextureClient
 #include "mozilla/mozalloc.h"           // for operator new, etc
 #include "nsISupportsImpl.h"            // for ImageContainer::AddRef, etc
 #include "nsTArray.h"                   // for AutoTArray, nsTArray, etc
 #include "nsTArrayForwardDeclare.h"     // for AutoTArray
 #include "nsThreadUtils.h"              // for NS_IsMainThread
 #include "nsXULAppAPI.h"                // for XRE_GetIOMessageLoop
 #include "mozilla/StaticPtr.h"          // for StaticRefPtr
@@ -1293,17 +1293,21 @@ ImageBridgeChild::RecvParentAsyncMessage
   }
   return true;
 }
 
 bool
 ImageBridgeChild::RecvDidComposite(InfallibleTArray<ImageCompositeNotification>&& aNotifications)
 {
   for (auto& n : aNotifications) {
-    ImageContainer::NotifyComposite(n);
+    ImageContainerChild* child =
+      static_cast<ImageContainerChild*>(n.imageContainerChild());
+    if (child) {
+      child->NotifyComposite(n);
+    }
   }
   return true;
 }
 
 PTextureChild*
 ImageBridgeChild::CreateTexture(const SurfaceDescriptor& aSharedData,
                                 LayersBackend aLayersBackend,
                                 TextureFlags aFlags,
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/ImageContainerChild.cpp
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ImageContainerChild.h"
+#include "ImageContainer.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/layers/ImageBridgeChild.h"
+
+namespace mozilla {
+namespace layers {
+
+ImageContainerChild::ImageContainerChild(ImageContainer* aImageContainer)
+  : mLock("ImageContainerChild")
+  , mImageContainer(aImageContainer)
+  , mImageContainerReleased(false)
+  , mIPCOpen(true)
+{
+}
+
+void
+ImageContainerChild::ForgetImageContainer()
+{
+  MutexAutoLock lock(mLock);
+  mImageContainer = nullptr;
+}
+
+void
+ImageContainerChild::NotifyComposite(const ImageCompositeNotification& aNotification)
+{
+  MOZ_ASSERT(InImageBridgeChildThread());
+
+  MutexAutoLock lock(mLock);
+  if (mImageContainer) {
+    mImageContainer->NotifyCompositeInternal(aNotification);
+  }
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/ImageContainerChild.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_gfx_layers_ImageContainerChild_h
+#define mozilla_gfx_layers_ImageContainerChild_h
+
+#include "mozilla/Mutex.h"
+#include "mozilla/layers/PImageContainerChild.h"
+
+namespace mozilla {
+namespace layers {
+
+class ImageContainer;
+class ImageCompositeNotification;
+
+/**
+ * The child side of PImageContainer. It's best to avoid ImageContainer filling
+ * this role since IPDL objects should be associated with a single thread and
+ * ImageContainer definitely isn't. This object belongs to (and is always
+ * destroyed on) the ImageBridge thread, except when we need to destroy it
+ * during shutdown.
+ * An ImageContainer owns one of these; we have a weak reference to our
+ * ImageContainer.
+ */
+class ImageContainerChild final : public PImageContainerChild
+{
+public:
+  explicit ImageContainerChild(ImageContainer* aImageContainer);
+
+  void ForgetImageContainer();
+
+  void NotifyComposite(const ImageCompositeNotification& aNotification);
+
+public:
+  // If mImageContainerReleased is false when we try to deallocate this actor,
+  // it means the ImageContainer is still holding a pointer to this.
+  // mImageContainerReleased must not be accessed off the ImageBridgeChild thread.
+  bool mImageContainerReleased;
+
+  // If mIPCOpen is false, it means the IPDL code tried to deallocate the actor
+  // before the ImageContainer released it. When this happens we don't actually
+  // delete the actor right away because the ImageContainer has a reference to
+  // it. In this case the actor will be deleted when the ImageContainer lets go
+  // of it.
+  // mIPCOpen must not be accessed off the ImageBridgeChild thread.
+  bool mIPCOpen;
+
+private:
+  Mutex mLock;
+  ImageContainer* mImageContainer;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // mozilla_gfx_layers_ImageContainerChild_h
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -165,16 +165,17 @@ EXPORTS.mozilla.layers += [
     'ipc/CompositorBridgeChild.h',
     'ipc/CompositorBridgeParent.h',
     'ipc/CompositorThread.h',
     'ipc/FenceUtils.h',
     'ipc/GonkNativeHandle.h',
     'ipc/GonkNativeHandleUtils.h',
     'ipc/ImageBridgeChild.h',
     'ipc/ImageBridgeParent.h',
+    'ipc/ImageContainerChild.h',
     'ipc/ImageContainerParent.h',
     'ipc/ISurfaceAllocator.h',
     'ipc/LayerAnimationUtils.h',
     'ipc/LayerTransactionChild.h',
     'ipc/LayerTransactionParent.h',
     'ipc/LayerTreeOwnerTracker.h',
     'ipc/RemoteContentController.h',
     'ipc/ShadowLayerChild.h',
@@ -358,16 +359,17 @@ UNIFIED_SOURCES += [
     'ipc/CompositableTransactionParent.cpp',
     'ipc/CompositorBench.cpp',
     'ipc/CompositorBridgeChild.cpp',
     'ipc/CompositorBridgeParent.cpp',
     'ipc/CompositorThread.cpp',
     'ipc/FenceUtils.cpp',
     'ipc/ImageBridgeChild.cpp',
     'ipc/ImageBridgeParent.cpp',
+    'ipc/ImageContainerChild.cpp',
     'ipc/ImageContainerParent.cpp',
     'ipc/ISurfaceAllocator.cpp',
     'ipc/LayerAnimationUtils.cpp',
     'ipc/LayerTransactionChild.cpp',
     'ipc/LayerTransactionParent.cpp',
     'ipc/LayerTreeOwnerTracker.cpp',
     'ipc/RemoteContentController.cpp',
     'ipc/ShadowLayerChild.cpp',