Qt 4.8
Public Functions | Protected Functions | Protected Variables | Properties | Friends | List of all members
QVGPixmapData Class Reference

#include <qpixmapdata_vg_p.h>

Inheritance diagram for QVGPixmapData:
QPixmapData

Public Functions

QImagebuffer ()
 
void copy (const QPixmapData *data, const QRect &rect)
 
QPixmapDatacreateCompatiblePixmapData () const
 
virtual void detachImageFromPool ()
 
virtual void ensureReadback (bool readOnly) const
 
void fill (const QColor &color)
 
bool fromData (const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
 
bool fromFile (const QString &filename, const char *format, Qt::ImageConversionFlags flags)
 
void fromImage (const QImage &image, Qt::ImageConversionFlags flags)
 
void fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags)
 
bool hasAlphaChannel () const
 
virtual void hibernate ()
 
bool isValid () const
 
QPaintEnginepaintEngine () const
 
 QVGPixmapData (PixelType type)
 
virtual void reclaimImages ()
 
void resize (int width, int height)
 
void setAlphaChannel (const QPixmap &alphaChannel)
 
QSize size () const
 
QImage toImage () const
 
virtual VGImage toVGImage ()
 
virtual VGImage toVGImage (qreal opacity)
 
 ~QVGPixmapData ()
 
- Public Functions inherited from QPixmapData
virtual QPixmap alphaChannel () const
 
qint64 cacheKey () const
 
ClassId classId () const
 
int colorCount () const
 
int depth () const
 
int height () const
 
bool isNull () const
 
virtual QBitmap mask () const
 
QT_DEPRECATED int numColors () const
 
PixelType pixelType () const
 
 QPixmapData (PixelType pixelType, int classId)
 
virtual QPixmapDataruntimeData () const
 
virtual bool scroll (int dx, int dy, const QRect &rect)
 
int serialNumber () const
 
virtual void setMask (const QBitmap &mask)
 
virtual QImage toImage (const QRect &rect) const
 
virtual QPixmap transformed (const QTransform &matrix, Qt::TransformationMode mode) const
 
int width () const
 
virtual ~QPixmapData ()
 

Protected Functions

