Move duplicated functionality to the base class.

svn path=/branches/work/kwin_composite/; revision=595639
This commit is contained in:
Luboš Luňák 2006-10-15 08:58:38 +00:00
parent a3538cd80a
commit d547cf8cd4
6 changed files with 137 additions and 226 deletions

View file

@ -9,6 +9,9 @@ License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "scene_basic.h"
#include "client.h"
#include <X11/extensions/shape.h>
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

65
scene.h
View file

@ -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

View file

@ -19,8 +19,6 @@ Based on glcompmgr code by Felix Bellaby.
#include <dlfcn.h>
#include <X11/extensions/shape.h>
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

View file

@ -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 <GL/gl.h>
#include <GL/glx.h>
@ -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

View file

@ -16,8 +16,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include "client.h"
#include "effects.h"
#include <X11/extensions/shape.h>
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

View file

@ -17,8 +17,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include <X11/extensions/Xrender.h>
#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