Qt 4.8
qpixmapdata_vg_p.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 QtOpenVG 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 QPIXMAPDATA_VG_P_H
43 #define QPIXMAPDATA_VG_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of other Qt classes. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtGui/private/qpixmap_raster_p.h>
57 #include <QtGui/private/qvolatileimage_p.h>
58 #include "qvg_p.h"
59 
60 #if defined(Q_OS_SYMBIAN)
61 class RSGImage;
62 #endif
63 
65 
66 class QEglContext;
67 class QVGImagePool;
68 class QImageReader;
69 
70 #if !defined(QT_NO_EGL)
71 class QVGPixmapData;
72 class QVGSharedContext;
73 
77 #endif
78 
80 
82 {
83 public:
85  ~QVGPixmapData();
86 
88 
89  // Is this pixmap valid (i.e. non-zero in size)?
90  bool isValid() const;
91 
92  void resize(int width, int height);
93  void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
94  void fromImageReader(QImageReader *imageReader,
95  Qt::ImageConversionFlags flags);
96  bool fromFile(const QString &filename, const char *format,
97  Qt::ImageConversionFlags flags);
98  bool fromData(const uchar *buffer, uint len, const char *format,
99  Qt::ImageConversionFlags flags);
100 
101  void fill(const QColor &color);
102  bool hasAlphaChannel() const;
103  void setAlphaChannel(const QPixmap &alphaChannel);
104  QImage toImage() const;
105  void copy(const QPixmapData *data, const QRect &rect);
106  QImage *buffer();
107  QPaintEngine* paintEngine() const;
108 
109  // Return the VGImage form of this pixmap, creating it if necessary.
110  // This assumes that there is a VG context current.
111  virtual VGImage toVGImage();
112 
113  // Return the VGImage form for a specific opacity setting.
114  virtual VGImage toVGImage(qreal opacity);
115 
116  // Detach this image from the image pool.
117  virtual void detachImageFromPool();
118 
119  // Release the VG resources associated with this pixmap and copy
120  // the pixmap's contents out of the GPU back into main memory.
121  // The VG resource will be automatically recreated the next time
122  // toVGImage() is called. Does nothing if the pixmap cannot be
123  // hibernated for some reason (e.g. VGImage is shared with another
124  // process via a SgImage).
125  virtual void hibernate();
126 
127  // Called when the QVGImagePool wants to reclaim this pixmap's
128  // VGImage objects to reuse storage.
129  virtual void reclaimImages();
130 
131  // If vgImage is valid but source is null, copies pixel data from GPU back
132  // into main memory and destroys vgImage. For a normal pixmap this function
133  // does nothing, however if the pixmap was created directly from a VGImage
134  // (e.g. via SgImage on Symbian) then by doing the readback this ensures
135  // that QImage-based functions can operate too.
136  virtual void ensureReadback(bool readOnly) const;
137 
138  QSize size() const { return QSize(w, h); }
139 
140 #if defined(Q_OS_SYMBIAN)
141  QVolatileImage toVolatileImage() const;
142  void* toNativeType(NativeType type);
143  void fromNativeType(void* pixmap, NativeType type);
144  bool initFromNativeImageHandle(void *handle, const QString &type);
145  void createFromNativeImageHandleProvider();
146  void releaseNativeImageHandle();
147 #endif
148 
149 protected:
150  int metric(QPaintDevice::PaintDeviceMetric metric) const;
151  void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace);
152 
153 #if defined(Q_OS_SYMBIAN)
154  void cleanup();
155 #endif
156 
157 private:
160  bool inLRU;
161  friend class QVGImagePool;
162  friend class QVGPaintEngine;
163 
164 #if !defined(QT_NO_EGL)
167 
168  friend void qt_vg_register_pixmap(QVGPixmapData *pd);
169  friend void qt_vg_unregister_pixmap(QVGPixmapData *pd);
170  friend void qt_vg_hibernate_pixmaps(QVGSharedContext *context);
171 #endif
172 
173 protected:
175  VGImage vgImage;
176  VGImage vgImageOpacity;
179  mutable bool recreate;
181 #if !defined(QT_NO_EGL)
183 #endif
184 
185 #if defined(Q_OS_SYMBIAN)
186  mutable QNativeImageHandleProvider *nativeImageHandleProvider;
187  void *nativeImageHandle;
188  QString nativeImageType;
189 #endif
190 
191  void forceToImage(bool allowReadback = true);
192  QImage::Format sourceFormat() const;
193  QImage::Format idealFormat(QImage *image, Qt::ImageConversionFlags flags) const;
194  void updateSerial();
195 
196  void destroyImageAndContext();
197  void destroyImages();
198 };
199 
201 
202 #endif
virtual QPixmapData * createCompatiblePixmapData() const
Definition: qpixmapdata.cpp:96
QSize size() const
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void qt_vg_unregister_pixmap(QVGPixmapData *pd)
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void fill(const QColor &color)=0
QVGPixmapData * next
virtual void resize(int width, int height)=0
QVGPixmapData * prev
virtual QPaintEngine * paintEngine() const =0
The QString class provides a Unicode character string.
Definition: qstring.h:83
QEglContext * context
virtual bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
QVGPixmapData * prevLRU
unsigned char uchar
Definition: qglobal.h:994
virtual QImage toImage() const =0
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
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 int metric(QPaintDevice::PaintDeviceMetric metric) const =0
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
void qt_vg_hibernate_pixmaps(QVGSharedContext *context)
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
virtual bool hasAlphaChannel() const =0
QVolatileImage source
static VGImage toVGImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
void qt_vg_register_pixmap(QVGPixmapData *pd)
QVGPixmapData * nextLRU
VGImage vgImageOpacity
virtual void copy(const QPixmapData *data, const QRect &rect)
static void cleanup()
Definition: qpicture.cpp:1508
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual QImage * buffer()
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
virtual void setAlphaChannel(const QPixmap &alphaChannel)
#define Q_OPENVG_EXPORT
Definition: qglobal.h:1457
virtual void fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags)