From f76ed9c6124f3c78576834f8114f8e03ab4c5e11 Mon Sep 17 00:00:00 2001 From: Morris Tseng Date: Fri, 18 Dec 2015 14:52:16 +0800 Subject: [PATCH] Bug 1215438 - Part 3: CairoImage can use in any thread. r=roc --HG-- extra : commitid : HbLlASdGESm --- gfx/layers/ImageContainer.h | 46 ++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/gfx/layers/ImageContainer.h b/gfx/layers/ImageContainer.h index fb082463465a..ebef6e098657 100644 --- a/gfx/layers/ImageContainer.h +++ b/gfx/layers/ImageContainer.h @@ -83,6 +83,50 @@ public: } }; +class nsOwningThreadSourceSurfaceRef; + +template <> +class nsAutoRefTraits { +public: + typedef mozilla::gfx::SourceSurface* RawRef; + + /** + * The XPCOM event that will do the actual release on the creation thread. + */ + class SurfaceReleaser : public nsRunnable { + public: + explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {} + NS_IMETHOD Run() { + 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 runnable = new SurfaceReleaser(aRawRef); + mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL); + } + void AddRef(RawRef aRawRef) + { + MOZ_ASSERT(!mOwningThread); + NS_GetCurrentThread(getter_AddRefs(mOwningThread)); + aRawRef->AddRef(); + } + +private: + nsCOMPtr mOwningThread; +}; + #endif #ifdef XP_WIN @@ -784,7 +828,7 @@ public: private: gfx::IntSize mSize; - nsCountedRef mSourceSurface; + nsCountedRef mSourceSurface; nsDataHashtable > mTextureClients; };