Prepare for scene rendering with different engines.

svn path=/branches/work/kwin_composite/; revision=558442
This commit is contained in:
Luboš Luňák 2006-07-05 12:30:03 +00:00
parent e76564c165
commit afcc9b6897
11 changed files with 227 additions and 49 deletions

View file

@ -43,6 +43,9 @@ set(kwin_KDEINIT_SRCS
composite.cpp composite.cpp
toplevel.cpp toplevel.cpp
unmanaged.cpp unmanaged.cpp
scene.cpp
scene_basic.cpp
scene_xrender.cpp
effects.cpp ) effects.cpp )
kde4_automoc(${kwin_KDEINIT_SRCS}) kde4_automoc(${kwin_KDEINIT_SRCS})

View file

@ -12,7 +12,8 @@ License. See the file "COPYING" for the exact licensing terms.
#include "workspace.h" #include "workspace.h"
#include "client.h" #include "client.h"
#include "unmanaged.h" #include "unmanaged.h"
#include "effects.h" #include "scene.h"
#include "scene_basic.h"
namespace KWinInternal namespace KWinInternal
{ {
@ -26,22 +27,24 @@ void Workspace::setupCompositing()
{ {
if( !Extensions::compositeAvailable() || !Extensions::damageAvailable()) if( !Extensions::compositeAvailable() || !Extensions::damageAvailable())
return; return;
if( composite_pixmap != None ) if( scene != NULL )
return; return;
// TODO start tracking unmanaged windows
compositeTimer.start( 20 ); compositeTimer.start( 20 );
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual ); XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
composite_pixmap = XCreatePixmap( display(), rootWindow(), displayWidth(), displayHeight(), QX11Info::appDepth());
setDamaged(); setDamaged();
scene = new SceneBasic( this );
} }
void Workspace::finishCompositing() void Workspace::finishCompositing()
{ {
if( composite_pixmap == None ) if( scene == NULL )
return; return;
XCompositeUnredirectSubwindows( display(), rootWindow(), CompositeRedirectManual ); XCompositeUnredirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
XFreePixmap( display(), composite_pixmap );
compositeTimer.stop(); compositeTimer.stop();
composite_pixmap = None; // TODO stop tracking unmanaged windows
delete scene;
scene = NULL;
} }
void Workspace::setDamaged() void Workspace::setDamaged()
@ -55,6 +58,7 @@ void Workspace::compositeTimeout()
{ {
if( !damaged ) if( !damaged )
return; return;
damaged = false;
ToplevelList windows; ToplevelList windows;
Window* children; Window* children;
unsigned int children_count; unsigned int children_count;
@ -65,44 +69,15 @@ void Workspace::compositeTimeout()
++i ) ++i )
{ {
if( Client* c = findClient( FrameIdMatchPredicate( children[ i ] ))) if( Client* c = findClient( FrameIdMatchPredicate( children[ i ] )))
windows.append( c ); {
if( c->isShown( true ) && c->isOnCurrentDesktop())
windows.append( c );
}
else if( Unmanaged* c = findUnmanaged( HandleMatchPredicate( children[ i ] ))) else if( Unmanaged* c = findUnmanaged( HandleMatchPredicate( children[ i ] )))
windows.append( c ); windows.append( c );
} }
XGCValues val; scene->setWindows( windows );
val.foreground = WhitePixel( display(), DefaultScreen( display())); scene->paint();
val.subwindow_mode = IncludeInferiors;
GC gc = XCreateGC( display(), composite_pixmap, GCForeground | GCSubwindowMode, &val );
XFillRectangle( display(), composite_pixmap, gc, 0, 0, displayWidth(), displayHeight());
for( ToplevelList::ConstIterator it = windows.begin();
it != windows.end();
++it )
{
if( Client* c = dynamic_cast< Client* >( *it ))
{
if( !c->isShown( true ) || !c->isOnCurrentDesktop())
continue;
}
#if 1
(*it)->windowPixmap(); // trigger creation
effects->paintWindow( *it );
#else
QRect r = (*it)->geometry().intersect( QRect( 0, 0, displayWidth(), displayHeight()));
if( !r.isEmpty())
{
XCopyArea( display(), (*it)->windowPixmap(), composite_pixmap, gc,
qMax( 0, -(*it)->x()), qMax( 0, -(*it)->y()), r.width(), r.height(), r.x(), r.y());
}
#endif
}
#if 1
effects->paintWorkspace( this );
#else
XCopyArea( display(), composite_pixmap, rootWindow(), gc, 0, 0, displayWidth(), displayHeight(), 0, 0 );
#endif
XFreeGC( display(), gc );
XFlush( display());
damaged = false;
} }
//**************************************** //****************************************
@ -111,7 +86,7 @@ void Workspace::compositeTimeout()
void Toplevel::setupCompositing() void Toplevel::setupCompositing()
{ {
if( !workspace()->compositing()) if( !compositing())
return; return;
if( damage != None ) if( damage != None )
return; return;
@ -134,14 +109,14 @@ void Toplevel::finishCompositing()
void Toplevel::setDamaged() void Toplevel::setDamaged()
{ {
if( !workspace()->compositing()) if( !compositing())
return; return;
workspace()->setDamaged(); workspace()->setDamaged();
} }
void Toplevel::resetWindowPixmap() void Toplevel::resetWindowPixmap()
{ {
if( !workspace()->compositing()) if( !compositing())
return; return;
if( window_pixmap != None ) if( window_pixmap != None )
XFreePixmap( display(), window_pixmap ); XFreePixmap( display(), window_pixmap );
@ -150,7 +125,7 @@ void Toplevel::resetWindowPixmap()
Pixmap Toplevel::windowPixmap() const Pixmap Toplevel::windowPixmap() const
{ {
if( window_pixmap == None && workspace()->compositing()) if( window_pixmap == None && compositing())
window_pixmap = XCompositeNameWindowPixmap( display(), handle()); window_pixmap = XCompositeNameWindowPixmap( display(), handle());
return window_pixmap; return window_pixmap;
} }

36
scene.cpp Normal file
View file

@ -0,0 +1,36 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "scene_basic.h"
namespace KWinInternal
{
//****************************************
// Scene
//****************************************
Scene::Scene( Workspace* ws )
: wspace( ws )
{
}
Scene::~Scene()
{
}
void Scene::setWindows( const ToplevelList& list )
{
windows = list;
}
Scene* scene;
} // namespace

37
scene.h Normal file
View file

@ -0,0 +1,37 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#ifndef KWIN_SCENE_H
#define KWIN_SCENE_H
#include "utils.h"
namespace KWinInternal
{
class Workspace;
class Scene
{
public:
Scene( Workspace* ws );
virtual ~Scene();
void setWindows( const ToplevelList& list );
virtual void paint() = 0;
protected:
Workspace* wspace;
ToplevelList windows;
};
extern Scene* scene;
} // namespace
#endif

57
scene_basic.cpp Normal file
View file

@ -0,0 +1,57 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "scene_basic.h"
#include "utils.h"
#include "client.h"
namespace KWinInternal
{
//****************************************
// SceneBasic
//****************************************
SceneBasic::SceneBasic( Workspace* ws )
: Scene( ws )
{
}
SceneBasic::~SceneBasic()
{
}
void SceneBasic::paint()
{
Pixmap composite_pixmap = XCreatePixmap( display(), rootWindow(), displayWidth(), displayHeight(), QX11Info::appDepth());
XGCValues val;
val.foreground = WhitePixel( display(), DefaultScreen( display()));
val.subwindow_mode = IncludeInferiors;
GC gc = XCreateGC( display(), composite_pixmap, GCForeground | GCSubwindowMode, &val );
XFillRectangle( display(), composite_pixmap, gc, 0, 0, displayWidth(), displayHeight());
for( ToplevelList::ConstIterator it = windows.begin();
it != windows.end();
++it )
{
QRect r = (*it)->geometry().intersect( QRect( 0, 0, displayWidth(), displayHeight()));
if( !r.isEmpty())
{
XCopyArea( display(), (*it)->windowPixmap(), composite_pixmap, gc,
qMax( 0, -(*it)->x()), qMax( 0, -(*it)->y()), r.width(), r.height(), r.x(), r.y());
}
}
XCopyArea( display(), composite_pixmap, rootWindow(), gc, 0, 0, displayWidth(), displayHeight(), 0, 0 );
XFreeGC( display(), gc );
XFreePixmap( display(), composite_pixmap );
XFlush( display());
}
} // namespace

31
scene_basic.h Normal file
View file

@ -0,0 +1,31 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#ifndef KWIN_SCENE_BASIC_H
#define KWIN_SCENE_BASIC_H
#include "scene.h"
namespace KWinInternal
{
class SceneBasic
: public Scene
{
public:
SceneBasic( Workspace* ws );
virtual ~SceneBasic();
virtual void paint();
};
} // namespace
#endif

20
scene_xrender.cpp Normal file
View file

@ -0,0 +1,20 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "scene_xrender.h"
namespace KWinInternal
{
//****************************************
// SceneXrender
//****************************************
} // namespace

19
scene_xrender.h Normal file
View file

@ -0,0 +1,19 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#ifndef KWIN_SCENE_XRENDER_H
#define KWIN_SCENE_XRENDER_H
namespace KWinInternal
{
} // namespace
#endif

View file

@ -250,6 +250,10 @@ int displayHeight()
return XDisplayHeight( display(), DefaultScreen( display())); return XDisplayHeight( display(), DefaultScreen( display()));
} }
class Scene;
extern Scene* scene;
inline bool compositing() { return scene != NULL; }
// the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
#ifndef UrgencyHint #ifndef UrgencyHint
#define UrgencyHint XUrgencyHint #define UrgencyHint XUrgencyHint

View file

@ -124,7 +124,6 @@ Workspace::Workspace( bool restore )
set_active_client_recursion( 0 ), set_active_client_recursion( 0 ),
block_stacking_updates( 0 ), block_stacking_updates( 0 ),
forced_global_mouse_grab( false ), forced_global_mouse_grab( false ),
composite_pixmap( None ),
damaged( false ) damaged( false )
{ {
new KWinAdaptor( "org.kde.kwin", "/KWin", QDBus::sessionBus(), this ); new KWinAdaptor( "org.kde.kwin", "/KWin", QDBus::sessionBus(), this );

View file

@ -78,8 +78,6 @@ class Workspace : public QObject, public KDecorationDefines
static Workspace * self() { return _self; } static Workspace * self() { return _self; }
bool compositing() const { return composite_pixmap != None; }
bool workspaceEvent( XEvent * ); bool workspaceEvent( XEvent * );
KDecoration* createDecoration( KDecorationBridge* bridge ); KDecoration* createDecoration( KDecorationBridge* bridge );
@ -632,7 +630,6 @@ class Workspace : public QObject, public KDecorationDefines
bool forced_global_mouse_grab; bool forced_global_mouse_grab;
friend class StackingUpdatesBlocker; friend class StackingUpdatesBlocker;
Pixmap composite_pixmap;
bool damaged; bool damaged;
QTimer compositeTimer; QTimer compositeTimer;