From d547cf8cd4f52f7a4b8c131e73bd4865a1b0a130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Sun, 15 Oct 2006 08:58:38 +0000 Subject: [PATCH] Move duplicated functionality to the base class. svn path=/branches/work/kwin_composite/; revision=595639 --- scene.cpp | 59 +++++++++++++++++++++++++++++++++++++++++- scene.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++ scene_opengl.cpp | 62 ++++---------------------------------------- scene_opengl.h | 57 ++--------------------------------------- scene_xrender.cpp | 61 ++++---------------------------------------- scene_xrender.h | 59 ++---------------------------------------- 6 files changed, 137 insertions(+), 226 deletions(-) diff --git a/scene.cpp b/scene.cpp index 11726a8fde..65ff484b01 100644 --- a/scene.cpp +++ b/scene.cpp @@ -9,6 +9,9 @@ License. See the file "COPYING" for the exact licensing terms. ******************************************************************/ #include "scene_basic.h" +#include "client.h" + +#include namespace KWinInternal { @@ -17,6 +20,8 @@ namespace KWinInternal // Scene //**************************************** +Scene* scene; + Scene::Scene( Workspace* ws ) : wspace( ws ) { @@ -42,6 +47,58 @@ void Scene::windowDeleted( Toplevel* ) { } -Scene* scene; +Scene::Window::Window( Toplevel * c ) + : toplevel( c ) + , shape_valid( false ) + { + } + +void Scene::Window::discardShape() + { + shape_valid = false; + } + +QRegion Scene::Window::shape() const + { + if( !shape_valid ) + { + Client* c = dynamic_cast< Client* >( toplevel ); + if( toplevel->shape() || ( c != NULL && !c->mask().isEmpty())) + { + int count, order; + XRectangle* rects = XShapeGetRectangles( display(), toplevel->handle(), + ShapeBounding, &count, &order ); + if(rects) + { + shape_region = QRegion(); + for( int i = 0; + i < count; + ++i ) + shape_region += QRegion( rects[ i ].x, rects[ i ].y, + rects[ i ].width, rects[ i ].height ); + XFree(rects); + } + else + shape_region = QRegion( 0, 0, width(), height()); + } + else + shape_region = QRegion( 0, 0, width(), height()); + shape_valid = true; + } + return shape_region; + } + +bool Scene::Window::isVisible() const + { + // TODO mapping state? + return !toplevel->geometry() + .intersect( QRect( 0, 0, displayWidth(), displayHeight())) + .isEmpty(); + } + +bool Scene::Window::isOpaque() const + { + return toplevel->opacity() == 1.0 && !toplevel->hasAlpha(); + } } // namespace diff --git a/scene.h b/scene.h index ac17d3a1c1..c6f2b9e041 100644 --- a/scene.h +++ b/scene.h @@ -12,6 +12,7 @@ License. See the file "COPYING" for the exact licensing terms. #define KWIN_SCENE_H #include "utils.h" +#include "toplevel.h" namespace KWinInternal { @@ -34,11 +35,75 @@ class Scene // a window has been destroyed virtual void windowDeleted( Toplevel* ); protected: + enum + { + PAINT_OPAQUE = 1 << 0, + PAINT_TRANSLUCENT = 1 << 1 + }; + static QRegion infiniteRegion(); + class Window; + template< typename T > + struct Phase2Data + { + Phase2Data( T* w, QRegion r ) : window( w ), region( r ) {} + T* window; + QRegion region; + }; Workspace* wspace; }; +class Scene::Window + { + public: + Window( Toplevel* c ); + int x() const; + int y() const; + int width() const; + int height() const; + bool isVisible() const; + bool isOpaque() const; + QRegion shape() const; + void discardShape(); + Window() {} // QMap sucks even in Qt4 + protected: + Toplevel* toplevel; + private: + mutable QRegion shape_region; + mutable bool shape_valid; + }; + extern Scene* scene; +inline +QRegion Scene::infiniteRegion() + { // INT_MIN / 2 because it's width/height (INT_MIN+INT_MAX==-1) + return QRegion( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX ); + } + +inline +int Scene::Window::x() const + { + return toplevel->x(); + } + +inline +int Scene::Window::y() const + { + return toplevel->y(); + } + +inline +int Scene::Window::width() const + { + return toplevel->width(); + } + +inline +int Scene::Window::height() const + { + return toplevel->height(); + } + } // namespace #endif diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 2bd799a9fa..b30678fe0f 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -19,8 +19,6 @@ Based on glcompmgr code by Felix Bellaby. #include -#include - namespace KWinInternal { @@ -391,20 +389,19 @@ void SceneOpenGL::windowOpacityChanged( Toplevel* ) #endif } +//**************************************** +// SceneOpenGL::Window +//**************************************** + SceneOpenGL::Window::Window( Toplevel* c ) - : toplevel( c ) + : Scene::Window( c ) , texture( 0 ) , texture_y_inverted( false ) , bound_pixmap( None ) , bound_glxpixmap( None ) - , shape_valid( false ) { } -SceneOpenGL::Window::~Window() - { - } - void SceneOpenGL::Window::free() { discardTexture(); @@ -548,42 +545,6 @@ void SceneOpenGL::Window::discardTexture() texture = 0; } - -void SceneOpenGL::Window::discardShape() - { - shape_valid = false; - } - -QRegion SceneOpenGL::Window::shape() const - { - if( !shape_valid ) - { - Client* c = dynamic_cast< Client* >( toplevel ); - if( toplevel->shape() || ( c != NULL && !c->mask().isEmpty())) - { - int count, order; - XRectangle* rects = XShapeGetRectangles( display(), toplevel->handle(), - ShapeBounding, &count, &order ); - if(rects) - { - shape_region = QRegion(); - for( int i = 0; - i < count; - ++i ) - shape_region += QRegion( rects[ i ].x, rects[ i ].y, - rects[ i ].width, rects[ i ].height ); - XFree(rects); - } - else - shape_region = QRegion( 0, 0, width(), height()); - } - else - shape_region = QRegion( 0, 0, width(), height()); - shape_valid = true; - } - return shape_region; - } - static void quadPaint( int x1, int y1, int x2, int y2, bool invert_y ) { glTexCoord2i( x1, invert_y ? y2 : y1 ); @@ -664,17 +625,4 @@ void SceneOpenGL::Window::paint( QRegion region, int mask ) glBindTexture( GL_TEXTURE_RECTANGLE_ARB, 0 ); } -bool SceneOpenGL::Window::isVisible() const - { - // TODO mapping state? - return !toplevel->geometry() - .intersect( QRect( 0, 0, displayWidth(), displayHeight())) - .isEmpty(); - } - -bool SceneOpenGL::Window::isOpaque() const - { - return toplevel->opacity() == 1.0 && !toplevel->hasAlpha(); - } - } // namespace diff --git a/scene_opengl.h b/scene_opengl.h index 8abde12b9d..d7185d5398 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -12,7 +12,6 @@ License. See the file "COPYING" for the exact licensing terms. #define KWIN_SCENE_OPENGL_H #include "scene.h" -#include "toplevel.h" #include #include @@ -37,12 +36,6 @@ class SceneOpenGL void paintGenericScreen( ToplevelList windows ); void paintSimpleScreen( QRegion damage, ToplevelList windows ); void paintBackground( QRegion damage ); - static QRegion infiniteRegion(); - enum - { - PAINT_OPAQUE = 1 << 0, - PAINT_TRANSLUCENT = 1 << 1 - }; typedef GLuint Texture; GC gcroot; Drawable buffer; @@ -54,72 +47,26 @@ class SceneOpenGL static bool tfp_mode; class Window; QMap< Toplevel*, Window > windows; - struct Phase2Data - { - Phase2Data( Window* w, QRegion r ) : window( w ), region( r ) {} - Window* window; - QRegion region; - }; + typedef Scene::Phase2Data< Window > Phase2Data; }; class SceneOpenGL::Window + : public Scene::Window { public: Window( Toplevel* c ); - ~Window(); void free(); // is often copied by value, use manually instead of dtor - int x() const; - int y() const; - int width() const; - int height() const; void paint( QRegion region, int mask ); - bool isVisible() const; - bool isOpaque() const; void bindTexture(); - QRegion shape() const; void discardTexture(); - void discardShape(); Window() {} // QMap sucks even in Qt4 private: - Toplevel* toplevel; Texture texture; bool texture_y_inverted; Pixmap bound_pixmap; GLXPixmap bound_glxpixmap; // only for tfp_mode - mutable QRegion shape_region; - mutable bool shape_valid; }; -inline -QRegion SceneOpenGL::infiniteRegion() - { // INT_MIN / 2 because it's width/height (INT_MIN+INT_MAX==-1) - return QRegion( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX ); - } - -inline -int SceneOpenGL::Window::x() const - { - return toplevel->x(); - } - -inline -int SceneOpenGL::Window::y() const - { - return toplevel->y(); - } - -inline -int SceneOpenGL::Window::width() const - { - return toplevel->width(); - } - -inline -int SceneOpenGL::Window::height() const - { - return toplevel->height(); - } - } // namespace #endif diff --git a/scene_xrender.cpp b/scene_xrender.cpp index 42ebf83cc3..620d54b23a 100644 --- a/scene_xrender.cpp +++ b/scene_xrender.cpp @@ -16,8 +16,6 @@ License. See the file "COPYING" for the exact licensing terms. #include "client.h" #include "effects.h" -#include - namespace KWinInternal { @@ -215,12 +213,15 @@ XserverRegion SceneXrender::toXserverRegion( QRegion region ) return ret; } +//**************************************** +// SceneXrender::Window +//**************************************** + SceneXrender::Window::Window( Toplevel* c ) - : toplevel( c ) + : Scene::Window( c ) , _picture( None ) , format( XRenderFindVisualFormat( display(), c->visual())) , alpha( None ) - , shape_valid( false ) { } @@ -295,11 +296,6 @@ void SceneXrender::Window::discardAlpha() alpha = None; } -void SceneXrender::Window::discardShape() - { - shape_valid = false; - } - Picture SceneXrender::Window::alphaMask() { if( isOpaque()) @@ -330,36 +326,6 @@ Picture SceneXrender::Window::alphaMask() return alpha; } -QRegion SceneXrender::Window::shape() const - { - if( !shape_valid ) - { - Client* c = dynamic_cast< Client* >( toplevel ); - if( toplevel->shape() || ( c != NULL && !c->mask().isEmpty())) - { - int count, order; - XRectangle* rects = XShapeGetRectangles( display(), toplevel->handle(), - ShapeBounding, &count, &order ); - if(rects) - { - shape_region = QRegion(); - for( int i = 0; - i < count; - ++i ) - shape_region += QRegion( rects[ i ].x, rects[ i ].y, - rects[ i ].width, rects[ i ].height ); - XFree(rects); - } - else - shape_region = QRegion( 0, 0, width(), height()); - } - else - shape_region = QRegion( 0, 0, width(), height()); - shape_valid = true; - } - return shape_region; - } - void SceneXrender::Window::paint( QRegion region, int mask ) { if( mask & ( PAINT_OPAQUE | PAINT_TRANSLUCENT )) @@ -394,22 +360,5 @@ void SceneXrender::Window::paint( QRegion region, int mask ) XFixesSetPictureClipRegion( display(), buffer, 0, 0, None ); } -bool SceneXrender::Window::isVisible() const - { - // TODO mapping state? - return !toplevel->geometry() - .intersect( QRect( 0, 0, displayWidth(), displayHeight())) - .isEmpty(); - } - -bool SceneXrender::Window::isOpaque() const - { - if( format->type == PictTypeDirect && format->direct.alphaMask ) - return false; - if( toplevel->opacity() != 1.0 ) - return false; - return true; - } - } // namespace #endif diff --git a/scene_xrender.h b/scene_xrender.h index 62c1a1ee2b..2b41b48dee 100644 --- a/scene_xrender.h +++ b/scene_xrender.h @@ -17,8 +17,6 @@ License. See the file "COPYING" for the exact licensing terms. #include #include "scene.h" -#include "effects.h" -#include "toplevel.h" namespace KWinInternal { @@ -41,87 +39,34 @@ class SceneXrender void paintGenericScreen( ToplevelList windows ); void paintSimpleScreen( QRegion damage, ToplevelList windows ); void paintBackground( QRegion region ); - static QRegion infiniteRegion(); static XserverRegion toXserverRegion( QRegion region ); - enum - { - PAINT_OPAQUE = 1 << 0, - PAINT_TRANSLUCENT = 1 << 1 - }; XRenderPictFormat* format; Picture front; static Picture buffer; class Window; QMap< Toplevel*, Window > windows; - struct Phase2Data - { - Phase2Data( Window* w, QRegion r ) : window( w ), region( r ) {} - Window* window; - QRegion region; - }; + typedef Scene::Phase2Data< Window > Phase2Data; }; class SceneXrender::Window + : public Scene::Window { public: Window( Toplevel* c ); void free(); // is often copied by value, use manually instead of dtor - int x() const; - int y() const; - int width() const; - int height() const; void paint( QRegion region, int mask ); - bool isOpaque() const; - void geometryShapeChanged(); - void opacityChanged(); - bool isVisible() const; - QRegion shape() const; void discardPicture(); - void discardShape(); void discardAlpha(); Window() {} // QMap sucks even in Qt4 private: Picture picture(); Picture alphaMask(); - Toplevel* toplevel; Picture _picture; XRenderPictFormat* format; Picture alpha; double alpha_cached_opacity; - mutable QRegion shape_region; - mutable bool shape_valid; }; -inline -QRegion SceneXrender::infiniteRegion() - { // INT_MIN / 2 because it's width/height (INT_MIN+INT_MAX==-1) - return QRegion( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX ); - } - -inline -int SceneXrender::Window::x() const - { - return toplevel->x(); - } - -inline -int SceneXrender::Window::y() const - { - return toplevel->y(); - } - -inline -int SceneXrender::Window::width() const - { - return toplevel->width(); - } - -inline -int SceneXrender::Window::height() const - { - return toplevel->height(); - } - } // namespace #endif