00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include "scene.h"
00073
00074 #include <X11/extensions/shape.h>
00075
00076 #include "client.h"
00077 #include "deleted.h"
00078 #include "effects.h"
00079
00080 #include <kephal/screens.h>
00081
00082 namespace KWin
00083 {
00084
00085
00086
00087
00088
00089 Scene* scene;
00090
00091 Scene::Scene( Workspace* ws )
00092 : wspace( ws ),
00093 has_waitSync( false )
00094 {
00095 }
00096
00097 Scene::~Scene()
00098 {
00099 }
00100
00101
00102 void Scene::paintScreen( int* mask, QRegion* region )
00103 {
00104 *mask = ( *region == QRegion( 0, 0, displayWidth(), displayHeight()))
00105 ? 0 : PAINT_SCREEN_REGION;
00106 updateTimeDiff();
00107
00108 static_cast<EffectsHandlerImpl*>(effects)->startPaint();
00109 ScreenPrePaintData pdata;
00110 pdata.mask = *mask;
00111 pdata.paint = *region;
00112 effects->prePaintScreen( pdata, time_diff );
00113 *mask = pdata.mask;
00114 *region = pdata.paint;
00115 if( *mask & ( PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS ))
00116 {
00117
00118 *mask &= ~PAINT_SCREEN_REGION;
00119 *region = infiniteRegion();
00120 }
00121 else if( *mask & PAINT_SCREEN_REGION )
00122 {
00123 *region &= QRegion( 0, 0, displayWidth(), displayHeight());
00124 }
00125 else
00126 {
00127 *region = QRegion( 0, 0, displayWidth(), displayHeight());
00128 }
00129 painted_region = *region;
00130 if( *mask & PAINT_SCREEN_BACKGROUND_FIRST )
00131 paintBackground( *region );
00132 ScreenPaintData data;
00133 effects->paintScreen( *mask, *region, data );
00134 foreach( Window* w, stacking_order )
00135 effects->postPaintWindow( effectWindow( w ));
00136 effects->postPaintScreen();
00137 *region |= painted_region;
00138
00139 *region &= QRegion( 0, 0, displayWidth(), displayHeight());
00140
00141 Q_ASSERT( !PaintClipper::clip());
00142 }
00143
00144
00145 void Scene::updateTimeDiff()
00146 {
00147 if( last_time.isNull())
00148 {
00149
00150
00151
00152
00153 time_diff = 1;
00154 }
00155 else
00156 time_diff = last_time.elapsed();
00157 if( time_diff < 0 )
00158 time_diff = 1;
00159 last_time.start();;
00160 }
00161
00162
00163 void Scene::idle()
00164 {
00165
00166 last_time = QTime();
00167 }
00168
00169
00170 void Scene::finalPaintScreen( int mask, QRegion region, ScreenPaintData& data )
00171 {
00172 if( mask & ( PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS ))
00173 paintGenericScreen( mask, data );
00174 else
00175 paintSimpleScreen( mask, region );
00176 }
00177
00178
00179
00180 void Scene::paintGenericScreen( int orig_mask, ScreenPaintData )
00181 {
00182 if( !( orig_mask & PAINT_SCREEN_BACKGROUND_FIRST ))
00183 paintBackground( infiniteRegion());
00184 QList< Phase2Data > phase2;
00185 foreach( Window* w, stacking_order )
00186 {
00187 WindowPrePaintData data;
00188 data.mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
00189 w->resetPaintingEnabled();
00190 data.paint = infiniteRegion();
00191 data.clip = QRegion();
00192 data.quads = w->buildQuads();
00193
00194 effects->prePaintWindow( effectWindow( w ), data, time_diff );
00195 #ifndef NDEBUG
00196 foreach( const WindowQuad &q, data.quads )
00197 if( q.isTransformed())
00198 kFatal( 1212 ) << "Pre-paint calls are not allowed to transform quads!" ;
00199 #endif
00200 if( !w->isPaintingEnabled())
00201 continue;
00202 phase2.append( Phase2Data( w, infiniteRegion(), data.clip, data.mask, data.quads ));
00203
00204 w->suspendUnredirect( data.mask
00205 & ( PAINT_WINDOW_TRANSLUCENT | PAINT_SCREEN_TRANSFORMED | PAINT_WINDOW_TRANSFORMED ));
00206 }
00207
00208 foreach( const Phase2Data &d, phase2 )
00209 paintWindow( d.window, d.mask, d.region, d.quads );
00210 }
00211
00212
00213
00214
00215 void Scene::paintSimpleScreen( int orig_mask, QRegion region )
00216 {
00217
00218
00219 assert(( orig_mask & ( PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED
00220 | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS
00221 | PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_OPAQUE )) == 0 );
00222 QHash< Window*, Phase2Data > phase2data;
00223
00224
00225 for( int i = stacking_order.count() - 1;
00226 i >= 0;
00227 --i )
00228 {
00229 Window* w = stacking_order[ i ];
00230 WindowPrePaintData data;
00231 data.mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
00232 w->resetPaintingEnabled();
00233 data.paint = region;
00234 data.clip = w->isOpaque() ? w->shape().translated( w->x(), w->y()) : QRegion();
00235 data.quads = w->buildQuads();
00236
00237 effects->prePaintWindow( effectWindow( w ), data, time_diff );
00238 #ifndef NDEBUG
00239 foreach( const WindowQuad &q, data.quads )
00240 if( q.isTransformed())
00241 kFatal( 1212 ) << "Pre-paint calls are not allowed to transform quads!" ;
00242 if( data.mask & PAINT_WINDOW_TRANSFORMED )
00243 kFatal( 1212 ) << "PAINT_WINDOW_TRANSFORMED without PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS!";
00244 #endif
00245 if( !w->isPaintingEnabled())
00246 {
00247 w->suspendUnredirect( true );
00248 continue;
00249 }
00250 if( data.paint != region )
00251 painted_region |= data.paint;
00252
00253 phase2data[w] = Phase2Data( w, data.paint, data.clip, data.mask, data.quads );
00254
00255 w->suspendUnredirect( data.mask & PAINT_WINDOW_TRANSLUCENT );
00256 }
00257
00258
00259
00260
00261 QRegion allclips;
00262 for( int i = stacking_order.count() - 1; i >= 0; --i )
00263 {
00264 Window* w = stacking_order[ i ];
00265 if( !phase2data.contains( w ))
00266 continue;
00267 Phase2Data d = phase2data[w];
00268
00269 d.region = painted_region - allclips;
00270 allclips |= d.clip;
00271 if( d.mask & PAINT_WINDOW_TRANSLUCENT )
00272 {
00273
00274
00275
00276 phase2data[w].region = d.region;
00277 }
00278 else
00279 {
00280
00281 paintWindow( d.window, d.mask, d.region, d.quads );
00282 }
00283 }
00284
00285 if( !( orig_mask & PAINT_SCREEN_BACKGROUND_FIRST ))
00286 paintBackground( painted_region - allclips );
00287
00288 for( int i = 0; i < stacking_order.count(); i++ )
00289 {
00290 Window* w = stacking_order[ i ];
00291 if( !phase2data.contains( w ))
00292 continue;
00293 Phase2Data d = phase2data[w];
00294 if( d.mask & PAINT_WINDOW_TRANSLUCENT )
00295 paintWindow( d.window, d.mask, d.region, d.quads );
00296 }
00297 }
00298
00299 void Scene::paintWindow( Window* w, int mask, QRegion region, WindowQuadList quads )
00300 {
00301
00302 region &= QRect( 0, 0, displayWidth(), displayHeight());
00303 if( region.isEmpty())
00304 return;
00305
00306 WindowPaintData data( w->window()->effectWindow());
00307 data.quads = quads;
00308 effects->paintWindow( effectWindow( w ), mask, region, data );
00309 }
00310
00311
00312 void Scene::finalPaintWindow( EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data )
00313 {
00314 effects->drawWindow( w, mask, region, data );
00315 }
00316
00317
00318 void Scene::finalDrawWindow( EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data )
00319 {
00320 w->sceneWindow()->performPaint( mask, region, data );
00321 }
00322
00323 QList< QPoint > Scene::selfCheckPoints() const
00324 {
00325 QList< QPoint > ret;
00326
00327
00328
00329 for( int screen = 0;
00330 screen < Kephal::ScreenUtils::numScreens();
00331 ++screen )
00332 {
00333 ret.append( Kephal::ScreenUtils::screenGeometry( screen ).topLeft());
00334 ret.append( Kephal::ScreenUtils::screenGeometry( screen ).bottomRight() + QPoint( -3 + 1, -2 + 1 )
00335 + QPoint( -1, 0 ));
00336 }
00337 return ret;
00338 }
00339
00340
00341
00342
00343
00344 Scene::Window::Window( Toplevel * c )
00345 : toplevel( c )
00346 , filter( ImageFilterFast )
00347 , disable_painting( 0 )
00348 , shape_valid( false )
00349 , cached_quad_list( NULL )
00350 {
00351 }
00352
00353 Scene::Window::~Window()
00354 {
00355 delete cached_quad_list;
00356 }
00357
00358 void Scene::Window::discardShape()
00359 {
00360
00361
00362 shape_valid = false;
00363 delete cached_quad_list;
00364 cached_quad_list = NULL;
00365 }
00366
00367
00368
00369 QRegion Scene::Window::shape() const
00370 {
00371 if( !shape_valid )
00372 {
00373 Client* c = dynamic_cast< Client* >( toplevel );
00374 if( toplevel->shape() || ( c != NULL && !c->mask().isEmpty()))
00375 {
00376 int count, order;
00377 XRectangle* rects = XShapeGetRectangles( display(), toplevel->frameId(),
00378 ShapeBounding, &count, &order );
00379 if(rects)
00380 {
00381 shape_region = QRegion();
00382 for( int i = 0;
00383 i < count;
00384 ++i )
00385 shape_region += QRegion( rects[ i ].x, rects[ i ].y,
00386 rects[ i ].width, rects[ i ].height );
00387 XFree(rects);
00388
00389 shape_region &= QRegion( 0, 0, width(), height());
00390 }
00391 else
00392 shape_region = QRegion();
00393 }
00394 else
00395 shape_region = QRegion( 0, 0, width(), height());
00396 shape_valid = true;
00397 }
00398 return shape_region;
00399 }
00400
00401 bool Scene::Window::isVisible() const
00402 {
00403 if( dynamic_cast< Deleted* >( toplevel ) != NULL )
00404 return false;
00405 if( !toplevel->isOnCurrentDesktop())
00406 return false;
00407 if( Client* c = dynamic_cast< Client* >( toplevel ))
00408 return c->isShown( true );
00409 return true;
00410
00411 return !toplevel->geometry()
00412 .intersected( QRect( 0, 0, displayWidth(), displayHeight()))
00413 .isEmpty();
00414 }
00415
00416 bool Scene::Window::isOpaque() const
00417 {
00418 return toplevel->opacity() == 1.0 && !toplevel->hasAlpha();
00419 }
00420
00421 bool Scene::Window::isPaintingEnabled() const
00422 {
00423 return !disable_painting;
00424 }
00425
00426 void Scene::Window::resetPaintingEnabled()
00427 {
00428 disable_painting = 0;
00429 if( dynamic_cast< Deleted* >( toplevel ) != NULL )
00430 disable_painting |= PAINT_DISABLED_BY_DELETE;
00431 if( !toplevel->isOnCurrentDesktop())
00432 disable_painting |= PAINT_DISABLED_BY_DESKTOP;
00433 if( Client* c = dynamic_cast< Client* >( toplevel ))
00434 {
00435 if( c->isMinimized() )
00436 disable_painting |= PAINT_DISABLED_BY_MINIMIZE;
00437 if( c->isHiddenInternal())
00438 disable_painting |= PAINT_DISABLED;
00439 }
00440 }
00441
00442 void Scene::Window::enablePainting( int reason )
00443 {
00444 disable_painting &= ~reason;
00445 }
00446
00447 void Scene::Window::disablePainting( int reason )
00448 {
00449 disable_painting |= reason;
00450 }
00451
00452 WindowQuadList Scene::Window::buildQuads( bool force ) const
00453 {
00454 if( cached_quad_list != NULL && !force )
00455 return *cached_quad_list;
00456 WindowQuadList ret;
00457 if( toplevel->clientPos() == QPoint( 0, 0 ) && toplevel->clientSize() == toplevel->size())
00458 ret = makeQuads( WindowQuadContents, shape());
00459 else
00460 {
00461 QRegion contents = shape() & QRect( toplevel->clientPos(), toplevel->clientSize());
00462 QRegion decoration = shape() - contents;
00463 ret = makeQuads( WindowQuadContents, contents );
00464 ret += makeQuads( WindowQuadDecoration, decoration );
00465 }
00466 effects->buildQuads( static_cast<Client*>( toplevel )->effectWindow(), ret );
00467 cached_quad_list = new WindowQuadList( ret );
00468 return ret;
00469 }
00470
00471 WindowQuadList Scene::Window::makeQuads( WindowQuadType type, const QRegion& reg ) const
00472 {
00473 WindowQuadList ret;
00474 foreach( const QRect &r, reg.rects())
00475 {
00476 WindowQuad quad( type );
00477
00478 quad[ 0 ] = WindowVertex( r.x(), r.y(), r.x(), r.y());
00479 quad[ 1 ] = WindowVertex( r.x() + r.width(), r.y(), r.x() + r.width(), r.y());
00480 quad[ 2 ] = WindowVertex( r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height());
00481 quad[ 3 ] = WindowVertex( r.x(), r.y() + r.height(), r.x(), r.y() + r.height());
00482 ret.append( quad );
00483 }
00484 return ret;
00485 }
00486
00487 }