Bug 1329079 - Move SurfaceReleaser to cpp file. r?jrmuizel
MozReview-Commit-ID: CjtsxoCXMhy
--- 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(¤t);
+ 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(¤t);
- 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