From a4bf620619a64e38643efc11b9a05fca964df56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 15 Jan 2007 15:15:04 +0000 Subject: [PATCH] X pixmap is referenced by GLXPixmap, so there's no need to worry about its lifetime, just taking care of GLXPixmap is enough. svn path=/branches/work/kwin_composite/; revision=623812 --- scene_opengl.cpp | 34 +++++++++------------------------- scene_opengl.h | 1 - 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index eab12c95cf..dae85254e9 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -601,7 +601,6 @@ SceneOpenGL::Window::Window( Toplevel* c ) : Scene::Window( c ) , texture( 0 ) , texture_y_inverted( false ) - , bound_pixmap( None ) , bound_glxpixmap( None ) { } @@ -697,32 +696,25 @@ void SceneOpenGL::Window::bindTexture() } XFreeGC( display(), gc ); } - // if using copy_buffer, the pixmap is no longer needed, the - // texture will be updated only when the window changes anyway, - // so no need to cache the pixmap - if( copy_buffer ) - XFreePixmap( display(), pix ); texture_y_inverted = true; toplevel->resetDamage( toplevel->rect()); } else if( tfp_mode ) { // tfp mode, simply bind the pixmap to texture - // TODO what should the lifetime of bound_pixmap be? if( texture == None ) glGenTextures( 1, &texture ); - if( bound_pixmap != None && !strict_binding ) // release old if needed + if( bound_glxpixmap != None && !strict_binding ) // release old if needed { glXReleaseTexImageEXT( display(), bound_glxpixmap, GLX_FRONT_LEFT_EXT ); glXDestroyGLXPixmap( display(), bound_glxpixmap ); - // TODO bound_pixmap shouldn't always be freed - XFreePixmap( display(), bound_pixmap ); } static const int attrs[] = { GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT, None }; - bound_pixmap = pix; + // the GLXPixmap will reference the X pixmap, so it will be freed automatically + // when no longer needed bound_glxpixmap = glXCreatePixmap( display(), fbcdrawable, pix, attrs ); int value; glXGetFBConfigAttrib( display(), fbcdrawable, GLX_Y_INVERTED_EXT, &value ); @@ -767,11 +759,6 @@ void SceneOpenGL::Window::bindTexture() } } glXWaitGL(); - // if using copy_buffer, the pixmap is no longer needed, the - // texture will be updated only when the window changes anyway, - // so no need to cache the pixmap - if( copy_buffer ) - XFreePixmap( display(), pix ); if( db ) glDrawBuffer( GL_BACK ); glXMakeContextCurrent( display(), glxbuffer, glxbuffer, ctxbuffer ); @@ -779,6 +766,10 @@ void SceneOpenGL::Window::bindTexture() texture_y_inverted = false; toplevel->resetDamage( toplevel->rect()); } + // if using copy_buffer, the pixmap is no longer needed (either referenced + // by GLXPixmap in the tfp case or not needed at all in non-tfp cases) + if( copy_buffer ) + XFreePixmap( display(), pix ); } @@ -804,7 +795,7 @@ void SceneOpenGL::Window::enableTexture() glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texture ); if( tfp_mode && strict_binding ) { - assert( bound_pixmap != None ); + assert( bound_glxpixmap != None ); glXBindTexImageEXT( display(), bound_glxpixmap, GLX_FRONT_LEFT_EXT, NULL ); } if( options->smoothScale != 0 ) // default to yes @@ -823,7 +814,7 @@ void SceneOpenGL::Window::disableTexture() { if( tfp_mode && strict_binding ) { - assert( bound_pixmap != None ); + assert( bound_glxpixmap != None ); glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texture ); glXReleaseTexImageEXT( display(), bound_glxpixmap, GLX_FRONT_LEFT_EXT ); } @@ -840,13 +831,6 @@ void SceneOpenGL::Window::discardTexture() if( !strict_binding ) glXReleaseTexImageEXT( display(), bound_glxpixmap, GLX_FRONT_LEFT_EXT ); glXDestroyGLXPixmap( display(), bound_glxpixmap ); - // TODO this is broken, and may need changing anyway depending on - // how tfp_mode deals with the new windowPixmap() - if( bound_pixmap != toplevel->windowPixmap( false ) ) - // if using copy_buffer, bound_pixmap is independent of - // windowPixmap(), so free it now - XFreePixmap( display(), bound_pixmap ); - bound_pixmap = None; bound_glxpixmap = None; } glDeleteTextures( 1, &texture ); diff --git a/scene_opengl.h b/scene_opengl.h index ffe7a5aedb..4a0e25df8a 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -81,7 +81,6 @@ class SceneOpenGL::Window QRegion optimizeBindDamage( const QRegion& reg, int limit ); Texture texture; bool texture_y_inverted; // texture has y inverted - Pixmap bound_pixmap; // the pixmap the texture is bound to, only for tfp_mode GLXPixmap bound_glxpixmap; // the glx pixmap the texture is bound to, only for tfp_mode };