Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qwindowsurface_qws_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QWINDOWSURFACE_QWS_P_H
43 #define QWINDOWSURFACE_QWS_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qwindowsurface_p.h"
57 #include <qregion.h>
58 #include <qimage.h>
59 #include <qdirectpainter_qws.h>
60 #include <qmutex.h>
61 #include <private/qwssharedmemory_p.h>
62
63 QT_BEGIN_NAMESPACE
64
65 class QScreen;
66 class QWSWindowSurfacePrivate;
67
68 class Q_GUI_EXPORT QWSWindowSurface : public QWindowSurface
69 {
70 public:
71     QWSWindowSurface();
72     QWSWindowSurface(QWidget *widget);
73     ~QWSWindowSurface();
74
75     virtual bool isValid() const = 0;
76
77     virtual void setGeometry(const QRect &rect);
78     virtual void setGeometry(const QRect &rect, const QRegion &mask);
79     virtual void flush(QWidget *widget, const QRegion &region,
80                        const QPoint &offset);
81
82     virtual bool move(const QPoint &offset);
83     virtual QRegion move(const QPoint &offset, const QRegion &newClip);
84
85     virtual QPoint painterOffset() const; // remove!!!
86
87     virtual void beginPaint(const QRegion &);
88     virtual void endPaint(const QRegion &);
89
90     virtual bool lock(int timeout = -1);
91     virtual void unlock();
92
93     virtual QString key() const = 0;
94
95     // XXX: not good enough
96     virtual QByteArray transientState() const;
97     virtual QByteArray permanentState() const;
98     virtual void setTransientState(const QByteArray &state);
99     virtual void setPermanentState(const QByteArray &state);
100
101     virtual QImage image() const = 0;
102     virtual QPaintDevice *paintDevice() = 0;
103
104     const QRegion clipRegion() const;
105     void setClipRegion(const QRegion &);
106
107 #ifdef QT_QWS_CLIENTBLIT
108     virtual const QRegion directRegion() const;
109     virtual int directRegionId() const;
110     virtual void setDirectRegion(const QRegion &, int);
111 #endif
112
113     enum SurfaceFlag {
114         RegionReserved = 0x1,
115         Buffered = 0x2,
116         Opaque = 0x4
117     };
118     Q_DECLARE_FLAGS(SurfaceFlags, SurfaceFlag)
119
120     SurfaceFlags surfaceFlags() const;
121
122     inline bool isRegionReserved() const {
123         return surfaceFlags() & RegionReserved;
124     }
125     inline bool isBuffered() const { return surfaceFlags() & Buffered; }
126     inline bool isOpaque() const { return surfaceFlags() & Opaque; }
127
128     int winId() const;
129     virtual void releaseSurface();
130
131 protected:
132     void setSurfaceFlags(SurfaceFlags type);
133     void setWinId(int id);
134
135 private:
136     friend class QWidgetPrivate;
137
138     void invalidateBuffer();
139
140     QWSWindowSurfacePrivate *d_ptr;
141 };
142
143 Q_DECLARE_OPERATORS_FOR_FLAGS(QWSWindowSurface::SurfaceFlags)
144
145 class QWSWindowSurfacePrivate
146 {
147 public:
148     QWSWindowSurfacePrivate();
149
150     void setWinId(int id);
151
152     QWSWindowSurface::SurfaceFlags flags;
153     QRegion clip;
154 #ifdef QT_QWS_CLIENTBLIT
155     QRegion direct;
156     int directId;
157 #endif
158
159     int winId;
160 };
161
162 class QWSLock;
163
164 class Q_GUI_EXPORT QWSMemorySurface : public QWSWindowSurface
165 {
166 public:
167     QWSMemorySurface();
168     QWSMemorySurface(QWidget *widget);
169     ~QWSMemorySurface();
170
171     bool isValid() const;
172
173     QPaintDevice *paintDevice() { return &img; }
174     bool scroll(const QRegion &area, int dx, int dy);
175
176     QImage image() const { return img; }
177     QPoint painterOffset() const;
178
179     void beginPaint(const QRegion &rgn);
180
181     bool lock(int timeout = -1);
182     void unlock();
183
184 protected:
185     QImage::Format preferredImageFormat(const QWidget *widget) const;
186
187 #ifndef QT_NO_QWS_MULTIPROCESS
188     void setLock(int lockId);
189     QWSLock *memlock;
190 #endif
191 #ifndef QT_NO_THREAD
192     QMutex threadLock;
193 #endif
194
195     QImage img;
196 };
197
198 class Q_GUI_EXPORT QWSLocalMemSurface : public QWSMemorySurface
199 {
200 public:
201     QWSLocalMemSurface();
202     QWSLocalMemSurface(QWidget *widget);
203     ~QWSLocalMemSurface();
204
205     void setGeometry(const QRect &rect);
206
207     QString key() const { return QLatin1String("mem"); }
208     QByteArray permanentState() const;
209
210     void setPermanentState(const QByteArray &data);
211     virtual void releaseSurface();
212 protected:
213     uchar *mem;
214     int memsize;
215 };
216
217 #ifndef QT_NO_QWS_MULTIPROCESS
218 class Q_GUI_EXPORT QWSSharedMemSurface : public QWSMemorySurface
219 {
220 public:
221     QWSSharedMemSurface();
222     QWSSharedMemSurface(QWidget *widget);
223     ~QWSSharedMemSurface();
224
225     void setGeometry(const QRect &rect);
226
227     QString key() const { return QLatin1String("shm"); }
228     QByteArray permanentState() const;
229
230     void setPermanentState(const QByteArray &data);
231
232 #ifdef QT_QWS_CLIENTBLIT
233     virtual void setDirectRegion(const QRegion &, int);
234     virtual const QRegion directRegion() const;
235 #endif
236     virtual void releaseSurface();
237
238 private:
239     bool setMemory(int memId);
240
241     QWSSharedMemory mem;
242 };
243 #endif // QT_NO_QWS_MULTIPROCESS
244
245 #ifndef QT_NO_PAINTONSCREEN
246 class Q_GUI_EXPORT QWSOnScreenSurface : public QWSMemorySurface
247 {
248 public:
249     QWSOnScreenSurface();
250     QWSOnScreenSurface(QWidget *widget);
251     ~QWSOnScreenSurface();
252
253     bool isValid() const;
254     QPoint painterOffset() const;
255
256     QString key() const { return QLatin1String("OnScreen"); }
257     QByteArray permanentState() const;
258
259     void setPermanentState(const QByteArray &data);
260
261 private:
262     void attachToScreen(const QScreen *screen);
263
264     const QScreen *screen;
265 };
266 #endif // QT_NO_PAINTONSCREEN
267
268 #ifndef QT_NO_PAINT_DEBUG
269 class Q_GUI_EXPORT QWSYellowSurface : public QWSWindowSurface
270 {
271 public:
272     QWSYellowSurface(bool isClient = false);
273     ~QWSYellowSurface();
274
275     void setDelay(int msec) { delay = msec; }
276
277     bool isValid() const { return true; }
278
279     void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
280
281     QString key() const { return QLatin1String("Yellow"); }
282     QByteArray permanentState() const;
283
284     void setPermanentState(const QByteArray &data);
285
286     QPaintDevice *paintDevice() { return &img; }
287     QImage image() const { return img; }
288
289 private:
290     int delay;
291     QSize surfaceSize; // client side
292     QImage img; // server side
293 };
294 #endif // QT_NO_PAINT_DEBUG
295
296 #ifndef QT_NO_DIRECTPAINTER
297
298 class QScreen;
299
300 class Q_GUI_EXPORT QWSDirectPainterSurface : public QWSWindowSurface
301 {
302 public:
303     QWSDirectPainterSurface(bool isClient = false,
304                             QDirectPainter::SurfaceFlag flags = QDirectPainter::NonReserved);
305     ~QWSDirectPainterSurface();
306
307     void setReserved() { setSurfaceFlags(RegionReserved); }
308
309     void setGeometry(const QRect &rect) { setRegion(rect); }
310
311     void setRegion(const QRegion &region);
312     QRegion region() const { return clipRegion(); }
313
314     void flush(QWidget*, const QRegion &, const QPoint &);
315
316     bool isValid() const { return false; }
317
318     QString key() const { return QLatin1String("DirectPainter"); }
319     QByteArray permanentState() const;
320
321     void setPermanentState(const QByteArray &);
322
323     QImage image() const { return QImage(); }
324     QPaintDevice *paintDevice() { return 0; }
325
326     // hw: get rid of this
327     WId windowId() const { return static_cast<WId>(winId()); }
328
329     QScreen *screen() const { return _screen; }
330
331     void beginPaint(const QRegion &);
332     bool lock(int timeout = -1);
333     void unlock();
334
335     void setLocking(bool b) { doLocking = b; }
336
337     bool hasPendingRegionEvents() const;
338
339 private:
340     QScreen *_screen;
341 #ifndef QT_NO_THREAD
342     QMutex threadLock;
343 #endif
344
345     friend void qt_directpainter_region(QDirectPainter*, const QRegion&, int);
346     bool flushingRegionEvents;
347     bool synchronous;
348     bool doLocking;
349 };
350
351 #endif // QT_NO_DIRECTPAINTER
352
353 QT_END_NAMESPACE
354
355 #endif // QWINDOWSURFACE_QWS_P_H