diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-16 01:46:41 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-16 03:05:02 (GMT) |
commit | 10e1d939d6bf08249304cb2c555be2f74c3a0f02 (patch) | |
tree | bfda461b0e49c138bc408aa0c799f15ce5907513 /src/gui | |
parent | a4571547a38d68d6778bf0ebfa4dc26cc3d865a3 (diff) | |
download | Qt-10e1d939d6bf08249304cb2c555be2f74c3a0f02.zip Qt-10e1d939d6bf08249304cb2c555be2f74c3a0f02.tar.gz Qt-10e1d939d6bf08249304cb2c555be2f74c3a0f02.tar.bz2 |
Reduce overhead of paint engine-specific pixmap filters
Engine-specific pixmap filters were being created, used, and destroyed
every time draw() was called on QPixmapColorizeFilter, QPixmapBlurFilter,
and so on. This had a heavy performance penalty and made it difficult
for the GL paint engine to cache shaders from one request to the next.
A generic filter can request an engine-specific filter that matches its
parameters. The engine can either create a new one or return a previously
allocated filter object.
Ownership of engine-specific pixmap filter objects is moved to the
paint engine itself.
Reviewed-by: Andrew den Exter
Reviewed-by: Michael Brasser
Reviewed-by: Michael Goddard
Reviewed-by: Sarah Smith
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qpixmapfilter.cpp | 9 | ||||
-rw-r--r-- | src/gui/painting/qpaintengineex_p.h | 7 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp index 4fa2e6c..4fb650f 100644 --- a/src/gui/image/qpixmapfilter.cpp +++ b/src/gui/image/qpixmapfilter.cpp @@ -418,13 +418,12 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q return; QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ? - static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0; + static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0; QPixmapConvolutionFilter *convolutionFilter = static_cast<QPixmapConvolutionFilter*>(filter); if (convolutionFilter) { convolutionFilter->setConvolutionKernel(d->convolutionKernel, d->kernelWidth, d->kernelHeight); convolutionFilter->d_func()->convoluteAlpha = d->convoluteAlpha; convolutionFilter->draw(painter, p, src, srcRect); - delete convolutionFilter; return; } @@ -669,13 +668,12 @@ void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap } QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ? - static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0; + static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0; QPixmapBlurFilter *blurFilter = static_cast<QPixmapBlurFilter*>(filter); if (blurFilter) { blurFilter->setRadius(d->radius); blurFilter->setQuality(d->quality); blurFilter->draw(painter, p, src, srcRect); - delete blurFilter; return; } @@ -836,13 +834,12 @@ void QPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const Q { Q_D(const QPixmapColorizeFilter); QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ? - static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0; + static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0; QPixmapColorizeFilter *colorizeFilter = static_cast<QPixmapColorizeFilter*>(filter); if (colorizeFilter) { colorizeFilter->setColor(d->color); colorizeFilter->setStrength(d->strength); colorizeFilter->draw(painter, dest, src, srcRect); - delete colorizeFilter; return; } diff --git a/src/gui/painting/qpaintengineex_p.h b/src/gui/painting/qpaintengineex_p.h index 9f0d84a..a12a71f 100644 --- a/src/gui/painting/qpaintengineex_p.h +++ b/src/gui/painting/qpaintengineex_p.h @@ -207,7 +207,12 @@ public: virtual void beginNativePainting() {} virtual void endNativePainting() {} - virtual QPixmapFilter *createPixmapFilter(int /*type*/) const { return 0; } + // Return a pixmap filter of "type" that can render the parameters + // in "prototype". The returned filter is owned by the engine and + // will be destroyed when the engine is destroyed. The "prototype" + // allows the engine to pick different filters based on the parameters + // that will be requested, and not just the "type". + virtual QPixmapFilter *pixmapFilter(int /*type*/, const QPixmapFilter * /*prototype*/) { return 0; } // These flags are needed in the implementation of paint buffers. enum Flags |