From e9c5ac78deaae6775ad5cf08c022a0105f7702a7 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 11 Jun 2015 10:17:45 +0200 Subject: Add QQuickWindow::TextureIsOpaque as option to createTextureFromImage. Opaque textures can be a lot faster, so give this option without forcing the user to reimplement her/his own QSGTexture class. The old behavior was that createTextureFromImage() disregarded TextureHasAlphaChannel and looked solely at the image's format. To keep this behavior intact, we introduce a second opt-in flag to switch textures from auto-detect to false, namely TextureIsOpaque. [ChangeLog][QtQuick][QQuickWindow] Add TextureIsOpaque option to createTextureFromImage() Change-Id: I248db4bc5f7920864b6aa8d831ce24d23ad370ef Reviewed-by: Laszlo Agocs --- src/quick/scenegraph/qsgcontext.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/quick/scenegraph/qsgcontext.cpp') diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index 2af8bc73ba..ef31151691 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -735,22 +735,26 @@ QSGDepthStencilBufferManager *QSGRenderContext::depthStencilBufferManager() will be called with \a image as argument. */ -QSGTexture *QSGRenderContext::createTexture(const QImage &image) const -{ - if (!openglContext()) - return 0; - QSGTexture *t = m_atlasManager->create(image); - if (t) - return t; - return createTextureNoAtlas(image); -} +QSGTexture *QSGRenderContext::createTexture(const QImage &image, uint flags) const +{ + bool atlas = flags & CreateTexture_Atlas; + bool mipmap = flags & CreateTexture_Mipmap; + bool alpha = flags & CreateTexture_Alpha; + + // The atlas implementation is only supported from the render thread and + // does not support mipmaps. + if (!mipmap && atlas && openglContext() && QThread::currentThread() == openglContext()->thread()) { + QSGTexture *t = m_atlasManager->create(image, alpha); + if (t) + return t; + } -QSGTexture *QSGRenderContext::createTextureNoAtlas(const QImage &image) const -{ - QSGPlainTexture *t = new QSGPlainTexture(); - if (!image.isNull()) - t->setImage(image); - return t; + QSGPlainTexture *texture = new QSGPlainTexture(); + texture->setImage(image); + if (texture->hasAlphaChannel() && !alpha) + texture->setHasAlphaChannel(false); + + return texture; } /*! -- cgit v1.2.3