diff --git a/gfx/layers/opengl/CanvasLayerOGL.cpp b/gfx/layers/opengl/CanvasLayerOGL.cpp index ad77d763f91..2777eeae4f3 100644 --- a/gfx/layers/opengl/CanvasLayerOGL.cpp +++ b/gfx/layers/opengl/CanvasLayerOGL.cpp @@ -72,12 +72,6 @@ CanvasLayerOGL::Destroy() cx->MakeCurrent(); cx->fDeleteTextures(1, &mTexture); } -#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO) - if (mPixmap) { - sGLXLibrary.DestroyPixmap(mPixmap); - mPixmap = 0; - } -#endif mDestroyed = PR_TRUE; } @@ -101,14 +95,17 @@ CanvasLayerOGL::Initialize(const Data& aData) mCanvasSurface = aData.mSurface; mNeedsYFlip = PR_FALSE; #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO) - mPixmap = sGLXLibrary.CreatePixmap(aData.mSurface); - if (mPixmap) { - if (aData.mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) { - mLayerProgram = gl::RGBALayerProgramType; - } else { - mLayerProgram = gl::RGBXLayerProgramType; + if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) { + gfxXlibSurface *xsurf = static_cast(aData.mSurface); + mPixmap = xsurf->GetGLXPixmap(); + if (mPixmap) { + if (aData.mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) { + mLayerProgram = gl::RGBALayerProgramType; + } else { + mLayerProgram = gl::RGBXLayerProgramType; + } + MakeTexture(); } - MakeTexture(); } #endif } else if (aData.mGLContext) { diff --git a/gfx/thebes/gfxXlibSurface.cpp b/gfx/thebes/gfxXlibSurface.cpp index e4575e404f7..c5bc0ffe9e1 100644 --- a/gfx/thebes/gfxXlibSurface.cpp +++ b/gfx/thebes/gfxXlibSurface.cpp @@ -56,7 +56,7 @@ using namespace mozilla; #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) - : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable) + : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable), mGLXPixmap(None) { DoSizeQuery(); cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, mSize.width, mSize.height); @@ -64,7 +64,7 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) } gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size) - : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable), mSize(size) + : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable), mSize(size), mGLXPixmap(None) { NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), "Bad size"); @@ -76,7 +76,7 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format, const gfxIntSize& size) : mPixmapTaken(PR_FALSE), mDisplay(DisplayOfScreen(screen)), - mDrawable(drawable), mSize(size) + mDrawable(drawable), mSize(size), mGLXPixmap(None) { NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), "Bad Size"); @@ -91,7 +91,8 @@ gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFor gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) : mPixmapTaken(PR_FALSE), mSize(cairo_xlib_surface_get_width(csurf), - cairo_xlib_surface_get_height(csurf)) + cairo_xlib_surface_get_height(csurf)), + mGLXPixmap(None) { NS_PRECONDITION(cairo_surface_status(csurf) == 0, "Not expecting an error surface"); @@ -104,6 +105,9 @@ gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) gfxXlibSurface::~gfxXlibSurface() { + if (mGLXPixmap) { + gl::sGLXLibrary.DestroyPixmap(mGLXPixmap); + } // gfxASurface's destructor calls RecordMemoryFreed(). if (mPixmapTaken) { XFreePixmap (mDisplay, mDrawable); @@ -523,6 +527,16 @@ gfxXlibSurface::XRenderFormat() return cairo_xlib_surface_get_xrender_format(CairoSurface()); } +GLXPixmap +gfxXlibSurface::GetGLXPixmap() +{ + if (!mGLXPixmap) { + mGLXPixmap = gl::sGLXLibrary.CreatePixmap(this); + } + return mGLXPixmap; +} + + gfxASurface::MemoryLocation gfxXlibSurface::GetMemoryLocation() const { diff --git a/gfx/thebes/gfxXlibSurface.h b/gfx/thebes/gfxXlibSurface.h index 50aa558aa58..9dffad5db0b 100644 --- a/gfx/thebes/gfxXlibSurface.h +++ b/gfx/thebes/gfxXlibSurface.h @@ -44,6 +44,8 @@ #include #include +#include "GLXLibrary.h" + class THEBES_API gfxXlibSurface : public gfxASurface { public: // construct a wrapper around the specified drawable with dpy/visual. @@ -104,6 +106,8 @@ public: // server, not the main application. virtual gfxASurface::MemoryLocation GetMemoryLocation() const; + GLXPixmap GetGLXPixmap(); + protected: // if TakePixmap() has been called on this PRBool mPixmapTaken; @@ -114,6 +118,8 @@ protected: void DoSizeQuery(); gfxIntSize mSize; + + GLXPixmap mGLXPixmap; }; #endif /* GFX_XLIBSURFACE_H */