diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-03-07 12:45:24 (GMT) |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-03-07 12:45:24 (GMT) |
commit | cee7a42f5bf6473cecafc2bf98e9b383cb3edede (patch) | |
tree | cb9abed47016d03d956e59407eb43bf00dc3cae9 /tests/auto | |
parent | dda11ee48e323f4f4c6490822aa8921d5d6e3e69 (diff) | |
download | Qt-cee7a42f5bf6473cecafc2bf98e9b383cb3edede.zip Qt-cee7a42f5bf6473cecafc2bf98e9b383cb3edede.tar.gz Qt-cee7a42f5bf6473cecafc2bf98e9b383cb3edede.tar.bz2 |
VGImage readback support in QPixmap on OpenVG.
Enable readback of pixel data for pixmaps that are constructed directly
from a VGImage. These do not have any backing data in main memory
(i.e. 'source' is null), however certain operations, like toImage(),
fill(), or painting into the pixmap do not work without it. With this
patch the data is read back via vgGetImageSubData when needed.
Task-number: QT-4669
Reviewed-by: Jani Hautakangas
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qpixmap/qpixmap.pro | 1 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 106 |
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/qpixmap/qpixmap.pro b/tests/auto/qpixmap/qpixmap.pro index ff8258f..e6a8257 100644 --- a/tests/auto/qpixmap/qpixmap.pro +++ b/tests/auto/qpixmap/qpixmap.pro @@ -25,6 +25,7 @@ wince*: { LIBS += -lfbscli.dll -lbitgdi.dll -lgdi.dll contains(QT_CONFIG, openvg) { LIBS += $$QMAKE_LIBS_OPENVG + QT *= openvg } } else { DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 62a6eb4..bd9c26f 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -68,6 +68,10 @@ #include <fbs.h> #include <gdi.h> #include <bitdev.h> +#if !defined(QT_NO_OPENVG) +#include <QtOpenVG/qvg.h> +#include <QtOpenVG/private/qpixmapdata_vg_p.h> +#endif #endif #ifdef Q_WS_X11 @@ -185,6 +189,10 @@ private slots: void toImageDeepCopy(); void loadAsBitmapOrPixmap(); + +#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_OPENVG) + void vgImageReadBack(); +#endif }; static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) @@ -1767,6 +1775,104 @@ void tst_QPixmap::toImageDeepCopy() QVERIFY(first != second); } +#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_OPENVG) +Q_OPENVG_EXPORT VGImage qPixmapToVGImage(const QPixmap& pixmap); +class FriendlyVGPixmapData : public QVGPixmapData +{ +public: + FriendlyVGPixmapData(PixelType type) : QVGPixmapData(type) { } + bool sourceIsNull() { return source.isNull(); } + friend QPixmap pixmapFromVGImage(VGImage image); +}; +QPixmap pixmapFromVGImage(VGImage image) +{ + if (image != VG_INVALID_HANDLE) { + int w = vgGetParameteri(image, VG_IMAGE_WIDTH); + int h = vgGetParameteri(image, VG_IMAGE_HEIGHT); + FriendlyVGPixmapData *pd = new FriendlyVGPixmapData(QPixmapData::PixmapType); + pd->resize(w, h); + pd->vgImage = image; + pd->recreate = false; + pd->prevSize = QSize(pd->w, pd->h); + return QPixmap(pd); + } + return QPixmap(); +} +class Content : public QWidget +{ +public: + void paintEvent(QPaintEvent *) { + QPainter painter(this); + QColor testPixel(qRgb(200, 150, 100)); + if (pm.isNull()) { // first phase: create a VGImage + painter.beginNativePainting(); + vgimage = vgCreateImage(VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER); + QImage img(20, 10, QImage::Format_ARGB32_Premultiplied); + img.fill(qRgb(0, 0, 0)); + QPainter p(&img); + p.fillRect(0, 0, img.width(), img.height(), testPixel); + p.end(); + vgImageSubData(vgimage, img.bits(), img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, img.width(), img.height()); + // Now the area 0,0 20x10 (in OpenVG coords) is filled with some color. + painter.endNativePainting(); + } else { // second phase: check if readback works + painter.drawPixmap(0, 0, pm); + // Drawing should not cause readback, this is important for performance; + noreadback_ok = static_cast<FriendlyVGPixmapData *>(pm.pixmapData())->sourceIsNull(); + // However toImage() requires readback. + QImage img = pm.toImage(); + readback_ok = img.width() == pm.width(); + readback_ok &= img.height() == pm.height(); + readback_ok &= !static_cast<FriendlyVGPixmapData *>(pm.pixmapData())->sourceIsNull(); + uint pix = img.pixel(1, 1); + content_ok = qRed(pix) == testPixel.red(); + content_ok &= qGreen(pix) == testPixel.green(); + content_ok &= qBlue(pix) == testPixel.blue(); + pix = img.pixel(img.width() - 1, img.height() - 1); + content_ok &= qRed(pix) == 0; + content_ok &= qGreen(pix) == 0; + content_ok &= qBlue(pix) == 0; + } + } + int w; + int h; + VGImage vgimage; + QPixmap pm; + bool noreadback_ok; + bool readback_ok; + bool content_ok; +}; +void tst_QPixmap::vgImageReadBack() +{ + QPixmap tmp(10, 20); + if (tmp.pixmapData()->classId() == QPixmapData::OpenVGClass) { + Content c; + c.w = 50; + c.h = 60; + c.vgimage = VG_INVALID_HANDLE; + c.noreadback_ok = c.readback_ok = c.content_ok = false; + c.showFullScreen(); + QTest::qWaitForWindowShown(&c); + QVERIFY(c.vgimage != VG_INVALID_HANDLE); + QPixmap pm = pixmapFromVGImage(c.vgimage); + QVERIFY(!pm.isNull()); + QCOMPARE(pm.width(), c.w); + QCOMPARE(pm.height(), c.h); + QVERIFY(qPixmapToVGImage(pm) == c.vgimage); + QVERIFY(static_cast<FriendlyVGPixmapData *>(pm.pixmapData())->sourceIsNull()); + c.pm = pm; + // Make sure the second phase in paintEvent is executed too. + c.hide(); + c.showFullScreen(); + QTest::qWaitForWindowShown(&c); + QVERIFY(c.noreadback_ok); + QVERIFY(c.readback_ok); + QVERIFY(c.content_ok); + } else { + QSKIP("Not using openvg graphicssystem", SkipSingle); + } +} +#endif // Symbian & OpenVG QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" |