void createPixmapForImage (QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
 
void destroyImageAndContext ()
 
void destroyImages ()
 
void forceToImage (bool allowReadback=true)
 
QImage::Format idealFormat (QImage *image, Qt::ImageConversionFlags flags) const
 
int metric (QPaintDevice::PaintDeviceMetric metric) const
 
QImage::Format sourceFormat () const
 
void updateSerial ()
 
- Protected Functions inherited from QPixmapData
void setSerialNumber (int serNo)
 

Protected Variables

qreal cachedOpacity
 
QEglContextcontext
 
bool inImagePool
 
QSize prevSize
 
bool recreate
 
QVolatileImage source
 
VGImage vgImage
 
VGImage vgImageOpacity
 
- Protected Variables inherited from QPixmapData
int d
 
int h
 
bool is_null
 
int w
 

Properties

bool inLRU
 
QVGPixmapDatanext
 
QVGPixmapDatanextLRU
 
QVGPixmapDataprev
 
QVGPixmapDataprevLRU
 

Friends

void qt_vg_hibernate_pixmaps (QVGSharedContext *context)
 
void qt_vg_register_pixmap (QVGPixmapData *pd)
 
void qt_vg_unregister_pixmap (QVGPixmapData *pd)
 
class QVGImagePool
 
class QVGPaintEngine
 

Additional Inherited Members

- Public Types inherited from QPixmapData
enum  ClassId {
  RasterClass, X11Class, MacClass, DirectFBClass,
  OpenGLClass, OpenVGClass, RuntimeClass, BlitterClass,
  CustomClass = 1024
}
 
enum  PixelType { PixmapType, BitmapType }
 
- Static Public Functions inherited from QPixmapData
static QPixmapDatacreate (int w, int h, PixelType type)
 

Detailed Description

Definition at line 81 of file qpixmapdata_vg_p.h.

Constructors and Destructors

◆ QVGPixmapData()

QVGPixmapData::QVGPixmapData ( PixelType  type)

Definition at line 60 of file qpixmapdata_vg.cpp.

Referenced by createCompatiblePixmapData().

62 {
64  vgImage = VG_INVALID_HANDLE;
65  vgImageOpacity = VG_INVALID_HANDLE;
66  cachedOpacity = 1.0f;
67  recreate = true;
68  inImagePool = false;
69  inLRU = false;
70 #if defined(Q_OS_SYMBIAN)
71  nativeImageHandleProvider = 0;
72  nativeImageHandle = 0;
73 #endif
74 #if !defined(QT_NO_EGL)
75  context = 0;
77 #endif
78  updateSerial();
79 }
QEglContext * context
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
PixelType type
QPixmapData(PixelType pixelType, int classId)
Definition: qpixmapdata.cpp:68
friend void qt_vg_register_pixmap(QVGPixmapData *pd)
VGImage vgImageOpacity

◆ ~QVGPixmapData()

QVGPixmapData::~QVGPixmapData ( )

Definition at line 81 of file qpixmapdata_vg.cpp.

82 {
84 #if !defined(QT_NO_EGL)
86 #endif
87 }
void destroyImageAndContext()
friend void qt_vg_unregister_pixmap(QVGPixmapData *pd)

Functions

◆ buffer()

QImage * QVGPixmapData::buffer ( )
virtual

Reimplemented from QPixmapData.

Definition at line 329 of file qpixmapdata_vg.cpp.

330 {
331  // Cannot be safely implemented and QVGPixmapData is not (must not be) RasterClass anyway.
332  return 0;
333 }

◆ copy()

void QVGPixmapData::copy ( const QPixmapData data,
const QRect rect 
)
virtual

Reimplemented from QPixmapData.

Definition at line 305 of file qpixmapdata_vg.cpp.

306 {
307  // toImage() is potentially expensive with QVolatileImage so provide a
308  // more efficient implementation of copy() that does not rely on it.
309  if (!data) {
310  return;
311  }
312  if (data->classId() != OpenVGClass) {
314  return;
315  }
316  const QVGPixmapData *pd = static_cast<const QVGPixmapData *>(data);
317  QRect r = rect;
318  if (r.isNull() || r.contains(QRect(0, 0, pd->w, pd->h))) {
319  r = QRect(0, 0, pd->w, pd->h);
320  }
321  resize(r.width(), r.height());
322  recreate = true;
323  if (!pd->source.isNull()) {
324  source = QVolatileImage(r.width(), r.height(), pd->source.format());
325  source.copyFrom(&pd->source, r);
326  }
327 }
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
bool isNull() const
virtual QImage toImage() const =0
static const char * data(const QByteArray &arr)
ClassId classId() const
QImage::Format format() const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
QVolatileImage source
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void resize(int width, int height)
void copyFrom(QVolatileImage *source, const QRect &rect)

◆ createCompatiblePixmapData()

QPixmapData * QVGPixmapData::createCompatiblePixmapData ( ) const
virtual

Reimplemented from QPixmapData.

Definition at line 146 of file qpixmapdata_vg.cpp.

147 {
148  return new QVGPixmapData(pixelType());
149 }
QVGPixmapData(PixelType type)
PixelType pixelType() const

◆ createPixmapForImage()

void QVGPixmapData::createPixmapForImage ( QImage image,
Qt::ImageConversionFlags  flags,
bool  inPlace 
)
protected

Definition at line 237 of file qpixmapdata_vg.cpp.

Referenced by fromData(), fromFile(), fromImage(), and fromImageReader().

238 {
239  resize(image.width(), image.height());
240 
241  QImage::Format format = idealFormat(&image, flags);
242 
243  if (inPlace && image.data_ptr()->convertInPlace(format, flags)) {
244  source = QVolatileImage(image);
245  } else {
246  QImage convertedImage = image.convertToFormat(format);
247  // convertToFormat won't detach the image if format stays the
248  // same. Detaching is needed to prevent issues with painting
249  // onto this QPixmap later on.
250  convertedImage.detach();
251  if (convertedImage.isNull())
252  qWarning("QVGPixmapData: Failed to convert image data (out of memory? try increasing heap size)");
253  source = QVolatileImage(convertedImage);
254  }
255  recreate = true;
256 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QImage::Format idealFormat(QImage *image, Qt::ImageConversionFlags flags) const
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
DataPtr & data_ptr()
Definition: qimage.h:346
QVolatileImage source
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void resize(int width, int height)
bool convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags)
Definition: qimage.cpp:6935

◆ destroyImageAndContext()

void QVGPixmapData::destroyImageAndContext ( )
protected

Definition at line 112 of file qpixmapdata_vg.cpp.

Referenced by hibernate(), and ~QVGPixmapData().

113 {
114  if (vgImage != VG_INVALID_HANDLE) {
115  // We need to have a context current to destroy the image.
116 #if !defined(QT_NO_EGL)
117  if (!context)
119  if (context->isCurrent()) {
120  destroyImages();
121  } else {
122  // We don't currently have a widget surface active, but we
123  // need a surface to make the context current. So use the
124  // shared pbuffer surface instead.
126  destroyImages();
128  }
129 #else
130  destroyImages();
131 #endif
132  } else {
133 #if defined(Q_OS_SYMBIAN)
134  releaseNativeImageHandle();
135 #endif
136  }
137 #if !defined(QT_NO_EGL)
138  if (context) {
140  context = 0;
141  }
142 #endif
143  recreate = true;
144 }
Q_OPENVG_EXPORT QEglContext * qt_vg_create_context(QPaintDevice *device, int devType)
QEglContext * context
Q_OPENVG_EXPORT void qt_vg_destroy_context(QEglContext *context, int devType)
Q_OPENVG_EXPORT EGLSurface qt_vg_shared_surface(void)
bool isCurrent() const
Definition: qegl.cpp:121
bool lazyDoneCurrent()
Definition: qegl.cpp:519
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433

◆ destroyImages()

void QVGPixmapData::destroyImages ( )
protected

Definition at line 89 of file qpixmapdata_vg.cpp.

Referenced by destroyImageAndContext(), ensureReadback(), reclaimImages(), and toVGImage().

90 {
91  if (inImagePool) {
93  if (vgImage != VG_INVALID_HANDLE)
94  pool->releaseImage(this, vgImage);
95  if (vgImageOpacity != VG_INVALID_HANDLE)
96  pool->releaseImage(this, vgImageOpacity);
97  } else {
98  if (vgImage != VG_INVALID_HANDLE)
99  vgDestroyImage(vgImage);
100  if (vgImageOpacity != VG_INVALID_HANDLE)
101  vgDestroyImage(vgImageOpacity);
102  }
103  vgImage = VG_INVALID_HANDLE;
104  vgImageOpacity = VG_INVALID_HANDLE;
105  inImagePool = false;
106 
107 #if defined(Q_OS_SYMBIAN)
108  releaseNativeImageHandle();
109 #endif
110 }
static QVGImagePool * instance()
VGImage vgImageOpacity
virtual void releaseImage(QVGPixmapData *data, VGImage image)

◆ detachImageFromPool()

void QVGPixmapData::detachImageFromPool ( )
virtual

Definition at line 439 of file qpixmapdata_vg.cpp.

Referenced by QVGPaintEnginePrivate::setBrush().

440 {
441  if (inImagePool) {
443  inImagePool = false;
444  }
445 }
static QVGImagePool * instance()
virtual void detachImage(QVGPixmapData *data)

◆ ensureReadback()

void QVGPixmapData::ensureReadback ( bool  readOnly) const
virtual

Definition at line 516 of file qpixmapdata_vg.cpp.

Referenced by forceToImage(), hasAlphaChannel(), and toImage().

517 {
518  if (vgImage != VG_INVALID_HANDLE && source.isNull()) {
521  vgGetImageSubData(vgImage, source.bits(), source.bytesPerLine(),
523  0, 0, w, h);
525  if (readOnly) {
526  recreate = false;
527  } else {
528  // Once we did a readback, the original VGImage must be destroyed
529  // because it may be shared (e.g. created via SgImage) and a subsequent
530  // upload of the image data may produce unexpected results.
531  const_cast<QVGPixmapData *>(this)->destroyImages();
532 #if defined(Q_OS_SYMBIAN)
533  // There is now an own copy of the data so drop the handle provider,
534  // otherwise toVGImage() would request the handle again, which is wrong.
535  nativeImageHandleProvider = 0;
536 #endif
537  recreate = true;
538  }
539  }
540 }
VGImageFormat qt_vg_image_to_vg_format(QImage::Format format)
void beginDataAccess() const
QImage::Format sourceFormat() const
void endDataAccess(bool readOnly=false) const
bool isNull() const
uchar * bits()
Access to pixel data via bits() or constBits() should be guarded by begin/endDataAccess().
QImage::Format format() const
QVolatileImage source
int bytesPerLine() const

◆ fill()

void QVGPixmapData::fill ( const QColor color)
virtual

Implements QPixmapData.

Definition at line 258 of file qpixmapdata_vg.cpp.

259 {
260  if (!isValid())
261  return;
262  forceToImage();
263  if (source.depth() == 1) {
264  // Pick the best approximate color in the image's colortable.
265  int gray = qGray(color.rgba());
266  if (qAbs(qGray(source.imageRef().color(0)) - gray)
267  < qAbs(qGray(source.imageRef().color(1)) - gray))
268  source.fill(0);
269  else
270  source.fill(1);
271  } else {
272  source.fill(PREMUL(color.rgba()));
273  }
274 }
void forceToImage(bool allowReadback=true)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
void fill(uint pixelValue)
int depth() const
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
QVolatileImage source
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
bool isValid() const
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
QImage & imageRef()
Returns a reference to the image that is potentially using some native buffer internally.
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829

◆ forceToImage()

void QVGPixmapData::forceToImage ( bool  allowReadback = true)
protected

Definition at line 502 of file qpixmapdata_vg.cpp.

Referenced by fill(), hibernate(), paintEngine(), reclaimImages(), and setAlphaChannel().

503 {
504  if (!isValid())
505  return;
506 
507  if (allowReadback)
508  ensureReadback(false);
509 
510  if (source.isNull())
512 
513  recreate = true;
514 }
virtual void ensureReadback(bool readOnly) const
QImage::Format sourceFormat() const
bool isNull() const
QVolatileImage source
bool isValid() const

◆ fromData()

bool QVGPixmapData::fromData ( const uchar buffer,
uint  len,
const char *  format,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 209 of file qpixmapdata_vg.cpp.

211 {
212  QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
213  QBuffer b(&a);
214  b.open(QIODevice::ReadOnly);
215  QImage image = QImageReader(&b, format).read();
216  if (image.isNull())
217  return false;
218 
219  createPixmapForImage(image, flags, true);
220 
221  return !isNull();
222 }
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
long ASN1_INTEGER_get ASN1_INTEGER * a
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
QImage * buffer()
bool isNull() const
QImage read()
Reads an image from the device.

◆ fromFile()

bool QVGPixmapData::fromFile ( const QString filename,
const char *  format,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 197 of file qpixmapdata_vg.cpp.

199 {
200  QImage image = QImageReader(filename, format).read();
201  if (image.isNull())
202  return false;
203 
204  createPixmapForImage(image, flags, true);
205 
206  return !isNull();
207 }
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
bool isNull() const
QImage read()
Reads an image from the device.

◆ fromImage()

void QVGPixmapData::fromImage ( const QImage image,
Qt::ImageConversionFlags  flags 
)
virtual

Implements QPixmapData.

Definition at line 178 of file qpixmapdata_vg.cpp.

Referenced by copy().

179 {
180  if (image.isNull())
181  return;
182 
183  QImage img = image;
184  createPixmapForImage(img, flags, false);
185 }
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ fromImageReader()

void QVGPixmapData::fromImageReader ( QImageReader imageReader,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 187 of file qpixmapdata_vg.cpp.

189 {
190  QImage image = imageReader->read();
191  if (image.isNull())
192  return;
193 
194  createPixmapForImage(image, flags, true);
195 }
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage read()
Reads an image from the device.

◆ hasAlphaChannel()

bool QVGPixmapData::hasAlphaChannel ( ) const
virtual

Implements QPixmapData.

Definition at line 276 of file qpixmapdata_vg.cpp.

277 {
278  ensureReadback(true);
279  if (!source.isNull())
280  return source.hasAlphaChannel();
281  else
282  return isValid();
283 }
virtual void ensureReadback(bool readOnly) const
bool isNull() const
QVolatileImage source
bool isValid() const
bool hasAlphaChannel() const

◆ hibernate()

void QVGPixmapData::hibernate ( )
virtual

Definition at line 447 of file qpixmapdata_vg.cpp.

Referenced by QVGImagePool::hibernate(), and qt_vg_hibernate_pixmaps().

448 {
449  // If the image was imported (e.g, from an SgImage under Symbian), then
450  // skip the hibernation, there is no sense in copying it back to main
451  // memory because the data is most likely shared between several processes.
452  bool skipHibernate = (vgImage != VG_INVALID_HANDLE && source.isNull());
453 #if defined(Q_OS_SYMBIAN)
454  // However we have to proceed normally if the image was retrieved via
455  // a handle provider.
456  skipHibernate &= !nativeImageHandleProvider;
457 #endif
458  if (skipHibernate)
459  return;
460 
461  forceToImage(false); // no readback allowed here
463 }
void destroyImageAndContext()
void forceToImage(bool allowReadback=true)
bool isNull() const
QVolatileImage source

◆ idealFormat()

QImage::Format QVGPixmapData::idealFormat ( QImage image,
Qt::ImageConversionFlags  flags 
) const
protected

Definition at line 224 of file qpixmapdata_vg.cpp.

Referenced by createPixmapForImage().

225 {
227  int d = image->depth();
228  if (d == 1 || d == 16 || d == 24 || (d == 32 && !image->hasAlphaChannel()))
229  format = QImage::Format_RGB32;
230  else if (!(flags & Qt::NoOpaqueDetection) && image->data_ptr()->checkForAlphaPixels())
231  format = sourceFormat();
232  else
233  format = image->hasAlphaChannel() ? sourceFormat() : QImage::Format_RGB32;
234  return format;
235 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
QImage::Format sourceFormat() const
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
DataPtr & data_ptr()
Definition: qimage.h:346
bool checkForAlphaPixels() const
Definition: qimage.cpp:236

◆ isValid()

bool QVGPixmapData::isValid ( ) const

◆ metric()

int QVGPixmapData::metric ( QPaintDevice::PaintDeviceMetric  metric) const
protectedvirtual

Implements QPixmapData.

Definition at line 473 of file qpixmapdata_vg.cpp.

474 {
475  switch (metric) {
477  return w;
479  return h;
481  return 0;
483  return d;
485  return qRound(w * 25.4 / qt_defaultDpiX());
487  return qRound(h * 25.4 / qt_defaultDpiY());
490  return qt_defaultDpiX();
493  return qt_defaultDpiY();
494  default:
495  qWarning("QVGPixmapData::metric(): Invalid metric");
496  return 0;
497  }
498 }
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
Q_CORE_EXPORT void qWarning(const char *,...)
int metric(QPaintDevice::PaintDeviceMetric metric) const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ paintEngine()

QPaintEngine * QVGPixmapData::paintEngine ( ) const
virtual

Implements QPixmapData.

Definition at line 335 of file qpixmapdata_vg.cpp.

336 {
337  // If the application wants to paint into the QPixmap, we first
338  // force it to QImage format and then paint into that.
339  // This is simpler than juggling multiple VG contexts.
340  const_cast<QVGPixmapData *>(this)->forceToImage();
341  return source.paintEngine();
342 }
void forceToImage(bool allowReadback=true)
QVolatileImage source
QPaintEngine * paintEngine()
To be called from the PixmapData&#39;s paintEngine().

◆ reclaimImages()

void QVGPixmapData::reclaimImages ( )
virtual

Definition at line 465 of file qpixmapdata_vg.cpp.

Referenced by QVGImagePool::reclaimSpace().

466 {
467  if (!inImagePool)
468  return;
469  forceToImage();
470  destroyImages();
471 }
void forceToImage(bool allowReadback=true)

◆ resize()

void QVGPixmapData::resize ( int  width,
int  height 
)
virtual

Implements QPixmapData.

Definition at line 161 of file qpixmapdata_vg.cpp.

Referenced by copy(), and createPixmapForImage().

162 {
163  if (w == wid && h == ht) {
164  updateSerial();
165  return;
166  }
167 
168  w = wid;
169  h = ht;
170  d = 32; // We always use ARGB_Premultiplied for VG pixmaps.
171  is_null = (w <= 0 || h <= 0);
173  recreate = true;
174 
175  updateSerial();
176 }
QVolatileImage source

◆ setAlphaChannel()

void QVGPixmapData::setAlphaChannel ( const QPixmap alphaChannel)
virtual

Reimplemented from QPixmapData.

Definition at line 285 of file qpixmapdata_vg.cpp.

286 {
287  if (!isValid())
288  return;
289  forceToImage();
290  source.setAlphaChannel(alphaChannel);
291 }
void forceToImage(bool allowReadback=true)
QVolatileImage source
bool isValid() const
void setAlphaChannel(const QPixmap &alphaChannel)

◆ size()

QSize QVGPixmapData::size ( ) const
inline

Definition at line 138 of file qpixmapdata_vg_p.h.

Referenced by QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), QVGPixmapBlurFilter::draw(), QVGPaintEngine::drawPixmap(), and QVGPaintEngine::drawPixmapFragments().

138 { return QSize(w, h); }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ sourceFormat()

QImage::Format QVGPixmapData::sourceFormat ( ) const
protected

◆ toImage()

QImage QVGPixmapData::toImage ( ) const
virtual

Implements QPixmapData.

Definition at line 293 of file qpixmapdata_vg.cpp.

294 {
295  if (!isValid())
296  return QImage();
297  ensureReadback(true);
298  if (source.isNull()) {
300  recreate = true;
301  }
302  return source.toImage();
303 }
QImage toImage() const
This will always perform a copy of the pixel data.
virtual void ensureReadback(bool readOnly) const
QImage::Format sourceFormat() const
bool isNull() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QVolatileImage source
bool isValid() const

◆ toVGImage() [1/2]

VGImage QVGPixmapData::toVGImage ( )
virtual

Definition at line 344 of file qpixmapdata_vg.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), QVGPixmapBlurFilter::draw(), QVGCompositionHelper::drawCursorPixmap(), QVGPaintEngine::drawPixmap(), QVGPaintEngine::drawPixmapFragments(), qPixmapToVGImage(), QVGPaintEnginePrivate::setBrush(), and toVGImage().

345 {
346  if (!isValid())
347  return VG_INVALID_HANDLE;
348 
349 #if !defined(QT_NO_EGL)
350  // Increase the reference count on the shared context.
351  if (!context)
353 #endif
354 
355  if (recreate && prevSize != QSize(w, h))
356  destroyImages();
357  else if (recreate)
358  cachedOpacity = -1.0f; // Force opacity image to be refreshed later.
359 
360 #if defined(Q_OS_SYMBIAN)
361  if (recreate && nativeImageHandleProvider && !nativeImageHandle) {
362  createFromNativeImageHandleProvider();
363  }
364 #endif
365 
366  if (vgImage == VG_INVALID_HANDLE) {
368  (qt_vg_image_to_vg_format(source.format()), w, h, VG_IMAGE_QUALITY_FASTER, this);
369 
370  // Bail out if we run out of GPU memory - try again next time.
371  if (vgImage == VG_INVALID_HANDLE) {
372  return VG_INVALID_HANDLE;
373  }
374 
375  inImagePool = true;
376  } else if (inImagePool) {
378  }
379 
380  if (!source.isNull() && (recreate || source.paintingActive())) {
382  vgImageSubData
383  (vgImage,
386  source.endDataAccess(true);
387  }
388 
389  recreate = false;
390  prevSize = QSize(w, h);
391 
392  return vgImage;
393 }
virtual void useImage(QVGPixmapData *data)
VGImageFormat qt_vg_image_to_vg_format(QImage::Format format)
void beginDataAccess() const
Q_OPENVG_EXPORT QEglContext * qt_vg_create_context(QPaintDevice *device, int devType)
QEglContext * context
void endDataAccess(bool readOnly=false) const
virtual VGImage createImageForPixmap(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality, QVGPixmapData *data)
bool isNull() const
QImage::Format format() const
QVolatileImage source
static QVGImagePool * instance()
bool isValid() const
int bytesPerLine() const
bool paintingActive() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
const uchar * constBits() const

◆ toVGImage() [2/2]

VGImage QVGPixmapData::toVGImage ( qreal  opacity)
virtual

Definition at line 395 of file qpixmapdata_vg.cpp.

396 {
397 #if !defined(QT_SHIVAVG)
398  // Force the primary VG image to be recreated if necessary.
399  if (toVGImage() == VG_INVALID_HANDLE)
400  return VG_INVALID_HANDLE;
401 
402  if (opacity == 1.0f)
403  return vgImage;
404 
405  // Create an alternative image for the selected opacity.
406  if (vgImageOpacity == VG_INVALID_HANDLE || cachedOpacity != opacity) {
407  if (vgImageOpacity == VG_INVALID_HANDLE) {
408  if (inImagePool) {
410  (VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER, this);
411  } else {
412  vgImageOpacity = vgCreateImage
413  (VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER);
414  }
415 
416  // Bail out if we run out of GPU memory - try again next time.
417  if (vgImageOpacity == VG_INVALID_HANDLE)
418  return VG_INVALID_HANDLE;
419  }
420  VGfloat matrix[20] = {
421  1.0f, 0.0f, 0.0f, 0.0f,
422  0.0f, 1.0f, 0.0f, 0.0f,
423  0.0f, 0.0f, 1.0f, 0.0f,
424  0.0f, 0.0f, 0.0f, opacity,
425  0.0f, 0.0f, 0.0f, 0.0f
426  };
427  vgColorMatrix(vgImageOpacity, vgImage, matrix);
428  cachedOpacity = opacity;
429  }
430 
431  return vgImageOpacity;
432 #else
433  // vgColorMatrix() doesn't work with ShivaVG, so ignore the opacity.
434  Q_UNUSED(opacity);
435  return toVGImage();
436 #endif
437 }
virtual VGImage createImageForPixmap(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality, QVGPixmapData *data)
virtual VGImage toVGImage()
static QVGImagePool * instance()
VGImage vgImageOpacity
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ updateSerial()

void QVGPixmapData::updateSerial ( )
protected

Definition at line 156 of file qpixmapdata_vg.cpp.

Referenced by QVGPixmapData(), and resize().

157 {
159 }
static int qt_vg_pixmap_serial
void setSerialNumber(int serNo)

Friends and Related Functions

◆ qt_vg_hibernate_pixmaps

void qt_vg_hibernate_pixmaps ( QVGSharedContext context)
friend

Definition at line 333 of file qwindowsurface_vgegl.cpp.

334 {
335  // Artificially increase the reference count to prevent the
336  // context from being destroyed until after we have finished
337  // the hibernation process.
338  ++(shared->refCount);
339 
340  // We need a context current to hibernate the VGImage objects.
341  shared->context->makeCurrent(qt_vg_shared_surface());
342 
343  // Scan all QVGPixmapData objects in the system and hibernate them.
344  QVGPixmapData *pd = shared->firstPixmap;
345  while (pd != 0) {
346  pd->hibernate();
347  pd = pd->next;
348  }
349 
350  // Hibernate any remaining VGImage's in the image pool.
352 
353  // Don't need the current context any more.
354  shared->context->lazyDoneCurrent();
355 
356  // Decrease the reference count and destroy the context if necessary.
357  if (--(shared->refCount) <= 0)
359 }
EGLSurface qt_vg_shared_surface(void)
QVGPixmapData * next
static void qt_vg_destroy_shared_context(QVGSharedContext *shared)
static QVGImagePool * instance()
virtual void hibernate()
virtual void hibernate()

◆ qt_vg_register_pixmap

void qt_vg_register_pixmap ( QVGPixmapData pd)
friend

Definition at line 157 of file qwindowsurface_vgegl.cpp.

Referenced by QVGPixmapData().

158 {
159  QVGSharedContext *shared = sharedContext();
160  pd->next = shared->firstPixmap;
161  pd->prev = 0;
162  if (shared->firstPixmap)
163  shared->firstPixmap->prev = pd;
164  shared->firstPixmap = pd;
165 }
QVGPixmapData * next
QVGPixmapData * prev
QVGPixmapData * firstPixmap

◆ qt_vg_unregister_pixmap

void qt_vg_unregister_pixmap ( QVGPixmapData pd)
friend

Definition at line 167 of file qwindowsurface_vgegl.cpp.

Referenced by ~QVGPixmapData().

168 {
169  if (pd->next)
170  pd->next->prev = pd->prev;
171  if (pd->prev) {
172  pd->prev->next = pd->next;
173  } else {
174  QVGSharedContext *shared = sharedContext();
175  if (shared)
176  shared->firstPixmap = pd->next;
177  }
178 }
QVGPixmapData * next
QVGPixmapData * prev
QVGPixmapData * firstPixmap

◆ QVGImagePool

friend class QVGImagePool
friend

Definition at line 161 of file qpixmapdata_vg_p.h.

◆ QVGPaintEngine

friend class QVGPaintEngine
friend

Definition at line 162 of file qpixmapdata_vg_p.h.

Properties

◆ cachedOpacity

qreal QVGPixmapData::cachedOpacity
protected

Definition at line 177 of file qpixmapdata_vg_p.h.

Referenced by QVGPixmapData(), and toVGImage().

◆ context

QEglContext* QVGPixmapData::context
mutableprotected

Definition at line 182 of file qpixmapdata_vg_p.h.

Referenced by destroyImageAndContext(), QVGPixmapData(), and toVGImage().

◆ inImagePool

bool QVGPixmapData::inImagePool
protected

◆ inLRU

bool QVGPixmapData::inLRU
private

◆ next

QVGPixmapData* QVGPixmapData::next
private

◆ nextLRU

QVGPixmapData* QVGPixmapData::nextLRU
private

◆ prev

QVGPixmapData* QVGPixmapData::prev
private

Definition at line 166 of file qpixmapdata_vg_p.h.

Referenced by qt_vg_register_pixmap(), and qt_vg_unregister_pixmap().

◆ prevLRU

QVGPixmapData* QVGPixmapData::prevLRU
private

◆ prevSize

QSize QVGPixmapData::prevSize
protected

Definition at line 174 of file qpixmapdata_vg_p.h.

Referenced by toVGImage().

◆ recreate

bool QVGPixmapData::recreate
mutableprotected

◆ source

QVolatileImage QVGPixmapData::source
mutableprotected

◆ vgImage

VGImage QVGPixmapData::vgImage
protected

◆ vgImageOpacity

VGImage QVGPixmapData::vgImageOpacity
protected

Definition at line 176 of file qpixmapdata_vg_p.h.

Referenced by destroyImages(), QVGPixmapData(), and toVGImage().


The documentation for this class was generated from the following files: