Bug 925317. Check shmems are tracked whenever we send them across IPC. r=BenWa,bent
authorNicholas Cameron <ncameron@mozilla.com>
Mon, 21 Oct 2013 16:23:42 +0200
changeset 165306 6c85d3c1901222cf531321dce8652dea7734d126
parent 165305 651ea35bfb0b0ca9527125a67048204ac5b8d397
child 165307 9445d7191df4508d68bf618a6802db253aa49346
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa, bent
bugs925317
milestone27.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
Bug 925317. Check shmems are tracked whenever we send them across IPC. r=BenWa,bent
gfx/layers/ipc/ShadowLayers.cpp
gfx/layers/ipc/ShadowLayers.h
ipc/glue/Shmem.h
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -302,31 +302,49 @@ ShadowLayerForwarder::RepositionChild(Sh
   } else {
     MOZ_LAYERS_LOG(("[LayersForwarder] OpRaiseToTopChild container=%p child=%p",
                    aContainer->AsLayer(), aChild->AsLayer()));
     mTxn->AddEdit(OpRaiseToTopChild(nullptr, Shadow(aContainer),
                                     nullptr, Shadow(aChild)));
   }
 }
 
+
+#ifdef DEBUG
+void
+ShadowLayerForwarder::CheckSurfaceDescriptor(const SurfaceDescriptor* aDescriptor) const
+{
+  if (!aDescriptor) {
+    return;
+  }
+
+  if (aDescriptor->type() == SurfaceDescriptor::TShmem) {
+    const mozilla::ipc::Shmem& shmem = aDescriptor->get_Shmem();
+    shmem.AssertInvariants();
+    MOZ_ASSERT(mShadowManager->IsTrackingSharedMemory(shmem.mSegment));
+  }
+}
+#endif
+
 void
 ShadowLayerForwarder::PaintedTiledLayerBuffer(CompositableClient* aCompositable,
                                               const SurfaceDescriptorTiles& aTileLayerDescriptor)
 {
   mTxn->AddNoSwapPaint(OpPaintTiledLayerBuffer(nullptr, aCompositable->GetIPDLActor(),
                                                aTileLayerDescriptor));
 }
 
 void
 ShadowLayerForwarder::UpdateTexture(CompositableClient* aCompositable,
                                     TextureIdentifier aTextureId,
                                     SurfaceDescriptor* aDescriptor)
 {
   if (aDescriptor->type() != SurfaceDescriptor::T__None &&
       aDescriptor->type() != SurfaceDescriptor::Tnull_t) {
+    CheckSurfaceDescriptor(aDescriptor);
     MOZ_ASSERT(aCompositable);
     MOZ_ASSERT(aCompositable->GetIPDLActor());
     mTxn->AddPaint(OpPaintTexture(nullptr, aCompositable->GetIPDLActor(), 1,
                                   SurfaceDescriptor(*aDescriptor)));
     *aDescriptor = SurfaceDescriptor();
   } else {
     NS_WARNING("Trying to send a null SurfaceDescriptor.");
   }
@@ -334,16 +352,17 @@ ShadowLayerForwarder::UpdateTexture(Comp
 
 void
 ShadowLayerForwarder::UpdateTextureNoSwap(CompositableClient* aCompositable,
                                           TextureIdentifier aTextureId,
                                           SurfaceDescriptor* aDescriptor)
 {
   if (aDescriptor->type() != SurfaceDescriptor::T__None &&
       aDescriptor->type() != SurfaceDescriptor::Tnull_t) {
+    CheckSurfaceDescriptor(aDescriptor);
     MOZ_ASSERT(aCompositable);
     MOZ_ASSERT(aCompositable->GetIPDLActor());
     mTxn->AddNoSwapPaint(OpPaintTexture(nullptr, aCompositable->GetIPDLActor(), 1,
                                         SurfaceDescriptor(*aDescriptor)));
     *aDescriptor = SurfaceDescriptor();
   } else {
     NS_WARNING("Trying to send a null SurfaceDescriptor.");
   }
@@ -364,16 +383,17 @@ ShadowLayerForwarder::UpdateTextureRegio
 void
 ShadowLayerForwarder::UpdateTextureIncremental(CompositableClient* aCompositable,
                                                TextureIdentifier aTextureId,
                                                SurfaceDescriptor& aDescriptor,
                                                const nsIntRegion& aUpdatedRegion,
                                                const nsIntRect& aBufferRect,
                                                const nsIntPoint& aBufferRotation)
 {
+  CheckSurfaceDescriptor(&aDescriptor);
   MOZ_ASSERT(aCompositable);
   MOZ_ASSERT(aCompositable->GetIPDLActor());
   mTxn->AddNoSwapPaint(OpPaintTextureIncremental(nullptr, aCompositable->GetIPDLActor(),
                                                  aTextureId,
                                                  aDescriptor,
                                                  aUpdatedRegion,
                                                  aBufferRect,
                                                  aBufferRotation));
@@ -391,16 +411,19 @@ bool
 ShadowLayerForwarder::AddTexture(CompositableClient* aCompositable,
                                  TextureClient* aTexture)
 {
   SurfaceDescriptor descriptor;
   if (!aTexture->ToSurfaceDescriptor(descriptor)) {
     NS_WARNING("Failed to serialize a TextureClient");
     return false;
   }
+  CheckSurfaceDescriptor(&descriptor);
+  MOZ_ASSERT(aCompositable);
+  MOZ_ASSERT(aCompositable->GetIPDLActor());
   MOZ_ASSERT(aTexture->GetFlags() != 0);
   mTxn->AddEdit(OpAddTexture(nullptr, aCompositable->GetIPDLActor(),
                              aTexture->GetID(),
                              descriptor,
                              aTexture->GetFlags()));
   return true;
 }
 
@@ -847,16 +870,19 @@ ShadowLayerForwarder::Connect(Compositab
 }
 
 void
 ShadowLayerForwarder::CreatedSingleBuffer(CompositableClient* aCompositable,
                                           const SurfaceDescriptor& aDescriptor,
                                           const TextureInfo& aTextureInfo,
                                           const SurfaceDescriptor* aDescriptorOnWhite)
 {
+  CheckSurfaceDescriptor(&aDescriptor);
+  CheckSurfaceDescriptor(aDescriptorOnWhite);
+
   MOZ_ASSERT(aDescriptor.type() != SurfaceDescriptor::T__None &&
              aDescriptor.type() != SurfaceDescriptor::Tnull_t);
   mTxn->AddEdit(OpCreatedTexture(nullptr, aCompositable->GetIPDLActor(),
                                  TextureFront,
                                  aDescriptor,
                                  aTextureInfo));
   if (aDescriptorOnWhite) {
     mTxn->AddEdit(OpCreatedTexture(nullptr, aCompositable->GetIPDLActor(),
@@ -878,16 +904,20 @@ ShadowLayerForwarder::CreatedIncremental
 void
 ShadowLayerForwarder::CreatedDoubleBuffer(CompositableClient* aCompositable,
                                           const SurfaceDescriptor& aFrontDescriptor,
                                           const SurfaceDescriptor& aBackDescriptor,
                                           const TextureInfo& aTextureInfo,
                                           const SurfaceDescriptor* aFrontDescriptorOnWhite,
                                           const SurfaceDescriptor* aBackDescriptorOnWhite)
 {
+  CheckSurfaceDescriptor(&aFrontDescriptor);
+  CheckSurfaceDescriptor(&aBackDescriptor);
+  CheckSurfaceDescriptor(aFrontDescriptorOnWhite);
+  CheckSurfaceDescriptor(aBackDescriptorOnWhite);
   MOZ_ASSERT(aFrontDescriptor.type() != SurfaceDescriptor::T__None &&
              aBackDescriptor.type() != SurfaceDescriptor::T__None &&
              aFrontDescriptor.type() != SurfaceDescriptor::Tnull_t &&
              aBackDescriptor.type() != SurfaceDescriptor::Tnull_t);
   mTxn->AddEdit(OpCreatedTexture(nullptr, aCompositable->GetIPDLActor(),
                                  TextureFront,
                                  aFrontDescriptor,
                                  aTextureInfo));
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -408,16 +408,22 @@ public:
   static void PlatformSyncBeforeUpdate();
 
   static already_AddRefed<gfxASurface>
   OpenDescriptor(OpenMode aMode, const SurfaceDescriptor& aSurface);
 
 protected:
   ShadowLayerForwarder();
 
+#ifdef DEBUG
+  void CheckSurfaceDescriptor(const SurfaceDescriptor* aDescriptor) const;
+#else
+  void CheckSurfaceDescriptor(const SurfaceDescriptor* aDescriptor) const {}
+#endif
+
   PLayerTransactionChild* mShadowManager;
 
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
   // from ISurfaceAllocator
   virtual PGrallocBufferChild* AllocGrallocBuffer(const gfxIntSize& aSize,
                                                   uint32_t aFormat,
                                                   uint32_t aUsage,
                                                   MaybeMagicGrallocBufferHandle* aHandle) MOZ_OVERRIDE;
--- a/ipc/glue/Shmem.h
+++ b/ipc/glue/Shmem.h
@@ -49,21 +49,29 @@
  * If parent code wants to give access rights to the Shmem to the
  * child, it does so by sending its |Shmem| to the child, in an IPDL
  * message.  The parent's |Shmem| then "dies", i.e. becomes
  * inaccessible.  This process could be compared to passing a
  * "shmem-access baton" between parent and child.
  */
 
 namespace mozilla {
+namespace layers {
+class ShadowLayerForwarder;
+}
+
 namespace ipc {
 
 class Shmem MOZ_FINAL
 {
   friend struct IPC::ParamTraits<mozilla::ipc::Shmem>;
+#ifdef DEBUG
+  // For ShadowLayerForwarder::CheckSurfaceDescriptor
+  friend class mozilla::layers::ShadowLayerForwarder;
+#endif
 
 public:
   typedef int32_t id_t;
   // Low-level wrapper around platform shmem primitives.
   typedef mozilla::ipc::SharedMemory SharedMemory;
   typedef SharedMemory::SharedMemoryType SharedMemoryType;
   struct IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead {};