1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSCREEN_QWS_H
43 #define QSCREEN_QWS_H
44
45 #include <QtCore/qnamespace.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qstringlist.h>
48 #include <QtGui/qrgb.h>
49 #include <QtCore/qrect.h>
50 #include <QtGui/qimage.h>
51 #include <QtGui/qregion.h>
52
53 struct fb_cmap;
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59 QT_MODULE(Gui)
60
61 class QScreenCursor;
62 class QBrush;
63 class QWSWindow;
64 class QWSWindowSurface;
65 class QGraphicsSystem;
66 class QPixmapData;
67
68 #ifndef QT_QWS_DEPTH16_RGB
69 #define QT_QWS_DEPTH16_RGB 565
70 #endif
71 static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);
72 static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);
73 static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);
74 static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
75 static const int qt_green_shift = qt_bbits-(8-qt_gbits);
76 static const int qt_neg_blue_shift = 8-qt_bbits;
77 static const int qt_blue_mask = (1<<qt_bbits)-1;
78 static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);
79 static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
80
81 static const int qt_red_rounding_shift = qt_red_shift + qt_rbits;
82 static const int qt_green_rounding_shift = qt_green_shift + qt_gbits;
83 static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift;
84
85
qt_convRgbTo16(const int r,const int g,const int b)86 inline ushort qt_convRgbTo16(const int r, const int g, const int b)
87 {
88 const int tr = r << qt_red_shift;
89 const int tg = g << qt_green_shift;
90 const int tb = b >> qt_neg_blue_shift;
91
92 return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
93 }
94
qt_convRgbTo16(QRgb c)95 inline ushort qt_convRgbTo16(QRgb c)
96 {
97 const int tr = qRed(c) << qt_red_shift;
98 const int tg = qGreen(c) << qt_green_shift;
99 const int tb = qBlue(c) >> qt_neg_blue_shift;
100
101 return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
102 }
103
qt_conv16ToRgb(ushort c)104 inline QRgb qt_conv16ToRgb(ushort c)
105 {
106 const int r=(c & qt_red_mask);
107 const int g=(c & qt_green_mask);
108 const int b=(c & qt_blue_mask);
109 const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift;
110 const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift;
111 const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift;
112
113 return qRgb(tr,tg,tb);
114 }
115
qt_conv16ToRgb(ushort c,int & r,int & g,int & b)116 inline void qt_conv16ToRgb(ushort c, int& r, int& g, int& b)
117 {
118 const int tr=(c & qt_red_mask);
119 const int tg=(c & qt_green_mask);
120 const int tb=(c & qt_blue_mask);
121 r = tr >> qt_red_shift | tr >> qt_red_rounding_shift;
122 g = tg >> qt_green_shift | tg >> qt_green_rounding_shift;
123 b = tb << qt_neg_blue_shift | tb >> qt_blue_rounding_shift;
124 }
125
126 const int SourceSolid=0;
127 const int SourcePixmap=1;
128
129 #ifndef QT_NO_QWS_CURSOR
130
131 class QScreenCursor;
132 extern QScreenCursor *qt_screencursor;
133 extern bool qws_sw_cursor;
134
135 class Q_GUI_EXPORT QScreenCursor
136 {
137 public:
138 QScreenCursor();
139 virtual ~QScreenCursor();
140
141 virtual void set(const QImage &image, int hotx, int hoty);
142 virtual void move(int x, int y);
143 virtual void show();
144 virtual void hide();
145
supportsAlphaCursor()146 bool supportsAlphaCursor() const { return supportsAlpha; }
147
enabled()148 static bool enabled() { return qws_sw_cursor; }
149
boundingRect()150 QRect boundingRect() const { return QRect(pos - hotspot, size); }
image()151 QImage image() const { return cursor; }
isVisible()152 bool isVisible() const { return enable; }
isAccelerated()153 bool isAccelerated() const { return hwaccel; }
154
155 static void initSoftwareCursor();
instance()156 static QScreenCursor* instance() { return qt_screencursor; }
157
158 protected:
159 QImage cursor;
160
161 QSize size;
162 QPoint pos;
163 QPoint hotspot;
164 uint enable : 1;
165 uint hwaccel : 1;
166 uint supportsAlpha : 1;
167
168 private:
169 friend class QProxyScreenCursor;
170 };
171
172 #endif // QT_NO_QWS_CURSOR
173
174 // A (used) chunk of offscreen memory
175
176 class QPoolEntry
177 {
178 public:
179 unsigned int start;
180 unsigned int end;
181 int clientId;
182 };
183
184 class QScreen;
185 class QScreenPrivate;
186 class QPixmapDataFactory;
187
188 extern Q_GUI_EXPORT QScreen *qt_screen;
189 typedef void(*ClearCacheFunc)(QScreen *obj, int);
190
191 class Q_GUI_EXPORT QScreen {
192
193 public:
194 enum ClassId { LinuxFBClass, TransformedClass, VNCClass, MultiClass,
195 VFbClass, DirectFBClass, SvgalibClass, ProxyClass,
196 GLClass, IntfbClass, CustomClass = 1024 };
197
198 QScreen(int display_id, ClassId classId);
199 explicit QScreen(int display_id);
200 virtual ~QScreen();
instance()201 static QScreen* instance() { return qt_screen; }
202 virtual bool initDevice() = 0;
203 virtual bool connect(const QString &displaySpec) = 0;
204 virtual void disconnect() = 0;
205 virtual void shutdownDevice();
206 virtual void setMode(int,int,int) = 0;
207 virtual bool supportsDepth(int) const;
208
209 virtual void save();
210 virtual void restore();
211 virtual void blank(bool on);
212
pixmapOffsetAlignment()213 virtual int pixmapOffsetAlignment() { return 64; }
pixmapLinestepAlignment()214 virtual int pixmapLinestepAlignment() { return 64; }
sharedRamSize(void *)215 virtual int sharedRamSize(void *) { return 0; }
216
217 virtual bool onCard(const unsigned char *) const;
218 virtual bool onCard(const unsigned char *, ulong& out_offset) const;
219
220 enum PixelType { NormalPixel, BGRPixel };
221
222 // sets a single color in the colormap
223 virtual void set(unsigned int,unsigned int,unsigned int,unsigned int);
224 // allocates a color
225 virtual int alloc(unsigned int,unsigned int,unsigned int);
226
width()227 int width() const { return w; }
height()228 int height() const { return h; }
depth()229 int depth() const { return d; }
230 virtual int pixmapDepth() const;
pixelType()231 PixelType pixelType() const { return pixeltype; }
linestep()232 int linestep() const { return lstep; }
deviceWidth()233 int deviceWidth() const { return dw; }
deviceHeight()234 int deviceHeight() const { return dh; }
base()235 uchar * base() const { return data; }
236 // Ask for memory from card cache with alignment
cache(int)237 virtual uchar * cache(int) { return 0; }
uncache(uchar *)238 virtual void uncache(uchar *) {}
239
240 QImage::Format pixelFormat() const;
241
screenSize()242 int screenSize() const { return size; }
totalSize()243 int totalSize() const { return mapsize; }
244
clut()245 QRgb * clut() { return screenclut; }
246 #ifdef QT_DEPRECATED
numCols()247 QT_DEPRECATED int numCols() { return screencols; }
248 #endif
colorCount()249 int colorCount() { return screencols; }
250
251 virtual QSize mapToDevice(const QSize &) const;
252 virtual QSize mapFromDevice(const QSize &) const;
253 virtual QPoint mapToDevice(const QPoint &, const QSize &) const;
254 virtual QPoint mapFromDevice(const QPoint &, const QSize &) const;
255 virtual QRect mapToDevice(const QRect &, const QSize &) const;
256 virtual QRect mapFromDevice(const QRect &, const QSize &) const;
257 virtual QImage mapToDevice(const QImage &) const;
258 virtual QImage mapFromDevice(const QImage &) const;
259 virtual QRegion mapToDevice(const QRegion &, const QSize &) const;
260 virtual QRegion mapFromDevice(const QRegion &, const QSize &) const;
261 virtual int transformOrientation() const;
262 virtual bool isTransformed() const;
263 virtual bool isInterlaced() const;
264
265 virtual void setDirty(const QRect&);
266
267 virtual int memoryNeeded(const QString&);
268
269 virtual void haltUpdates();
270 virtual void resumeUpdates();
271
272 // composition manager methods
273 virtual void exposeRegion(QRegion r, int changing);
274
275 // these work directly on the screen
276 virtual void blit(const QImage &img, const QPoint &topLeft, const QRegion ®ion);
277 virtual void solidFill(const QColor &color, const QRegion ®ion);
278 void blit(QWSWindow *bs, const QRegion &clip);
279
280 virtual QWSWindowSurface* createSurface(QWidget *widget) const;
281 virtual QWSWindowSurface* createSurface(const QString &key) const;
282
subScreens()283 virtual QList<QScreen*> subScreens() const { return QList<QScreen*>(); }
region()284 virtual QRegion region() const { return QRect(offset(), QSize(w, h)); }
285 int subScreenIndexAt(const QPoint &p) const;
286
287 void setOffset(const QPoint &p);
288 QPoint offset() const;
289
physicalWidth()290 int physicalWidth() const { return physWidth; } // physical display size in mm
physicalHeight()291 int physicalHeight() const { return physHeight; } // physical display size in mm
292
293 QPixmapDataFactory* pixmapDataFactory() const; // Deprecated, will be removed in 4.6
294 QGraphicsSystem* graphicsSystem() const;
295
296 #ifdef QT_QWS_CLIENTBLIT
297 bool supportsBlitInClients() const;
298 void setSupportsBlitInClients(bool);
299 #endif
300
301 ClassId classId() const;
302
303 protected:
304 void setPixelFormat(QImage::Format format);
305 void setPixmapDataFactory(QPixmapDataFactory *factory); // Deprecated, will be removed in 4.6
306 void setGraphicsSystem(QGraphicsSystem* system);
307
308 QRgb screenclut[256];
309 int screencols;
310
311 uchar * data;
312
313 // Table of allocated lumps, kept in sorted highest-to-lowest order
314 // The table itself is allocated at the bottom of offscreen memory
315 // i.e. it's similar to having a stack (the table) and a heap
316 // (the allocated blocks). Freed space is implicitly described
317 // by the gaps between the allocated lumps (this saves entries and
318 // means we don't need to worry about coalescing freed lumps)
319
320 QPoolEntry * entries;
321 int * entryp;
322 unsigned int * lowest;
323
324 int w;
325 int lstep;
326 int h;
327 int d;
328 PixelType pixeltype;
329 bool grayscale;
330
331 int dw;
332 int dh;
333
334 int size; // Screen size
335 int mapsize; // Total mapped memory
336
337 int displayId;
338
339 int physWidth;
340 int physHeight;
341
342 friend class QWSServer;
343 friend class QWSServerPrivate;
344 static ClearCacheFunc clearCacheFunc;
345
346 private:
347 void compose(int level, const QRegion &exposed, QRegion &blend,
348 QImage **blendbuffer, int changing_level);
349 void paintBackground(const QRegion &);
350
351 friend class QWSOnScreenSurface;
352 static bool isWidgetPaintOnScreen(const QWidget *w);
353
354 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
355 void setFrameBufferLittleEndian(bool littleEndian);
356 bool frameBufferLittleEndian() const;
357 friend class QVNCScreen;
358 friend class QLinuxFbScreen;
359 friend class QVFbScreen;
360 friend class QQnxScreen;
361 friend class QProxyScreen;
362 friend class QIntfbScreen;
363 #endif
364 friend void qt_solidFill_setup(QScreen*, const QColor&, const QRegion&);
365 friend void qt_blit_setup(QScreen *screen, const QImage &image,
366 const QPoint &topLeft, const QRegion ®ion);
367 #ifdef QT_QWS_DEPTH_GENERIC
368 friend void qt_set_generic_blit(QScreen *screen, int bpp,
369 int len_red, int len_green, int len_blue,
370 int len_alpha, int off_red, int off_green,
371 int off_blue, int off_alpha);
372 #endif
373
374 QScreenPrivate *d_ptr;
375 };
376
377 // This lives in loadable modules
378
379 #ifndef QT_LOADABLE_MODULES
380 extern "C" QScreen * qt_get_screen(int display_id, const char* spec);
381 #endif
382
383 // This is in main lib, loads the right module, calls qt_get_screen
384 // In non-loadable cases just aliases to qt_get_screen
385
386 const unsigned char * qt_probe_bus();
387
388 QT_END_NAMESPACE
389
390 QT_END_HEADER
391
392 #endif // QSCREEN_QWS_H
393