Bug 1232456 - Renew EGL surface using existing compositor widget; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 23 Dec 2015 22:03:35 -0500
changeset 277597 fa4764e92630be77049acaed6aed57015a324dbd
parent 277596 4b23cb28ee3d5b19f6e67ea65a21967d87de3b1e
child 277598 c62897596ce10eb559f36b5732159ec4e7a27290
push id16783
push userryanvm@gmail.com
push dateSat, 26 Dec 2015 01:50:11 +0000
treeherderfx-team@4a559a618d67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1232456
milestone46.0a1
Bug 1232456 - Renew EGL surface using existing compositor widget; r=snorp GLContextEGL needs a widget in order to recreate its surface. This patch adds a widget parameter to RenewSurface so that the compositor can pass in its widget.
gfx/gl/GLContext.h
gfx/gl/GLContextEAGL.h
gfx/gl/GLContextEGL.h
gfx/gl/GLContextProviderEGL.cpp
gfx/layers/opengl/CompositingRenderTargetOGL.cpp
gfx/layers/opengl/CompositorOGL.cpp
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -46,16 +46,18 @@
 //#include "GLTextureImage.h"
 #include "SurfaceTypes.h"
 #include "GLContextSymbols.h"
 #include "base/platform_thread.h"       // for PlatformThreadId
 #include "mozilla/GenericRefCounted.h"
 #include "gfx2DGlue.h"
 #include "GeckoProfiler.h"
 
+class nsIWidget;
+
 namespace android {
     class GraphicBuffer;
 } // namespace android
 
 namespace mozilla {
     namespace gfx {
         class DataSourceSurface;
         class SourceSurface;
@@ -3325,17 +3327,17 @@ private:
 
 public:
 
     void ForceDirtyScreen();
     void CleanDirtyScreen();
 
     virtual GLenum GetPreferredARGB32Format() const { return LOCAL_GL_RGBA; }
 
-    virtual bool RenewSurface() { return false; }
+    virtual bool RenewSurface(nsIWidget* aWidget) { return false; }
 
     // Shared code for GL extensions and GLX extensions.
     static bool ListHasExtension(const GLubyte *extensions,
                                  const char *extension);
 
     GLint GetMaxTextureImageSize() { return mMaxTextureImageSize; }
 
 public:
--- a/gfx/gl/GLContextEAGL.h
+++ b/gfx/gl/GLContextEAGL.h
@@ -55,17 +55,18 @@ public:
     virtual bool SupportsRobustness() const override;
 
     virtual bool SwapBuffers() override;
 
     virtual GLuint GetDefaultFramebuffer() override {
         return mBackbufferFB;
     }
 
-    virtual bool RenewSurface() override {
+    virtual bool RenewSurface(nsIWidget* aWidget) override {
+        // FIXME: should use the passed widget instead of the existing one.
         return RecreateRB();
     }
 
 private:
     GLuint mBackbufferRB;
     GLuint mBackbufferFB;
 
     void* mLayer;
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -5,18 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GLCONTEXTEGL_H_
 #define GLCONTEXTEGL_H_
 
 #include "GLContext.h"
 #include "GLLibraryEGL.h"
 
-class nsIWidget;
-
 namespace mozilla {
 namespace gl {
 
 class GLContextEGL : public GLContext
 {
     friend class TextureImageEGL;
 
     static already_AddRefed<GLContextEGL>
@@ -76,17 +74,17 @@ public:
     virtual bool ReleaseTexImage() override;
 
     void SetEGLSurfaceOverride(EGLSurface surf);
 
     virtual bool MakeCurrentImpl(bool aForce) override;
 
     virtual bool IsCurrent() override;
 
-    virtual bool RenewSurface() override;
+    virtual bool RenewSurface(nsIWidget* aWidget) override;
 
     virtual void ReleaseSurface() override;
 
     virtual bool SetupLookupFunction() override;
 
     virtual bool SwapBuffers() override;
 
     // hold a reference to the given surface
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -377,32 +377,24 @@ GLContextEGL::MakeCurrentImpl(bool aForc
 }
 
 bool
 GLContextEGL::IsCurrent() {
     return sEGLLibrary.fGetCurrentContext() == mContext;
 }
 
 bool
-GLContextEGL::RenewSurface() {
+GLContextEGL::RenewSurface(nsIWidget* aWidget) {
     if (!mOwnsContext) {
         return false;
     }
-#ifndef MOZ_WIDGET_ANDROID
-    MOZ_CRASH("GFX: unimplemented");
-    // to support this on non-Android platforms, need to keep track of the nsIWidget that
-    // this GLContext was created for (with CreateForWindow) so that we know what to
-    // pass again to CreateSurfaceForWindow below.
-    // The reason why Android doesn't need this is that it delegates EGLSurface creation to
-    // Java code which is the only thing that knows about our actual widget.
-#endif
     // unconditionally release the surface and create a new one. Don't try to optimize this away.
     // If we get here, then by definition we know that we want to get a new surface.
     ReleaseSurface();
-    mSurface = mozilla::gl::CreateSurfaceForWindow(nullptr, mConfig); // the nullptr here is where we assume Android.
+    mSurface = mozilla::gl::CreateSurfaceForWindow(aWidget, mConfig);
     if (!mSurface) {
         return false;
     }
     return MakeCurrent(true);
 }
 
 void
 GLContextEGL::ReleaseSurface() {
--- a/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
@@ -46,17 +46,17 @@ CompositingRenderTargetOGL::BindRenderTa
     MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
     GLuint fbo = mFBO == 0 ? mGL->GetDefaultFramebuffer() : mFBO;
     mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo);
     GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
     if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
       // The main framebuffer (0) of non-offscreen contexts
       // might be backed by a EGLSurface that needs to be renewed.
       if (mFBO == 0 && !mGL->IsOffscreen()) {
-        mGL->RenewSurface();
+        mGL->RenewSurface(mCompositor->GetWidget());
         result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
       }
       if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
         nsAutoCString msg;
         msg.AppendPrintf("Framebuffer not complete -- CheckFramebufferStatus returned 0x%x, "
                          "GLContext=%p, IsOffscreen()=%d, mFBO=%d, aFBOTextureTarget=0x%x, "
                          "aRect.width=%d, aRect.height=%d",
                          result, mGL, mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget,
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -1533,17 +1533,17 @@ CompositorOGL::Pause()
 bool
 CompositorOGL::Resume()
 {
 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT)
   if (!gl() || gl()->IsDestroyed())
     return false;
 
   // RenewSurface internally calls MakeCurrent.
-  return gl()->RenewSurface();
+  return gl()->RenewSurface(GetWidget());
 #endif
   return true;
 }
 
 already_AddRefed<DataTextureSource>
 CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
 {
   return MakeAndAddRef<TextureImageTextureSourceOGL>(this, aFlags);