Fortify SharedSurface dtors against MakeCurrent failure. r?jrmuizel
draft
Fortify SharedSurface dtors against MakeCurrent failure. r?jrmuizel
From 1f9516bc5b0a938fd26b32ae1892cd325e600752 Mon Sep 17 00:00:00 2001
---
gfx/gl/SharedSurfaceANGLE.cpp | 4 +++-
gfx/gl/SharedSurfaceD3D11Interop.cpp | 7 +++++--
gfx/gl/SharedSurfaceEGL.cpp | 20 +++++++++++---------
gfx/gl/SharedSurfaceGLX.cpp | 8 ++++----
gfx/gl/SharedSurfaceGralloc.cpp | 6 +++---
gfx/gl/SharedSurfaceIO.cpp | 9 ++++-----
6 files changed, 30 insertions(+), 24 deletions(-)
MozReview-Commit-ID: IpsmcPXI1JX
--- a/gfx/gl/SharedSurfaceANGLE.cpp
+++ b/gfx/gl/SharedSurfaceANGLE.cpp
@@ -112,18 +112,20 @@ SharedSurface_ANGLEShareHandle::SharedSu
{
}
SharedSurface_ANGLEShareHandle::~SharedSurface_ANGLEShareHandle()
{
mEGL->fDestroySurface(Display(), mPBuffer);
+ if (!mGL->MakeCurrent())
+ return;
+
if (mFence) {
- mGL->MakeCurrent();
mGL->fDeleteFences(1, &mFence);
}
}
void
SharedSurface_ANGLEShareHandle::LockProdImpl()
{
GLContextEGL::Cast(mGL)->SetEGLSurfaceOverride(mPBuffer);
--- a/gfx/gl/SharedSurfaceD3D11Interop.cpp
+++ b/gfx/gl/SharedSurfaceD3D11Interop.cpp
@@ -295,22 +295,25 @@ SharedSurface_D3D11Interop::SharedSurfac
, mKeyedMutex(keyedMutex)
, mLockedForGL(false)
{ }
SharedSurface_D3D11Interop::~SharedSurface_D3D11Interop()
{
MOZ_ASSERT(!mLockedForGL);
- mGL->fDeleteRenderbuffers(1, &mProdRB);
-
if (!mDXGL->UnregisterObject(mObjectWGL)) {
NS_WARNING("Failed to release a DXGL object, possibly leaking it.");
}
+ if (!mGL->MakeCurrent())
+ return;
+
+ mGL->fDeleteRenderbuffers(1, &mProdRB);
+
// mDXGL is closed when it runs out of refs.
}
void
SharedSurface_D3D11Interop::LockProdImpl()
{ }
void
--- a/gfx/gl/SharedSurfaceEGL.cpp
+++ b/gfx/gl/SharedSurfaceEGL.cpp
@@ -83,32 +83,34 @@ SharedSurface_EGLImage::SharedSurface_EG
, mConsTex(0)
, mSync(0)
{}
SharedSurface_EGLImage::~SharedSurface_EGLImage()
{
mEGL->fDestroyImage(Display(), mImage);
- mGL->MakeCurrent();
- mGL->fDeleteTextures(1, &mProdTex);
- mProdTex = 0;
+ if (mSync) {
+ // We can't call this unless we have the ext, but we will always have
+ // the ext if we have something to destroy.
+ mEGL->fDestroySync(Display(), mSync);
+ mSync = 0;
+ }
if (mConsTex) {
MOZ_ASSERT(mGarbageBin);
mGarbageBin->Trash(mConsTex);
mConsTex = 0;
}
- if (mSync) {
- // We can't call this unless we have the ext, but we will always have
- // the ext if we have something to destroy.
- mEGL->fDestroySync(Display(), mSync);
- mSync = 0;
- }
+ if (!mGL->MakeCurrent())
+ return;
+
+ mGL->fDeleteTextures(1, &mProdTex);
+ mProdTex = 0;
}
layers::TextureFlags
SharedSurface_EGLImage::GetTextureFlags() const
{
return layers::TextureFlags::DEALLOCATE_CLIENT;
}
--- a/gfx/gl/SharedSurfaceGLX.cpp
+++ b/gfx/gl/SharedSurfaceGLX.cpp
@@ -72,21 +72,21 @@ void
SharedSurface_GLXDrawable::UnlockProdImpl()
{
GLContextGLX::Cast(mGL)->RestoreDrawable();
}
bool
SharedSurface_GLXDrawable::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
{
- if (!mXlibSurface)
- return false;
+ if (!mXlibSurface)
+ return false;
- *out_descriptor = layers::SurfaceDescriptorX11(mXlibSurface, mInSameProcess);
- return true;
+ *out_descriptor = layers::SurfaceDescriptorX11(mXlibSurface, mInSameProcess);
+ return true;
}
bool
SharedSurface_GLXDrawable::ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface)
{
MOZ_ASSERT(out_surface);
RefPtr<gfx::DataSourceSurface> dataSurf =
new gfx::DataSourceSurfaceCairo(mXlibSurface->CairoSurface());
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -130,30 +130,30 @@ SharedSurface_Gralloc::SharedSurface_Gra
, mEGL(egl)
, mSync(0)
, mAllocator(allocator)
, mTextureClient(textureClient)
, mProdTex(prodTex)
{
}
-
bool
SharedSurface_Gralloc::HasExtensions(GLLibraryEGL* egl, GLContext* gl)
{
return egl->HasKHRImageBase() &&
gl->IsExtensionSupported(GLContext::OES_EGL_image);
}
SharedSurface_Gralloc::~SharedSurface_Gralloc()
{
-
DEBUG_PRINT("[SharedSurface_Gralloc %p] destroyed\n", this);
- mGL->MakeCurrent();
+ if (!mGL->MakeCurrent())
+ return;
+
mGL->fDeleteTextures(1, &mProdTex);
if (mSync) {
MOZ_ALWAYS_TRUE( mEGL->fDestroySync(mEGL->Display(), mSync) );
mSync = 0;
}
}
--- a/gfx/gl/SharedSurfaceIO.cpp
+++ b/gfx/gl/SharedSurfaceIO.cpp
@@ -160,21 +160,20 @@ SharedSurface_IOSurface::SharedSurface_I
gl->MakeCurrent();
mProdTex = 0;
gl->fGenTextures(1, &mProdTex);
BackTextureWithIOSurf(gl, mProdTex, mIOSurf);
}
SharedSurface_IOSurface::~SharedSurface_IOSurface()
{
- if (mProdTex) {
- DebugOnly<bool> success = mGL->MakeCurrent();
- MOZ_ASSERT(success);
- mGL->fDeleteTextures(1, &mProdTex);
- }
+ if (!mGL->MakeCurrent())
+ return;
+
+ mGL->fDeleteTextures(1, &mProdTex);
}
bool
SharedSurface_IOSurface::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
{
bool isOpaque = !mHasAlpha;
*out_descriptor = layers::SurfaceDescriptorMacIOSurface(mIOSurf->GetIOSurfaceID(),
mIOSurf->GetContentsScaleFactor(),