Qt 4.8
qgraphicssystem_runtime.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 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 #include <private/qgraphicssystem_runtime_p.h>
43 #include <private/qgraphicssystem_raster_p.h>
44 #include <private/qgraphicssystemfactory_p.h>
45 #include <private/qapplication_p.h>
46 #include <private/qwidget_p.h>
47 #include <QtCore/QDebug>
48 #include <QtCore/QTimer>
49 #include <QtGui/QBitmap>
50 
52 
53 static int qt_pixmap_serial = 0;
54 
55 #define READBACK(f) \
56  f \
57  readBackInfo();
58 
59 
61 {
62  Q_OBJECT
63 
64 public:
66  : m_graphicsSystem(gs), m_graphicsSystemName(graphicsSystemName)
67  {
68  }
69 
70  void launch()
71  {
72  QTimer::singleShot(0, this, SLOT(doChange()));
73  }
74 
75 private slots:
76 
77  void doChange()
78  {
80  deleteLater();
81  }
82 
83 private:
84 
87 };
88 
90  : QPixmapData(type, RuntimeClass), m_graphicsSystem(gs)
91 {
93 }
94 
96 {
99  delete m_data;
100 }
101 
103 {
104  w = m_data->width();
105  h = m_data->height();
106  d = m_data->depth();
107  is_null = m_data->isNull();
108 }
109 
110 
112 {
115  return rtData;
116 }
117 
118 
120 {
121  READBACK(
122  m_data->resize(width, height);
123  )
124 }
125 
126 
128  Qt::ImageConversionFlags flags)
129 {
130  READBACK(
131  m_data->fromImage(image, flags);
132  )
133 }
134 
135 
136 bool QRuntimePixmapData::fromFile(const QString &filename, const char *format,
137  Qt::ImageConversionFlags flags)
138 {
139  bool success(false);
140  READBACK(
141  success = m_data->fromFile(filename, format, flags);
142  )
143  return success;
144 }
145 
146 bool QRuntimePixmapData::fromData(const uchar *buffer, uint len, const char *format,
147  Qt::ImageConversionFlags flags)
148 {
149  bool success(false);
150  READBACK(
151  success = m_data->fromData(buffer, len, format, flags);
152  )
153  return success;
154 }
155 
156 
158 {
159  if (data->runtimeData()) {
160  READBACK(
161  m_data->copy(data->runtimeData(), rect);
162  )
163  } else {
164  READBACK(
165  m_data->copy(data, rect);
166  )
167  }
168 }
169 
170 bool QRuntimePixmapData::scroll(int dx, int dy, const QRect &rect)
171 {
172  return m_data->scroll(dx, dy, rect);
173 }
174 
175 
177 {
178  return m_data->metric(metric);
179 }
180 
182 {
183  return m_data->fill(color);
184 }
185 
187 {
188  return m_data->mask();
189 }
190 
192 {
193  READBACK(
194  m_data->setMask(mask);
195  )
196 }
197 
199 {
200  return m_data->hasAlphaChannel();
201 }
202 
204  Qt::TransformationMode mode) const
205 {
206  return m_data->transformed(matrix, mode);
207 }
208 
210 {
211  READBACK(
212  m_data->setAlphaChannel(alphaChannel);
213  )
214 }
215 
217 {
218  return m_data->alphaChannel();
219 }
220 
222 {
223  return m_data->toImage();
224 }
225 
227 {
228  return m_data->paintEngine();
229 }
230 
232 {
233  return m_data->buffer();
234 }
235 
236 #if defined(Q_OS_SYMBIAN)
237 void* QRuntimePixmapData::toNativeType(NativeType type)
238 {
239  return m_data->toNativeType(type);
240 }
241 
242 void QRuntimePixmapData::fromNativeType(void *pixmap, NativeType type)
243 {
244  m_data->fromNativeType(pixmap, type);
245  readBackInfo();
246 }
247 #endif
248 
250 {
251  return m_data;
252 }
253 
255  : QWindowSurface(window), m_graphicsSystem(gs)
256 {
257 
258 }
259 
261 {
264 }
265 
267 {
268  return m_windowSurface->paintDevice();
269 }
270 
272  const QPoint &offset)
273 {
274  m_windowSurface->flush(widget, region, offset);
275 
276  int destroyPolicy = m_graphicsSystem->windowSurfaceDestroyPolicy();
279 #ifdef QT_DEBUG
280  qDebug() << "QRuntimeWindowSurface::flush() - destroy pending window surface";
281 #endif
283  }
284 }
285 
287 {
290 }
291 
292 bool QRuntimeWindowSurface::scroll(const QRegion &area, int dx, int dy)
293 {
294  return m_windowSurface->scroll(area, dx, dy);
295 }
296 
298 {
300 }
301 
303 {
305 }
306 
308 {
309  return m_windowSurface->buffer(widget);
310 }
311 
313 {
314  return m_windowSurface->grabWidget(widget, rectangle);
315 }
316 
318 {
319  return m_windowSurface->offset(widget);
320 }
321 
322 QWindowSurface::WindowSurfaceFeatures QRuntimeWindowSurface::features() const
323 {
324  return m_windowSurface->features();
325 }
326 
328  : m_windowSurfaceDestroyPolicy(DestroyImmediately),
330 {
332 
333  if (!qgetenv("QT_DEFAULT_RUNTIME_SYSTEM").isEmpty()) {
334  m_graphicsSystemName = QString::fromLocal8Bit(qgetenv("QT_DEFAULT_RUNTIME_SYSTEM"));
335  } else {
336 #ifdef QT_DEFAULT_RUNTIME_SYSTEM
337  m_graphicsSystemName = QLatin1String(QT_DEFAULT_RUNTIME_SYSTEM);
339 #endif
341  }
342 
343 #ifdef Q_OS_SYMBIAN
345 #endif
346 
348 
350 }
351 
352 
354 {
357 
358  QRuntimePixmapData *rtData = new QRuntimePixmapData(this, type);
359  rtData->m_data = data;
360  m_pixmapDatas << rtData;
361 
362  return rtData;
363 }
364 
366 {
368  QRuntimeWindowSurface *rtSurface = new QRuntimeWindowSurface(this, widget);
370  widget->setWindowSurface(rtSurface);
371  m_windowSurfaces << rtSurface;
372  return rtSurface;
373 }
374 
376 {
377  if (m_graphicsSystemName == name)
378  return;
379 #ifdef QT_DEBUG
380  qDebug() << "QRuntimeGraphicsSystem::setGraphicsSystem( " << name << " )";
381 #endif
382  QGraphicsSystem *oldSystem = m_graphicsSystem;
385 
387 
389 
390  for (int i = 0; i < m_pixmapDatas.size(); ++i) {
391  QRuntimePixmapData *proxy = m_pixmapDatas.at(i);
393  newData->fromImage(proxy->m_data->toImage(), Qt::NoOpaqueDetection);
394  delete proxy->m_data;
395  proxy->m_data = newData;
396  proxy->readBackInfo();
397  }
398 
399  for (int i = 0; i < m_windowSurfaces.size(); ++i) {
401  QWidget *widget = proxy->m_windowSurface->window();
402 
405 
406  QWindowSurface *newWindowSurface = m_graphicsSystem->createWindowSurface(widget);
407  newWindowSurface->setGeometry(proxy->geometry());
408 
409  proxy->m_windowSurface.reset(newWindowSurface);
410  qt_widget_private(widget)->invalidateBuffer(widget->rect());
411  }
412 
413  delete oldSystem;
414 }
415 
417 {
418  int index = m_pixmapDatas.lastIndexOf(pixmapData);
419  m_pixmapDatas.removeAt(index);
420 }
421 
423 {
424  int index = m_windowSurfaces.lastIndexOf(windowSurface);
425  m_windowSurfaces.removeAt(index);
426 }
427 
428 #include "qgraphicssystem_runtime.moc"
429 
virtual QPixmapData * createCompatiblePixmapData() const
Definition: qpixmapdata.cpp:96
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
QRect geometry() const
Returns the currently allocated area on the screen.
virtual QPixmapData * createCompatiblePixmapData() const
void setWindowSurface(QWindowSurface *surface)
Sets the window surface to be the surface specified.
Definition: qwidget.cpp:12774
virtual QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const
virtual QPixmap grabWidget(const QWidget *widget, const QRect &rectangle=QRect()) const
Returns a QPixmap generated from the part of the backing store corresponding to widget.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
int type
Definition: qmetatype.cpp:239
QScopedPointer< QWindowSurface > m_pendingWindowSurface
virtual QPixmapData * runtimeData() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
QRuntimeWindowSurface(const QRuntimeGraphicsSystem *gs, QWidget *window)
void removePixmapData(QRuntimePixmapData *pixmapData) const
virtual bool scroll(const QRegion &area, int dx, int dy)
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative...
const QRuntimeGraphicsSystem * m_graphicsSystem
virtual QPixmapData * runtimeData() const
virtual void fill(const QColor &color)=0
virtual QImage toImage() const
const QRuntimeGraphicsSystem * m_graphicsSystem
QRuntimeGraphicsSystem * m_graphicsSystem
QList< QRuntimeWindowSurface * > m_windowSurfaces
#define SLOT(a)
Definition: qobjectdefs.h:226
T * take()
Returns the value of the pointer referenced by this object.
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
virtual void copy(const QPixmapData *data, const QRect &rect)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setGraphicsSystem(const QString &name)
virtual void resize(int width, int height)=0
int width() const
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual QPaintEngine * paintEngine() const =0
virtual QPaintEngine * paintEngine() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QWindowSurface * createWindowSurface(QWidget *widget) const =0
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual QBitmap mask() const
virtual WindowSurfaceFeatures features() const
virtual bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
virtual void beginPaint(const QRegion &)
This function is called before painting onto the surface begins, with the region in which the paintin...
virtual QPixmap grabWidget(const QWidget *widget, const QRect &rectangle=QRect()) const
Returns a QPixmap generated from the part of the backing store corresponding to widget.
virtual bool hasAlphaChannel() const
Q_CORE_EXPORT void qDebug(const char *,...)
PixelType pixelType() const
virtual QPixmap alphaChannel() const
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
NSWindow * window
virtual QImage toImage() const =0
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const
static QGraphicsSystem * create(const QString &)
static bool isEmpty(const char *str)
int lastIndexOf(const T &t, int from=-1) const
Returns the index position of the last occurrence of value in the list, searching backward from index...
Definition: qlist.h:862
virtual void flush(QWidget *widget, const QRegion &region, const QPoint &offset)=0
Flushes the given region from the specified widget onto the screen.
QWindowSurface * createWindowSurface(QWidget *widget) const
virtual void setAlphaChannel(const QPixmap &alphaChannel)
virtual bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
static int qt_pixmap_serial
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
TransformationMode
Definition: qnamespace.h:1510
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
virtual QBitmap mask() const
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const =0
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual void setMask(const QBitmap &mask)
static bool runtime_graphics_system
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
PixelType type
static QString graphics_system_name
virtual void flush(QWidget *widget, const QRegion &region, const QPoint &offset)
Flushes the given region from the specified widget onto the screen.
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QWindowSurface class provides the drawing area for top-level windows.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
virtual bool hasAlphaChannel() const =0
void invalidateBuffer(const QRegion &)
Invalidates the rgn (in widget&#39;s coordinates) of the backing store, i.e.
QPixmapData * createPixmapData(QPixmapData::PixelType type) const
virtual QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
QList< QRuntimePixmapData * > m_pixmapDatas
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
virtual QPixmap alphaChannel() const
virtual void endPaint(const QRegion &)
This function is called after painting onto the surface has ended, with the region in which the paint...
int depth() const
virtual void endPaint(const QRegion &)
This function is called after painting onto the surface has ended, with the region in which the paint...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
virtual bool scroll(int dx, int dy, const QRect &rect)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual QImage * buffer(const QWidget *widget)
Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is ...
virtual void copy(const QPixmapData *data, const QRect &rect)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QGraphicsSystem * graphics_system
virtual QImage * buffer(const QWidget *widget)
Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is ...
virtual void setMask(const QBitmap &mask)
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual QImage * buffer()
virtual void resize(int width, int height)
int height() const
bool isNull() const
virtual void setAlphaChannel(const QPixmap &alphaChannel)
QRuntimePixmapData(const QRuntimeGraphicsSystem *gs, PixelType type)
QScopedPointer< QWindowSurface > m_windowSurface
virtual QPixmapData * createPixmapData(QPixmapData::PixelType type) const =0
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
#define slots
Definition: qobjectdefs.h:68
void setSerialNumber(int serNo)
#define READBACK(f)
virtual void fill(const QColor &color)
virtual void beginPaint(const QRegion &)
This function is called before painting onto the surface begins, with the region in which the paintin...
virtual WindowSurfaceFeatures features() const
virtual bool scroll(const QRegion &area, int dx, int dy)
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative...
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
virtual bool scroll(int dx, int dy, const QRect &rect)
QDeferredGraphicsSystemChange(QRuntimeGraphicsSystem *gs, const QString &graphicsSystemName)
void removeWindowSurface(QRuntimeWindowSurface *windowSurface) const
virtual QPaintDevice * paintDevice()=0
Implement this function to return the appropriate paint device.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
static int area(const QSize &s)
Definition: qicon.cpp:155
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480