Qt 4.8
qdirectfbpaintdevice.cpp
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 #include "qdirectfbscreen.h"
43 #include "qdirectfbpaintdevice.h"
44 #include "qdirectfbpaintengine.h"
45 
46 #ifndef QT_NO_QWS_DIRECTFB
47 
49 
51  : QCustomRasterPaintDevice(0), dfbSurface(0), screen(scr),
52  bpl(-1), lockFlgs(DFBSurfaceLockFlags(0)), mem(0), engine(0), imageFormat(QImage::Format_Invalid)
53 {
54 #ifdef QT_DIRECTFB_SUBSURFACE
55  subSurface = 0;
56  syncPending = false;
57 #endif
58 }
59 
61 {
63  unlockSurface();
64 #ifdef QT_DIRECTFB_SUBSURFACE
65  releaseSubSurface();
66 #endif
67  if (dfbSurface) {
69  }
70  }
71  delete engine;
72 }
73 
74 IDirectFBSurface *QDirectFBPaintDevice::directFBSurface() const
75 {
76  return dfbSurface;
77 }
78 
80 {
81  if (lockFlgs && (lockFlags & ~lockFlgs))
82  unlockSurface();
83  if (!mem) {
85 #ifdef QT_DIRECTFB_SUBSURFACE
86  if (!subSurface) {
87  DFBResult result;
88  subSurface = screen->getSubSurface(dfbSurface, QRect(), QDirectFBScreen::TrackSurface, &result);
89  if (result != DFB_OK || !subSurface) {
90  DirectFBError("Couldn't create sub surface", result);
91  return false;
92  }
93  }
94  IDirectFBSurface *surface = subSurface;
95 #else
96  IDirectFBSurface *surface = dfbSurface;
97 #endif
98  Q_ASSERT(surface);
99  mem = QDirectFBScreen::lockSurface(surface, lockFlags, &bpl);
101  Q_ASSERT(mem);
102  Q_ASSERT(bpl > 0);
103  const QSize s = size();
104  lockedImage = QImage(mem, s.width(), s.height(), bpl,
106  return true;
107  }
108 #ifdef QT_DIRECTFB_SUBSURFACE
109  if (syncPending) {
110  syncPending = false;
111  screen->waitIdle();
112  }
113 #endif
114  return false;
115 }
116 
118 {
120 #ifdef QT_DIRECTFB_SUBSURFACE
121  IDirectFBSurface *surface = subSurface;
122 #else
123  IDirectFBSurface *surface = dfbSurface;
124 #endif
125  if (surface) {
126  surface->Unlock(surface);
127  lockFlgs = static_cast<DFBSurfaceLockFlags>(0);
128  mem = 0;
129  }
130  }
131 }
132 
134 {
135  return mem;
136 }
137 
139 {
140  return imageFormat;
141 }
142 
144 {
145  Q_ASSERT(!mem || bpl != -1);
146  return bpl;
147 }
148 
150 {
151  int w, h;
152  dfbSurface->GetSize(dfbSurface, &w, &h);
153  return QSize(w, h);
154 }
155 
157 {
158  if (!dfbSurface)
159  return 0;
160 
161  switch (metric) {
164  return (metric == PdmWidth ? size().width() : size().height());
166  return (size().width() * 1000) / dotsPerMeterX();
168  return (size().height() * 1000) / dotsPerMeterY();
171  return (dotsPerMeterX() * 254) / 10000; // 0.0254 meters-per-inch
174  return (dotsPerMeterY() * 254) / 10000; // 0.0254 meters-per-inch
178  if (!lockedImage.isNull())
179  return lockedImage.colorCount();
180 
181  DFBResult result;
182  IDirectFBPalette *palette = 0;
183  unsigned int numColors = 0;
184 
185  result = dfbSurface->GetPalette(dfbSurface, &palette);
186  if ((result != DFB_OK) || !palette)
187  return 0;
188 
189  result = palette->GetSize(palette, &numColors);
190  palette->Release(palette);
191  if (result != DFB_OK)
192  return 0;
193 
194  return numColors;
195  }
196  default:
197  qCritical("QDirectFBPaintDevice::metric(): Unhandled metric!");
198  return 0;
199  }
200 }
201 
203 {
204  return engine;
205 }
206 
207 #ifdef QT_DIRECTFB_SUBSURFACE
208 void QDirectFBPaintDevice::releaseSubSurface()
209 {
211  if (subSurface) {
212  unlockSurface();
213  screen->releaseDFBSurface(subSurface);
214  subSurface = 0;
215  }
216 }
217 #endif
218 
220 
221 #endif // QT_NO_QWS_DIRECTFB
Format
The following image formats are available in Qt.
Definition: qimage.h:91
DFBSurfaceLockFlags lockFlgs
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QCustomRasterPaintDevice class is provided to activate hardware accelerated paint engines in Qt f...
void releaseDFBSurface(IDirectFBSurface *surface)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
int height() const
Definition: qpaintdevice.h:92
QDirectFBPaintDevice(QDirectFBScreen *scr)
QDirectFBScreen * screen
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QDirectFBPaintEngine * engine
void * memory() const
Returns a pointer to the paint device&#39;s memory buffer, or 0 if no such buffer exists.
DFBSurfaceLockFlags lockFlags() const
int width() const
Returns the width.
Definition: qsize.h:126
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int width() const
Definition: qpaintdevice.h:91
QImage::Format format() const
Returns the format of the device&#39;s memory buffet.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QImage::Format getImageFormat(IDirectFBSurface *surface)
int metric(QPaintDevice::PaintDeviceMetric metric) const
Reimplemented Function
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
IDirectFBSurface * dfbSurface
QT_DEPRECATED int numColors() const
Definition: qpaintdevice.h:100
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static uchar * lockSurface(IDirectFBSurface *surface, DFBSurfaceLockFlags flags, int *bpl=0)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QDirectFBScreen * instance()
virtual IDirectFBSurface * directFBSurface() const
bool lockSurface(DFBSurfaceLockFlags lockFlags)
int bytesPerLine() const
Returns the number of bytes per line in the framebuffer.
Q_CORE_EXPORT void qCritical(const char *,...)
int depth() const
Returns the depth of the framebuffer, in bits per pixel.
Definition: qscreen_qws.h:229
QPaintEngine * paintEngine() const