summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopenglpaintengine.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-09-19 15:19:28 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-09-23 11:29:43 +0200
commite8ef241d0f35704433ba331dee9578190a5c98a6 (patch)
tree9b8fe7a12c3b6f30dd51b8c0abad63b0120e2301 /src/gui/opengl/qopenglpaintengine.cpp
parent7b7ad02681f2c28fb18d053618f6804e989b2f56 (diff)
Use NonPremultipliedImageSrc shader when painting non-premuled images
Recognize non-premultiplied images and draw them using the existing NonPremultipliedImageSrc shader so we save premultiplying them on the CPU. Change-Id: I3dfc8f9385ff91502d64ccabf4bf54049cc28040 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui/opengl/qopenglpaintengine.cpp')
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index d82abd73dc..fb1f582214 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -501,7 +501,6 @@ void QOpenGL2PaintEngineExPrivate::drawTexture(const QOpenGLRect& dest, const QO
{
// Setup for texture drawing
currentBrush = noBrush;
- shaderManager->setSrcPixelType(pattern ? QOpenGLEngineShaderManager::PatternSrc : QOpenGLEngineShaderManager::ImageSrc);
if (snapToPixelGrid) {
snapToPixelGrid = false;
@@ -1367,6 +1366,11 @@ void QOpenGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixma
Q_D(QOpenGL2PaintEngineEx);
QOpenGLContext *ctx = d->ctx;
+ // Draw pixmaps that are really images as images since drawImage has
+ // better handling of non-default image formats.
+ if (pixmap.paintEngine()->type() == QPaintEngine::Raster && !pixmap.isQBitmap())
+ return drawImage(dest, pixmap.toImage(), src);
+
int max_texture_size = ctx->d_func()->maxTextureSize();
if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
@@ -1391,6 +1395,8 @@ void QOpenGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixma
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
state()->renderHints & QPainter::SmoothPixmapTransform, id);
+
+ d->shaderManager->setSrcPixelType(isBitmap ? QOpenGLEngineShaderManager::PatternSrc : QOpenGLEngineShaderManager::ImageSrc);
d->drawTexture(dest, srcRect, pixmap.size(), isOpaque, isBitmap);
}
@@ -1414,12 +1420,25 @@ void QOpenGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, c
ensureActive();
d->transferMode(ImageDrawingMode);
- d->funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
+ QOpenGLTextureCache::BindOptions bindOption = QOpenGLTextureCache::PremultipliedAlphaBindOption;
+ // Use specialized bind for formats we have specialized shaders for.
+ switch (image.format()) {
+ case QImage::Format_RGBA8888:
+ case QImage::Format_ARGB32:
+ d->shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::NonPremultipliedImageSrc);
+ bindOption = 0;
+ break;
+ default:
+ d->shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::ImageSrc);
+ break;
+ }
- GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, image);
+ d->funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
+ GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, image, bindOption);
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
state()->renderHints & QPainter::SmoothPixmapTransform, id);
+
d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel());
}
@@ -1466,6 +1485,7 @@ bool QOpenGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, co
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
state()->renderHints & QPainter::SmoothPixmapTransform, textureId);
+ d->shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::ImageSrc);
d->drawTexture(dest, srcRect, size, false);
return true;
}