Bug 578649 - ThebesLayerOGL using wrong shader program on QT GL build. r=vlad,a=blocking-fennec
authorOleg Romashin <romaxa@gmail.com>
Tue, 07 Sep 2010 17:37:34 -0700
changeset 52152 4bb022d84a31
parent 52151 d91b0d9fd0a2
child 52165 34249acca1cc
push id15555
push userbobbyholley@stanford.edu
push date2010-09-08 00:39 +0000
Treeherderresults
reviewersvlad, blocking-fennec
bugs578649
milestone2.0b6pre
Bug 578649 - ThebesLayerOGL using wrong shader program on QT GL build. r=vlad,a=blocking-fennec
gfx/layers/opengl/LayerManagerOGL.h
gfx/layers/opengl/ThebesLayerOGL.cpp
gfx/thebes/GLContext.h
gfx/thebes/GLContextProviderEGL.cpp
--- a/gfx/layers/opengl/LayerManagerOGL.h
+++ b/gfx/layers/opengl/LayerManagerOGL.h
@@ -160,16 +160,29 @@ public:
     return static_cast<ColorTextureLayerProgram*>(mPrograms[BGRALayerProgramType]);
   }
   ColorTextureLayerProgram *GetRGBXLayerProgram() {
     return static_cast<ColorTextureLayerProgram*>(mPrograms[RGBXLayerProgramType]);
   }
   ColorTextureLayerProgram *GetBGRXLayerProgram() {
     return static_cast<ColorTextureLayerProgram*>(mPrograms[BGRXLayerProgramType]);
   }
+  ColorTextureLayerProgram *GetBasicLayerProgram(PRBool aOpaque, PRBool aIsRGB)
+  {
+    if (aIsRGB) {
+      return aOpaque
+        ? GetRGBXLayerProgram()
+        : GetRGBALayerProgram();
+    } else {
+      return aOpaque
+        ? GetBGRXLayerProgram()
+        : GetBGRALayerProgram();
+    }
+  }
+
   ColorTextureLayerProgram *GetRGBARectLayerProgram() {
     return static_cast<ColorTextureLayerProgram*>(mPrograms[RGBARectLayerProgramType]);
   }
   SolidColorLayerProgram *GetColorLayerProgram() {
     return static_cast<SolidColorLayerProgram*>(mPrograms[ColorLayerProgramType]);
   }
   YCbCrTextureLayerProgram *GetYCbCrLayerProgram() {
     return static_cast<YCbCrTextureLayerProgram*>(mPrograms[YCbCrLayerProgramType]);
--- a/gfx/layers/opengl/ThebesLayerOGL.cpp
+++ b/gfx/layers/opengl/ThebesLayerOGL.cpp
@@ -138,19 +138,18 @@ protected:
 
 void
 ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
                                LayerManagerOGL* aManager)
 {
   // Note BGR: Cairo's image surfaces are always in what
   // OpenGL and our shaders consider BGR format.
   ColorTextureLayerProgram *program =
-    mLayer->CanUseOpaqueSurface()
-    ? aManager->GetBGRXLayerProgram()
-    : aManager->GetBGRALayerProgram();
+    aManager->GetBasicLayerProgram(mLayer->CanUseOpaqueSurface(),
+                                   mTexImage->IsRGB());
 
   if (!mTexImage->InUpdate() || !mTexImage->EndUpdate()) {
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexImage->Texture());
   }
 
   nsIntRect quadRect = mLayer->GetVisibleRegion().GetBounds();
   program->Activate();
   program->SetLayerQuadRect(quadRect);
--- a/gfx/thebes/GLContext.h
+++ b/gfx/thebes/GLContext.h
@@ -194,32 +194,36 @@ public:
      */
     virtual already_AddRefed<gfxASurface> GetBackingSurface()
     { return NULL; }
 
     const nsIntSize& GetSize() const { return mSize; }
     ContentType GetContentType() const { return mContentType; }
     virtual PRBool InUpdate() const = 0;
 
+    PRBool IsRGB() const { return mIsRGBFormat; }
+
 protected:
     /**
      * After the ctor, the TextureImage is invalid.  Implementations
      * must allocate resources successfully before returning the new
      * TextureImage from GLContext::CreateTextureImage().  That is,
      * clients must not be given partially-constructed TextureImages.
      */
-    TextureImage(GLuint aTexture, const nsIntSize& aSize, ContentType aContentType)
+    TextureImage(GLuint aTexture, const nsIntSize& aSize, ContentType aContentType, PRBool aIsRGB = PR_FALSE)
         : mTexture(aTexture)
         , mSize(aSize)
         , mContentType(aContentType)
+        , mIsRGBFormat(aIsRGB)
     {}
 
     GLuint mTexture;
     nsIntSize mSize;
     ContentType mContentType;
+    PRPackedBool mIsRGBFormat;
 };
 
 /**
  * BasicTextureImage is the baseline TextureImage implementation ---
  * it updates its texture by allocating a scratch buffer for the
  * client to draw into, then using glTexSubImage2D() to upload the new
  * pixels.  Platforms must provide the code to create a new surface
  * into which the updated pixels will be drawn, and the code to
--- a/gfx/thebes/GLContextProviderEGL.cpp
+++ b/gfx/thebes/GLContextProviderEGL.cpp
@@ -814,18 +814,19 @@ GetGlobalContextEGL()
 
 class TextureImageEGL : public TextureImage
 {
 public:
     TextureImageEGL(GLuint aTexture,
                     const nsIntSize& aSize,
                     ContentType aContentType,
                     GLContext* aContext,
-                    GLContextEGL* aImpl)
-        : TextureImage(aTexture, aSize, aContentType)
+                    GLContextEGL* aImpl,
+                    PRBool aIsRGB)
+        : TextureImage(aTexture, aSize, aContentType, aIsRGB)
         , mGLContext(aContext)
         , mImpl(aImpl)
     { }
 
     virtual ~TextureImageEGL()
     {
         mGLContext->MakeCurrent();
         mImpl->ReleaseTexImage();
@@ -878,16 +879,18 @@ GLContextEGL::CreateTextureImage(const n
                                  TextureImage::ContentType aContentType,
                                  GLint aWrapMode,
                                  PRBool aUseNearestFilter)
 {
   gfxASurface::gfxImageFormat imageFormat =
       (gfxASurface::CONTENT_COLOR == aContentType) ?
       gfxASurface::ImageFormatRGB24 : gfxASurface::ImageFormatARGB32;
 
+  PRBool isRGB = PR_TRUE; // ^ this is always RGB
+
   nsRefPtr<gfxASurface> pixmap =
     gfxPlatform::GetPlatform()->
       CreateOffscreenSurface(gfxIntSize(aSize.width, aSize.height),
                              imageFormat);
 
   nsRefPtr<GLContext> impl =
       GLContextProviderEGL::CreateForNativePixmapSurface(pixmap);
   if (!impl)
@@ -907,17 +910,18 @@ GLContextEGL::CreateTextureImage(const n
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, aWrapMode);
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, aWrapMode);
 
   impl->BindTexImage();
 
   nsRefPtr<TextureImageEGL> teximage =
       new TextureImageEGL(texture, aSize, aContentType, this,
-                          static_cast<GLContextEGL*>(impl.get()));
+                          static_cast<GLContextEGL*>(impl.get()),
+                          isRGB);
   return teximage.forget();
 }
 
 already_AddRefed<GLContext>
 GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
 {
     if (!sEGLLibrary.EnsureInitialized()) {
         return nsnull;