/src/gui/embedded/qscreen_qws.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 392 lines · 256 code · 81 blank · 55 comment · 1 complexity · 81da368f4657c3502226f1551f20ff68 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 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. #ifndef QSCREEN_QWS_H
  42. #define QSCREEN_QWS_H
  43. #include <QtCore/qnamespace.h>
  44. #include <QtCore/qpoint.h>
  45. #include <QtCore/qstringlist.h>
  46. #include <QtGui/qrgb.h>
  47. #include <QtCore/qrect.h>
  48. #include <QtGui/qimage.h>
  49. #include <QtGui/qregion.h>
  50. struct fb_cmap;
  51. QT_BEGIN_HEADER
  52. QT_BEGIN_NAMESPACE
  53. QT_MODULE(Gui)
  54. class QScreenCursor;
  55. class QBrush;
  56. class QWSWindow;
  57. class QWSWindowSurface;
  58. class QGraphicsSystem;
  59. class QPixmapData;
  60. #ifndef QT_QWS_DEPTH16_RGB
  61. #define QT_QWS_DEPTH16_RGB 565
  62. #endif
  63. static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);
  64. static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);
  65. static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);
  66. static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
  67. static const int qt_green_shift = qt_bbits-(8-qt_gbits);
  68. static const int qt_neg_blue_shift = 8-qt_bbits;
  69. static const int qt_blue_mask = (1<<qt_bbits)-1;
  70. static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);
  71. static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
  72. static const int qt_red_rounding_shift = qt_red_shift + qt_rbits;
  73. static const int qt_green_rounding_shift = qt_green_shift + qt_gbits;
  74. static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift;
  75. inline ushort qt_convRgbTo16(const int r, const int g, const int b)
  76. {
  77. const int tr = r << qt_red_shift;
  78. const int tg = g << qt_green_shift;
  79. const int tb = b >> qt_neg_blue_shift;
  80. return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
  81. }
  82. inline ushort qt_convRgbTo16(QRgb c)
  83. {
  84. const int tr = qRed(c) << qt_red_shift;
  85. const int tg = qGreen(c) << qt_green_shift;
  86. const int tb = qBlue(c) >> qt_neg_blue_shift;
  87. return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
  88. }
  89. inline QRgb qt_conv16ToRgb(ushort c)
  90. {
  91. const int r=(c & qt_red_mask);
  92. const int g=(c & qt_green_mask);
  93. const int b=(c & qt_blue_mask);
  94. const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift;
  95. const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift;
  96. const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift;
  97. return qRgb(tr,tg,tb);
  98. }
  99. inline void qt_conv16ToRgb(ushort c, int& r, int& g, int& b)
  100. {
  101. const int tr=(c & qt_red_mask);
  102. const int tg=(c & qt_green_mask);
  103. const int tb=(c & qt_blue_mask);
  104. r = tr >> qt_red_shift | tr >> qt_red_rounding_shift;
  105. g = tg >> qt_green_shift | tg >> qt_green_rounding_shift;
  106. b = tb << qt_neg_blue_shift | tb >> qt_blue_rounding_shift;
  107. }
  108. const int SourceSolid=0;
  109. const int SourcePixmap=1;
  110. #ifndef QT_NO_QWS_CURSOR
  111. class QScreenCursor;
  112. extern QScreenCursor *qt_screencursor;
  113. extern bool qws_sw_cursor;
  114. class Q_GUI_EXPORT QScreenCursor
  115. {
  116. public:
  117. QScreenCursor();
  118. virtual ~QScreenCursor();
  119. virtual void set(const QImage &image, int hotx, int hoty);
  120. virtual void move(int x, int y);
  121. virtual void show();
  122. virtual void hide();
  123. bool supportsAlphaCursor() const { return supportsAlpha; }
  124. static bool enabled() { return qws_sw_cursor; }
  125. QRect boundingRect() const { return QRect(pos - hotspot, size); }
  126. QImage image() const { return cursor; }
  127. bool isVisible() const { return enable; }
  128. bool isAccelerated() const { return hwaccel; }
  129. static void initSoftwareCursor();
  130. static QScreenCursor* instance() { return qt_screencursor; }
  131. protected:
  132. QImage cursor;
  133. QSize size;
  134. QPoint pos;
  135. QPoint hotspot;
  136. uint enable : 1;
  137. uint hwaccel : 1;
  138. uint supportsAlpha : 1;
  139. private:
  140. friend class QProxyScreenCursor;
  141. };
  142. #endif // QT_NO_QWS_CURSOR
  143. // A (used) chunk of offscreen memory
  144. class QPoolEntry
  145. {
  146. public:
  147. unsigned int start;
  148. unsigned int end;
  149. int clientId;
  150. };
  151. class QScreen;
  152. class QScreenPrivate;
  153. class QPixmapDataFactory;
  154. extern Q_GUI_EXPORT QScreen *qt_screen;
  155. typedef void(*ClearCacheFunc)(QScreen *obj, int);
  156. class Q_GUI_EXPORT QScreen {
  157. public:
  158. enum ClassId { LinuxFBClass, TransformedClass, VNCClass, MultiClass,
  159. VFbClass, DirectFBClass, SvgalibClass, ProxyClass,
  160. GLClass, IntfbClass, CustomClass = 1024 };
  161. QScreen(int display_id, ClassId classId);
  162. explicit QScreen(int display_id);
  163. virtual ~QScreen();
  164. static QScreen* instance() { return qt_screen; }
  165. virtual bool initDevice() = 0;
  166. virtual bool connect(const QString &displaySpec) = 0;
  167. virtual void disconnect() = 0;
  168. virtual void shutdownDevice();
  169. virtual void setMode(int,int,int) = 0;
  170. virtual bool supportsDepth(int) const;
  171. virtual void save();
  172. virtual void restore();
  173. virtual void blank(bool on);
  174. virtual int pixmapOffsetAlignment() { return 64; }
  175. virtual int pixmapLinestepAlignment() { return 64; }
  176. virtual int sharedRamSize(void *) { return 0; }
  177. virtual bool onCard(const unsigned char *) const;
  178. virtual bool onCard(const unsigned char *, ulong& out_offset) const;
  179. enum PixelType { NormalPixel, BGRPixel };
  180. // sets a single color in the colormap
  181. virtual void set(unsigned int,unsigned int,unsigned int,unsigned int);
  182. // allocates a color
  183. virtual int alloc(unsigned int,unsigned int,unsigned int);
  184. int width() const { return w; }
  185. int height() const { return h; }
  186. int depth() const { return d; }
  187. virtual int pixmapDepth() const;
  188. PixelType pixelType() const { return pixeltype; }
  189. int linestep() const { return lstep; }
  190. int deviceWidth() const { return dw; }
  191. int deviceHeight() const { return dh; }
  192. uchar * base() const { return data; }
  193. // Ask for memory from card cache with alignment
  194. virtual uchar * cache(int) { return 0; }
  195. virtual void uncache(uchar *) {}
  196. QImage::Format pixelFormat() const;
  197. int screenSize() const { return size; }
  198. int totalSize() const { return mapsize; }
  199. QRgb * clut() { return screenclut; }
  200. #ifdef QT_DEPRECATED
  201. QT_DEPRECATED int numCols() { return screencols; }
  202. #endif
  203. int colorCount() { return screencols; }
  204. virtual QSize mapToDevice(const QSize &) const;
  205. virtual QSize mapFromDevice(const QSize &) const;
  206. virtual QPoint mapToDevice(const QPoint &, const QSize &) const;
  207. virtual QPoint mapFromDevice(const QPoint &, const QSize &) const;
  208. virtual QRect mapToDevice(const QRect &, const QSize &) const;
  209. virtual QRect mapFromDevice(const QRect &, const QSize &) const;
  210. virtual QImage mapToDevice(const QImage &) const;
  211. virtual QImage mapFromDevice(const QImage &) const;
  212. virtual QRegion mapToDevice(const QRegion &, const QSize &) const;
  213. virtual QRegion mapFromDevice(const QRegion &, const QSize &) const;
  214. virtual int transformOrientation() const;
  215. virtual bool isTransformed() const;
  216. virtual bool isInterlaced() const;
  217. virtual void setDirty(const QRect&);
  218. virtual int memoryNeeded(const QString&);
  219. virtual void haltUpdates();
  220. virtual void resumeUpdates();
  221. // composition manager methods
  222. virtual void exposeRegion(QRegion r, int changing);
  223. // these work directly on the screen
  224. virtual void blit(const QImage &img, const QPoint &topLeft, const QRegion &region);
  225. virtual void solidFill(const QColor &color, const QRegion &region);
  226. void blit(QWSWindow *bs, const QRegion &clip);
  227. virtual QWSWindowSurface* createSurface(QWidget *widget) const;
  228. virtual QWSWindowSurface* createSurface(const QString &key) const;
  229. virtual QList<QScreen*> subScreens() const { return QList<QScreen*>(); }
  230. virtual QRegion region() const { return QRect(offset(), QSize(w, h)); }
  231. int subScreenIndexAt(const QPoint &p) const;
  232. void setOffset(const QPoint &p);
  233. QPoint offset() const;
  234. int physicalWidth() const { return physWidth; } // physical display size in mm
  235. int physicalHeight() const { return physHeight; } // physical display size in mm
  236. QPixmapDataFactory* pixmapDataFactory() const; // Deprecated, will be removed in 4.6
  237. QGraphicsSystem* graphicsSystem() const;
  238. #ifdef QT_QWS_CLIENTBLIT
  239. bool supportsBlitInClients() const;
  240. void setSupportsBlitInClients(bool);
  241. #endif
  242. ClassId classId() const;
  243. protected:
  244. void setPixelFormat(QImage::Format format);
  245. void setPixmapDataFactory(QPixmapDataFactory *factory); // Deprecated, will be removed in 4.6
  246. void setGraphicsSystem(QGraphicsSystem* system);
  247. QRgb screenclut[256];
  248. int screencols;
  249. uchar * data;
  250. // Table of allocated lumps, kept in sorted highest-to-lowest order
  251. // The table itself is allocated at the bottom of offscreen memory
  252. // i.e. it's similar to having a stack (the table) and a heap
  253. // (the allocated blocks). Freed space is implicitly described
  254. // by the gaps between the allocated lumps (this saves entries and
  255. // means we don't need to worry about coalescing freed lumps)
  256. QPoolEntry * entries;
  257. int * entryp;
  258. unsigned int * lowest;
  259. int w;
  260. int lstep;
  261. int h;
  262. int d;
  263. PixelType pixeltype;
  264. bool grayscale;
  265. int dw;
  266. int dh;
  267. int size; // Screen size
  268. int mapsize; // Total mapped memory
  269. int displayId;
  270. int physWidth;
  271. int physHeight;
  272. friend class QWSServer;
  273. friend class QWSServerPrivate;
  274. static ClearCacheFunc clearCacheFunc;
  275. private:
  276. void compose(int level, const QRegion &exposed, QRegion &blend,
  277. QImage **blendbuffer, int changing_level);
  278. void paintBackground(const QRegion &);
  279. friend class QWSOnScreenSurface;
  280. static bool isWidgetPaintOnScreen(const QWidget *w);
  281. #if Q_BYTE_ORDER == Q_BIG_ENDIAN
  282. void setFrameBufferLittleEndian(bool littleEndian);
  283. bool frameBufferLittleEndian() const;
  284. friend class QVNCScreen;
  285. friend class QLinuxFbScreen;
  286. friend class QVFbScreen;
  287. friend class QQnxScreen;
  288. friend class QProxyScreen;
  289. friend class QIntfbScreen;
  290. #endif
  291. friend void qt_solidFill_setup(QScreen*, const QColor&, const QRegion&);
  292. friend void qt_blit_setup(QScreen *screen, const QImage &image,
  293. const QPoint &topLeft, const QRegion &region);
  294. #ifdef QT_QWS_DEPTH_GENERIC
  295. friend void qt_set_generic_blit(QScreen *screen, int bpp,
  296. int len_red, int len_green, int len_blue,
  297. int len_alpha, int off_red, int off_green,
  298. int off_blue, int off_alpha);
  299. #endif
  300. QScreenPrivate *d_ptr;
  301. };
  302. // This lives in loadable modules
  303. #ifndef QT_LOADABLE_MODULES
  304. extern "C" QScreen * qt_get_screen(int display_id, const char* spec);
  305. #endif
  306. // This is in main lib, loads the right module, calls qt_get_screen
  307. // In non-loadable cases just aliases to qt_get_screen
  308. const unsigned char * qt_probe_bus();
  309. QT_END_NAMESPACE
  310. QT_END_HEADER
  311. #endif // QSCREEN_QWS_H