2006-07-05 12:30:03 +00:00
|
|
|
/*****************************************************************
|
|
|
|
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.
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
/*
|
|
|
|
(NOTE: The compositing code is work in progress. As such this design
|
|
|
|
documentation may get outdated in some areas.)
|
|
|
|
|
|
|
|
The base class for compositing, implementing shared functionality
|
|
|
|
between the OpenGL and XRender backends.
|
|
|
|
|
|
|
|
Design:
|
|
|
|
|
|
|
|
When compositing is turned on, XComposite extension is used to redirect
|
|
|
|
drawing of windows to pixmaps and XDamage extension is used to get informed
|
|
|
|
about damage (changes) to window contents. This code is mostly in composite.cpp .
|
|
|
|
|
|
|
|
Workspace::performCompositing() starts one painting pass. Painting is done
|
|
|
|
by painting the screen, which in turn paints every window. Painting can be affected
|
|
|
|
using effects, which are chained. E.g. painting a screen means that actually
|
|
|
|
paintScreen() of the first effect is called, which possibly does modifications
|
|
|
|
and calls next effect's paintScreen() and so on, until Scene::finalPaintScreen()
|
|
|
|
is called.
|
|
|
|
|
|
|
|
There are 3 phases of every paint (not necessarily done together):
|
|
|
|
The pre-paint phase, the paint phase and the post-paint phase.
|
|
|
|
|
|
|
|
The pre-paint phase is used to find out about how the painting will be actually
|
|
|
|
done (i.e. what the effects will do). For example when only a part of the screen
|
|
|
|
needs to be updated and no effect will do any transformation it is possible to use
|
|
|
|
an optimized paint function. How the painting will be done is controlled
|
|
|
|
by the mask argument, see PAINT_WINDOW_* and PAINT_SCREEN_* flags in scene.h .
|
|
|
|
For example an effect that decides to paint a normal windows as translucent
|
|
|
|
will need to modify the mask in its prePaintWindow() to include
|
|
|
|
the PAINT_WINDOW_TRANSLUCENT flag. The paintWindow() function will then get
|
|
|
|
the mask with this flag turned on and will also paint using transparency.
|
|
|
|
|
|
|
|
The paint pass does the actual painting, based on the information collected
|
|
|
|
using the pre-paint pass. After running through the effects' paintScreen()
|
|
|
|
either paintGenericScreen() or optimized paintSimpleScreen() are called.
|
|
|
|
Those call paintWindow() on windows (not necessarily all), possibly using
|
|
|
|
clipping to optimize performance and calling paintWindow() first with only
|
|
|
|
PAINT_WINDOW_OPAQUE to paint the opaque parts and then later
|
|
|
|
with PAINT_WINDOW_TRANSLUCENT to paint the transparent parts. Function
|
|
|
|
paintWindow() again goes through effects' paintWindow() until
|
|
|
|
finalPaintWindow() is called, which calls the window's performPaint() to
|
|
|
|
do the actual painting.
|
|
|
|
|
|
|
|
The post-paint can be used for cleanups and is also used for scheduling
|
|
|
|
repaints during the next painting pass for animations. Effects wanting to
|
|
|
|
repaint certain parts can manually damage them during post-paint and repaint
|
|
|
|
of these parts will be done during the next paint pass.
|
|
|
|
|
|
|
|
|
|
|
|
Various notes:
|
|
|
|
|
|
|
|
- When the screen or a window are transformed (*_TRANSFORMED flag), clipping
|
|
|
|
and similar optimizations are not done (too complicated), so in such cases
|
|
|
|
infiniteRegion() should be always used. Make sure not to make any transformations
|
|
|
|
of such regions.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-10-24 19:17:48 +00:00
|
|
|
#include "scene.h"
|
2006-10-15 08:58:38 +00:00
|
|
|
|
|
|
|
#include <X11/extensions/shape.h>
|
2006-07-05 12:30:03 +00:00
|
|
|
|
2006-10-24 19:17:48 +00:00
|
|
|
#include "client.h"
|
2006-10-16 21:06:34 +00:00
|
|
|
#include "effects.h"
|
|
|
|
|
2006-07-05 12:30:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Scene
|
|
|
|
//****************************************
|
|
|
|
|
2006-10-15 08:58:38 +00:00
|
|
|
Scene* scene;
|
|
|
|
|
2006-07-05 12:30:03 +00:00
|
|
|
Scene::Scene( Workspace* ws )
|
|
|
|
: wspace( ws )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene()
|
|
|
|
{
|
|
|
|
}
|
2006-10-16 21:06:34 +00:00
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
void Scene::initPaint()
|
2006-10-29 19:07:10 +00:00
|
|
|
{
|
|
|
|
effects->startPaint();
|
|
|
|
// do the rest of prepaint pass together with paint pass
|
|
|
|
}
|
|
|
|
|
2006-10-24 13:38:31 +00:00
|
|
|
// returns mask and possibly modified region
|
|
|
|
void Scene::paintScreen( int* mask, QRegion* region )
|
|
|
|
{
|
|
|
|
*mask = ( *region == QRegion( 0, 0, displayWidth(), displayHeight()))
|
|
|
|
? 0 : PAINT_SCREEN_REGION;
|
2006-10-24 19:17:48 +00:00
|
|
|
updateTimeDiff();
|
2006-10-24 13:38:31 +00:00
|
|
|
// preparation step
|
2006-10-29 19:06:32 +00:00
|
|
|
effects->prePaintScreen( mask, region, time_diff );
|
2006-10-29 19:23:45 +00:00
|
|
|
// optimized painting is not possible with transformations
|
2006-10-24 13:38:31 +00:00
|
|
|
if( *mask & ( PAINT_SCREEN_TRANSFORMED | PAINT_WINDOW_TRANSFORMED ))
|
|
|
|
*mask &= ~PAINT_SCREEN_REGION;
|
|
|
|
ScreenPaintData data;
|
2006-10-29 19:06:32 +00:00
|
|
|
effects->paintScreen( *mask, *region, data );
|
2006-10-24 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Compute time since the last painting pass.
|
2006-10-24 19:17:48 +00:00
|
|
|
void Scene::updateTimeDiff()
|
|
|
|
{
|
|
|
|
if( last_time.isNull())
|
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// Painting has been idle (optimized out) for some time,
|
|
|
|
// which means time_diff would be huge and would break animations.
|
|
|
|
// Simply set it to zero.
|
2006-10-24 19:17:48 +00:00
|
|
|
time_diff = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
time_diff = last_time.elapsed();
|
2006-10-29 19:23:45 +00:00
|
|
|
if( time_diff < 0 ) // check time rollback
|
2006-10-24 19:17:48 +00:00
|
|
|
time_diff = 0;
|
|
|
|
last_time.start();;
|
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Painting pass is optimized away.
|
2006-10-24 19:17:48 +00:00
|
|
|
void Scene::idle()
|
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// Don't break time since last paint for the next pass.
|
2006-10-24 19:17:48 +00:00
|
|
|
last_time = QTime();
|
|
|
|
}
|
|
|
|
|
2006-10-16 21:06:34 +00:00
|
|
|
// the function that'll be eventually called by paintScreen() above
|
2006-10-29 19:06:32 +00:00
|
|
|
void Scene::finalPaintScreen( int mask, QRegion region, ScreenPaintData& data )
|
2006-10-16 21:06:34 +00:00
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
if( mask & PAINT_SCREEN_REGION ) // can do optimized case?
|
2006-10-29 19:06:32 +00:00
|
|
|
paintSimpleScreen( mask, region );
|
2006-10-16 21:06:34 +00:00
|
|
|
else
|
2006-10-29 19:06:32 +00:00
|
|
|
paintGenericScreen( mask, data );
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
2006-10-21 18:07:00 +00:00
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// The generic painting code that can handle even transformations.
|
|
|
|
// It simply paints bottom-to-top.
|
2006-10-22 10:15:19 +00:00
|
|
|
void Scene::paintGenericScreen( int orig_mask, ScreenPaintData )
|
2006-10-16 21:06:34 +00:00
|
|
|
{
|
|
|
|
paintBackground( infiniteRegion());
|
|
|
|
foreach( Window* w, stacking_order ) // bottom to top
|
|
|
|
{
|
|
|
|
if( !w->isVisible())
|
|
|
|
continue;
|
2006-10-22 10:15:19 +00:00
|
|
|
int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
|
|
|
|
QRegion damage = infiniteRegion();
|
|
|
|
// preparation step
|
2006-10-29 19:06:32 +00:00
|
|
|
effects->prePaintWindow( w, &mask, &damage, time_diff );
|
2006-10-22 10:15:19 +00:00
|
|
|
paintWindow( w, mask, damage );
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// The optimized case without any transformations at all.
|
|
|
|
// It can paint only the requested region and can use clipping
|
|
|
|
// to reduce painting and improve performance.
|
2006-10-22 10:15:19 +00:00
|
|
|
void Scene::paintSimpleScreen( int orig_mask, QRegion region )
|
2006-10-16 21:06:34 +00:00
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// TODO PAINT_WINDOW_* flags don't belong here, that's why it's in the assert,
|
|
|
|
// perhaps the two enums should be separated
|
2006-10-22 10:15:19 +00:00
|
|
|
assert(( orig_mask & ( PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED
|
2006-10-21 18:07:00 +00:00
|
|
|
| PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_OPAQUE )) == 0 );
|
2006-10-16 21:06:34 +00:00
|
|
|
QList< Phase2Data > phase2;
|
|
|
|
// Draw each opaque window top to bottom, subtracting the bounding rect of
|
|
|
|
// each window from the clip region after it's been drawn.
|
|
|
|
for( int i = stacking_order.count() - 1; // top to bottom
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
|
|
|
{
|
|
|
|
Window* w = stacking_order[ i ];
|
|
|
|
if( !w->isVisible())
|
|
|
|
continue;
|
|
|
|
if( region.isEmpty()) // completely clipped
|
|
|
|
continue;
|
2006-10-22 10:15:19 +00:00
|
|
|
int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
|
|
|
|
QRegion damage = region;
|
|
|
|
// preparation step
|
2006-10-29 19:06:32 +00:00
|
|
|
effects->prePaintWindow( w, &mask, &damage, time_diff );
|
2006-10-29 19:23:45 +00:00
|
|
|
// If the window is transparent, the transparent part will be done
|
|
|
|
// in the 2nd pass.
|
2006-10-22 10:15:19 +00:00
|
|
|
if( mask & PAINT_WINDOW_TRANSLUCENT )
|
|
|
|
phase2.prepend( Phase2Data( w, region, mask ));
|
|
|
|
if( mask & PAINT_WINDOW_OPAQUE )
|
2006-10-16 21:06:34 +00:00
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
paintWindow( w, mask, region );
|
2006-10-29 19:23:45 +00:00
|
|
|
// If the window is not transparent at all, it can clip windows below.
|
|
|
|
if( ( mask & PAINT_WINDOW_TRANSLUCENT ) == 0 )
|
2006-10-22 10:15:19 +00:00
|
|
|
region -= w->shape().translated( w->x(), w->y());
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fill any areas of the root window not covered by windows
|
|
|
|
paintBackground( region );
|
|
|
|
// Now walk the list bottom to top, drawing translucent windows.
|
|
|
|
// That we draw bottom to top is important now since we're drawing translucent objects
|
|
|
|
// and also are clipping only by opaque windows.
|
|
|
|
foreach( Phase2Data d, phase2 )
|
|
|
|
{
|
|
|
|
Window* w = d.window;
|
2006-10-22 10:15:19 +00:00
|
|
|
paintWindow( w, d.mask, d.region );
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::paintWindow( Window* w, int mask, QRegion region )
|
|
|
|
{
|
|
|
|
WindowPaintData data;
|
2006-10-22 10:15:19 +00:00
|
|
|
data.opacity = w->window()->opacity();
|
2006-10-29 19:06:32 +00:00
|
|
|
effects->paintWindow( w, mask, region, data );
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the function that'll be eventually called by paintWindow() above
|
2006-10-29 19:06:32 +00:00
|
|
|
void Scene::finalPaintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
|
2006-10-16 21:06:34 +00:00
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
w->performPaint( mask, region, data );
|
2006-10-16 21:06:34 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:07:10 +00:00
|
|
|
void Scene::postPaint()
|
|
|
|
{
|
|
|
|
effects->postPaintScreen();
|
|
|
|
foreach( Window* w, stacking_order )
|
|
|
|
effects->postPaintWindow( w );
|
2006-10-29 19:23:45 +00:00
|
|
|
// do cleanup
|
2006-10-29 19:07:10 +00:00
|
|
|
stacking_order.clear();
|
|
|
|
}
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
//****************************************
|
|
|
|
// Scene::Window
|
|
|
|
//****************************************
|
|
|
|
|
2006-10-15 08:58:38 +00:00
|
|
|
Scene::Window::Window( Toplevel * c )
|
|
|
|
: toplevel( c )
|
|
|
|
, shape_valid( false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
Scene::Window::~Window()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-16 21:06:34 +00:00
|
|
|
void Scene::Window::free()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-15 08:58:38 +00:00
|
|
|
void Scene::Window::discardShape()
|
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// it is created on-demand and cached, simply
|
|
|
|
// reset the flag
|
2006-10-15 08:58:38 +00:00
|
|
|
shape_valid = false;
|
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Find out the shape of the window using the XShape extension
|
|
|
|
// or if not shape is set then simply it's the window geometry.
|
2006-10-15 08:58:38 +00:00
|
|
|
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
|
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
return true; // TODO there may be transformations, so always true for now
|
2006-10-15 08:58:38 +00:00
|
|
|
// 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();
|
|
|
|
}
|
2006-07-05 12:30:03 +00:00
|
|
|
|
|
|
|
} // namespace
|