Bug 1329079 - Move SurfaceReleaser to cpp file. r?jrmuizel draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 26 Jan 2017 12:51:30 +0100
changeset 466736 c43613039e822f8b91f8464a332dc50370f2be5d
parent 466735 8ff81080422385698343980fe2db4725cc491235
child 466737 47019c794614e02ea6875187b28eb98fefb35da7
push id42982
push userbmo:pehrson@telenordigital.com
push dateThu, 26 Jan 2017 12:38:43 +0000
reviewersjrmuizel
bugs1329079
milestone53.0a1
Bug 1329079 - Move SurfaceReleaser to cpp file. r?jrmuizel MozReview-Commit-ID: CjtsxoCXMhy
gfx/layers/ImageContainer.cpp
gfx/layers/ImageContainer.h
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -30,16 +30,72 @@
 #include "mozilla/gfx/QuartzSupport.h"
 #endif
 
 #ifdef XP_WIN
 #include "gfxWindowsPlatform.h"
 #include <d3d10_1.h>
 #endif
 
+/**
+ * The XPCOM event that will do the actual release on the main thread.
+ */
+class SurfaceReleaser : public mozilla::Runnable {
+public:
+  typedef mozilla::gfx::SourceSurface* RawRef;
+
+  explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {}
+  NS_IMETHOD Run() override {
+    mRef->Release();
+    return NS_OK;
+  }
+  RawRef mRef;
+};
+
+void
+nsAutoRefTraits<nsMainThreadSourceSurfaceRef>::Release(RawRef aRawRef)
+{
+  if (NS_IsMainThread()) {
+    aRawRef->Release();
+    return;
+  }
+  nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
+  NS_DispatchToMainThread(runnable);
+}
+
+void
+nsAutoRefTraits<nsMainThreadSourceSurfaceRef>::AddRef(RawRef aRawRef)
+{
+  NS_ASSERTION(NS_IsMainThread(),
+               "Can only add a reference on the main thread");
+  aRawRef->AddRef();
+}
+
+void
+nsAutoRefTraits<nsOwningThreadSourceSurfaceRef>::Release(RawRef aRawRef)
+{
+  MOZ_ASSERT(mOwningThread);
+  bool current;
+  mOwningThread->IsOnCurrentThread(&current);
+  if (current) {
+    aRawRef->Release();
+    return;
+  }
+  nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
+  mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
+}
+
+void
+nsAutoRefTraits<nsOwningThreadSourceSurfaceRef>::AddRef(RawRef aRawRef)
+{
+  MOZ_ASSERT(!mOwningThread);
+  NS_GetCurrentThread(getter_AddRefs(mOwningThread));
+  aRawRef->AddRef();
+}
+
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::ipc;
 using namespace android;
 using namespace mozilla::gfx;
 
 Atomic<int32_t> Image::sSerialCounter(0);
--- a/gfx/layers/ImageContainer.h
+++ b/gfx/layers/ImageContainer.h
@@ -48,86 +48,31 @@
  */
 class nsMainThreadSourceSurfaceRef;
 
 template <>
 class nsAutoRefTraits<nsMainThreadSourceSurfaceRef> {
 public:
   typedef mozilla::gfx::SourceSurface* RawRef;
 
-  /**
-   * The XPCOM event that will do the actual release on the main thread.
-   */
-  class SurfaceReleaser : public mozilla::Runnable {
-  public:
-    explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {}
-    NS_IMETHOD Run() override {
-      mRef->Release();
-      return NS_OK;
-    }
-    RawRef mRef;
-  };
-
   static RawRef Void() { return nullptr; }
-  static void Release(RawRef aRawRef)
-  {
-    if (NS_IsMainThread()) {
-      aRawRef->Release();
-      return;
-    }
-    nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
-    NS_DispatchToMainThread(runnable);
-  }
-  static void AddRef(RawRef aRawRef)
-  {
-    NS_ASSERTION(NS_IsMainThread(),
-                 "Can only add a reference on the main thread");
-    aRawRef->AddRef();
-  }
+  static void Release(RawRef aRawRef);
+  static void AddRef(RawRef aRawRef);
 };
 
 class nsOwningThreadSourceSurfaceRef;
 
 template <>
 class nsAutoRefTraits<nsOwningThreadSourceSurfaceRef> {
 public:
   typedef mozilla::gfx::SourceSurface* RawRef;
 
-  /**
-   * The XPCOM event that will do the actual release on the creation thread.
-   */
-  class SurfaceReleaser : public mozilla::Runnable {
-  public:
-    explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {}
-    NS_IMETHOD Run() override {
-      mRef->Release();
-      return NS_OK;
-    }
-    RawRef mRef;
-  };
-
   static RawRef Void() { return nullptr; }
-  void Release(RawRef aRawRef)
-  {
-    MOZ_ASSERT(mOwningThread);
-    bool current;
-    mOwningThread->IsOnCurrentThread(&current);
-    if (current) {
-      aRawRef->Release();
-      return;
-    }
-    nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
-  }
-  void AddRef(RawRef aRawRef)
-  {
-    MOZ_ASSERT(!mOwningThread);
-    NS_GetCurrentThread(getter_AddRefs(mOwningThread));
-    aRawRef->AddRef();
-  }
+  void Release(RawRef aRawRef);
+  void AddRef(RawRef aRawRef);
 
 private:
   nsCOMPtr<nsIThread> mOwningThread;
 };
 
 #endif
 
 #ifdef XP_WIN