From 868719ed6572f67f1dc5b549f35ae702d96b0e49 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Sat, 21 Apr 2007 12:57:15 +0000 Subject: [PATCH] Port ExplosionEffect to plugin system svn path=/branches/work/kwin_composite/; revision=656456 --- effects.cpp | 7 ++++++ effects.h | 1 + effects/CMakeLists.txt | 2 ++ effects/explosion.desktop | 4 +++ effects/explosioneffect.cpp | 49 ++++++++++++++++++++----------------- effects/explosioneffect.h | 6 ++++- lib/kwineffects.h | 2 ++ 7 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 effects/explosion.desktop diff --git a/effects.cpp b/effects.cpp index 3d0f3bdae1..54a734fb75 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1017,6 +1017,13 @@ void EffectWindowImpl::markVerticesDirty() abort(); // TODO } + void EffectWindowImpl::setShader(GLShader* shader) + { + if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow())) + return w->setShader(shader); + abort(); // TODO + } + EffectWindow* effectWindow( Toplevel* w ) { EffectWindowImpl* ret = w->effectWindow(); diff --git a/effects.h b/effects.h index 9859351c38..007c349bf7 100644 --- a/effects.h +++ b/effects.h @@ -178,6 +178,7 @@ class EffectWindowImpl : public EffectWindow virtual QVector& vertices(); virtual void requestVertexGrid(int maxquadsize); virtual void markVerticesDirty(); + virtual void setShader(GLShader* shader); const Toplevel* window() const; Toplevel* window(); diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 01054bacff..7e4aa257e8 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -39,6 +39,7 @@ SET(kwin4_effect_tests_sources if(OPENGL_FOUND) SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} + explosioneffect.cpp magnifier.cpp shadow.cpp trackmouse.cpp @@ -50,6 +51,7 @@ if(OPENGL_FOUND) ) install( FILES + explosion.desktop magnifier.desktop shadow.desktop trackmouse.desktop diff --git a/effects/explosion.desktop b/effects/explosion.desktop new file mode 100644 index 0000000000..7a2e2b0ef7 --- /dev/null +++ b/effects/explosion.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Explosion +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/explosioneffect.cpp b/effects/explosioneffect.cpp index 900c2ec8d2..aa5a267625 100644 --- a/effects/explosioneffect.cpp +++ b/effects/explosioneffect.cpp @@ -11,14 +11,11 @@ License. See the file "COPYING" for the exact licensing terms. #include "explosioneffect.h" -#include -#include -#include -#include -#include +#include #include #include +#include #include @@ -26,6 +23,9 @@ License. See the file "COPYING" for the exact licensing terms. namespace KWin { +KWIN_EFFECT( Explosion, ExplosionEffect ); +KWIN_EFFECT_SUPPORTED( Explosion, ExplosionEffect::supported() ); + ExplosionEffect::ExplosionEffect() : Effect() { mActiveAnimations = 0; @@ -33,6 +33,12 @@ ExplosionEffect::ExplosionEffect() : Effect() mInited = false; } + bool ExplosionEffect::supported() + { + return GLShader::fragmentShaderSupported() && + (effects->compositingType() == OpenGLCompositing); + } + bool ExplosionEffect::loadData() { mInited = true; @@ -88,7 +94,7 @@ void ExplosionEffect::prePaintScreen( int* mask, QRegion* region, int time ) if( mActiveAnimations > 0 ) // We need to mark the screen as transformed. Otherwise the whole screen // won't be repainted, resulting in artefacts - *mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + *mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; effects->prePaintScreen(mask, region, time); } @@ -97,22 +103,21 @@ void ExplosionEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint { if( mWindows.contains( w )) { - SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() ); - if( mValid && glwin && !mInited ) + if( mValid && !mInited ) mValid = loadData(); if( mValid ) { mWindows[ w ] += time / 700.0; // complete change in 700ms if( mWindows[ w ] < 1 ) { - *mask |= Scene::PAINT_WINDOW_TRANSLUCENT | Scene::PAINT_WINDOW_TRANSFORMED; - *mask &= ~Scene::PAINT_WINDOW_OPAQUE; - w->enablePainting( Scene::Window::PAINT_DISABLED_BY_DELETE ); + *mask |= PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_TRANSFORMED; + *mask &= ~PAINT_WINDOW_OPAQUE; + w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE ); } else { mWindows.remove( w ); - static_cast< Deleted* >( w->window())->unrefWindow(); + w->unrefWindow(); mActiveAnimations--; } } @@ -125,16 +130,15 @@ void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi { // Make sure we have OpenGL compositing and the window is vidible and not a // special window - SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() ); - bool useshader = ( mValid && glwin && mWindows.contains( w ) ); + bool useshader = ( mValid && mWindows.contains( w ) ); if( useshader ) { float maxscaleadd = 1.5f; float scale = 1 + maxscaleadd*mWindows[w]; data.xScale = scale; data.yScale = scale; - data.xTranslate += int( w->window()->width() / 2 * ( 1 - scale )); - data.yTranslate += int( w->window()->height() / 2 * ( 1 - scale )); + data.xTranslate += int( w->width() / 2 * ( 1 - scale )); + data.yTranslate += int( w->height() / 2 * ( 1 - scale )); data.opacity *= 0.99; // Force blending mShader->bind(); mShader->setUniform("factor", (float)mWindows[w]); @@ -144,7 +148,7 @@ void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi glActiveTexture(GL_TEXTURE5); mEndOffsetTex->bind(); glActiveTexture(GL_TEXTURE0); - glwin->setShader(mShader); + w->setShader(mShader); } // Call the next effect. @@ -164,7 +168,7 @@ void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi void ExplosionEffect::postPaintScreen() { if( mActiveAnimations > 0 ) - workspace()->addRepaintFull(); + effects->addRepaintFull(); // Call the next effect. effects->postPaintScreen(); @@ -172,19 +176,18 @@ void ExplosionEffect::postPaintScreen() void ExplosionEffect::windowClosed( EffectWindow* c ) { - Client* cc = dynamic_cast< Client* >( c->window()); - if( cc == NULL || (cc->isOnCurrentDesktop() && !cc->isMinimized())) + if( c->isOnCurrentDesktop() && !c->isMinimized()) { mWindows[ c ] = 0; // count up to 1 - c->window()->addRepaintFull(); - static_cast< Deleted* >( c->window())->refWindow(); + c->addRepaintFull(); + c->refWindow(); mActiveAnimations++; } } void ExplosionEffect::windowDeleted( EffectWindow* c ) { - mWindows.remove( c ); + mWindows.remove( c ); } } // namespace diff --git a/effects/explosioneffect.h b/effects/explosioneffect.h index f8abed2b4a..64af753fb6 100644 --- a/effects/explosioneffect.h +++ b/effects/explosioneffect.h @@ -12,7 +12,9 @@ License. See the file "COPYING" for the exact licensing terms. #define KWIN_EXPLOSIONEFFECT_H // Include with base class for effects. -#include +#include + +#include namespace KWin { @@ -37,6 +39,8 @@ class ExplosionEffect virtual void windowClosed( EffectWindow* c ); virtual void windowDeleted( EffectWindow* c ); + static bool supported(); + protected: bool loadData(); diff --git a/lib/kwineffects.h b/lib/kwineffects.h index e6cfda9b02..885edb9e8f 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -37,6 +37,7 @@ class EffectWindowGroup; class Effect; class Vertex; class GLRenderTarget; +class GLShader; typedef QPair< QString, Effect* > EffectPair; typedef QPair< Effect*, Window > InputWindowPair; @@ -322,6 +323,7 @@ class KWIN_EXPORT EffectWindow // Marks vertices of the window as dirty. Call this if you change // position of the vertices virtual void markVerticesDirty() = 0; + virtual void setShader(GLShader* shader) = 0; }; class KWIN_EXPORT EffectWindowGroup