diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-11-04 06:38:36 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-11-04 06:38:36 (GMT) |
commit | 764f558846b8ee6f115004fc939b890991c40bfa (patch) | |
tree | 9bd47140cedbc9d8d28702618e6ad86fa6f2f666 /src/openvg/qpaintengine_vg.cpp | |
parent | 9b0c0faf73dbdc382f1c02a42b10018bf9961d72 (diff) | |
parent | 1400ce5b85fbe7c67899f5f62bfd276eecb21ae0 (diff) | |
download | Qt-764f558846b8ee6f115004fc939b890991c40bfa.zip Qt-764f558846b8ee6f115004fc939b890991c40bfa.tar.gz Qt-764f558846b8ee6f115004fc939b890991c40bfa.tar.bz2 |
Merge branch '4.6' of c:\dev\qt-graphics-4.6
Conflicts:
tools/qdoc3/test/qt-build-docs.qdocconf
tools/qdoc3/test/qt-inc.qdocconf
Diffstat (limited to 'src/openvg/qpaintengine_vg.cpp')
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 175 |
1 files changed, 103 insertions, 72 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index da07c1d..047d9d8 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -1178,6 +1178,8 @@ VGPaintType QVGPaintEnginePrivate::setBrush case Qt::TexturePattern: { // The brush is a texture specified by a QPixmap/QImage. QPixmapData *pd = brush.texture().pixmapData(); + if (!pd) + break; // null QPixmap VGImage vgImg; bool deref = false; if (pd->pixelType() == QPixmapData::BitmapType) { @@ -2893,6 +2895,8 @@ void qt_vg_drawVGImageStencil void QVGPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) { QPixmapData *pd = pm.pixmapData(); + if (!pd) + return; // null QPixmap if (pd->classId() == QPixmapData::OpenVGClass) { Q_D(QVGPaintEngine); QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); @@ -2910,6 +2914,8 @@ void QVGPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF void QVGPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pm) { QPixmapData *pd = pm.pixmapData(); + if (!pd) + return; // null QPixmap if (pd->classId() == QPixmapData::OpenVGClass) { Q_D(QVGPaintEngine); QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); @@ -2985,6 +2991,8 @@ void QVGPaintEngine::drawPixmaps // If the pixmap is not VG, or the transformation is projective, // then fall back to the default implementation. QPixmapData *pd = pixmap.pixmapData(); + if (!pd) + return; // null QPixmap if (pd->classId() != QPixmapData::OpenVGClass || !d->simpleTransform) { QPaintEngineEx::drawPixmaps(drawingData, dataCount, pixmap, hints); return; @@ -3455,28 +3463,24 @@ void QVGCompositionHelper::blitWindow // Set the image transform. QTransform transform; int y = screenSize.height() - (rect.bottom() + 1); - transform.translate(rect.x() + 0.5f, y + 0.5f); + transform.translate(rect.x() - 0.5f, y - 0.5f); d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); // Enable opacity for image drawing if necessary. - if (opacity < 255) { - if (opacity != d->paintOpacity) { - VGfloat values[4]; - values[0] = 1.0f; - values[1] = 1.0f; - values[2] = 1.0f; - values[3] = ((VGfloat)opacity) / 255.0f; - vgSetParameterfv(d->opacityPaint, VG_PAINT_COLOR, 4, values); - d->paintOpacity = values[3]; - } - if (d->fillPaint != d->opacityPaint) { - vgSetPaint(d->opacityPaint, VG_FILL_PATH); - d->fillPaint = d->opacityPaint; - } - d->setImageMode(VG_DRAW_IMAGE_MULTIPLY); - } else { - d->setImageMode(VG_DRAW_IMAGE_NORMAL); + if (opacity != d->paintOpacity) { + VGfloat values[4]; + values[0] = 1.0f; + values[1] = 1.0f; + values[2] = 1.0f; + values[3] = ((VGfloat)opacity) / 255.0f; + vgSetParameterfv(d->opacityPaint, VG_PAINT_COLOR, 4, values); + d->paintOpacity = values[3]; } + if (d->fillPaint != d->opacityPaint) { + vgSetPaint(d->opacityPaint, VG_FILL_PATH); + d->fillPaint = d->opacityPaint; + } + d->setImageMode(VG_DRAW_IMAGE_MULTIPLY); // Draw the child image. vgDrawImage(child); @@ -3527,74 +3531,101 @@ static void fillBackgroundRect(const QRect& rect, QVGPaintEnginePrivate *d) void QVGCompositionHelper::fillBackground (const QRegion& region, const QBrush& brush) { - // Set the path transform to the default viewport transformation. - VGfloat devh = screenSize.height() - 1; - QTransform viewport(1.0f, 0.0f, 0.0f, - 0.0f, -1.0f, 0.0f, - 0.5f, devh + 0.5f, 1.0f); - d->setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, viewport); - - // Set the brush to use to fill the background. - d->ensureBrush(brush); - d->setFillRule(VG_EVEN_ODD); + if (brush.style() == Qt::SolidPattern) { + // Use vgClear() to quickly fill the background. + QColor color = brush.color(); + if (d->clearColor != color || d->clearOpacity != 1.0f) { + VGfloat values[4]; + values[0] = color.redF(); + values[1] = color.greenF(); + values[2] = color.blueF(); + values[3] = color.alphaF(); + vgSetfv(VG_CLEAR_COLOR, 4, values); + d->clearColor = color; + d->clearOpacity = 1.0f; + } + if (region.numRects() == 1) { + QRect r = region.boundingRect(); + vgClear(r.x(), screenSize.height() - r.y() - r.height(), + r.width(), r.height()); + } else { + const QVector<QRect> rects = region.rects(); + for (int i = 0; i < rects.size(); ++i) { + QRect r = rects.at(i); + vgClear(r.x(), screenSize.height() - r.y() - r.height(), + r.width(), r.height()); + } + } - if (region.numRects() == 1) { - fillBackgroundRect(region.boundingRect(), d); } else { - const QVector<QRect> rects = region.rects(); - for (int i = 0; i < rects.size(); ++i) - fillBackgroundRect(rects.at(i), d); - } + // Set the path transform to the default viewport transformation. + VGfloat devh = screenSize.height() - 1; + QTransform viewport(1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + -0.5f, devh + 0.5f, 1.0f); + d->setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, viewport); + + // Set the brush to use to fill the background. + d->ensureBrush(brush); + d->setFillRule(VG_EVEN_ODD); + + if (region.numRects() == 1) { + fillBackgroundRect(region.boundingRect(), d); + } else { + const QVector<QRect> rects = region.rects(); + for (int i = 0; i < rects.size(); ++i) + fillBackgroundRect(rects.at(i), d); + } - // We will need to reset the path transform during the next paint. - d->pathTransformSet = false; + // We will need to reset the path transform during the next paint. + d->pathTransformSet = false; + } } -void QVGCompositionHelper::drawCursorImage - (const QImage& image, const QPoint& offset) +void QVGCompositionHelper::drawCursorPixmap + (const QPixmap& pixmap, const QPoint& offset) { - QImage img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + VGImage vgImage = VG_INVALID_HANDLE; - VGImage vgImg = vgCreateImage - (VG_sARGB_8888_PRE, img.width(), img.height(), - VG_IMAGE_QUALITY_FASTER); - vgImageSubData - (vgImg, img.bits() + img.bytesPerLine() * (img.height() - 1), - -(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0, - img.width(), img.height()); + // Fetch the VGImage from the pixmap if possible. + QPixmapData *pd = pixmap.pixmapData(); + if (!pd) + return; // null QPixmap + if (pd->classId() == QPixmapData::OpenVGClass) { + QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); + if (vgpd->isValid()) + vgImage = vgpd->toVGImage(); + } - QTransform transform; - int y = screenSize.height() - (offset.y() + img.height()); - transform.translate(offset.x() + 0.5f, y + 0.5f); + // Set the image transformation and modes. + VGfloat devh = screenSize.height() - 1; + QTransform transform(1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + -0.5f, devh + 0.5f, 1.0f); + transform.translate(offset.x(), offset.y()); d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); - d->setImageMode(VG_DRAW_IMAGE_NORMAL); - vgDrawImage(vgImg); - vgDestroyImage(vgImg); -} + // Draw the VGImage. + if (vgImage != VG_INVALID_HANDLE) { + vgDrawImage(vgImage); + } else { + QImage img = pixmap.toImage().convertToFormat + (QImage::Format_ARGB32_Premultiplied); -void QVGCompositionHelper::drawCursorPixmap - (const QPixmap& pixmap, const QPoint& offset) -{ - QPixmapData *pd = pixmap.pixmapData(); - if (pd->classId() == QPixmapData::OpenVGClass) { - QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); - if (vgpd->isValid()) { - VGfloat devh = screenSize.height() - 1; - QTransform transform(1.0f, 0.0f, 0.0f, - 0.0f, -1.0f, 0.0f, - 0.5f, devh + 0.5f, 1.0f); - transform.translate(offset.x(), offset.y()); - d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); - - d->setImageMode(VG_DRAW_IMAGE_NORMAL); - vgDrawImage(vgpd->toVGImage()); + vgImage = vgCreateImage + (VG_sARGB_8888_PRE, img.width(), img.height(), + VG_IMAGE_QUALITY_FASTER); + if (vgImage == VG_INVALID_HANDLE) return; - } - } + vgImageSubData + (vgImage, img.bits() + img.bytesPerLine() * (img.height() - 1), + -(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0, + img.width(), img.height()); - drawCursorImage(pixmap.toImage(), offset); + vgDrawImage(vgImage); + vgDestroyImage(vgImage); + } } void QVGCompositionHelper::setScissor(const QRegion& region) |