~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/showpaint/showpaint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
 
6
Copyright (C) 2010 Martin Gräßlin <kde@martin-graesslin.com>
 
7
 
 
8
This program is free software; you can redistribute it and/or modify
 
9
it under the terms of the GNU General Public License as published by
 
10
the Free Software Foundation; either version 2 of the License, or
 
11
(at your option) any later version.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*********************************************************************/
 
21
 
 
22
#include "showpaint.h"
 
23
 
 
24
#include <kwinconfig.h>
 
25
 
 
26
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
 
27
#include <kwinglutils.h>
 
28
#endif
 
29
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
 
30
#include <X11/Xlib.h>
 
31
#include <X11/extensions/Xrender.h>
 
32
#endif
 
33
 
 
34
#include <math.h>
 
35
 
 
36
#include <qcolor.h>
 
37
 
 
38
namespace KWin
 
39
{
 
40
 
 
41
KWIN_EFFECT(showpaint, ShowPaintEffect)
 
42
 
 
43
static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta,
 
44
                           Qt::yellow, Qt::gray
 
45
                         };
 
46
 
 
47
ShowPaintEffect::ShowPaintEffect()
 
48
    : color_index(0)
 
49
{
 
50
}
 
51
 
 
52
ShowPaintEffect::~ShowPaintEffect()
 
53
{
 
54
}
 
55
 
 
56
void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
 
57
{
 
58
    painted = QRegion();
 
59
    effects->paintScreen(mask, region, data);
 
60
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
 
61
    if (effects->compositingType() == OpenGLCompositing)
 
62
        paintGL();
 
63
#endif
 
64
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
 
65
    if (effects->compositingType() == XRenderCompositing)
 
66
        paintXrender();
 
67
#endif
 
68
    if (++color_index == sizeof(colors) / sizeof(colors[ 0 ]))
 
69
        color_index = 0;
 
70
}
 
71
 
 
72
void ShowPaintEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
73
{
 
74
    painted |= region;
 
75
    effects->paintWindow(w, mask, region, data);
 
76
}
 
77
 
 
78
void ShowPaintEffect::paintGL()
 
79
{
 
80
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
 
81
#ifndef KWIN_HAVE_OPENGLES
 
82
    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
 
83
#endif
 
84
    GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
 
85
    vbo->reset();
 
86
    vbo->setUseColor(true);
 
87
    if (ShaderManager::instance()->isValid()) {
 
88
        ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
 
89
    }
 
90
    glEnable(GL_BLEND);
 
91
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
92
    QColor color = colors[ color_index ];
 
93
    color.setAlphaF(0.2);
 
94
    vbo->setColor(color);
 
95
    QVector<float> verts;
 
96
    verts.reserve(painted.rects().count() * 12);
 
97
    foreach (const QRect & r, painted.rects()) {
 
98
        verts << r.x() + r.width() << r.y();
 
99
        verts << r.x() << r.y();
 
100
        verts << r.x() << r.y() + r.height();
 
101
        verts << r.x() << r.y() + r.height();
 
102
        verts << r.x() + r.width() << r.y() + r.height();
 
103
        verts << r.x() + r.width() << r.y();
 
104
    }
 
105
    vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
 
106
    vbo->render(GL_TRIANGLES);
 
107
    if (ShaderManager::instance()->isValid()) {
 
108
        ShaderManager::instance()->popShader();
 
109
    }
 
110
    glDisable(GL_BLEND);
 
111
#ifndef KWIN_HAVE_OPENGLES
 
112
    glPopAttrib();
 
113
#endif
 
114
#endif
 
115
}
 
116
 
 
117
void ShowPaintEffect::paintXrender()
 
118
{
 
119
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
 
120
    XRenderColor col;
 
121
    float alpha = 0.2;
 
122
    const QColor& color = colors[ color_index ];
 
123
    col.alpha = int(alpha * 0xffff);
 
124
    col.red = int(alpha * 0xffff * color.red() / 255);
 
125
    col.green = int(alpha * 0xffff * color.green() / 255);
 
126
    col.blue = int(alpha * 0xffff * color.blue() / 255);
 
127
    foreach (const QRect & r, painted.rects())
 
128
    XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
 
129
                         &col, r.x(), r.y(), r.width(), r.height());
 
130
#endif
 
131
}
 
132
 
 
133
} // namespace