Bug 1484624 - Don't create texture sources if the compositor doesn't have a GL context. r=sotaro
authorNicolas Silva <nsilva@mozilla.com>
Wed, 22 Aug 2018 13:59:15 +0200
changeset 432805 389ffe7befeeee61318659e3c76b4ae2b93bb446
parent 432804 3db3f0761004289cef06241977003539e2abef62
child 432806 aebd6f51d2e5125b1a0be102a6f1c93fa377425f
push id106873
push usernsilva@mozilla.com
push dateWed, 22 Aug 2018 12:01:03 +0000
treeherdermozilla-inbound@389ffe7befee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1484624
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484624 - Don't create texture sources if the compositor doesn't have a GL context. r=sotaro
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/TextureHostOGL.cpp
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -1899,22 +1899,30 @@ CompositorOGL::Resume()
   return gl()->RenewSurface(GetWidget());
 #endif
   return true;
 }
 
 already_AddRefed<DataTextureSource>
 CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
 {
+  if (!gl()) {
+    return nullptr;
+  }
+
   return MakeAndAddRef<TextureImageTextureSourceOGL>(this, aFlags);
 }
 
 already_AddRefed<DataTextureSource>
 CompositorOGL::CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture)
 {
+  if (!gl()) {
+    return nullptr;
+  }
+
   BufferTextureHost* bufferTexture = aTexture->AsBufferTextureHost();
   MOZ_ASSERT(bufferTexture);
 
   if (!bufferTexture) {
     return nullptr;
   }
 
   uint8_t* buf = bufferTexture->GetBuffer();
@@ -1986,16 +1994,20 @@ CompositorOGL::TryUnlockTextures()
     TextureSync::SetTexturesUnlocked(it.Key(), *it.UserData());
   }
 }
 #endif
 
 already_AddRefed<DataTextureSource>
 CompositorOGL::CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface)
 {
+  if (!gl()) {
+    return nullptr;
+  }
+
   return MakeAndAddRef<DirectMapTextureSource>(this, aSurface);
 }
 
 bool
 CompositorOGL::SupportsPartialTextureUpdate()
 {
   return CanUploadSubTextures(mGLContext);
 }
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -335,34 +335,43 @@ DirectMapTextureSource::Update(gfx::Data
   }
 
   return UpdateInternal(aSurface, aDestRegion, aSrcOffset, false);
 }
 
 bool
 DirectMapTextureSource::Sync(bool aBlocking)
 {
-  gl()->MakeCurrent();
+  if (!gl() || !gl()->MakeCurrent()) {
+    // We use this function to decide whether we can unlock the texture
+    // and clean it up. If we return false here and for whatever reason
+    // the context is absent or invalid, the compositor will keep a
+    // reference to this texture forever.
+    return true;
+  }
+
   if (!gl()->IsDestroyed()) {
     if (aBlocking) {
       gl()->fFinishObjectAPPLE(LOCAL_GL_TEXTURE, mTextureHandle);
     } else {
       return gl()->fTestObjectAPPLE(LOCAL_GL_TEXTURE, mTextureHandle);
     }
   }
   return true;
 }
 
 bool
 DirectMapTextureSource::UpdateInternal(gfx::DataSourceSurface* aSurface,
                                        nsIntRegion* aDestRegion,
                                        gfx::IntPoint* aSrcOffset,
                                        bool aInit)
 {
-  gl()->MakeCurrent();
+  if (!gl() || !gl()->MakeCurrent()) {
+    return false;
+  }
 
   if (aInit) {
     gl()->fGenTextures(1, &mTextureHandle);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, mTextureHandle);
 
     gl()->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
                          LOCAL_GL_TEXTURE_STORAGE_HINT_APPLE,
                          LOCAL_GL_STORAGE_CACHED_APPLE);