diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-15 23:31:01 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-15 23:31:01 (GMT) |
commit | dcd4b15595a63864ee59a19d80f1ba33b4821aa3 (patch) | |
tree | 7fad53282d633ee8b91766e5a196d17ea269bb4d | |
parent | d0742b84e085fb1f38cd127c43da07275f5553ac (diff) | |
download | Qt-dcd4b15595a63864ee59a19d80f1ba33b4821aa3.zip Qt-dcd4b15595a63864ee59a19d80f1ba33b4821aa3.tar.gz Qt-dcd4b15595a63864ee59a19d80f1ba33b4821aa3.tar.bz2 |
Only regenerate pixmap filter source if the parameters have changed.
Reviewed-by: trustme
-rw-r--r-- | src/opengl/qglpixmapfilter.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index e4df69e..43f1990 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -71,6 +71,8 @@ void QGLPixmapFilterBase::drawImpl(QPainter *painter, const QPointF &pos, const class QGLPixmapColorizeFilter: public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapColorizeFilter> { public: + QGLPixmapColorizeFilter(); + void setUniforms(QGLShaderProgram *program); protected: @@ -100,6 +102,8 @@ private: class QGLPixmapBlurFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapBlurFilter> { public: + QGLPixmapBlurFilter(); + void setUniforms(QGLShaderProgram *program); protected: @@ -111,6 +115,10 @@ private: mutable QSize m_textureSize; mutable bool m_horizontalBlur; + + mutable bool m_haveCached; + mutable int m_cachedRadius; + mutable Qt::TransformationMode m_cachedQuality; }; extern QGLWidget *qt_gl_share_widget(); @@ -182,10 +190,14 @@ static const char *qt_gl_colorize_filter = " return vec4(mix(srcPixel.rgb, colorized * srcPixel.a, colorizeStrength), srcPixel.a);" "}"; +QGLPixmapColorizeFilter::QGLPixmapColorizeFilter() +{ + setSource(qt_gl_colorize_filter); +} + bool QGLPixmapColorizeFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const { QGLPixmapColorizeFilter *filter = const_cast<QGLPixmapColorizeFilter *>(this); - filter->setSource(qt_gl_colorize_filter); filter->setOnPainter(painter); painter->drawPixmap(pos, src); @@ -292,10 +304,27 @@ bool QGLPixmapConvolutionFilter::processGL(QPainter *, const QPointF &pos, const return true; } +QGLPixmapBlurFilter::QGLPixmapBlurFilter() + : m_haveCached(false), m_cachedRadius(5), + m_cachedQuality(Qt::FastTransformation) +{ +} + bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const { QGLPixmapBlurFilter *filter = const_cast<QGLPixmapBlurFilter *>(this); - filter->setSource(generateBlurShader(radius(), quality() == Qt::SmoothTransformation)); + + int radius = this->radius(); + Qt::TransformationMode quality = this->quality(); + + if (!m_haveCached || radius != m_cachedRadius || + quality != m_cachedQuality) { + // Only regenerate the shader from source if parameters have changed. + m_haveCached = true; + m_cachedRadius = radius; + m_cachedQuality = quality; + filter->setSource(generateBlurShader(radius, quality == Qt::SmoothTransformation)); + } QGLFramebufferObjectFormat format; format.setInternalTextureFormat(GLenum(src.hasAlphaChannel() ? GL_RGBA : GL_RGB)); |