Bug 670106 - Check the surface type before attempting to create a GLXPixmap. r=joe
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 15 Jul 2011 08:45:33 +1200
changeset 72845 9672ad924796d0cbf3a96665dc99696546f6a996
parent 72844 7ce783faf48f2785d3aed6075554b78d568f9f89
child 72846 dcdd255aedf31be161200e5faa3c8f1a6c178436
push id20776
push usereakhgari@mozilla.com
push dateFri, 15 Jul 2011 12:13:35 +0000
treeherdermozilla-central@9349ae9094f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs670106
milestone8.0a1
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 670106 - Check the surface type before attempting to create a GLXPixmap. r=joe
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/thebes/GLContextProviderGLX.cpp
gfx/thebes/GLXLibrary.h
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -458,17 +458,20 @@ ImageLayerOGL::RenderLayer(int,
     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);
+        NS_ASSERTION(pixmap, "Failed to create pixmap!");
+        if (pixmap) {
+            sGLXLibrary.BindTexImage(pixmap);
+        }
     }
 #endif
 
     ColorTextureLayerProgram *program = 
       mOGLManager->GetColorTextureLayerProgram(cairoImage->mLayerProgram);
 
     ApplyFilter(mFilter);
 
@@ -564,17 +567,17 @@ ImageLayerOGL::RenderLayer(int,
         {
             gl()->fEnableVertexAttribArray(vertAttribIndex);
             gl()->fDrawArrays(LOCAL_GL_TRIANGLES, 0, triangleBuffer.elements());
             gl()->fDisableVertexAttribArray(vertAttribIndex);
         }
         gl()->fDisableVertexAttribArray(texCoordAttribIndex);
     }
 #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
-    if (cairoImage->mSurface) {
+    if (cairoImage->mSurface && pixmap) {
         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());
@@ -762,17 +765,17 @@ CairoImageOGL::SetData(const CairoImage:
   mozilla::gl::GLContext *gl = mTexture.GetGLContext();
   gl->MakeCurrent();
 
   GLuint tex = mTexture.GetTextureID();
   gl->fActiveTexture(LOCAL_GL_TEXTURE0);
   mSize = aData.mSize;
 
 #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
-  if (sGLXLibrary.HasTextureFromPixmap()) {
+  if (sGLXLibrary.SupportsTextureFromPixmap(aData.mSurface)) {
     mSurface = aData.mSurface;
     if (mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
       mLayerProgram = gl::RGBALayerProgramType;
     } else {
       mLayerProgram = gl::RGBXLayerProgramType;
     }
     return;
   }
--- a/gfx/thebes/GLContextProviderGLX.cpp
+++ b/gfx/thebes/GLContextProviderGLX.cpp
@@ -247,24 +247,34 @@ GLXLibrary::EnsureInitialized()
                    DoesVendorStringMatch(serverVendor, "Chromium")) ||
         (serverVersionStr &&
          DoesVendorStringMatch(serverVersionStr, "Chromium"));
 
     mInitialized = PR_TRUE;
     return PR_TRUE;
 }
 
+PRBool
+GLXLibrary::SupportsTextureFromPixmap(gfxASurface* aSurface)
+{
+    if (!EnsureInitialized()) {
+        return PR_FALSE;
+    }
+    
+    if (aSurface->GetType() != gfxASurface::SurfaceTypeXlib || !mHasTextureFromPixmap) {
+        return PR_FALSE;
+    }
+
+    return PR_TRUE;
+}
+
 GLXPixmap 
 GLXLibrary::CreatePixmap(gfxASurface* aSurface)
 {
-    if (aSurface->GetType() != gfxASurface::SurfaceTypeXlib || !mHasTextureFromPixmap) {
-        return 0;
-    }
-
-    if (!EnsureInitialized()) {
+    if (!SupportsTextureFromPixmap(aSurface)) {
         return 0;
     }
 
     int attribs[] = { GLX_DOUBLEBUFFER, False,
                       GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
                       GLX_BIND_TO_TEXTURE_RGBA_EXT, True,
                       None };
 
--- a/gfx/thebes/GLXLibrary.h
+++ b/gfx/thebes/GLXLibrary.h
@@ -140,16 +140,17 @@ public:
     PRBool EnsureInitialized();
 
     GLXPixmap CreatePixmap(gfxASurface* aSurface);
     void DestroyPixmap(GLXPixmap aPixmap);
     void BindTexImage(GLXPixmap aPixmap);
     void ReleaseTexImage(GLXPixmap aPixmap);
 
     PRBool HasTextureFromPixmap() { return mHasTextureFromPixmap; }
+    PRBool SupportsTextureFromPixmap(gfxASurface* aSurface);
 
 private:
     PRBool mInitialized;
     PRBool mTriedInitializing;
     PRBool mHasTextureFromPixmap;
     PRLibrary *mOGLLibrary;
 };