add more spacing
[personal-kdebase.git] / workspace / kwin / scene.h
blob680e3433a82bf5ed3c8bd4f3389ff1e49f722bc1
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
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.
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.
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 *********************************************************************/
21 #ifndef KWIN_SCENE_H
22 #define KWIN_SCENE_H
24 #include <QDateTime>
26 #include "toplevel.h"
27 #include "utils.h"
28 #include "kwineffects.h"
30 namespace KWin
33 class Workspace;
34 class Deleted;
35 class EffectWindowImpl;
37 // The base class for compositing backends.
38 class Scene
40 public:
41 Scene( Workspace* ws );
42 virtual ~Scene() = 0;
43 class Window;
45 // Returns true if the ctor failed to properly initialize.
46 virtual bool initFailed() const = 0;
47 virtual CompositingType compositingType() const = 0;
48 // Repaints the given screen areas, windows provides the stacking order.
49 // The entry point for the main part of the painting pass.
50 virtual void paint( QRegion damage, ToplevelList windows ) = 0;
52 // Notification function - KWin core informs about changes.
53 // Used to mainly discard cached data.
55 // shape/size of a window changed
56 virtual void windowGeometryShapeChanged( Toplevel* ) = 0;
57 // opacity of a window changed
58 virtual void windowOpacityChanged( Toplevel* ) = 0;
59 // a new window has been created
60 virtual void windowAdded( Toplevel* ) = 0;
61 // a window has been closed
62 virtual void windowClosed( Toplevel*, Deleted* ) = 0;
63 // a window has been destroyed
64 virtual void windowDeleted( Deleted* ) = 0;
65 // Flags controlling how painting is done.
66 enum
68 // Window (or at least part of it) will be painted opaque.
69 PAINT_WINDOW_OPAQUE = 1 << 0,
70 // Window (or at least part of it) will be painted translucent.
71 PAINT_WINDOW_TRANSLUCENT = 1 << 1,
72 // Window will be painted with transformed geometry.
73 PAINT_WINDOW_TRANSFORMED = 1 << 2,
74 // Paint only a region of the screen (can be optimized, cannot
75 // be used together with TRANSFORMED flags).
76 PAINT_SCREEN_REGION = 1 << 3,
77 // Whole screen will be painted with transformed geometry.
78 PAINT_SCREEN_TRANSFORMED = 1 << 4,
79 // At least one window will be painted with transformed geometry.
80 PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
81 // Clear whole background as the very first step, without optimizing it
82 PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6
84 // types of filtering available
85 enum ImageFilterType { ImageFilterFast, ImageFilterGood };
86 // there's nothing to paint (adjust time_diff later)
87 void idle();
88 bool waitSyncAvailable() { return has_waitSync; }
89 protected:
90 // shared implementation, starts painting the screen
91 void paintScreen( int* mask, QRegion* region );
92 friend class EffectsHandlerImpl;
93 // called after all effects had their paintScreen() called
94 void finalPaintScreen( int mask, QRegion region, ScreenPaintData& data );
95 // shared implementation of painting the screen in the generic
96 // (unoptimized) way
97 virtual void paintGenericScreen( int mask, ScreenPaintData data );
98 // shared implementation of painting the screen in an optimized way
99 virtual void paintSimpleScreen( int mask, QRegion region );
100 // paint the background (not the desktop background - the whole background)
101 virtual void paintBackground( QRegion region ) = 0;
102 // called after all effects had their paintWindow() called
103 void finalPaintWindow( EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data );
104 // shared implementation, starts painting the window
105 virtual void paintWindow( Window* w, int mask, QRegion region, WindowQuadList quads );
106 // called after all effects had their drawWindow() called
107 void finalDrawWindow( EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data );
108 // compute time since the last repaint
109 void updateTimeDiff();
110 QList< QPoint > selfCheckPoints() const;
111 // saved data for 2nd pass of optimized screen painting
112 struct Phase2Data
114 Phase2Data( Window* w, QRegion r, QRegion c, int m, const WindowQuadList& q )
115 : window( w ), region( r ), clip( c ), mask( m ), quads( q ) {}
116 Phase2Data() { window = 0; mask = 0; }
117 Window* window;
118 QRegion region;
119 QRegion clip;
120 int mask;
121 WindowQuadList quads;
123 // windows in their stacking order
124 QVector< Window* > stacking_order;
125 // The region which actually has been painted by paintScreen() and should be
126 // copied from the buffer to the screen. I.e. the region returned from Scene::paintScreen().
127 // Since prePaintWindow() can extend areas to paint, these changes would have to propagate
128 // up all the way from paintSimpleScreen() up to paintScreen(), so save them here rather
129 // than propagate them up in arguments.
130 QRegion painted_region;
131 // time since last repaint
132 int time_diff;
133 QTime last_time;
134 Workspace* wspace;
135 bool has_waitSync;
138 // The base class for windows representations in composite backends
139 class Scene::Window
141 public:
142 Window( Toplevel* c );
143 virtual ~Window();
144 // perform the actual painting of the window
145 virtual void performPaint( int mask, QRegion region, WindowPaintData data ) = 0;
146 // do any cleanup needed when the window's composite pixmap is discarded
147 virtual void pixmapDiscarded() {}
148 int x() const;
149 int y() const;
150 int width() const;
151 int height() const;
152 QRect geometry() const;
153 QPoint pos() const;
154 QSize size() const;
155 QRect rect() const;
156 // access to the internal window class
157 // TODO eventually get rid of this
158 Toplevel* window();
159 // should the window be painted
160 bool isPaintingEnabled() const;
161 void resetPaintingEnabled();
162 // Flags explaining why painting should be disabled
163 enum
165 // Window will not be painted
166 PAINT_DISABLED = 1 << 0,
167 // Window will not be painted because it is deleted
168 PAINT_DISABLED_BY_DELETE = 1 << 1,
169 // Window will not be painted because of which desktop it's on
170 PAINT_DISABLED_BY_DESKTOP = 1 << 2,
171 // Window will not be painted because it is minimized
172 PAINT_DISABLED_BY_MINIMIZE = 1 << 3
174 void enablePainting( int reason );
175 void disablePainting( int reason );
176 // is the window visible at all
177 bool isVisible() const;
178 // is the window fully opaque
179 bool isOpaque() const;
180 // shape of the window
181 QRegion shape() const;
182 void discardShape();
183 void updateToplevel( Toplevel* c );
184 // creates initial quad list for the window
185 virtual WindowQuadList buildQuads( bool force = false ) const;
186 void suspendUnredirect( bool suspend );
187 protected:
188 WindowQuadList makeQuads( WindowQuadType type, const QRegion& reg ) const;
189 Toplevel* toplevel;
190 ImageFilterType filter;
191 private:
192 int disable_painting;
193 mutable QRegion shape_region;
194 mutable bool shape_valid;
195 mutable WindowQuadList* cached_quad_list;
196 Q_DISABLE_COPY(Window)
199 extern Scene* scene;
201 inline
202 int Scene::Window::x() const
204 return toplevel->x();
207 inline
208 int Scene::Window::y() const
210 return toplevel->y();
213 inline
214 int Scene::Window::width() const
216 return toplevel->width();
219 inline
220 int Scene::Window::height() const
222 return toplevel->height();
225 inline
226 QRect Scene::Window::geometry() const
228 return toplevel->geometry();
231 inline
232 QSize Scene::Window::size() const
234 return toplevel->size();
237 inline
238 QPoint Scene::Window::pos() const
240 return toplevel->pos();
243 inline
244 QRect Scene::Window::rect() const
246 return toplevel->rect();
249 inline
250 Toplevel* Scene::Window::window()
252 return toplevel;
255 inline
256 void Scene::Window::updateToplevel( Toplevel* c )
258 toplevel = c;
261 inline
262 void Scene::Window::suspendUnredirect( bool suspend )
264 toplevel->suspendUnredirect( suspend );
267 } // namespace
269 #endif