1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*********************************************************************/
20
21#ifndef KWIN_SCENE_XRENDER_H
22#define KWIN_SCENE_XRENDER_H
23
24#include "scene.h"
25#include "shadow.h"
26
27#ifdef KWIN_HAVE_XRENDER_COMPOSITING
28
29namespace KWin
30{
31
32
33class SceneXrender
34 : public Scene
35{
36 Q_OBJECT
37public:
38 class EffectFrame;
39 explicit SceneXrender(Workspace* ws);
40 virtual ~SceneXrender();
41 virtual bool initFailed() const;
42 virtual CompositingType compositingType() const {
43 return XRenderCompositing;
44 }
45 virtual qint64 paint(QRegion damage, ToplevelList windows);
46 virtual void windowAdded(Toplevel*);
47 virtual void windowDeleted(Deleted*);
48 virtual void screenGeometryChanged(const QSize &size);
49 xcb_render_picture_t bufferPicture();
50 virtual OverlayWindow *overlayWindow() {
51 return m_overlayWindow;
52 }
53protected:
54 virtual void paintBackground(QRegion region);
55 virtual void paintGenericScreen(int mask, ScreenPaintData data);
56 virtual void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data);
57public Q_SLOTS:
58 virtual void windowOpacityChanged(KWin::Toplevel* c);
59 virtual void windowGeometryShapeChanged(KWin::Toplevel* c);
60 virtual void windowClosed(KWin::Toplevel* c, KWin::Deleted* deleted);
61private:
62 void createBuffer();
63 void present(int mask, QRegion damage);
64 void initXRender(bool createOverlay);
65 xcb_render_pictformat_t format;
66 xcb_render_picture_t front;
67 static xcb_render_picture_t buffer;
68 static ScreenPaintData screen_paint;
69 class Window;
70 QHash< Toplevel*, Window* > windows;
71 OverlayWindow* m_overlayWindow;
72 bool init_ok;
73};
74
75class SceneXrender::Window
76 : public Scene::Window
77{
78public:
79 Window(Toplevel* c);
80 virtual ~Window();
81 virtual void performPaint(int mask, QRegion region, WindowPaintData data);
82 QRegion transformedShape() const;
83 void setTransformedShape(const QRegion& shape);
84 static void cleanup();
85protected:
86 virtual WindowPixmap* createWindowPixmap();
87private:
88 QRect mapToScreen(int mask, const WindowPaintData &data, const QRect &rect) const;
89 QPoint mapToScreen(int mask, const WindowPaintData &data, const QPoint &point) const;
90 void prepareTempPixmap();
91 void setPictureFilter(xcb_render_picture_t pic, ImageFilterType filter);
92 xcb_render_pictformat_t format;
93 double alpha_cached_opacity;
94 QRegion transformed_shape;
95 static QRect temp_visibleRect;
96 static XRenderPicture *s_tempPicture;
97};
98
99class XRenderWindowPixmap : public WindowPixmap
100{
101public:
102 explicit XRenderWindowPixmap(Scene::Window *window, xcb_render_pictformat_t format);
103 virtual ~XRenderWindowPixmap();
104 xcb_render_picture_t picture() const;
105 virtual void create();
106private:
107 xcb_render_picture_t m_picture;
108 xcb_render_pictformat_t m_format;
109};
110
111class SceneXrender::EffectFrame
112 : public Scene::EffectFrame
113{
114public:
115 EffectFrame(EffectFrameImpl* frame);
116 virtual ~EffectFrame();
117
118 virtual void free();
119 virtual void freeIconFrame();
120 virtual void freeTextFrame();
121 virtual void freeSelection();
122 virtual void crossFadeIcon();
123 virtual void crossFadeText();
124 virtual void render(QRegion region, double opacity, double frameOpacity);
125 static void cleanup();
126
127private:
128 void updatePicture();
129 void updateTextPicture();
130 void renderUnstyled(xcb_render_picture_t pict, const QRect &rect, qreal opacity);
131
132 XRenderPicture* m_picture;
133 XRenderPicture* m_textPicture;
134 XRenderPicture* m_iconPicture;
135 XRenderPicture* m_selectionPicture;
136 static XRenderPicture* s_effectFrameCircle;
137};
138
139inline
140xcb_render_picture_t SceneXrender::bufferPicture()
141{
142 return buffer;
143}
144
145inline
146QRegion SceneXrender::Window::transformedShape() const
147{
148 return transformed_shape;
149}
150
151inline
152void SceneXrender::Window::setTransformedShape(const QRegion& shape)
153{
154 transformed_shape = shape;
155}
156
157inline
158xcb_render_picture_t XRenderWindowPixmap::picture() const
159{
160 return m_picture;
161}
162
163/**
164 * @short XRender implementation of Shadow.
165 *
166 * This class extends Shadow by the elements required for XRender rendering.
167 * @author Jacopo De Simoi <wilderkde@gmail.org>
168 **/
169
170class SceneXRenderShadow
171 : public Shadow
172{
173public:
174 explicit SceneXRenderShadow(Toplevel *toplevel);
175 using Shadow::ShadowElements;
176 using Shadow::ShadowElementTop;
177 using Shadow::ShadowElementTopRight;
178 using Shadow::ShadowElementRight;
179 using Shadow::ShadowElementBottomRight;
180 using Shadow::ShadowElementBottom;
181 using Shadow::ShadowElementBottomLeft;
182 using Shadow::ShadowElementLeft;
183 using Shadow::ShadowElementTopLeft;
184 using Shadow::ShadowElementsCount;
185 using Shadow::shadowPixmap;
186 virtual ~SceneXRenderShadow();
187
188 void layoutShadowRects(QRect& top, QRect& topRight,
189 QRect& right, QRect& bottomRight,
190 QRect& bottom, QRect& bottomLeft,
191 QRect& Left, QRect& topLeft);
192 xcb_render_picture_t picture(ShadowElements element) const;
193
194protected:
195 virtual void buildQuads();
196 virtual bool prepareBackend();
197private:
198 XRenderPicture* m_pictures[ShadowElementsCount];
199};
200
201} // namespace
202
203#endif
204
205#endif
206