void tst_QVolatileImage::create() { QVolatileImage nullImg; QVERIFY(nullImg.isNull()); QVolatileImage img(100, 200, QImage::Format_ARGB32); QVERIFY(!img.isNull()); QCOMPARE(img.width(), 100); QCOMPARE(img.height(), 200); QCOMPARE(img.format(), QImage::Format_ARGB32); QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height()); QCOMPARE(img.hasAlphaChannel(), true); QCOMPARE(img.depth(), 32); QImage source(12, 23, QImage::Format_ARGB32_Premultiplied); img = QVolatileImage(source); QVERIFY(!img.isNull()); QCOMPARE(img.width(), 12); QCOMPARE(img.height(), 23); QCOMPARE(img.format(), source.format()); QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height()); QVERIFY(img.imageRef() == source); QVERIFY(img.toImage() == source); QCOMPARE(img.hasAlphaChannel(), true); QCOMPARE(img.hasAlphaChannel(), img.imageRef().hasAlphaChannel()); QCOMPARE(img.hasAlphaChannel(), img.toImage().hasAlphaChannel()); QCOMPARE(img.depth(), 32); }
void QGLPixmapData::fromNativeType(void* pixmap, NativeType type) { if (type == QPixmapData::SgImage && pixmap) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); m_sgImage = new RSgImage; m_sgImage->Open(sgImage->Id()); TSgImageInfo info; sgImage->GetInfo(info); w = info.iSizeInPixels.iWidth; h = info.iSizeInPixels.iHeight; d = symbianPixeFormatBitsPerPixel((TUidPixelFormat)info.iPixelFormat); m_source = QVolatileImage(); m_hasAlpha = true; m_hasFillColor = false; m_dirty = true; is_null = (w <= 0 || h <= 0); #endif } else if (type == QPixmapData::FbsBitmap && pixmap) { CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap); QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight); if (size.width() == w && size.height() == h) setSerialNumber(++qt_gl_pixmap_serial); resize(size.width(), size.height()); m_source = QVolatileImage(bitmap); if (pixelType() == BitmapType) { m_source.ensureFormat(QImage::Format_MonoLSB); } else if (!knownGoodFormat(m_source.format())) { m_source.beginDataAccess(); QImage::Format format = idealFormat(m_source.imageRef(), Qt::AutoColor); m_source.endDataAccess(true); m_source.ensureFormat(format); } m_hasAlpha = m_source.hasAlphaChannel(); m_hasFillColor = false; m_dirty = true; d = m_source.depth(); } else if (type == QPixmapData::VolatileImage && pixmap) { // Support QS60Style in more efficient skin graphics retrieval. QVolatileImage *img = static_cast<QVolatileImage *>(pixmap); if (img->width() == w && img->height() == h) setSerialNumber(++qt_gl_pixmap_serial); resize(img->width(), img->height()); m_source = *img; m_hasAlpha = m_source.hasAlphaChannel(); m_hasFillColor = false; m_dirty = true; d = m_source.depth(); } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) { destroyTexture(); nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap); // Cannot defer the retrieval, we need at least the size right away. createFromNativeImageHandleProvider(); } }
void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) { if (type == QPixmapData::SgImage && pixmap) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); destroyImages(); prevSize = QSize(); vgImage = sgImageToVGImage(context, *sgImage); if (vgImage != VG_INVALID_HANDLE) { w = vgGetParameteri(vgImage, VG_IMAGE_WIDTH); h = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT); d = 32; // We always use ARGB_Premultiplied for VG pixmaps. } is_null = (w <= 0 || h <= 0); source = QVolatileImage(); // readback will be done later, only when needed recreate = false; prevSize = QSize(w, h); updateSerial(); #endif } else if (type == QPixmapData::FbsBitmap && pixmap) { CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap); QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight); resize(size.width(), size.height()); source = QVolatileImage(bitmap); // duplicates only, if possible if (source.isNull()) return; if (!conversionLessFormat(source.format())) { // Here we may need to copy if the formats do not match. // (e.g. for display modes other than EColor16MAP and EColor16MU) source.beginDataAccess(); QImage::Format format = idealFormat(&source.imageRef(), Qt::AutoColor); source.endDataAccess(true); source.ensureFormat(format); } recreate = true; } else if (type == QPixmapData::VolatileImage && pixmap) { QVolatileImage *img = static_cast<QVolatileImage *>(pixmap); resize(img->width(), img->height()); source = *img; recreate = true; } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) { destroyImages(); nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap); // Cannot defer the retrieval, we need at least the size right away. createFromNativeImageHandleProvider(); } }
void QVolatileImagePaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) { #ifdef Q_OS_SYMBIAN QVolatileImage img = pm.pixmapData()->toVolatileImage(); if (!img.isNull()) { img.beginDataAccess(); QRasterPaintEngine::drawImage(r, img.constImageRef(), sr); img.endDataAccess(true); } else { QRasterPaintEngine::drawPixmap(r, pm, sr); } #else QRasterPaintEngine::drawPixmap(r, pm, sr); #endif }
void QVolatileImagePaintEngine::drawPixmap(const QPointF &p, const QPixmap &pm) { #ifdef Q_OS_SYMBIAN QVolatileImage img = pm.pixmapData()->toVolatileImage(); if (!img.isNull()) { img.beginDataAccess(); // imageRef() would detach and since we received the QVolatileImage from // toVolatileImage() by value, it would cause a copy which would ruin // our goal. So use constImageRef() instead. QRasterPaintEngine::drawImage(p, img.constImageRef()); img.endDataAccess(true); } else { QRasterPaintEngine::drawPixmap(p, pm); } #else QRasterPaintEngine::drawPixmap(p, pm); #endif }
void tst_QVolatileImage::create() { QVolatileImage nullImg; QVERIFY(nullImg.isNull()); QVolatileImage img(100, 200, QImage::Format_ARGB32); QVERIFY(!img.isNull()); QCOMPARE(img.width(), 100); QCOMPARE(img.height(), 200); QCOMPARE(img.format(), QImage::Format_ARGB32); QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height()); QCOMPARE(img.hasAlphaChannel(), true); QCOMPARE(img.depth(), 32); QImage source(12, 23, QImage::Format_ARGB32_Premultiplied); img = QVolatileImage(source); QVERIFY(!img.isNull()); QCOMPARE(img.width(), 12); QCOMPARE(img.height(), 23); QCOMPARE(img.format(), source.format()); QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height()); QVERIFY(img.imageRef() == source); QVERIFY(img.toImage() == source); QCOMPARE(img.hasAlphaChannel(), true); QCOMPARE(img.hasAlphaChannel(), img.imageRef().hasAlphaChannel()); QCOMPARE(img.hasAlphaChannel(), img.toImage().hasAlphaChannel()); QCOMPARE(img.depth(), 32); #ifdef Q_OS_SYMBIAN CFbsBitmap *bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(100, 50), EColor16MAP) == KErrNone); QVolatileImage bmpimg(bmp); QVERIFY(!bmpimg.isNull()); QCOMPARE(bmpimg.width(), 100); QCOMPARE(bmpimg.height(), 50); // Verify that we only did handle duplication, not pixel data copying. QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); delete bmp; // Check if content is still valid. QImage copyimg = bmpimg.toImage(); QCOMPARE(copyimg.format(), QImage::Format_ARGB32_Premultiplied); #endif }