Use BGRX shader for RGB24 image surfaces (bug 738178, r=joe).
authorAndreas Gal <gal@mozilla.com>
Thu, 22 Mar 2012 11:37:47 -0700
changeset 93371 7e6750f282cc12fadc7c1235bfc673f65d9d88ff
parent 93370 7b54766189f3bf6ad26b62742b030a4e10a46dc3
child 93372 70ac5065caeed3fe56b6368a6d04ffe7fd00b8ad
child 93377 19ed27abdd23413a44f07ae3199a0fd954f0dc19
push idunknown
push userunknown
push dateunknown
reviewersjoe
bugs738178
milestone14.0a1
Use BGRX shader for RGB24 image surfaces (bug 738178, r=joe).
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -797,21 +797,18 @@ GetGlobalContextEGL()
     return static_cast<GLContextEGL*>(GLContextProviderEGL::GetGlobalContext());
 }
 
 static GLenum
 GLFormatForImage(gfxASurface::gfxImageFormat aFormat)
 {
     switch (aFormat) {
     case gfxASurface::ImageFormatARGB32:
-        return LOCAL_GL_RGBA;
     case gfxASurface::ImageFormatRGB24:
-        // this often isn't correct, because we can't guarantee that
-        // the alpha byte will be 0xff coming from the image surface
-        NS_WARNING("Using GL_RGBA for ImageFormatRGB24, are you sure you know what you're doing?");
+        // Thebes only supports RGBX, not packed RGB.
         return LOCAL_GL_RGBA;
     case gfxASurface::ImageFormatRGB16_565:
         return LOCAL_GL_RGB;
     default:
         NS_WARNING("Unknown GL format for Image format");
     }
     return 0;
 }
@@ -862,28 +859,24 @@ public:
                 mUpdateFormat = gfxASurface::ImageFormatARGB32;
                 mShaderType = RGBALayerProgramType;
 #endif
             } else {
                 mShaderType = RGBALayerProgramType;
             }
             Resize(aSize);
         } else {
-            // Convert RGB24 to either ARGB32 on mobile.  We can't
-            // generate GL_RGB data, so we'll always have an alpha byte
-            // for RGB24.  No easy way to upload that to GL.
-            // 
-            // Note that if we start using RGB565 here, we'll need to
-            // watch for a) setting the correct format; and b) getting
-            // the stride right.
             if (mUpdateFormat == gfxASurface::ImageFormatRGB24) {
-                mUpdateFormat = gfxASurface::ImageFormatARGB32;
+                // RGB24 means really RGBX for Thebes, which means we have to
+                // use the right shader and ignore the uninitialized alpha
+                // value.
+                mShaderType = BGRXLayerProgramType;
+            } else {
+                mShaderType = BGRALayerProgramType;
             }
-            // We currently always use BGRA type textures
-            mShaderType = BGRALayerProgramType;
         }
     }
 
     virtual ~TextureImageEGL()
     {
         GLContext *ctx = mGLContext;
         if (ctx->IsDestroyed() || !NS_IsMainThread()) {
             ctx = ctx->GetSharedContext();