Qt 4.8
qdirectfbscreen.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 plugins 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 QDIRECTFBSCREEN_H
43 #define QDIRECTFBSCREEN_H
44 
45 #include <qglobal.h>
46 #ifndef QT_NO_QWS_DIRECTFB
47 #include <QtGui/qscreen_qws.h>
48 #include <directfb.h>
49 #include <directfb_version.h>
50 
52 
54 
55 QT_MODULE(Gui)
56 
57 #if !defined QT_DIRECTFB_SUBSURFACE && !defined QT_NO_DIRECTFB_SUBSURFACE
58 #define QT_NO_DIRECTFB_SUBSURFACE
59 #endif
60 #if !defined QT_NO_DIRECTFB_LAYER && !defined QT_DIRECTFB_LAYER
61 #define QT_DIRECTFB_LAYER
62 #endif
63 #if !defined QT_NO_DIRECTFB_WM && !defined QT_DIRECTFB_WM
64 #define QT_DIRECTFB_WM
65 #endif
66 #if !defined QT_DIRECTFB_IMAGECACHE && !defined QT_NO_DIRECTFB_IMAGECACHE
67 #define QT_NO_DIRECTFB_IMAGECACHE
68 #endif
69 #if !defined QT_NO_DIRECTFB_IMAGEPROVIDER && !defined QT_DIRECTFB_IMAGEPROVIDER
70 #define QT_DIRECTFB_IMAGEPROVIDER
71 #endif
72 #if !defined QT_NO_DIRECTFB_STRETCHBLIT && !defined QT_DIRECTFB_STRETCHBLIT
73 #define QT_DIRECTFB_STRETCHBLIT
74 #endif
75 #if !defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE && !defined QT_NO_DIRECTFB_IMAGEPROVIDER_KEEPALIVE
76 #define QT_NO_DIRECTFB_IMAGEPROVIDER_KEEPALIVE
77 #endif
78 #if !defined QT_DIRECTFB_WINDOW_AS_CURSOR && !defined QT_NO_DIRECTFB_WINDOW_AS_CURSOR
79 #define QT_NO_DIRECTFB_WINDOW_AS_CURSOR
80 #endif
81 #if !defined QT_DIRECTFB_PALETTE && !defined QT_NO_DIRECTFB_PALETTE
82 #define QT_NO_DIRECTFB_PALETTE
83 #endif
84 #if !defined QT_NO_DIRECTFB_PREALLOCATED && !defined QT_DIRECTFB_PREALLOCATED
85 #define QT_DIRECTFB_PREALLOCATED
86 #endif
87 #if !defined QT_NO_DIRECTFB_MOUSE && !defined QT_DIRECTFB_MOUSE
88 #define QT_DIRECTFB_MOUSE
89 #endif
90 #if !defined QT_NO_DIRECTFB_KEYBOARD && !defined QT_DIRECTFB_KEYBOARD
91 #define QT_DIRECTFB_KEYBOARD
92 #endif
93 #if !defined QT_NO_DIRECTFB_OPAQUE_DETECTION && !defined QT_DIRECTFB_OPAQUE_DETECTION
94 #define QT_DIRECTFB_OPAQUE_DETECTION
95 #endif
96 #ifndef QT_NO_QWS_CURSOR
97 #if defined QT_DIRECTFB_WM && defined QT_DIRECTFB_WINDOW_AS_CURSOR
98 #define QT_DIRECTFB_CURSOR
99 #elif defined QT_DIRECTFB_LAYER
100 #define QT_DIRECTFB_CURSOR
101 #endif
102 #endif
103 #ifndef QT_DIRECTFB_CURSOR
104 #define QT_NO_DIRECTFB_CURSOR
105 #endif
106 #if defined QT_NO_DIRECTFB_LAYER && defined QT_DIRECTFB_WM
107 #error QT_NO_DIRECTFB_LAYER requires QT_NO_DIRECTFB_WM
108 #endif
109 #if defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE && defined QT_NO_DIRECTFB_IMAGEPROVIDER
110 #error QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE requires QT_DIRECTFB_IMAGEPROVIDER to be defined
111 #endif
112 #if defined QT_DIRECTFB_WINDOW_AS_CURSOR && defined QT_NO_DIRECTFB_WM
113 #error QT_DIRECTFB_WINDOW_AS_CURSOR requires QT_DIRECTFB_WM to be defined
114 #endif
115 
116 #define Q_DIRECTFB_VERSION ((DIRECTFB_MAJOR_VERSION << 16) | (DIRECTFB_MINOR_VERSION << 8) | DIRECTFB_MICRO_VERSION)
117 
118 #define DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(F) \
119  static inline F operator~(F f) { return F(~int(f)); } \
120  static inline F operator&(F left, F right) { return F(int(left) & int(right)); } \
121  static inline F operator|(F left, F right) { return F(int(left) | int(right)); } \
122  static inline F &operator|=(F &left, F right) { left = (left | right); return left; } \
123  static inline F &operator&=(F &left, F right) { left = (left & right); return left; }
124 
125 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBInputDeviceCapabilities);
126 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBWindowDescriptionFlags);
127 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBWindowCapabilities);
128 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBWindowOptions);
129 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceDescriptionFlags);
130 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceCapabilities);
131 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceLockFlags);
132 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceBlittingFlags);
133 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceDrawingFlags);
134 DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceFlipFlags);
135 
138 {
139 public:
140  QDirectFBScreen(int display_id);
141  ~QDirectFBScreen();
142 
144  NoFlags = 0x00,
145  VideoOnly = 0x01,
146  SystemOnly = 0x02,
147  BoundingRectFlip = 0x04,
148  NoPartialFlip = 0x08
149  };
150 
151  Q_DECLARE_FLAGS(DirectFBFlags, DirectFBFlag);
152 
153  DirectFBFlags directFBFlags() const;
154 
155  bool connect(const QString &displaySpec);
156  void disconnect();
157  bool initDevice();
158  void shutdownDevice();
159 
160  void exposeRegion(QRegion r, int changing);
161  void solidFill(const QColor &color, const QRegion &region);
162  static void solidFill(IDirectFBSurface *surface, const QColor &color, const QRegion &region);
163 
164  void setMode(int width, int height, int depth);
165  void blank(bool on);
166 
168  QWSWindowSurface *createSurface(const QString &key) const;
169 
170  static QDirectFBScreen *instance();
171  void waitIdle();
172  IDirectFBSurface *surfaceForWidget(const QWidget *widget, QRect *rect) const;
173 #ifdef QT_DIRECTFB_SUBSURFACE
174  IDirectFBSurface *subSurfaceForWidget(const QWidget *widget, const QRect &area = QRect()) const;
175 #endif
176  IDirectFB *dfb();
177 #ifdef QT_DIRECTFB_WM
178  IDirectFBWindow *windowForWidget(const QWidget *widget) const;
179 #else
180  IDirectFBSurface *primarySurface();
181 #endif
182 #ifndef QT_NO_DIRECTFB_LAYER
183  IDirectFBDisplayLayer *dfbDisplayLayer();
184 #endif
185 
186  // Track surface creation/release so we can release all on exit
188  DontTrackSurface = 0x1,
189  TrackSurface = 0x2,
190  NoPreallocated = 0x4
191  };
192  Q_DECLARE_FLAGS(SurfaceCreationOptions, SurfaceCreationOption);
193  IDirectFBSurface *createDFBSurface(const QImage &image,
195  SurfaceCreationOptions options,
196  DFBResult *result = 0);
197  IDirectFBSurface *createDFBSurface(const QSize &size,
199  SurfaceCreationOptions options,
200  DFBResult *result = 0);
201  IDirectFBSurface *copyDFBSurface(IDirectFBSurface *src,
203  SurfaceCreationOptions options,
204  DFBResult *result = 0);
205  IDirectFBSurface *createDFBSurface(DFBSurfaceDescription desc,
206  SurfaceCreationOptions options,
207  DFBResult *result);
208 #ifdef QT_DIRECTFB_SUBSURFACE
209  IDirectFBSurface *getSubSurface(IDirectFBSurface *surface,
210  const QRect &rect,
211  SurfaceCreationOptions options,
212  DFBResult *result);
213 #endif
214 
215  void flipSurface(IDirectFBSurface *surface, DFBSurfaceFlipFlags flipFlags,
216  const QRegion &region, const QPoint &offset);
217  void releaseDFBSurface(IDirectFBSurface *surface);
218 
219  using QScreen::depth;
220  static int depth(DFBSurfacePixelFormat format);
221  static int depth(QImage::Format format);
222 
223  static DFBSurfacePixelFormat getSurfacePixelFormat(QImage::Format format);
224  static DFBSurfaceDescription getSurfaceDescription(const uint *buffer,
225  int length);
226  static QImage::Format getImageFormat(IDirectFBSurface *surface);
227  static bool initSurfaceDescriptionPixelFormat(DFBSurfaceDescription *description, QImage::Format format);
228  static inline bool isPremultiplied(QImage::Format format);
229  static inline bool hasAlphaChannel(DFBSurfacePixelFormat format);
230  static inline bool hasAlphaChannel(IDirectFBSurface *surface);
231  QImage::Format alphaPixmapFormat() const;
232 
233 #ifndef QT_NO_DIRECTFB_PALETTE
234  static void setSurfaceColorTable(IDirectFBSurface *surface,
235  const QImage &image);
236 #endif
237 
238  static uchar *lockSurface(IDirectFBSurface *surface, DFBSurfaceLockFlags flags, int *bpl = 0);
239 #if defined QT_DIRECTFB_IMAGEPROVIDER && defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE
240  void setDirectFBImageProvider(IDirectFBImageProvider *provider);
241 #endif
242 private:
244 };
245 
246 Q_DECLARE_OPERATORS_FOR_FLAGS(QDirectFBScreen::SurfaceCreationOptions);
247 Q_DECLARE_OPERATORS_FOR_FLAGS(QDirectFBScreen::DirectFBFlags);
248 
250 {
251  switch (format) {
257  return true;
258  default:
259  break;
260  }
261  return false;
262 }
263 
264 inline bool QDirectFBScreen::hasAlphaChannel(DFBSurfacePixelFormat format)
265 {
266  switch (format) {
267  case DSPF_ARGB1555:
268  case DSPF_ARGB:
269  case DSPF_LUT8:
270  case DSPF_AiRGB:
271  case DSPF_A1:
272  case DSPF_ARGB2554:
273  case DSPF_ARGB4444:
274 #if (Q_DIRECTFB_VERSION >= 0x000923)
275  case DSPF_AYUV:
276 #endif
277 #if (Q_DIRECTFB_VERSION >= 0x010000)
278  case DSPF_A4:
279  case DSPF_ARGB1666:
280  case DSPF_ARGB6666:
281  case DSPF_LUT2:
282 #endif
283  return true;
284  default:
285  return false;
286  }
287 }
288 
289 inline bool QDirectFBScreen::hasAlphaChannel(IDirectFBSurface *surface)
290 {
291  Q_ASSERT(surface);
292  DFBSurfacePixelFormat format;
293  surface->GetPixelFormat(surface, &format);
294  return QDirectFBScreen::hasAlphaChannel(format);
295 }
296 
298 
300 
301 #endif // QT_NO_QWS_DIRECTFB
302 #endif // QDIRECTFBSCREEN_H
303 
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
Format
The following image formats are available in Qt.
Definition: qimage.h:91
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
static bool hasAlphaChannel(DFBSurfacePixelFormat format)
#define DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(F)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
static bool isPremultiplied(QImage::Format format)
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual bool connect(const QString &displaySpec)=0
This function is called by every Qt for Embedded Linux application on startup, and must be implemente...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void setMode(int, int, int)=0
Implement this function to reset the framebuffer&#39;s resolution (width and height) and bit depth...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual void disconnect()=0
This function is called by every Qt for Embedded Linux application before exiting, and must be implemented to unmap the framebuffer.
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual bool initDevice()=0
This function is called by the Qt for Embedded Linux server to initialize the framebuffer.
QDirectFBScreenPrivate * d_ptr
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
static QScreen * instance()
Returns a pointer to the application&#39;s QScreen instance.
Definition: qscreen_qws.h:201
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual QWSWindowSurface * createSurface(QWidget *widget) const
Creates and returns a new window surface for the given widget.
virtual void blank(bool on)
Prevents the screen driver form displaying any content on the screen.
Q_DECLARE_OPERATORS_FOR_FLAGS(QDirectFBScreen::SurfaceCreationOptions)
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
virtual void shutdownDevice()
This function is called by the Qt for Embedded Linux server before it calls the disconnect() function...
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
virtual void exposeRegion(QRegion r, int changing)
This function is called by the Qt for Embedded Linux server whenever a screen update is required...
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void solidFill(const QColor &color, const QRegion &region)
Fills the given region of the screen with the specified color.
int depth() const
Returns the depth of the framebuffer, in bits per pixel.
Definition: qscreen_qws.h:229
static int area(const QSize &s)
Definition: qicon.cpp:155