summaryrefslogtreecommitdiffstats
path: root/src/openvg
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-19 23:00:02 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-19 23:00:02 (GMT)
commitbbbb62552b1c0f68b960c1412c66b6381e7dd4d1 (patch)
tree96d670a612de86e854480d403474238fe3e940c1 /src/openvg
parent02c15e6a8cdb0f8a0bb6ee36880877fe90334d69 (diff)
downloadQt-bbbb62552b1c0f68b960c1412c66b6381e7dd4d1.zip
Qt-bbbb62552b1c0f68b960c1412c66b6381e7dd4d1.tar.gz
Qt-bbbb62552b1c0f68b960c1412c66b6381e7dd4d1.tar.bz2
Optimize QVGPixmapDropShadowFilter by removing colorize step
Previously, the drop shadow was colorizing the incoming image and then blurring the colorized version. This change first blurs the image to an alpha-only VGImage and then uses that VGImage as a stencil to draw the drop shadow color. This way, there is only 1 filter step and a draw instead of 2 filter steps and a draw. The result is to make the performance of the drop shadow filter almost identical to the blur filter. Reviewed-by: trustme
Diffstat (limited to 'src/openvg')
-rw-r--r--src/openvg/qpaintengine_vg.cpp18
-rw-r--r--src/openvg/qpixmapfilter_vg.cpp54
-rw-r--r--src/openvg/qpixmapfilter_vg_p.h5
3 files changed, 25 insertions, 52 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp
index fdd61ea..da07c1d 100644
--- a/src/openvg/qpaintengine_vg.cpp
+++ b/src/openvg/qpaintengine_vg.cpp
@@ -2872,6 +2872,24 @@ void qt_vg_drawVGImage(QPainter *painter, const QPointF& pos, VGImage vgImg)
drawVGImage(engine->vgPrivate(), pos, vgImg);
}
+// Used by qpixmapfilter_vg.cpp to draw filtered VGImage's as a stencil.
+void qt_vg_drawVGImageStencil
+ (QPainter *painter, const QPointF& pos, VGImage vgImg, const QBrush& brush)
+{
+ QVGPaintEngine *engine =
+ static_cast<QVGPaintEngine *>(painter->paintEngine());
+
+ QVGPaintEnginePrivate *d = engine->vgPrivate();
+
+ QTransform transform(d->imageTransform);
+ transform.translate(pos.x(), pos.y());
+ d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
+
+ d->ensureBrush(brush);
+ d->setImageMode(VG_DRAW_IMAGE_STENCIL);
+ vgDrawImage(vgImg);
+}
+
void QVGPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
{
QPixmapData *pd = pm.pixmapData();
diff --git a/src/openvg/qpixmapfilter_vg.cpp b/src/openvg/qpixmapfilter_vg.cpp
index 3305bbb..8e104db 100644
--- a/src/openvg/qpixmapfilter_vg.cpp
+++ b/src/openvg/qpixmapfilter_vg.cpp
@@ -58,6 +58,8 @@ QVGPixmapConvolutionFilter::~QVGPixmapConvolutionFilter()
extern void qt_vg_drawVGImage
(QPainter *painter, const QPointF& pos, VGImage vgImg);
+extern void qt_vg_drawVGImageStencil
+ (QPainter *painter, const QPointF& pos, VGImage vgImg, const QBrush& brush);
void QVGPixmapConvolutionFilter::draw
(QPainter *painter, const QPointF &dest,
@@ -213,8 +215,7 @@ void QVGPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const
}
QVGPixmapDropShadowFilter::QVGPixmapDropShadowFilter()
- : QPixmapDropShadowFilter(),
- firstTime(true)
+ : QPixmapDropShadowFilter()
{
}
@@ -238,49 +239,11 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con
return;
QSize size = pd->size();
- VGImage tmpImage = vgCreateImage
- (VG_sARGB_8888_PRE, size.width(), size.height(),
- VG_IMAGE_QUALITY_FASTER);
- if (tmpImage == VG_INVALID_HANDLE)
- return;
-
VGImage dstImage = vgCreateImage
- (VG_sARGB_8888_PRE, size.width(), size.height(),
+ (VG_A_8, size.width(), size.height(),
VG_IMAGE_QUALITY_FASTER);
- if (dstImage == VG_INVALID_HANDLE) {
- vgDestroyImage(tmpImage);
+ if (dstImage == VG_INVALID_HANDLE)
return;
- }
-
- // Recompute the color matrix if the color has changed.
- QColor c = color();
- if (c != prevColor || firstTime) {
- prevColor = c;
-
- matrix[0][0] = 0.0f;
- matrix[0][1] = 0.0f;
- matrix[0][2] = 0.0f;
- matrix[0][3] = 0.0f;
- matrix[1][0] = 0.0f;
- matrix[1][1] = 0.0f;
- matrix[1][2] = 0.0f;
- matrix[1][3] = 0.0f;
- matrix[2][0] = 0.0f;
- matrix[2][1] = 0.0f;
- matrix[2][2] = 0.0f;
- matrix[2][3] = 0.0f;
- matrix[3][0] = c.redF();
- matrix[3][1] = c.greenF();
- matrix[3][2] = c.blueF();
- matrix[3][3] = c.alphaF();
- matrix[4][0] = 0.0f;
- matrix[4][1] = 0.0f;
- matrix[4][2] = 0.0f;
- matrix[4][3] = 0.0f;
- }
-
- // Blacken the source image.
- vgColorMatrix(tmpImage, srcImage, matrix[0]);
// Clamp the radius range. We divide by 2 because the OpenVG blur
// is "too blurry" compared to the default raster implementation.
@@ -292,9 +255,7 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con
radiusF = maxRadius;
// Blur the blackened source image.
- vgGaussianBlur(dstImage, tmpImage, radiusF, radiusF, VG_TILE_PAD);
-
- firstTime = false;
+ vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD);
VGImage child = VG_INVALID_HANDLE;
@@ -308,11 +269,10 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con
child = vgChildImage(dstImage, srect.x(), srect.y(), srect.width(), srect.height());
}
- qt_vg_drawVGImage(painter, dest + offset(), child);
+ qt_vg_drawVGImageStencil(painter, dest + offset(), child, color());
if(child != dstImage)
vgDestroyImage(child);
- vgDestroyImage(tmpImage);
vgDestroyImage(dstImage);
// Now draw the actual pixmap over the top.
diff --git a/src/openvg/qpixmapfilter_vg_p.h b/src/openvg/qpixmapfilter_vg_p.h
index f79b6c2..efbbc7b 100644
--- a/src/openvg/qpixmapfilter_vg_p.h
+++ b/src/openvg/qpixmapfilter_vg_p.h
@@ -89,11 +89,6 @@ public:
~QVGPixmapDropShadowFilter();
void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src) const;
-
-private:
- mutable VGfloat matrix[5][4];
- mutable QColor prevColor;
- mutable bool firstTime;
};
class Q_OPENVG_EXPORT QVGPixmapBlurFilter : public QPixmapBlurFilter