Bug 925645 - Turn SharedSurface::mGL into a WeakPtr<> - r=jgilbert
authorEdwin Flores <eflores@mozilla.com>
Mon, 24 Oct 2016 16:35:31 +0100
changeset 428750 1d1dd53f792ce5f856ed14fb22948d8c58b639c7
parent 428749 1fc115bbc7bebf25b9685dfff2f4a0c2ba9f9a11
child 428751 b443899d03b49b3e0af52e9274b287c990798315
push id33413
push usermozilla@kaply.com
push dateMon, 24 Oct 2016 15:54:36 +0000
reviewersjgilbert
bugs925645
milestone52.0a1
Bug 925645 - Turn SharedSurface::mGL into a WeakPtr<> - r=jgilbert
gfx/gl/GLContext.h
gfx/gl/SharedSurface.h
gfx/gl/SharedSurfaceD3D11Interop.cpp
gfx/gl/SharedSurfaceEGL.cpp
gfx/gl/SharedSurfaceGL.cpp
gfx/gl/SharedSurfaceGralloc.cpp
gfx/gl/SharedSurfaceIO.cpp
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -36,16 +36,17 @@
 #include "GLLibraryLoader.h"
 #include "nsISupportsImpl.h"
 #include "plstr.h"
 #include "GLContextTypes.h"
 #include "SurfaceTypes.h"
 #include "GLContextSymbols.h"
 #include "base/platform_thread.h"       // for PlatformThreadId
 #include "mozilla/GenericRefCounted.h"
+#include "mozilla/WeakPtr.h"
 #include "gfx2DGlue.h"
 #include "GeckoProfiler.h"
 
 class nsIWidget;
 
 namespace android {
     class GraphicBuffer;
 } // namespace android
@@ -185,17 +186,21 @@ enum class GLRenderer {
     IntelHD3000,
     MicrosoftBasicRenderDriver,
     Other
 };
 
 class GLContext
     : public GLLibraryLoader
     , public GenericAtomicRefCounted
+    , public SupportsWeakPtr<GLContext>
 {
+public:
+    MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
+
 // -----------------------------------------------------------------------------
 // basic enums
 public:
 
 // -----------------------------------------------------------------------------
 // basic getters
 public:
 
--- a/gfx/gl/SharedSurface.h
+++ b/gfx/gl/SharedSurface.h
@@ -55,17 +55,17 @@ class ShSurfHandle;
 class SharedSurface
 {
 public:
     static void ProdCopy(SharedSurface* src, SharedSurface* dest,
                          SurfaceFactory* factory);
 
     const SharedSurfaceType mType;
     const AttachmentType mAttachType;
-    GLContext* const mGL;
+    const WeakPtr<GLContext> mGL;
     const gfx::IntSize mSize;
     const bool mHasAlpha;
     const bool mCanRecycle;
 protected:
     bool mIsLocked;
     bool mIsProducerAcquired;
 #ifdef DEBUG
     nsIThread* const mOwningThread;
--- a/gfx/gl/SharedSurfaceD3D11Interop.cpp
+++ b/gfx/gl/SharedSurfaceD3D11Interop.cpp
@@ -334,17 +334,17 @@ SharedSurface_D3D11Interop::SharedSurfac
     , mNeedsFinish(gfxPrefs::WebGLDXGLNeedsFinish())
     , mLockedForGL(false)
 { }
 
 SharedSurface_D3D11Interop::~SharedSurface_D3D11Interop()
 {
     MOZ_ASSERT(!IsProducerAcquired());
 
-    if (!mGL->MakeCurrent())
+    if (!mGL || !mGL->MakeCurrent())
         return;
 
     if (!mInterop->UnregisterObject(mLockHandle)) {
         NS_WARNING("Failed to release mLockHandle, possibly leaking it.");
     }
 
     mGL->fDeleteRenderbuffers(1, &mProdRB);
 }
--- a/gfx/gl/SharedSurfaceEGL.cpp
+++ b/gfx/gl/SharedSurfaceEGL.cpp
@@ -89,17 +89,17 @@ SharedSurface_EGLImage::~SharedSurface_E
 
     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())
+    if (!mGL || !mGL->MakeCurrent())
         return;
 
     mGL->fDeleteTextures(1, &mProdTex);
     mProdTex = 0;
 }
 
 layers::TextureFlags
 SharedSurface_EGLImage::GetTextureFlags() const
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -80,17 +80,17 @@ SharedSurface_Basic::SharedSurface_Basic
                               0);
 
     DebugOnly<GLenum> status = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
     MOZ_ASSERT(status == LOCAL_GL_FRAMEBUFFER_COMPLETE);
 }
 
 SharedSurface_Basic::~SharedSurface_Basic()
 {
-    if (!mGL->MakeCurrent())
+    if (!mGL || !mGL->MakeCurrent())
         return;
 
     if (mFB)
         mGL->fDeleteFramebuffers(1, &mFB);
 
     if (mOwnsTex)
         mGL->fDeleteTextures(1, &mTex);
 }
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -141,17 +141,17 @@ SharedSurface_Gralloc::HasExtensions(GLL
     return egl->HasKHRImageBase() &&
            gl->IsExtensionSupported(GLContext::OES_EGL_image);
 }
 
 SharedSurface_Gralloc::~SharedSurface_Gralloc()
 {
     DEBUG_PRINT("[SharedSurface_Gralloc %p] destroyed\n", this);
 
-    if (!mGL->MakeCurrent())
+    if (!mGL || !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,17 +160,17 @@ SharedSurface_IOSurface::SharedSurface_I
     gl->MakeCurrent();
     mProdTex = 0;
     gl->fGenTextures(1, &mProdTex);
     BackTextureWithIOSurf(gl, mProdTex, mIOSurf);
 }
 
 SharedSurface_IOSurface::~SharedSurface_IOSurface()
 {
-    if (!mGL->MakeCurrent())
+    if (!mGL || !mGL->MakeCurrent())
         return;
 
     mGL->fDeleteTextures(1, &mProdTex);
 }
 
 bool
 SharedSurface_IOSurface::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
 {