|
|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
This file is part of the KDE project. |
|
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org> |
|
|
|
|
Copyright (C) 2010 Martin Gräßlin <kde@martin-graesslin.com> |
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
|
|
|
it under the terms of the GNU General Public License as published by |
|
|
|
|
@ -23,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
#include <kwinconfig.h> |
|
|
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING |
|
|
|
|
#include <GL/gl.h> |
|
|
|
|
#include <kwinglutils.h> |
|
|
|
|
#endif |
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING |
|
|
|
|
#include <X11/Xlib.h> |
|
|
|
|
@ -33,6 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
#include <qcolor.h> |
|
|
|
|
#include <QVector2D> |
|
|
|
|
#include <QVector4D> |
|
|
|
|
|
|
|
|
|
namespace KWin |
|
|
|
|
{ |
|
|
|
|
@ -44,9 +47,43 @@ static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, |
|
|
|
|
|
|
|
|
|
ShowPaintEffect::ShowPaintEffect() |
|
|
|
|
: color_index( 0 ) |
|
|
|
|
, useShader( false ) |
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING |
|
|
|
|
, vbo( 0 ) |
|
|
|
|
, colorShader( 0 ) |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING |
|
|
|
|
if (effects->compositingType() == OpenGLCompositing) { |
|
|
|
|
vbo = new GLVertexBuffer(GLVertexBuffer::Stream); |
|
|
|
|
vbo->setUseColor(true); |
|
|
|
|
// TODO: use GLPlatform
|
|
|
|
|
if (GLShader::vertexShaderSupported() && GLShader::fragmentShaderSupported()) { |
|
|
|
|
colorShader = new GLShader(":/resources/scene-color-vertex.glsl", ":/resources/scene-color-fragment.glsl"); |
|
|
|
|
if (colorShader->isValid()) { |
|
|
|
|
colorShader->bind(); |
|
|
|
|
colorShader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight())); |
|
|
|
|
colorShader->setUniform("geometry", QVector4D(0, 0, 0, 0)); |
|
|
|
|
colorShader->unbind(); |
|
|
|
|
vbo->setUseShader(true); |
|
|
|
|
useShader = true; |
|
|
|
|
kDebug(1212) << "Show Paint Shader is valid"; |
|
|
|
|
} else { |
|
|
|
|
kDebug(1212) << "Show Paint Shader not valid"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ShowPaintEffect::~ShowPaintEffect() |
|
|
|
|
{ |
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING |
|
|
|
|
delete vbo; |
|
|
|
|
delete colorShader; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ShowPaintEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) |
|
|
|
|
{ |
|
|
|
|
painted = QRegion(); |
|
|
|
|
@ -69,26 +106,39 @@ void ShowPaintEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi |
|
|
|
|
effects->paintWindow( w, mask, region, data ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO I think we need some kind of generic paintRect()
|
|
|
|
|
void ShowPaintEffect::paintGL() |
|
|
|
|
{ |
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING |
|
|
|
|
#ifndef KWIN_HAVE_OPENGLES |
|
|
|
|
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); |
|
|
|
|
#endif |
|
|
|
|
if (useShader) { |
|
|
|
|
colorShader->bind(); |
|
|
|
|
} |
|
|
|
|
glEnable( GL_BLEND ); |
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
|
|
|
|
float alpha = 0.2; |
|
|
|
|
const QColor& color = colors[ color_index ]; |
|
|
|
|
glColor4f( color.red() / 255., color.green() / 255., color.blue() / 255., alpha ); |
|
|
|
|
glBegin( GL_QUADS ); |
|
|
|
|
foreach( const QRect &r, painted.rects()) |
|
|
|
|
{ |
|
|
|
|
glVertex2i( r.x(), r.y()); |
|
|
|
|
glVertex2i( r.x() + r.width(), r.y()); |
|
|
|
|
glVertex2i( r.x() + r.width(), r.y() + r.height()); |
|
|
|
|
glVertex2i( r.x(), r.y() + r.height()); |
|
|
|
|
} |
|
|
|
|
glEnd(); |
|
|
|
|
QColor color = colors[ color_index ]; |
|
|
|
|
color.setAlphaF(0.2); |
|
|
|
|
vbo->setColor(color); |
|
|
|
|
QVector<float> verts; |
|
|
|
|
verts.reserve(painted.rects().count()*12); |
|
|
|
|
foreach (const QRect &r, painted.rects()) { |
|
|
|
|
verts << r.x() + r.width() << r.y(); |
|
|
|
|
verts << r.x() << r.y(); |
|
|
|
|
verts << r.x() << r.y() + r.height(); |
|
|
|
|
verts << r.x() << r.y() + r.height(); |
|
|
|
|
verts << r.x() + r.width() << r.y() + r.height(); |
|
|
|
|
verts << r.x() + r.width() << r.y(); |
|
|
|
|
} |
|
|
|
|
vbo->setData(verts.count()/2, 2, verts.data(), NULL); |
|
|
|
|
vbo->render(GL_TRIANGLES); |
|
|
|
|
if (useShader) { |
|
|
|
|
colorShader->unbind(); |
|
|
|
|
} |
|
|
|
|
glDisable( GL_BLEND ); |
|
|
|
|
#ifndef KWIN_HAVE_OPENGLES |
|
|
|
|
glPopAttrib(); |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|