From b3c72383ca9794efb2281963cbd725b5dfdd76bc Mon Sep 17 00:00:00 2001 From: John Lin Date: Wed, 9 Sep 2020 00:05:20 +0000 Subject: [PATCH] Bug 1655915 - p3: make AndroidSharedBlitGL unique. r=jgilbert AndroidSharedBlitGL is never shared with other objects and doesn't have to be ref-counted. Differential Revision: https://phabricator.services.mozilla.com/D89532 --- gfx/gl/AndroidSurfaceTexture.cpp | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/gfx/gl/AndroidSurfaceTexture.cpp b/gfx/gl/AndroidSurfaceTexture.cpp index bf2d46572050..811f0b255003 100644 --- a/gfx/gl/AndroidSurfaceTexture.cpp +++ b/gfx/gl/AndroidSurfaceTexture.cpp @@ -20,8 +20,6 @@ namespace gl { class AndroidSharedBlitGL final { public: - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSharedBlitGL); - explicit AndroidSharedBlitGL(const EGLNativeWindowType window) { StaticMutexAutoLock lock(sMutex); @@ -39,6 +37,20 @@ class AndroidSharedBlitGL final { ++sInstanceCount; } + ~AndroidSharedBlitGL() { + StaticMutexAutoLock lock(sMutex); + + if (mTargetSurface != EGL_NO_SURFACE) { + const auto& egl = *(sContext->mEgl); + egl.fDestroySurface(mTargetSurface); + } + + // Destroy shared GL context when no one uses it. + if (--sInstanceCount == 0) { + sContext = nullptr; + } + } + void Blit(layers::SurfaceTextureImage* img, const gfx::IntSize& imageSize) { StaticMutexAutoLock lock(sMutex); MOZ_ASSERT(sContext); @@ -58,19 +70,6 @@ class AndroidSharedBlitGL final { } private: - ~AndroidSharedBlitGL() { - StaticMutexAutoLock lock(sMutex); - - if (mTargetSurface != EGL_NO_SURFACE) { - const auto& egl = *(sContext->mEgl); - egl.fDestroySurface(mTargetSurface); - } - - // Destroy shared GL context when no one uses it. - if (--sInstanceCount == 0) { - sContext = nullptr; - } - } static already_AddRefed CreateContextImpl(bool aUseGles) { sMutex.AssertCurrentThreadOwns(); @@ -161,16 +160,16 @@ class GLBlitterSupport final AndroidNativeWindow win(java::GeckoSurface::Ref::From(targetSurface)); auto helper = java::GeckoSurfaceTexture::NativeGLBlitHelper::New(); const auto& eglWindow = win.NativeWindow(); - RefPtr gl = new AndroidSharedBlitGL(eglWindow); GLBlitterSupport::AttachNative( - helper, MakeUnique(std::move(gl), sourceTextureHandle, - width, height)); + helper, + MakeUnique(MakeUnique(eglWindow), + sourceTextureHandle, width, height)); return helper; } - GLBlitterSupport(RefPtr&& gl, jint sourceTextureHandle, - jint width, jint height) - : mGl(gl), + GLBlitterSupport(UniquePtr&& gl, + jint sourceTextureHandle, jint width, jint height) + : mGl(std::move(gl)), mSourceTextureHandle(sourceTextureHandle), mSize(width, height) {} @@ -181,7 +180,7 @@ class GLBlitterSupport final } private: - const RefPtr mGl; + const UniquePtr mGl; const AndroidSurfaceTextureHandle mSourceTextureHandle; const gfx::IntSize mSize; };