QtGui/qscreen_qws.h Source File

qscreen_qws.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
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 
56 
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 
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 
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 
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;
112 
113  return qRgb(tr,tg,tb);
114 }
115 
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 
146  bool supportsAlphaCursor() const { return supportsAlpha; }
147 
148  static bool enabled() { return qws_sw_cursor; }
149 
150  QRect boundingRect() const { return QRect(pos - hotspot, size); }
151  QImage image() const { return cursor; }
152  bool isVisible() const { return enable; }
153  bool isAccelerated() const { return hwaccel; }
154 
155  static void initSoftwareCursor();
156  static QScreenCursor* instance() { return qt_screencursor; }
157 
158 protected:
160 
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 
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;
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();
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 
213  virtual int pixmapOffsetAlignment() { return 64; }
214  virtual int pixmapLinestepAlignment() { return 64; }
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 
227  int width() const { return w; }
228  int height() const { return h; }
229  int depth() const { return d; }
230  virtual int pixmapDepth() const;
231  PixelType pixelType() const { return pixeltype; }
232  int linestep() const { return lstep; }
233  int deviceWidth() const { return dw; }
234  int deviceHeight() const { return dh; }
235  uchar * base() const { return data; }
236  // Ask for memory from card cache with alignment
237  virtual uchar * cache(int) { return 0; }
238  virtual void uncache(uchar *) {}
239 
240  QImage::Format pixelFormat() const;
241 
242  int screenSize() const { return size; }
243  int totalSize() const { return mapsize; }
244 
245  QRgb * clut() { return screenclut; }
246 #ifdef QT_DEPRECATED
247  QT_DEPRECATED int numCols() { return screencols; }
248 #endif
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 &region);
277  virtual void solidFill(const QColor &color, const QRegion &region);
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 
283  virtual QList<QScreen*> subScreens() const { return QList<QScreen*>(); }
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 
290  int physicalWidth() const { return physWidth; } // physical display size in mm
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];
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 
321  int * entryp;
322  unsigned int * lowest;
323 
324  int w;
325  int lstep;
326  int h;
327  int d;
329  bool grayscale;
330 
331  int dw;
332  int dh;
333 
334  int size; // Screen size
335  int mapsize; // Total mapped memory
336 
338 
341 
342  friend class QWSServer;
343  friend class QWSServerPrivate;
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 &region);
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 
389 
391 
392 #endif // QSCREEN_QWS_H
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
Definition: GLee.h:10762
static const int qt_red_rounding_shift
Definition: qscreen_qws.h:81
GLenum GLint GLint y
Definition: GLee.h:876
bool isAccelerated() const
Definition: qscreen_qws.h:153
int physicalWidth() const
Definition: qscreen_qws.h:290
int physHeight
Definition: qscreen_qws.h:340
GLint level
Definition: GLee.h:905
#define QT_END_NAMESPACE
Definition: qglobal.h:128
GLintptr offset
Definition: GLee.h:1562
virtual QRegion region() const
Definition: qscreen_qws.h:284
int colorCount()
Definition: qscreen_qws.h:249
const int SourcePixmap
Definition: qscreen_qws.h:127
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
QRgb * clut()
Definition: qscreen_qws.h:245
int screen
Definition: GLee.h:10533
static const int qt_bbits
Definition: qscreen_qws.h:73
bool grayscale
Definition: qscreen_qws.h:329
void(* ClearCacheFunc)(QScreen *obj, int)
Definition: qscreen_qws.h:189
virtual int sharedRamSize(void *)
Definition: qscreen_qws.h:215
GLsizei GLsizei GLuint * obj
Definition: GLee.h:1715
QPoint hotspot
Definition: qscreen_qws.h:163
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
Definition: qcolor.h:67
virtual int pixmapOffsetAlignment()
Definition: qscreen_qws.h:213
unsigned int end
Definition: qscreen_qws.h:180
friend void qt_blit_setup(QScreen *screen, const QImage &image, const QPoint &topLeft, const QRegion &region)
int totalSize() const
Definition: qscreen_qws.h:243
static const int qt_blue_mask
Definition: qscreen_qws.h:77
ushort qt_convRgbTo16(const int r, const int g, const int b)
Definition: qscreen_qws.h:86
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: GLee.h:882
static const int qt_red_mask
Definition: qscreen_qws.h:79
QT_BEGIN_HEADER QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition: qrgb.h:53
int int int int int int * dh
Definition: GLee.h:10535
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
static QScreen * instance()
Definition: qscreen_qws.h:201
int depth() const
Definition: qscreen_qws.h:229
virtual int pixmapLinestepAlignment()
Definition: qscreen_qws.h:214
unsigned int * lowest
Definition: qscreen_qws.h:322
Definition: qpoint.h:53
int screenSize() const
Definition: qscreen_qws.h:242
PixelType pixeltype
Definition: qscreen_qws.h:328
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
int deviceHeight() const
Definition: qscreen_qws.h:234
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:880
GLint GLvoid * img
Definition: GLee.h:1216
QRect boundingRect() const
Definition: qscreen_qws.h:150
GLenum GLsizei GLenum format
Definition: GLee.h:873
GLubyte g
Definition: GLee.h:5404
int * entryp
Definition: qscreen_qws.h:321
static const int qt_gbits
Definition: qscreen_qws.h:72
Definition: qimage.h:87
int screencols
Definition: qscreen_qws.h:309
QImage image() const
Definition: qscreen_qws.h:151
PixelType pixelType() const
Definition: qscreen_qws.h:231
GLenum GLint x
Definition: GLee.h:876
int clientId
Definition: qscreen_qws.h:181
static const int qt_green_shift
Definition: qscreen_qws.h:75
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
QRgb qt_conv16ToRgb(ushort c)
Definition: qscreen_qws.h:104
int displayId
Definition: qscreen_qws.h:337
static const int qt_green_mask
Definition: qscreen_qws.h:78
int height() const
Definition: qscreen_qws.h:228
static const int qt_rbits
Definition: qscreen_qws.h:71
GLubyte GLubyte b
Definition: GLee.h:5404
Format
Definition: qimage.h:91
uchar * base() const
Definition: qscreen_qws.h:235
#define QT_QWS_DEPTH16_RGB
Definition: qscreen_qws.h:69
unsigned int start
Definition: qscreen_qws.h:179
virtual void uncache(uchar *)
Definition: qscreen_qws.h:238
int mapsize
Definition: qscreen_qws.h:335
Definition: qrect.h:58
GLfloat GLfloat p
Definition: GLee.h:5416
static const int qt_neg_blue_shift
Definition: qscreen_qws.h:76
const GLubyte * c
Definition: GLee.h:5419
int int int int int int h
Definition: GLee.h:10534
Definition: qsize.h:53
Q_GUI_EXPORT QScreen * qt_screen
const int SourceSolid
Definition: qscreen_qws.h:126
QPoolEntry * entries
Definition: qscreen_qws.h:320
int deviceWidth() const
Definition: qscreen_qws.h:233
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
static const int qt_red_shift
Definition: qscreen_qws.h:74
int physicalHeight() const
Definition: qscreen_qws.h:291
int linestep() const
Definition: qscreen_qws.h:232
QScreen * qt_get_screen(int display_id, const char *spec)
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
Definition: qbrush.h:76
bool supportsAlphaCursor() const
Definition: qscreen_qws.h:146
QScreenCursor * qt_screencursor
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
bool isVisible() const
Definition: qscreen_qws.h:152
static bool enabled()
Definition: qscreen_qws.h:148
bool qws_sw_cursor
static const int qt_blue_rounding_shift
Definition: qscreen_qws.h:83
const unsigned char * qt_probe_bus()
int width() const
Definition: qscreen_qws.h:227
#define QT_END_HEADER
Definition: qglobal.h:142
int int int int int * dw
Definition: GLee.h:10535
int lstep
Definition: qscreen_qws.h:325
virtual uchar * cache(int)
Definition: qscreen_qws.h:237
uchar * data
Definition: qscreen_qws.h:311
static const int qt_green_rounding_shift
Definition: qscreen_qws.h:82
Definition: qscreen_qws.h:176
GLsizeiptr size
Definition: GLee.h:1561
friend void qt_solidFill_setup(QScreen *, const QColor &, const QRegion &)
static ClearCacheFunc clearCacheFunc
Definition: qscreen_qws.h:344
static QScreenCursor * instance()
Definition: qscreen_qws.h:156
int physWidth
Definition: qscreen_qws.h:339
int size
Definition: qscreen_qws.h:334
GLuint color
Definition: GLee.h:8456