Bug 705024 - Guarantee GLContexts are resolved properly - r=bjacob
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 16 Dec 2011 14:24:46 -0800
changeset 82827 9ba4a7f652fbbceb0948a1e2a31ae65c524c5bc3
parent 82826 84f4cb3c8b9e9af507badf5343de4a84d8221343
child 82828 a5c58e9199a3293f22e8a40d81612bdc5dba82bc
push id4137
push userjgilbert@mozilla.com
push dateFri, 16 Dec 2011 22:25:36 +0000
treeherdermozilla-inbound@a5c58e9199a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs705024
milestone11.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 705024 - Guarantee GLContexts are resolved properly - r=bjacob
content/canvas/src/WebGLContext.cpp
gfx/gl/GLContext.h
gfx/layers/d3d10/CanvasLayerD3D10.cpp
gfx/layers/opengl/CanvasLayerOGL.cpp
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -594,18 +594,24 @@ WebGLContext::SetDimensions(PRInt32 widt
         }
         LogMessage("Using software rendering via OSMesa (THIS WILL BE SLOW)");
     }
 
 #ifdef XP_WIN
     // if we want EGL, try it now
     if (!gl && (preferEGL || useANGLE) && !preferOpenGL) {
         gl = gl::GLContextProviderEGL::CreateOffscreen(gfxIntSize(width, height), format);
-        if (gl && !InitAndValidateGL()) {
-            gl = nsnull;
+        if (gl) {
+            if (InitAndValidateGL()) {
+                if (useANGLE) {
+                    gl->SetFlushGuaranteesResolve(true);
+                }
+            } else {
+                gl = nsnull;
+            }
         }
     }
 
     // if it failed, then try the default provider, whatever that is
     if (!gl && useOpenGL) {
         gl = gl::GLContextProvider::CreateOffscreen(gfxIntSize(width, height), format);
         if (gl && !InitAndValidateGL()) {
             gl = nsnull;
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -527,17 +527,18 @@ struct THEBES_API ContextFormat
 class GLContext
     : public LibrarySymbolLoader
 {
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GLContext)
 public:
     GLContext(const ContextFormat& aFormat,
               bool aIsOffscreen = false,
               GLContext *aSharedContext = nsnull)
-      : mOffscreenFBOsDirty(false),
+      : mFlushGuaranteesResolve(false),
+        mOffscreenFBOsDirty(false),
         mInitialized(false),
         mIsOffscreen(aIsOffscreen),
 #ifdef USE_GLES2
         mIsGLES2(true),
 #else
         mIsGLES2(false),
 #endif
         mIsGlobalSharedContext(false),
@@ -757,16 +758,33 @@ public:
     }
 
     virtual void UnbindTex2DOffscreen(GLContext *aOffscreen) { }
 
     bool IsOffscreen() {
         return mIsOffscreen;
     }
 
+protected:
+    bool mFlushGuaranteesResolve;
+
+public:
+    void SetFlushGuaranteesResolve(bool aFlushGuaranteesResolve) {
+        mFlushGuaranteesResolve = aFlushGuaranteesResolve;
+    }
+
+    void GuaranteeResolve() {
+        if (mFlushGuaranteesResolve) {
+            BlitDirtyFBOs();
+            fFlush();
+        } else {
+            fFinish();
+        }
+    }
+
     /*
      * Resize the current offscreen buffer.  Returns true on success.
      * If it returns false, the context should be treated as unusable
      * and should be recreated.  After the resize, the viewport is not
      * changed; glViewport should be called as appropriate.
      *
      * Only valid if IsOffscreen() returns true.
      */
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -151,17 +151,17 @@ CanvasLayerD3D10::UpdateSurface()
     mSurface->Flush();
     return;
   }
 
   if (mUsingSharedTexture) {
     // need to sync on the d3d9 device
     if (mGLContext) {
       mGLContext->MakeCurrent();
-      mGLContext->fFinish();
+      mGLContext->GuaranteeResolve();
     }
     return;
   }
 
   if (mGLContext) {
     // WebGL reads entire surface.
     D3D10_MAPPED_TEXTURE2D map;
     
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -237,17 +237,17 @@ CanvasLayerOGL::RenderLayer(int aPreviou
 
   bool useGLContext = mCanvasGLContext &&
     mCanvasGLContext->GetContextType() == gl()->GetContextType();
 
   nsIntRect drawRect = mBounds;
 
   if (useGLContext) {
     mCanvasGLContext->MakeCurrent();
-    mCanvasGLContext->fFinish();
+    mCanvasGLContext->GuaranteeResolve();
 
     gl()->MakeCurrent();
     gl()->BindTex2DOffscreen(mCanvasGLContext);
     program = mOGLManager->GetBasicLayerProgram(CanUseOpaqueSurface(), true);
   } else if (mDelayedUpdates) {
     NS_ABORT_IF_FALSE(mCanvasSurface, "WebGL canvases should always be using full texture upload");
     
     drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds());