Bug 640082 - Part 5 - Use texture_from_pixmap in CairoImageOGL. r=joe
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 07 Apr 2011 16:58:08 -0700
changeset 67637 24a6d10dd3a2eb0aa2cebf11e843ac07ae6810ca
parent 67636 6f831c7a1990d880af0b9837793570bb57dfaa87
child 67638 50de57368f92e77fdf34bcba34a232900614d386
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs640082
milestone2.2a1pre
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 640082 - Part 5 - Use texture_from_pixmap in CairoImageOGL. r=joe
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/layers/opengl/ImageLayerOGL.h
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -38,16 +38,20 @@
 
 #include "gfxSharedImageSurface.h"
 
 #include "ImageLayerOGL.h"
 #include "gfxImageSurface.h"
 #include "yuv_convert.h"
 #include "GLContextProvider.h"
 #include "MacIOSurfaceImageOGL.h"
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+# include "GLXLibrary.h"
+# include "mozilla/X11Util.h"
+#endif
 
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
 /**
  * This is an event used to unref a GLContext on the main thread and
@@ -435,31 +439,47 @@ 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());
 
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+    GLXPixmap pixmap;
+
+    if (cairoImage->mSurface) {
+        pixmap = sGLXLibrary.CreatePixmap(cairoImage->mSurface);
+        sGLXLibrary.BindTexImage(pixmap);
+    }
+#endif
+    
     ColorTextureLayerProgram *program = 
       mOGLManager->GetColorTextureLayerProgram(cairoImage->mLayerProgram);
 
     ApplyFilter(mFilter);
 
     program->Activate();
     program->SetLayerQuadRect(nsIntRect(0, 0,
                                         cairoImage->mSize.width,
                                         cairoImage->mSize.height));
     program->SetLayerTransform(GetEffectiveTransform());
     program->SetLayerOpacity(GetEffectiveOpacity());
     program->SetRenderOffset(aOffset);
     program->SetTextureUnit(0);
 
     mOGLManager->BindAndDrawQuad(program);
+
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+    if (cairoImage->mSurface) {
+        sGLXLibrary.ReleaseTexImage(pixmap);
+        sGLXLibrary.DestroyPixmap(pixmap);
+    }
+#endif
 #ifdef XP_MACOSX
   } else if (image->GetFormat() == Image::MAC_IO_SURFACE) {
      MacIOSurfaceImageOGL *ioImage =
        static_cast<MacIOSurfaceImageOGL*>(image.get());
 
      if (!mOGLManager->GetThebesLayerCallback()) {
        // If its an empty transaction we still need to update
        // the plugin IO Surface and make sure we grab the
@@ -720,27 +740,43 @@ CairoImageOGL::CairoImageOGL(LayerManage
     // Allocate texture now to grab a reference to the GLContext
     mTexture.Allocate(aManager->glForResources());
   }
 }
 
 void
 CairoImageOGL::SetData(const CairoImage::Data &aData)
 {
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+  mSurface = nsnull;
+#endif
+
   if (!mTexture.IsAllocated())
     return;
 
   mozilla::gl::GLContext *gl = mTexture.GetGLContext();
   gl->MakeCurrent();
 
   GLuint tex = mTexture.GetTextureID();
+  gl->fActiveTexture(LOCAL_GL_TEXTURE0);
+  mSize = aData.mSize;
 
-  gl->fActiveTexture(LOCAL_GL_TEXTURE0);
-  InitTexture(gl, tex, LOCAL_GL_RGBA, aData.mSize);
-  mSize = aData.mSize;
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+  if (sGLXLibrary.HasTextureFromPixmap()) {
+    mSurface = aData.mSurface;
+    if (mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
+      mLayerProgram = gl::RGBALayerProgramType;
+    } else {
+      mLayerProgram = gl::RGBXLayerProgramType;
+    }
+    return;
+  }
+#endif
+
+  InitTexture(gl, tex, LOCAL_GL_RGBA, mSize);
 
   mLayerProgram =
     gl->UploadSurfaceToTexture(aData.mSurface,
                                nsIntRect(0,0, mSize.width, mSize.height),
                                tex);
 }
 
 ShadowImageLayerOGL::ShadowImageLayerOGL(LayerManagerOGL* aManager)
--- a/gfx/layers/opengl/ImageLayerOGL.h
+++ b/gfx/layers/opengl/ImageLayerOGL.h
@@ -225,16 +225,19 @@ class THEBES_API CairoImageOGL : public 
 public:
   CairoImageOGL(LayerManagerOGL *aManager);
 
   void SetData(const Data &aData);
 
   GLTexture mTexture;
   gfxIntSize mSize;
   gl::ShaderProgramType mLayerProgram;
+#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
+  nsRefPtr<gfxASurface> mSurface;
+#endif
 };
 
 class ShadowImageLayerOGL : public ShadowImageLayer,
                             public LayerOGL
 {
   typedef gl::TextureImage TextureImage;
 
 public: