Remove the WrapperEffect hack, it's ugly.

svn path=/branches/work/kwin_composite/; revision=600155
This commit is contained in:
Luboš Luňák 2006-10-29 19:06:32 +00:00
parent d4be8267d5
commit 6b41c062c8
5 changed files with 65 additions and 108 deletions

View file

@ -156,6 +156,7 @@ void Workspace::compositeTimeout()
else if( Unmanaged* c = findUnmanaged( HandleMatchPredicate( children[ i ] ))) else if( Unmanaged* c = findUnmanaged( HandleMatchPredicate( children[ i ] )))
windows.append( c ); windows.append( c );
} }
effects->startPaint();
// TODO when effects cause damage, it should be only enqueued for next repaint // TODO when effects cause damage, it should be only enqueued for next repaint
QRegion r = damage_region; QRegion r = damage_region;
damage_region = QRegion(); damage_region = QRegion();

View file

@ -39,22 +39,22 @@ void Effect::windowDeleted( Toplevel* )
void Effect::prePaintScreen( int* mask, QRegion* region, int time ) void Effect::prePaintScreen( int* mask, QRegion* region, int time )
{ {
effects->nextPrePaintScreen( mask, region, time ); effects->prePaintScreen( mask, region, time );
} }
void Effect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) void Effect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
{ {
effects->nextPaintScreen( mask, region, data ); effects->paintScreen( mask, region, data );
} }
void Effect::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time ) void Effect::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time )
{ {
effects->nextPrePaintWindow( w, mask, region, time ); effects->prePaintWindow( w, mask, region, time );
} }
void Effect::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void Effect::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
{ {
effects->nextPaintWindow( w, mask, region, data ); effects->paintWindow( w, mask, region, data );
} }
void MakeHalfTransparent::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time ) void MakeHalfTransparent::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time )
@ -65,7 +65,7 @@ void MakeHalfTransparent::prePaintWindow( Scene::Window* w, int* mask, QRegion*
*mask |= Scene::PAINT_WINDOW_TRANSLUCENT; *mask |= Scene::PAINT_WINDOW_TRANSLUCENT;
*mask &= ~Scene::PAINT_WINDOW_OPAQUE; *mask &= ~Scene::PAINT_WINDOW_OPAQUE;
} }
effects->nextPrePaintWindow( w, mask, region, time ); effects->prePaintWindow( w, mask, region, time );
} }
void MakeHalfTransparent::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void MakeHalfTransparent::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
@ -75,7 +75,7 @@ void MakeHalfTransparent::paintWindow( Scene::Window* w, int mask, QRegion regio
data.opacity *= 0.8; data.opacity *= 0.8;
if( c->isMove() || c->isResize()) if( c->isMove() || c->isResize())
data.opacity *= 0.5; data.opacity *= 0.5;
effects->nextPaintWindow( w, mask, region, data ); effects->paintWindow( w, mask, region, data );
} }
void MakeHalfTransparent::windowUserMovedResized( Toplevel* c, bool first, bool last ) void MakeHalfTransparent::windowUserMovedResized( Toplevel* c, bool first, bool last )
@ -96,21 +96,21 @@ void ShakyMove::prePaintScreen( int* mask, QRegion* region, int time )
{ {
if( !windows.isEmpty()) if( !windows.isEmpty())
*mask |= Scene::PAINT_WINDOW_TRANSFORMED; *mask |= Scene::PAINT_WINDOW_TRANSFORMED;
effects->nextPrePaintScreen( mask, region, time ); effects->prePaintScreen( mask, region, time );
} }
void ShakyMove::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time ) void ShakyMove::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time )
{ {
if( windows.contains( w->window())) if( windows.contains( w->window()))
*mask |= Scene::PAINT_WINDOW_TRANSFORMED; *mask |= Scene::PAINT_WINDOW_TRANSFORMED;
effects->nextPrePaintWindow( w, mask, region, time ); effects->prePaintWindow( w, mask, region, time );
} }
void ShakyMove::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void ShakyMove::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
{ {
if( windows.contains( w->window())) if( windows.contains( w->window()))
data.xTranslate += shaky_diff[ windows[ w->window() ]]; data.xTranslate += shaky_diff[ windows[ w->window() ]];
effects->nextPaintWindow( w, mask, region, data ); effects->paintWindow( w, mask, region, data );
} }
void ShakyMove::windowUserMovedResized( Toplevel* c, bool first, bool last ) void ShakyMove::windowUserMovedResized( Toplevel* c, bool first, bool last )
@ -201,14 +201,14 @@ void ShiftWorkspaceUp::prePaintScreen( int* mask, QRegion* region, int time )
} }
if( diff != 0 ) if( diff != 0 )
*mask |= Scene::PAINT_SCREEN_TRANSFORMED; *mask |= Scene::PAINT_SCREEN_TRANSFORMED;
effects->nextPrePaintScreen( mask, region, time ); effects->prePaintScreen( mask, region, time );
} }
void ShiftWorkspaceUp::paintScreen( int mask, QRegion region, ScreenPaintData& data ) void ShiftWorkspaceUp::paintScreen( int mask, QRegion region, ScreenPaintData& data )
{ {
if( diff != 0 ) if( diff != 0 )
data.yTranslate -= diff / 100; data.yTranslate -= diff / 100;
effects->nextPaintScreen( mask, region, data ); effects->paintScreen( mask, region, data );
} }
void ShiftWorkspaceUp::tick() void ShiftWorkspaceUp::tick()
@ -234,7 +234,7 @@ void FadeIn::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int t
else else
windows.remove( w->window()); windows.remove( w->window());
} }
effects->nextPrePaintWindow( w, mask, region, time ); effects->prePaintWindow( w, mask, region, time );
} }
void FadeIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void FadeIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
@ -243,7 +243,7 @@ void FadeIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPain
{ {
data.opacity *= windows[ w->window()]; data.opacity *= windows[ w->window()];
} }
effects->nextPaintWindow( w, mask, region, data ); effects->paintWindow( w, mask, region, data );
} }
void FadeIn::windowAdded( Toplevel* c ) void FadeIn::windowAdded( Toplevel* c )
@ -277,7 +277,7 @@ void ScaleIn::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int
else else
windows.remove( w->window()); windows.remove( w->window());
} }
effects->nextPrePaintWindow( w, mask, region, time ); effects->prePaintWindow( w, mask, region, time );
} }
void ScaleIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void ScaleIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
@ -289,7 +289,7 @@ void ScaleIn::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPai
data.xTranslate += w->window()->width() / 2 * ( 1 - windows[ w->window()] ); data.xTranslate += w->window()->width() / 2 * ( 1 - windows[ w->window()] );
data.yTranslate += w->window()->height() / 2 * ( 1 - windows[ w->window()] ); data.yTranslate += w->window()->height() / 2 * ( 1 - windows[ w->window()] );
} }
effects->nextPaintWindow( w, mask, region, data ); effects->paintWindow( w, mask, region, data );
} }
void ScaleIn::windowAdded( Toplevel* c ) void ScaleIn::windowAdded( Toplevel* c )
@ -349,61 +349,54 @@ void EffectsHandler::windowDeleted( Toplevel* c )
e->windowDeleted( c ); e->windowDeleted( c );
} }
void EffectsHandler::prePaintScreen( int* mask, QRegion* region, int time, Effect* final ) // start another painting pass
void EffectsHandler::startPaint()
{ {
assert( current_paint_screen == 0 ); assert( current_paint_screen == 0 );
effects.append( final );
nextPrePaintScreen( mask, region, time );
effects.pop_back();
}
void EffectsHandler::paintScreen( int mask, QRegion region, ScreenPaintData& data, Effect* final )
{
assert( current_paint_screen == 0 );
effects.append( final );
nextPaintScreen( mask, region, data );
effects.pop_back();
}
void EffectsHandler::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time, Effect* final )
{
assert( current_paint_window == 0 ); assert( current_paint_window == 0 );
effects.append( final );
nextPrePaintWindow( w, mask, region, time );
effects.pop_back();
}
void EffectsHandler::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data, Effect* final )
{
assert( current_paint_window == 0 );
effects.append( final );
nextPaintWindow( w, mask, region, data );
effects.pop_back();
} }
// the idea is that effects call this function again which calls the next one // the idea is that effects call this function again which calls the next one
void EffectsHandler::nextPrePaintScreen( int* mask, QRegion* region, int time ) void EffectsHandler::prePaintScreen( int* mask, QRegion* region, int time )
{ {
effects[ current_paint_screen++ ]->prePaintScreen( mask, region, time ); if( current_paint_screen < effects.size() - 1 )
--current_paint_screen; {
effects[ current_paint_screen++ ]->prePaintScreen( mask, region, time );
--current_paint_screen;
}
// no special final code
} }
void EffectsHandler::nextPaintScreen( int mask, QRegion region, ScreenPaintData& data ) void EffectsHandler::paintScreen( int mask, QRegion region, ScreenPaintData& data )
{ {
effects[ current_paint_screen++ ]->paintScreen( mask, region, data ); if( current_paint_screen < effects.size() - 1 )
--current_paint_screen; {
effects[ current_paint_screen++ ]->paintScreen( mask, region, data );
--current_paint_screen;
}
else
scene->finalPaintScreen( mask, region, data );
} }
void EffectsHandler::nextPrePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time ) void EffectsHandler::prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time )
{ {
effects[ current_paint_window++ ]->prePaintWindow( w, mask, region, time ); if( current_paint_window < effects.size() - 1 )
--current_paint_window; {
effects[ current_paint_window++ ]->prePaintWindow( w, mask, region, time );
--current_paint_window;
}
// no special final code
} }
void EffectsHandler::nextPaintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void EffectsHandler::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
{ {
effects[ current_paint_window++ ]->paintWindow( w, mask, region, data ); if( current_paint_window < effects.size() - 1 )
--current_paint_window; {
effects[ current_paint_window++ ]->paintWindow( w, mask, region, data );
--current_paint_window;
}
else
scene->finalPaintWindow( w, mask, region, data );
} }
EffectsHandler* effects; EffectsHandler* effects;

View file

@ -64,15 +64,12 @@ class EffectsHandler
EffectsHandler( Workspace* ws ); EffectsHandler( Workspace* ws );
~EffectsHandler(); ~EffectsHandler();
// for use by effects // for use by effects
void nextPrePaintScreen( int* mask, QRegion* region, int time ); void prePaintScreen( int* mask, QRegion* region, int time );
void nextPaintScreen( int mask, QRegion region, ScreenPaintData& data ); void paintScreen( int mask, QRegion region, ScreenPaintData& data );
void nextPrePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time ); void prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time );
void nextPaintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ); void paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data );
// internal (used by kwin core or compositing code) // internal (used by kwin core or compositing code)
void prePaintScreen( int* mask, QRegion* region, int time, Effect* final ); void startPaint();
void paintScreen( int mask, QRegion region, ScreenPaintData& data, Effect* final );
void prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time, Effect* final );
void paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data, Effect* final );
void windowUserMovedResized( Toplevel* c, bool first, bool last ); void windowUserMovedResized( Toplevel* c, bool first, bool last );
void windowAdded( Toplevel* c ); void windowAdded( Toplevel* c );
void windowDeleted( Toplevel* c ); void windowDeleted( Toplevel* c );
@ -164,20 +161,6 @@ class ScaleIn
QMap< const Toplevel*, double > windows; QMap< const Toplevel*, double > windows;
}; };
// a special effect that is last in the order that'll actually call the painting functions
// TODO this should actually be in scene.h
class Scene::WrapperEffect
: public Effect
{
public:
virtual ~WrapperEffect();
virtual void prePaintScreen( int* mask, QRegion* region, int time );
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void prePaintWindow( Scene::Window* w, int* mask, QRegion* region, int time );
virtual void paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data );
};
inline inline
WindowPaintData::WindowPaintData() WindowPaintData::WindowPaintData()
: opacity( 1.0 ) : opacity( 1.0 )

View file

@ -18,14 +18,6 @@ License. See the file "COPYING" for the exact licensing terms.
namespace KWinInternal namespace KWinInternal
{ {
//****************************************
// Scene::WrapperEffect
//****************************************
Scene::WrapperEffect::~WrapperEffect()
{
}
//**************************************** //****************************************
// Scene // Scene
//**************************************** //****************************************
@ -46,15 +38,14 @@ void Scene::paintScreen( int* mask, QRegion* region )
{ {
*mask = ( *region == QRegion( 0, 0, displayWidth(), displayHeight())) *mask = ( *region == QRegion( 0, 0, displayWidth(), displayHeight()))
? 0 : PAINT_SCREEN_REGION; ? 0 : PAINT_SCREEN_REGION;
WrapperEffect wrapper;
updateTimeDiff(); updateTimeDiff();
// preparation step // preparation step
effects->prePaintScreen( mask, region, time_diff, &wrapper ); effects->prePaintScreen( mask, region, time_diff );
if( *mask & ( PAINT_SCREEN_TRANSFORMED | PAINT_WINDOW_TRANSFORMED )) if( *mask & ( PAINT_SCREEN_TRANSFORMED | PAINT_WINDOW_TRANSFORMED ))
*mask &= ~PAINT_SCREEN_REGION; *mask &= ~PAINT_SCREEN_REGION;
// TODO call also prePaintWindow() for all windows // TODO call also prePaintWindow() for all windows
ScreenPaintData data; ScreenPaintData data;
effects->paintScreen( *mask, *region, data, &wrapper ); effects->paintScreen( *mask, *region, data );
} }
void Scene::updateTimeDiff() void Scene::updateTimeDiff()
@ -76,18 +67,13 @@ void Scene::idle()
last_time = QTime(); last_time = QTime();
} }
void Scene::WrapperEffect::prePaintScreen( int*, QRegion*, int )
{
// nothing, no changes
}
// the function that'll be eventually called by paintScreen() above // the function that'll be eventually called by paintScreen() above
void Scene::WrapperEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) void Scene::finalPaintScreen( int mask, QRegion region, ScreenPaintData& data )
{ {
if( mask & PAINT_SCREEN_REGION ) if( mask & PAINT_SCREEN_REGION )
scene->paintSimpleScreen( mask, region ); paintSimpleScreen( mask, region );
else else
scene->paintGenericScreen( mask, data ); paintGenericScreen( mask, data );
} }
// the generic painting code that should eventually handle even // the generic painting code that should eventually handle even
@ -101,9 +87,8 @@ void Scene::paintGenericScreen( int orig_mask, ScreenPaintData )
continue; continue;
int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT ); int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
QRegion damage = infiniteRegion(); QRegion damage = infiniteRegion();
WrapperEffect wrapper;
// preparation step // preparation step
effects->prePaintWindow( w, &mask, &damage, time_diff, &wrapper ); effects->prePaintWindow( w, &mask, &damage, time_diff );
paintWindow( w, mask, damage ); paintWindow( w, mask, damage );
} }
} }
@ -127,9 +112,8 @@ void Scene::paintSimpleScreen( int orig_mask, QRegion region )
continue; continue;
int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT ); int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
QRegion damage = region; QRegion damage = region;
WrapperEffect wrapper;
// preparation step // preparation step
effects->prePaintWindow( w, &mask, &damage, time_diff, &wrapper ); effects->prePaintWindow( w, &mask, &damage, time_diff );
if( mask & PAINT_WINDOW_TRANSLUCENT ) if( mask & PAINT_WINDOW_TRANSLUCENT )
phase2.prepend( Phase2Data( w, region, mask )); phase2.prepend( Phase2Data( w, region, mask ));
if( mask & PAINT_WINDOW_OPAQUE ) if( mask & PAINT_WINDOW_OPAQUE )
@ -151,21 +135,15 @@ void Scene::paintSimpleScreen( int orig_mask, QRegion region )
} }
} }
void Scene::WrapperEffect::prePaintWindow( Scene::Window* , int*, QRegion*, int )
{
// nothing, no changes
}
void Scene::paintWindow( Window* w, int mask, QRegion region ) void Scene::paintWindow( Window* w, int mask, QRegion region )
{ {
WindowPaintData data; WindowPaintData data;
data.opacity = w->window()->opacity(); data.opacity = w->window()->opacity();
WrapperEffect wrapper; effects->paintWindow( w, mask, region, data );
effects->paintWindow( w, mask, region, data, &wrapper );
} }
// the function that'll be eventually called by paintWindow() above // the function that'll be eventually called by paintWindow() above
void Scene::WrapperEffect::paintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data ) void Scene::finalPaintWindow( Scene::Window* w, int mask, QRegion region, WindowPaintData& data )
{ {
w->performPaint( mask, region, data ); w->performPaint( mask, region, data );
} }

View file

@ -51,9 +51,12 @@ class Scene
void idle(); void idle();
protected: protected:
void paintScreen( int* mask, QRegion* region ); void paintScreen( int* mask, QRegion* region );
friend class EffectsHandler;
void finalPaintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void paintGenericScreen( int mask, ScreenPaintData data ); virtual void paintGenericScreen( int mask, ScreenPaintData data );
virtual void paintSimpleScreen( int mask, QRegion region ); virtual void paintSimpleScreen( int mask, QRegion region );
virtual void paintBackground( QRegion region ) = 0; virtual void paintBackground( QRegion region ) = 0;
void finalPaintWindow( Window* w, int mask, QRegion region, WindowPaintData& data );
virtual void paintWindow( Window* w, int mask, QRegion region ); virtual void paintWindow( Window* w, int mask, QRegion region );
static QRegion infiniteRegion(); static QRegion infiniteRegion();
void updateTimeDiff(); void updateTimeDiff();
@ -68,7 +71,6 @@ class Scene
int time_diff; int time_diff;
QTime last_time; QTime last_time;
Workspace* wspace; Workspace* wspace;
class WrapperEffect;
}; };
class Scene::Window class Scene::Window