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

« back to all changes in this revision

Viewing changes to kwin/scene.h

  • 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) 2006 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#ifndef KWIN_SCENE_H
 
22
#define KWIN_SCENE_H
 
23
 
 
24
#include <QDateTime>
 
25
 
 
26
#include "toplevel.h"
 
27
#include "utils.h"
 
28
#include "kwineffects.h"
 
29
 
 
30
namespace KWin
 
31
{
 
32
 
 
33
class Workspace;
 
34
class Deleted;
 
35
class EffectFrameImpl;
 
36
class EffectWindowImpl;
 
37
class LanczosFilter;
 
38
class Shadow;
 
39
 
 
40
// The base class for compositing backends.
 
41
class Scene
 
42
{
 
43
public:
 
44
    Scene(Workspace* ws);
 
45
    virtual ~Scene() = 0;
 
46
    class EffectFrame;
 
47
    class Window;
 
48
 
 
49
    // Returns true if the ctor failed to properly initialize.
 
50
    virtual bool initFailed() const = 0;
 
51
    virtual CompositingType compositingType() const = 0;
 
52
    // Repaints the given screen areas, windows provides the stacking order.
 
53
    // The entry point for the main part of the painting pass.
 
54
    virtual void paint(QRegion damage, ToplevelList windows) = 0;
 
55
 
 
56
    // Notification function - KWin core informs about changes.
 
57
    // Used to mainly discard cached data.
 
58
 
 
59
    // shape/size of a window changed
 
60
    virtual void windowGeometryShapeChanged(Toplevel*) = 0;
 
61
    // opacity of a window changed
 
62
    virtual void windowOpacityChanged(Toplevel*) = 0;
 
63
    // a new window has been created
 
64
    virtual void windowAdded(Toplevel*) = 0;
 
65
    // a window has been closed
 
66
    virtual void windowClosed(Toplevel*, Deleted*) = 0;
 
67
    // a window has been destroyed
 
68
    virtual void windowDeleted(Deleted*) = 0;
 
69
    // Flags controlling how painting is done.
 
70
    enum {
 
71
        // Window (or at least part of it) will be painted opaque.
 
72
        PAINT_WINDOW_OPAQUE         = 1 << 0,
 
73
        // Window (or at least part of it) will be painted translucent.
 
74
        PAINT_WINDOW_TRANSLUCENT    = 1 << 1,
 
75
        // Window will be painted with transformed geometry.
 
76
        PAINT_WINDOW_TRANSFORMED    = 1 << 2,
 
77
        // Paint only a region of the screen (can be optimized, cannot
 
78
        // be used together with TRANSFORMED flags).
 
79
        PAINT_SCREEN_REGION         = 1 << 3,
 
80
        // Whole screen will be painted with transformed geometry.
 
81
        PAINT_SCREEN_TRANSFORMED    = 1 << 4,
 
82
        // At least one window will be painted with transformed geometry.
 
83
        PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
 
84
        // Clear whole background as the very first step, without optimizing it
 
85
        PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6,
 
86
        // Temporary solution since (_OPAQUE | _TRANSLUCENT) is not working currently.
 
87
        PAINT_DECORATION_ONLY = 1 << 7,
 
88
        // Window will be painted with a lanczos filter.
 
89
        PAINT_WINDOW_LANCZOS = 1 << 8,
 
90
        // same as PAINT_SCREEN_TRANSFORMED without full repainting
 
91
        PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS = 1 << 9
 
92
    };
 
93
    // types of filtering available
 
94
    enum ImageFilterType { ImageFilterFast, ImageFilterGood };
 
95
    inline uint estimatedRenderTime() {
 
96
        return lastRenderTime;
 
97
    }
 
98
    // there's nothing to paint (adjust time_diff later)
 
99
    void idle();
 
100
    bool waitSyncAvailable() {
 
101
        return has_waitSync;
 
102
    }
 
103
protected:
 
104
    // shared implementation, starts painting the screen
 
105
    void paintScreen(int* mask, QRegion* region);
 
106
    friend class EffectsHandlerImpl;
 
107
    // called after all effects had their paintScreen() called
 
108
    void finalPaintScreen(int mask, QRegion region, ScreenPaintData& data);
 
109
    // shared implementation of painting the screen in the generic
 
110
    // (unoptimized) way
 
111
    virtual void paintGenericScreen(int mask, ScreenPaintData data);
 
112
    // shared implementation of painting the screen in an optimized way
 
113
    virtual void paintSimpleScreen(int mask, QRegion region);
 
114
    // paint the background (not the desktop background - the whole background)
 
115
    virtual void paintBackground(QRegion region) = 0;
 
116
    // called after all effects had their paintWindow() called
 
117
    void finalPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
 
118
    // shared implementation, starts painting the window
 
119
    virtual void paintWindow(Window* w, int mask, QRegion region, WindowQuadList quads);
 
120
    // called after all effects had their drawWindow() called
 
121
    void finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
 
122
    // compute time since the last repaint
 
123
    void updateTimeDiff();
 
124
    QList< QPoint > selfCheckPoints() const;
 
125
    QRegion selfCheckRegion() const;
 
126
    // dimensions of the test pixmap for selfcheck
 
127
    int selfCheckWidth() const;
 
128
    int selfCheckHeight() const;
 
129
    // saved data for 2nd pass of optimized screen painting
 
130
    struct Phase2Data {
 
131
        Phase2Data(Window* w, QRegion r, QRegion c, int m, const WindowQuadList& q)
 
132
            : window(w), region(r), clip(c), mask(m), quads(q) {}
 
133
        Phase2Data()  {
 
134
            window = 0;
 
135
            mask = 0;
 
136
        }
 
137
        Window* window;
 
138
        QRegion region;
 
139
        QRegion clip;
 
140
        int mask;
 
141
        WindowQuadList quads;
 
142
    };
 
143
    // windows in their stacking order
 
144
    QVector< Window* > stacking_order;
 
145
    // The region which actually has been painted by paintScreen() and should be
 
146
    // copied from the buffer to the screen. I.e. the region returned from Scene::paintScreen().
 
147
    // Since prePaintWindow() can extend areas to paint, these changes would have to propagate
 
148
    // up all the way from paintSimpleScreen() up to paintScreen(), so save them here rather
 
149
    // than propagate them up in arguments.
 
150
    QRegion painted_region;
 
151
    // time since last repaint
 
152
    int time_diff;
 
153
    uint lastRenderTime;
 
154
    QTime last_time;
 
155
    Workspace* wspace;
 
156
    bool has_waitSync;
 
157
    bool selfCheckDone;
 
158
    LanczosFilter* lanczos_filter;
 
159
};
 
160
 
 
161
// The base class for windows representations in composite backends
 
162
class Scene::Window
 
163
{
 
164
public:
 
165
    Window(Toplevel* c);
 
166
    virtual ~Window();
 
167
    // perform the actual painting of the window
 
168
    virtual void performPaint(int mask, QRegion region, WindowPaintData data) = 0;
 
169
    // do any cleanup needed when the window's composite pixmap is discarded
 
170
    virtual void pixmapDiscarded()  {}
 
171
    int x() const;
 
172
    int y() const;
 
173
    int width() const;
 
174
    int height() const;
 
175
    QRect geometry() const;
 
176
    QPoint pos() const;
 
177
    QSize size() const;
 
178
    QRect rect() const;
 
179
    // access to the internal window class
 
180
    // TODO eventually get rid of this
 
181
    Toplevel* window();
 
182
    // should the window be painted
 
183
    bool isPaintingEnabled() const;
 
184
    void resetPaintingEnabled();
 
185
    // Flags explaining why painting should be disabled
 
186
    enum {
 
187
        // Window will not be painted
 
188
        PAINT_DISABLED                 = 1 << 0,
 
189
        // Window will not be painted because it is deleted
 
190
        PAINT_DISABLED_BY_DELETE       = 1 << 1,
 
191
        // Window will not be painted because of which desktop it's on
 
192
        PAINT_DISABLED_BY_DESKTOP      = 1 << 2,
 
193
        // Window will not be painted because it is minimized
 
194
        PAINT_DISABLED_BY_MINIMIZE     = 1 << 3,
 
195
        // Window will not be painted because it is not the active window in a client group
 
196
        PAINT_DISABLED_BY_CLIENT_GROUP = 1 << 4,
 
197
        // Window will not be painted because it's not on the current activity
 
198
        PAINT_DISABLED_BY_ACTIVITY     = 1 << 5
 
199
    };
 
200
    void enablePainting(int reason);
 
201
    void disablePainting(int reason);
 
202
    // is the window visible at all
 
203
    bool isVisible() const;
 
204
    // is the window fully opaque
 
205
    bool isOpaque() const;
 
206
    // shape of the window
 
207
    QRegion shape() const;
 
208
    QRegion clientShape() const;
 
209
    void discardShape();
 
210
    void updateToplevel(Toplevel* c);
 
211
    // creates initial quad list for the window
 
212
    virtual WindowQuadList buildQuads(bool force = false) const;
 
213
    void suspendUnredirect(bool suspend);
 
214
    void updateShadow(Shadow* shadow);
 
215
    const Shadow* shadow() const;
 
216
    Shadow* shadow();
 
217
protected:
 
218
    WindowQuadList makeQuads(WindowQuadType type, const QRegion& reg) const;
 
219
    Toplevel* toplevel;
 
220
    ImageFilterType filter;
 
221
    Shadow *m_shadow;
 
222
private:
 
223
    int disable_painting;
 
224
    mutable QRegion shape_region;
 
225
    mutable bool shape_valid;
 
226
    mutable WindowQuadList* cached_quad_list;
 
227
    Q_DISABLE_COPY(Window)
 
228
};
 
229
 
 
230
class Scene::EffectFrame
 
231
{
 
232
public:
 
233
    EffectFrame(EffectFrameImpl* frame);
 
234
    virtual ~EffectFrame();
 
235
    virtual void render(QRegion region, double opacity, double frameOpacity) = 0;
 
236
    virtual void free() = 0;
 
237
    virtual void freeIconFrame() = 0;
 
238
    virtual void freeTextFrame() = 0;
 
239
    virtual void freeSelection() = 0;
 
240
    virtual void crossFadeIcon() = 0;
 
241
    virtual void crossFadeText() = 0;
 
242
 
 
243
protected:
 
244
    EffectFrameImpl* m_effectFrame;
 
245
};
 
246
 
 
247
extern Scene* scene;
 
248
 
 
249
inline
 
250
int Scene::selfCheckWidth() const
 
251
{
 
252
    return 3;
 
253
}
 
254
 
 
255
inline
 
256
int Scene::selfCheckHeight() const
 
257
{
 
258
    return 2;
 
259
}
 
260
 
 
261
inline
 
262
int Scene::Window::x() const
 
263
{
 
264
    return toplevel->x();
 
265
}
 
266
 
 
267
inline
 
268
int Scene::Window::y() const
 
269
{
 
270
    return toplevel->y();
 
271
}
 
272
 
 
273
inline
 
274
int Scene::Window::width() const
 
275
{
 
276
    return toplevel->width();
 
277
}
 
278
 
 
279
inline
 
280
int Scene::Window::height() const
 
281
{
 
282
    return toplevel->height();
 
283
}
 
284
 
 
285
inline
 
286
QRect Scene::Window::geometry() const
 
287
{
 
288
    return toplevel->geometry();
 
289
}
 
290
 
 
291
inline
 
292
QSize Scene::Window::size() const
 
293
{
 
294
    return toplevel->size();
 
295
}
 
296
 
 
297
inline
 
298
QPoint Scene::Window::pos() const
 
299
{
 
300
    return toplevel->pos();
 
301
}
 
302
 
 
303
inline
 
304
QRect Scene::Window::rect() const
 
305
{
 
306
    return toplevel->rect();
 
307
}
 
308
 
 
309
inline
 
310
Toplevel* Scene::Window::window()
 
311
{
 
312
    return toplevel;
 
313
}
 
314
 
 
315
inline
 
316
void Scene::Window::updateToplevel(Toplevel* c)
 
317
{
 
318
    toplevel = c;
 
319
}
 
320
 
 
321
inline
 
322
void Scene::Window::suspendUnredirect(bool suspend)
 
323
{
 
324
    toplevel->suspendUnredirect(suspend);
 
325
}
 
326
 
 
327
inline
 
328
void Scene::Window::updateShadow(Shadow* shadow)
 
329
{
 
330
    m_shadow = shadow;
 
331
}
 
332
 
 
333
inline
 
334
const Shadow* Scene::Window::shadow() const
 
335
{
 
336
    return m_shadow;
 
337
}
 
338
 
 
339
inline
 
340
Shadow* Scene::Window::shadow()
 
341
{
 
342
    return m_shadow;
 
343
}
 
344
 
 
345
} // namespace
 
346
 
 
347
#endif