Convert WavyWindows to plugins (and move Vertex class to the effects lib).

svn path=/branches/work/kwin_composite/; revision=652628
This commit is contained in:
Luboš Luňák 2007-04-11 15:46:46 +00:00
parent f285fe4af8
commit ca5451fef0
8 changed files with 75 additions and 38 deletions

View file

@ -14,6 +14,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include "client.h"
#include "group.h"
#include "scene_xrender.h"
#include "scene_opengl.h"
#include "workspace.h"
#include <QFile>
@ -717,6 +718,27 @@ bool EffectWindowImpl::isDNDIcon() const
return toplevel->isDNDIcon();
}
QVector<Vertex>& EffectWindowImpl::vertices()
{
if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow()))
return w->vertices();
abort(); // TODO
}
void EffectWindowImpl::requestVertexGrid(int maxquadsize)
{
if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow()))
return w->requestVertexGrid( maxquadsize );
abort(); // TODO
}
void EffectWindowImpl::markVerticesDirty()
{
if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow()))
return w->markVerticesDirty();
abort(); // TODO
}
EffectWindow* effectWindow( Toplevel* w )
{
EffectWindowImpl* ret = w->effectWindow();

View file

@ -129,6 +129,10 @@ class EffectWindowImpl : public EffectWindow
virtual bool isComboBox() const;
virtual bool isDNDIcon() const;
virtual QVector<Vertex>& vertices();
virtual void requestVertexGrid(int maxquadsize);
virtual void markVerticesDirty();
const Toplevel* window() const;
Toplevel* window();

View file

@ -19,9 +19,11 @@ SET(kwin4_effect_builtins_sources
if(OPENGL_FOUND)
SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
shadow.cpp
wavywindows.cpp
)
install( FILES
shadow.desktop
wavywindows.desktop
DESTINATION ${DATA_INSTALL_DIR}/kwin/effects )
endif(OPENGL_FOUND)

View file

@ -11,10 +11,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include "wavywindows.h"
#include <scene_opengl.h>
#include <workspace.h>
#include <client.h>
#include <math.h>
@ -24,6 +20,8 @@ License. See the file "COPYING" for the exact licensing terms.
namespace KWin
{
KWIN_EFFECT( WavyWindows, WavyWindowsEffect )
WavyWindowsEffect::WavyWindowsEffect()
{
mTimeElapsed = 0.0f;
@ -36,7 +34,7 @@ void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time )
mTimeElapsed += (time / 1000.0f);
// We need to mark the screen windows 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);
}
@ -44,13 +42,11 @@ void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time )
void WavyWindowsEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
{
// This window will be transformed by the effect
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
*mask |= PAINT_WINDOW_TRANSFORMED;
// Check if OpenGL compositing is used
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window *>( w->sceneWindow() );
if(glwin)
// Request the window to be divided into cells which are at most 30x30
// pixels big
glwin->requestVertexGrid(30);
// Request the window to be divided into cells which are at most 30x30
// pixels big
w->requestVertexGrid(30);
effects->prePaintWindow( w, mask, paint, clip, time );
}
@ -59,14 +55,13 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region,
{
// 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() );
Client* c = qobject_cast< Client* >( w->window() );
if( glwin && glwin->isVisible() && c && !c->isSpecialWindow() )
// TODO if( w->isVisible() && !w->isSpecialWindow() )
if( !w->isSpecialWindow() )
{
// We have OpenGL compositing and the window has been subdivided
// because of our request (in pre-paint pass)
// Transform all the vertices to create wavy effect
QVector< SceneOpenGL::Window::Vertex >& vertices = glwin->vertices();
QVector< Vertex >& vertices = w->vertices();
for(int i = 0; i < vertices.count(); i++)
{
vertices[i].pos[0] += sin(mTimeElapsed + vertices[i].texcoord[1] / 60 + 0.5f) * 10;
@ -74,7 +69,7 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region,
}
// We have changed the vertices, so they will have to be reset before
// the next paint pass
glwin->markVerticesDirty();
w->markVerticesDirty();
}
// Call the next effect.
@ -84,7 +79,7 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region,
void WavyWindowsEffect::postPaintScreen()
{
// Repaint the workspace so that everything would be repainted next time
workspace()->addRepaintFull();
effects->addRepaintFull();
// Call the next effect.
effects->postPaintScreen();

View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=WavyWindows
X-KDE-Library=kwin4_effect_builtins

View file

@ -12,7 +12,7 @@ License. See the file "COPYING" for the exact licensing terms.
#define KWIN_WAVYWINDOWS_H
// Include with base class for effects.
#include <effects.h>
#include <kwineffects.h>
namespace KWin

View file

@ -34,6 +34,7 @@ namespace KWin
class EffectWindow;
class EffectWindowGroup;
class Effect;
class Vertex;
typedef QPair< QString, Effect* > EffectPair;
typedef QPair< Effect*, Window > InputWindowPair;
@ -270,6 +271,14 @@ class KWIN_EXPORT EffectWindow
virtual bool isComboBox() const = 0;
virtual bool isDNDIcon() const = 0;
virtual QVector<Vertex>& vertices() = 0;
// Can be called in pre-paint pass. Makes sure that all quads that the
// window consists of are not bigger than maxquadsize x maxquadsize
// (in pixels) in the following paint pass.
virtual void requestVertexGrid(int maxquadsize) = 0;
// Marks vertices of the window as dirty. Call this if you change
// position of the vertices
virtual void markVerticesDirty() = 0;
};
class KWIN_EXPORT EffectWindowGroup
@ -279,6 +288,27 @@ class KWIN_EXPORT EffectWindowGroup
virtual EffectWindowList members() const = 0;
};
/**
* @short Vertex class
* Vertex has position and texture coordinate which are equal at first,
* however effects can e.g. modify position to move the window or part of it.
**/
class KWIN_EXPORT Vertex
{
public:
Vertex() {}
Vertex(float x, float y)
{
pos[0] = texcoord[0] = x; pos[1] = texcoord[1] = y; pos[2] = 0.0f;
}
Vertex(float x, float y, float u, float v)
{
pos[0] = x; pos[1] = y; pos[2] = 0.0f; texcoord[0] = u; texcoord[1] = v;
}
float pos[3];
float texcoord[2];
};
extern KWIN_EXPORT EffectsHandler* effects;

View file

@ -122,26 +122,6 @@ class SceneOpenGL::Window
void discardTexture();
void discardVertices();
/**
* @short Vertex class
* Vertex has position and texture coordinate which are equal at first,
* however effects can e.g. modify position to move the window or part of it.
**/
class Vertex
{
public:
Vertex() {}
Vertex(float x, float y)
{
pos[0] = texcoord[0] = x; pos[1] = texcoord[1] = y; pos[2] = 0.0f;
}
Vertex(float x, float y, float u, float v)
{
pos[0] = x; pos[1] = y; pos[2] = 0.0f; texcoord[0] = u; texcoord[1] = v;
}
float pos[3];
float texcoord[2];
};
// Returns list of vertices
QVector<Vertex>& vertices() { return verticeslist; }
// Can be called in pre-paint pass. Makes sure that all quads that the