summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-05 05:10:59 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-05 05:39:29 (GMT)
commit3909d97e86d62fd94e149925b5f3111c8f391334 (patch)
tree748a1db0fde9f07136da835c141be7e0cdb5ec29 /src
parent7b19bfec4c496f2112b363cbdc8a0c302a48cfce (diff)
downloadQt-3909d97e86d62fd94e149925b5f3111c8f391334.zip
Qt-3909d97e86d62fd94e149925b5f3111c8f391334.tar.gz
Qt-3909d97e86d62fd94e149925b5f3111c8f391334.tar.bz2
Make it possible to implement engine-specific drop shadow filters
It wasn't possible for the paint engine to override the drop shadow filter because QPixmapDropShadowFilter::draw() was not asking for an engine-specific filter object. Also, change the OpenVG filter to use vgGaussianBlur() instead of vgConvolve(), and draw the original image on top of the shadow. Task-number: QTBUG-4583 Reviewed-by: trustme
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qpixmapfilter.cpp10
-rw-r--r--src/openvg/qpixmapfilter_vg.cpp44
-rw-r--r--src/openvg/qpixmapfilter_vg_p.h3
3 files changed, 27 insertions, 30 deletions
diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp
index 749b8f3..df445db 100644
--- a/src/gui/image/qpixmapfilter.cpp
+++ b/src/gui/image/qpixmapfilter.cpp
@@ -1074,6 +1074,16 @@ void QPixmapDropShadowFilter::draw(QPainter *p,
const QRectF &src) const
{
Q_D(const QPixmapDropShadowFilter);
+ QPixmapFilter *filter = p->paintEngine() && p->paintEngine()->isExtended() ?
+ static_cast<QPaintEngineEx *>(p->paintEngine())->pixmapFilter(type(), this) : 0;
+ QPixmapDropShadowFilter *dropShadowFilter = static_cast<QPixmapDropShadowFilter*>(filter);
+ if (dropShadowFilter) {
+ dropShadowFilter->setColor(d->color);
+ dropShadowFilter->setBlurRadius(d->blurFilter->radius());
+ dropShadowFilter->setOffset(d->offset);
+ dropShadowFilter->draw(p, pos, px, src);
+ return;
+ }
QImage tmp = src.isNull() ? px.toImage() : px.copy(src.toRect()).toImage();
QPainter tmpPainter(&tmp);
diff --git a/src/openvg/qpixmapfilter_vg.cpp b/src/openvg/qpixmapfilter_vg.cpp
index ca4db38..613f4ea 100644
--- a/src/openvg/qpixmapfilter_vg.cpp
+++ b/src/openvg/qpixmapfilter_vg.cpp
@@ -220,8 +220,6 @@ void QVGPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const
QVGPixmapDropShadowFilter::QVGPixmapDropShadowFilter()
: QPixmapDropShadowFilter(),
- prevRadius(0.0f),
- kernelSize(0),
firstTime(true)
{
}
@@ -290,41 +288,30 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con
// Blacken the source image.
vgColorMatrix(tmpImage, srcImage, matrix[0]);
- // Recompute the convolution kernel if the blur radius has changed.
- qreal radius = blurRadius();
- if (radius != prevRadius || firstTime) {
- prevRadius = radius;
- int dim = 2 * qRound(radius) + 1;
- int size = dim * dim;
- VGshort f = VGshort(1024.0f / size);
- kernel.resize(size);
- for (int i = 0; i < size; ++i)
- kernel[i] = f;
- kernelSize = dim;
- }
+ // Clamp the radius range. We divide by 2 because the OpenVG blur
+ // is "too blurry" compared to the default raster implementation.
+ VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION));
+ VGfloat radiusF = VGfloat(blurRadius()) / 2.0f;
+ if (radiusF < 0.001f)
+ radiusF = 0.001f;
+ else if (radiusF > maxRadius)
+ radiusF = maxRadius;
- // Apply the convolution filter using the kernel.
- VGfloat values[4];
- values[0] = 0.0f;
- values[1] = 0.0f;
- values[2] = 0.0f;
- values[3] = 0.0f;
- vgSetfv(VG_TILE_FILL_COLOR, 4, values);
- vgConvolve(dstImage, tmpImage,
- kernelSize, kernelSize, 0, 0,
- kernel.constData(), 1.0f / 1024.0f, 0.0f,
- VG_TILE_FILL);
+ // Blur the blackened source image.
+ vgGaussianBlur(dstImage, tmpImage, radiusF, radiusF, VG_TILE_PAD);
firstTime = false;
VGImage child = VG_INVALID_HANDLE;
+ QRect srect;
if (srcRect.isNull() ||
(srcRect.topLeft().isNull() && srcRect.size() == size)) {
child = dstImage;
+ srect = QRect(0, 0, size.width(), size.height());
} else {
- QRect src = srcRect.toRect();
- child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height());
+ srect = srcRect.toRect();
+ child = vgChildImage(dstImage, srect.x(), srect.y(), srect.width(), srect.height());
}
qt_vg_drawVGImage(painter, dest + offset(), child);
@@ -333,6 +320,9 @@ void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, con
vgDestroyImage(child);
vgDestroyImage(tmpImage);
vgDestroyImage(dstImage);
+
+ // Now draw the actual pixmap over the top.
+ painter->drawPixmap(dest, src, srect);
}
QVGPixmapBlurFilter::QVGPixmapBlurFilter(QObject *parent)
diff --git a/src/openvg/qpixmapfilter_vg_p.h b/src/openvg/qpixmapfilter_vg_p.h
index 8bd4f7e..58111ec 100644
--- a/src/openvg/qpixmapfilter_vg_p.h
+++ b/src/openvg/qpixmapfilter_vg_p.h
@@ -98,10 +98,7 @@ public:
private:
mutable VGfloat matrix[5][4];
mutable QColor prevColor;
- mutable qreal prevRadius;
- mutable int kernelSize;
mutable bool firstTime;
- mutable QVarLengthArray<VGshort, 16> kernel;
};
class Q_OPENVG_EXPORT QVGPixmapBlurFilter : public QPixmapBlurFilter