Bug 985302 - Make ISurfaceAllocator use AtomicRefCountedWithFinalize to avoid calling virtual functions from its destructor. r=Bas, a=1.4+
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 19 Mar 2014 12:02:42 +0800
changeset 192102 96c6d0653458c49f715138f23c98e4fbccf86a18
parent 192101 388a241f4e1115050e8627ce7d7bfee8aa7cefa8
child 192103 fa4aff8faf05ebc992f4e2fb4e8a0028a88703f6
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, 1
bugs985302
milestone30.0a2
Bug 985302 - Make ISurfaceAllocator use AtomicRefCountedWithFinalize to avoid calling virtual functions from its destructor. r=Bas, a=1.4+
gfx/layers/ipc/ISurfaceAllocator.cpp
gfx/layers/ipc/ISurfaceAllocator.h
--- a/gfx/layers/ipc/ISurfaceAllocator.cpp
+++ b/gfx/layers/ipc/ISurfaceAllocator.cpp
@@ -42,22 +42,26 @@ bool
 IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface)
 {
   return aSurface.type() != SurfaceDescriptor::T__None &&
          aSurface.type() != SurfaceDescriptor::Tnull_t;
 }
 
 ISurfaceAllocator::~ISurfaceAllocator()
 {
-  ShrinkShmemSectionHeap();
-
   // Check if we're not leaking..
   MOZ_ASSERT(mUsedShmems.empty());
 }
 
+void
+ISurfaceAllocator::Finalize()
+{
+  ShrinkShmemSectionHeap();
+}
+
 bool
 ISurfaceAllocator::AllocSharedImageSurface(const gfx::IntSize& aSize,
                                gfxContentType aContent,
                                gfxSharedImageSurface** aBuffer)
 {
   mozilla::ipc::SharedMemory::SharedMemoryType shmemType = OptimalShmemType();
   gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
 
--- a/gfx/layers/ipc/ISurfaceAllocator.h
+++ b/gfx/layers/ipc/ISurfaceAllocator.h
@@ -12,16 +12,17 @@
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
 #include "mozilla/RefPtr.h"
 #include "nsIMemoryReporter.h"          // for nsIMemoryReporter
 #include "mozilla/Atomics.h"            // for Atomic
 #include "mozilla/layers/LayersMessages.h" // for ShmemSection
 #include "LayersTypes.h"
 #include <vector>
+#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
 
 /*
  * FIXME [bjacob] *** PURE CRAZYNESS WARNING ***
  *
  * This #define is actually needed here, because subclasses of ISurfaceAllocator,
  * namely ShadowLayerForwarder, will or will not override AllocGrallocBuffer
  * depending on whether MOZ_HAVE_SURFACEDESCRIPTORGRALLOC is defined.
  */
@@ -71,22 +72,24 @@ bool ReleaseOwnedSurfaceDescriptor(const
  * An interface used to create and destroy surfaces that are shared with the
  * Compositor process (using shmem, or gralloc, or other platform specific memory)
  *
  * Most of the methods here correspond to methods that are implemented by IPDL
  * actors without a common polymorphic interface.
  * These methods should be only called in the ipdl implementor's thread, unless
  * specified otherwise in the implementing class.
  */
-class ISurfaceAllocator : public AtomicRefCounted<ISurfaceAllocator>
+class ISurfaceAllocator : public AtomicRefCountedWithFinalize<ISurfaceAllocator>
 {
 public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(ISurfaceAllocator)
   ISurfaceAllocator() {}
 
+  void Finalize();
+
   /**
    * Returns the type of backend that is used off the main thread.
    * We only don't allow changing the backend type at runtime so this value can
    * be queried once and will not change until Gecko is restarted.
    *
    * XXX - With e10s this may not be true anymore. we can have accelerated widgets
    * and non-accelerated widgets (small popups, etc.)
    */
@@ -176,17 +179,17 @@ protected:
 
   virtual ~ISurfaceAllocator();
 
   void ShrinkShmemSectionHeap();
 
   // This is used to implement an extremely simple & naive heap allocator.
   std::vector<mozilla::ipc::Shmem> mUsedShmems;
 
-  friend class detail::RefCounted<ISurfaceAllocator, detail::AtomicRefCount>;
+  friend class AtomicRefCountedWithFinalize<ISurfaceAllocator>;
 };
 
 class GfxMemoryImageReporter MOZ_FINAL : public nsIMemoryReporter
 {
 public:
   NS_DECL_ISUPPORTS
 
   GfxMemoryImageReporter()