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
This commit is contained in:
John Lin 2020-09-09 00:05:20 +00:00
parent 40829db9bc
commit b3c72383ca

View File

@ -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<GLContextEGL> 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<AndroidSharedBlitGL> gl = new AndroidSharedBlitGL(eglWindow);
GLBlitterSupport::AttachNative(
helper, MakeUnique<GLBlitterSupport>(std::move(gl), sourceTextureHandle,
width, height));
helper,
MakeUnique<GLBlitterSupport>(MakeUnique<AndroidSharedBlitGL>(eglWindow),
sourceTextureHandle, width, height));
return helper;
}
GLBlitterSupport(RefPtr<AndroidSharedBlitGL>&& gl, jint sourceTextureHandle,
jint width, jint height)
: mGl(gl),
GLBlitterSupport(UniquePtr<AndroidSharedBlitGL>&& 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<AndroidSharedBlitGL> mGl;
const UniquePtr<AndroidSharedBlitGL> mGl;
const AndroidSurfaceTextureHandle mSourceTextureHandle;
const gfx::IntSize mSize;
};