Bug 1516787 - Add GLContextEGL::OnMarkDestroyed(). r=jgilbert, a=RyanVM
authorsotaro <sotaro.ikeda.g@gmail.com>
Fri, 11 Jan 2019 09:04:26 +0900
changeset 509489 44fe44a6a340b557bda4467ec632db5f4ac47c02
parent 509488 4b5ae6076e03ae92c5be593491bedea65ca5336c
child 509490 c10cd6aadb9656703e01212906b77d3232694f3b
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert, RyanVM
bugs1516787
milestone65.0
Bug 1516787 - Add GLContextEGL::OnMarkDestroyed(). r=jgilbert, a=RyanVM
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextEGL.h
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/SharedSurfaceANGLE.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1918,16 +1918,18 @@ bool GLContext::AssembleOffscreenFBs(con
   }
 
   return isComplete;
 }
 
 void GLContext::MarkDestroyed() {
   if (IsDestroyed()) return;
 
+  OnMarkDestroyed();
+
   // Null these before they're naturally nulled after dtor, as we want GLContext
   // to still be alive in *their* dtors.
   mScreen = nullptr;
   mBlitHelper = nullptr;
   mReadTexImageHelper = nullptr;
 
   mContextLost = true;
   mSymbols = {};
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -3317,16 +3317,19 @@ class GLContext : public GLLibraryLoader
   // Destructor
  public:
   virtual ~GLContext();
 
   // Mark this context as destroyed.  This will nullptr out all
   // the GL function pointers!
   void MarkDestroyed();
 
+ protected:
+  virtual void OnMarkDestroyed() {}
+
   // -----------------------------------------------------------------------------
   // Everything that isn't standard GL APIs
  protected:
   typedef gfx::SurfaceFormat SurfaceFormat;
 
  public:
   virtual bool Init() = 0;
 
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -90,16 +90,18 @@ class GLContextEGL : public GLContext {
   static already_AddRefed<GLContextEGL> CreateEGLPBufferOffscreenContext(
       CreateContextFlags flags, const gfx::IntSize& size,
       const SurfaceCaps& minCaps, nsACString* const out_FailureId);
 
  protected:
   friend class GLContextProviderEGL;
   friend class GLContextEGLFactory;
 
+  virtual void OnMarkDestroyed() override;
+
  public:
   const EGLConfig mConfig;
 
  protected:
   const RefPtr<GLLibraryEGL> mEgl;
   EGLSurface mSurface;
   const EGLSurface mFallbackSurface;
 
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -305,16 +305,23 @@ GLContextEGL::GLContextEGL(CreateContext
       mFallbackSurface(CreateFallbackSurface(config)),
       mContext(context) {
 #ifdef DEBUG
   printf_stderr("Initializing context %p surface %p on display %p\n", mContext,
                 mSurface, EGL_DISPLAY());
 #endif
 }
 
+void
+GLContextEGL::OnMarkDestroyed() {
+  if (mSurfaceOverride != EGL_NO_SURFACE) {
+    SetEGLSurfaceOverride(EGL_NO_SURFACE);
+  }
+}
+
 GLContextEGL::~GLContextEGL() {
   MarkDestroyed();
 
   // Wrapped context should not destroy eglContext/Surface
   if (!mOwnsContext) {
     return;
   }
 
--- a/gfx/gl/SharedSurfaceANGLE.cpp
+++ b/gfx/gl/SharedSurfaceANGLE.cpp
@@ -93,18 +93,20 @@ SharedSurface_ANGLEShareHandle::SharedSu
     : SharedSurface(SharedSurfaceType::EGLSurfaceANGLE, AttachmentType::Screen,
                     gl, size, hasAlpha, true),
       mEGL(egl),
       mPBuffer(pbuffer),
       mShareHandle(shareHandle),
       mKeyedMutex(keyedMutex) {}
 
 SharedSurface_ANGLEShareHandle::~SharedSurface_ANGLEShareHandle() {
-  if (GLContextEGL::Cast(mGL)->GetEGLSurfaceOverride() == mPBuffer) {
-    GLContextEGL::Cast(mGL)->SetEGLSurfaceOverride(EGL_NO_SURFACE);
+  GLContext* gl = mGL;
+
+  if (gl && GLContextEGL::Cast(gl)->GetEGLSurfaceOverride() == mPBuffer) {
+    GLContextEGL::Cast(gl)->SetEGLSurfaceOverride(EGL_NO_SURFACE);
   }
   mEGL->fDestroySurface(Display(), mPBuffer);
 }
 
 void SharedSurface_ANGLEShareHandle::LockProdImpl() {
   GLContextEGL::Cast(mGL)->SetEGLSurfaceOverride(mPBuffer);
 }