Bug 604101 - Part 2 - Use UploadSurfaceToTexture in CairoImageOGL. r=joe a=blocking2.0
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 16 Dec 2010 23:27:56 -0800
changeset 59437 c304184d7459d552178dca03da30a165471a2cdc
parent 59436 e86ea759809b72ad3d8895289d14384cbe6742ef
child 59438 d8d69903f209983d03d8567636d4d87f776415c3
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjoe, blocking2
bugs604101
milestone2.0b9pre
Bug 604101 - Part 2 - Use UploadSurfaceToTexture in CairoImageOGL. r=joe a=blocking2.0
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/layers/opengl/ImageLayerOGL.h
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -424,19 +424,18 @@ ImageLayerOGL::RenderLayer(int,
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
   } else if (image->GetFormat() == Image::CAIRO_SURFACE) {
     CairoImageOGL *cairoImage =
       static_cast<CairoImageOGL*>(image.get());
 
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, cairoImage->mTexture.GetTextureID());
 
-    ColorTextureLayerProgram *program =
-      mOGLManager->GetBasicLayerProgram(CanUseOpaqueSurface(),
-                                        cairoImage->mASurfaceAsGLContext != 0);
+    ColorTextureLayerProgram *program = 
+      mOGLManager->GetColorTextureLayerProgram(cairoImage->mLayerProgram);
 
     ApplyFilter(mFilter);
 
     program->Activate();
     program->SetLayerQuadRect(nsIntRect(0, 0,
                                         cairoImage->mSize.width,
                                         cairoImage->mSize.height));
     program->SetLayerTransform(GetEffectiveTransform());
@@ -675,49 +674,37 @@ void
 CairoImageOGL::SetData(const CairoImage::Data &aData)
 {
   if (!mTexture.IsAllocated())
     return;
 
   mozilla::gl::GLContext *gl = mTexture.GetGLContext();
   gl->MakeCurrent();
 
+  GLuint tex = mTexture.GetTextureID();
+
   if (mSize != aData.mSize) {
     gl->fActiveTexture(LOCAL_GL_TEXTURE0);
-    InitTexture(gl, mTexture.GetTextureID(), LOCAL_GL_RGBA, aData.mSize);
+    InitTexture(gl, tex, LOCAL_GL_RGBA, aData.mSize);
     mSize = aData.mSize;
-  } else {
-    gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture.GetTextureID());
   }
 
   if (!mASurfaceAsGLContext) {
     mASurfaceAsGLContext = GLContextProvider::CreateForNativePixmapSurface(aData.mSurface);
     if (mASurfaceAsGLContext)
       mASurfaceAsGLContext->BindTexImage();
   }
 
   if (mASurfaceAsGLContext)
     return;
 
-  // XXX This could be a lot more efficient if we already have an image-compatible
-  // surface
-  // XXX if we ever create an ImageFormatRGB24 surface, make sure that we use
-  // a BGRX program in that case (instead of BGRA)
-  nsRefPtr<gfxImageSurface> imageSurface =
-    new gfxImageSurface(aData.mSize, gfxASurface::ImageFormatARGB32);
-  nsRefPtr<gfxContext> context = new gfxContext(imageSurface);
-
-  context->SetSource(aData.mSurface);
-  context->Paint();
-
-  gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
-                     0, 0, mSize.width, mSize.height,
-                     LOCAL_GL_RGBA,
-                     LOCAL_GL_UNSIGNED_BYTE,
-                     imageSurface->Data());
+  mLayerProgram =
+    gl->UploadSurfaceToTexture(aData.mSurface,
+                               nsIntRect(0,0, mSize.width, mSize.height),
+                               tex);
 }
 
 
 #ifdef MOZ_IPC
 
 ShadowImageLayerOGL::ShadowImageLayerOGL(LayerManagerOGL* aManager)
   : ShadowImageLayer(aManager, nsnull)
   , LayerOGL(aManager)
--- a/gfx/layers/opengl/ImageLayerOGL.h
+++ b/gfx/layers/opengl/ImageLayerOGL.h
@@ -230,16 +230,17 @@ class THEBES_API CairoImageOGL : public 
 public:
   CairoImageOGL(LayerManagerOGL *aManager);
 
   void SetData(const Data &aData);
 
   GLTexture mTexture;
   gfxIntSize mSize;
   nsRefPtr<GLContext> mASurfaceAsGLContext;
+  gl::ShaderProgramType mLayerProgram;
 };
 
 
 #ifdef MOZ_IPC
 class ShadowImageLayerOGL : public ShadowImageLayer,
                             public LayerOGL
 {
   typedef gl::TextureImage TextureImage;