Fixes for support for multisampled Mac/CGL GLContexts
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 19 Oct 2011 15:09:57 -0400
changeset 79600 e393f548f8cbf2a9c0c21886a2294774230382a1
parent 79599 01ec87781de74a8fe199ada2b90ac34a760ceee8
child 79601 6cef5f8378a4b720d5cd301b5d7250b3dc13bf09
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone10.0a1
Fixes for support for multisampled Mac/CGL GLContexts
gfx/thebes/GLContextProviderCGL.mm
--- a/gfx/thebes/GLContextProviderCGL.mm
+++ b/gfx/thebes/GLContextProviderCGL.mm
@@ -273,32 +273,36 @@ GLContextCGL::ResizeOffscreen(const gfxI
                                    textureInternalFormat:(mCreationFormat.alpha ? LOCAL_GL_RGBA : LOCAL_GL_RGB)
                                    textureMaxMipMapLevel:0
                                    pixelsWide:aNewSize.width
                                    pixelsHigh:aNewSize.height];
         if (!pb) {
             return false;
         }
 
+        if (!ResizeOffscreenFBO(aNewSize, false)) {
+            return false;
+        }
+
         [mPBuffer release];
         mPBuffer = pb;
 
         mOffscreenSize = aNewSize;
         mOffscreenActualSize = aNewSize;
 
         [mContext setPixelBuffer:pb cubeMapFace:0 mipMapLevel:0
          currentVirtualScreen:[mContext currentVirtualScreen]];
 
         MakeCurrent();
         ClearSafely();
 
         return true;
     }
 
-    return ResizeOffscreenFBO(aNewSize);
+    return ResizeOffscreenFBO(aNewSize, true);
 }
 
 class TextureImageCGL : public BasicTextureImage
 {
     friend already_AddRefed<TextureImage>
     GLContextCGL::CreateBasicTextureImage(GLuint,
                                           const nsIntSize&,
                                           GLenum,
@@ -527,18 +531,17 @@ CreateOffscreenPBufferContext(const gfxI
 
     [pbFormat release];
 
     nsRefPtr<GLContextCGL> glContext = new GLContextCGL(aFormat, shareContext, context, pb);
     return glContext.forget();
 }
 
 static already_AddRefed<GLContextCGL>
-CreateOffscreenFBOContext(const gfxIntSize& aSize,
-                          const ContextFormat& aFormat,
+CreateOffscreenFBOContext(const ContextFormat& aFormat,
                           bool aShare = true)
 {
     if (!sCGLLibrary.EnsureInitialized()) {
         return nsnull;
     }
 
     GLContextCGL *shareContext = aShare ? GetGlobalContextCGL() : nsnull;
     if (aShare && !shareContext) {
@@ -556,40 +559,44 @@ CreateOffscreenFBOContext(const gfxIntSi
     nsRefPtr<GLContextCGL> glContext = new GLContextCGL(aFormat, shareContext, context, true);
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
 GLContextProviderCGL::CreateOffscreen(const gfxIntSize& aSize,
                                       const ContextFormat& aFormat)
 {
+    ContextFormat actualFormat(aFormat);
+    actualFormat.samples = 0;
+
     nsRefPtr<GLContextCGL> glContext;
     
     NS_ENSURE_TRUE(Preferences::GetRootBranch(), nsnull);
     const bool preferFBOs = Preferences::GetBool("cgl.prefer-fbo", false);
     if (!preferFBOs)
     {
-        glContext = CreateOffscreenPBufferContext(aSize, aFormat);
+        glContext = CreateOffscreenPBufferContext(aSize, actualFormat);
         if (glContext &&
-            glContext->Init())
+            glContext->Init() &&
+            glContext->ResizeOffscreenFBO(aSize, false))
         {
             glContext->mOffscreenSize = aSize;
             glContext->mOffscreenActualSize = aSize;
 
             printf("GL Offscreen: CGL+PBuffer\n");
 
             return glContext.forget();
         }
     }
 
     // try a FBO as second choice
-    glContext = CreateOffscreenFBOContext(aSize, aFormat);
+    glContext = CreateOffscreenFBOContext(actualFormat);
     if (glContext &&
         glContext->Init() &&
-        glContext->ResizeOffscreenFBO(aSize))
+        glContext->ResizeOffscreenFBO(aSize, true))
     {
         return glContext.forget();
     }
 
     // everything failed
     return nsnull;
 }
 
@@ -608,18 +615,17 @@ GLContextProviderCGL::GetGlobalContext()
         return nsnull;
     }
 
     if (!gGlobalContext) {
         // There are bugs in some older drivers with pbuffers less
         // than 16x16 in size; also 16x16 is POT so that we can do
         // a FBO with it on older video cards.  A FBO context for
         // sharing is preferred since it has no associated target.
-        gGlobalContext = CreateOffscreenFBOContext(gfxIntSize(16, 16),
-                                                   ContextFormat(ContextFormat::BasicRGB24),
+        gGlobalContext = CreateOffscreenFBOContext(ContextFormat(ContextFormat::BasicRGB24),
                                                    false);
         if (!gGlobalContext || !static_cast<GLContextCGL*>(gGlobalContext.get())->Init()) {
             NS_WARNING("Couldn't init gGlobalContext.");
             gGlobalContext = nsnull;
             return nsnull; 
         }
 
         gGlobalContext->SetIsGlobalSharedContext(true);