diff options
author | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-10-17 14:53:33 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-30 08:29:49 +0100 |
commit | 906d5c5c40183468f9521277c6244a6c46730de6 (patch) | |
tree | 0eb46a8f88d59993ab659e2dc07970d1ce2f0d73 /src/quick/scenegraph/util | |
parent | c084d32d92b2df55532fa1599e590c29bf2b5bfb (diff) |
Use one render loop per QQuickWindow
See the task for the full reasoning behind this patch.
The threaded renderloop has been refactored to have one window per
thread. This is mostly a simplification of the current code path where
for loops over multiple windows are turned into if (window).
The QSGContext has been split into two classes, QSGRenderContext
for which there is one per OpenGLContext.
The rest of the patch is name changes and a couple of cleanups
in the hopes of simplifying this change.
Task-number: QTBUG-33993
Change-Id: I31c81f9694d7da7474a72333169be38de62613c4
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture.cpp | 40 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture_p.h | 10 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgpainternode.cpp | 6 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgpainternode_p.h | 2 |
4 files changed, 38 insertions, 20 deletions
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 12ab48e193..b180bc43bd 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -47,11 +47,14 @@ #include <QtGui/QOpenGLContext> #include <QtGui/QGuiApplication> #include <QtGui/QScreen> +#include <QtGui/QSurface> #include <private/qsgtexture_p.h> #include <private/qqmlprofilerservice_p.h> +QT_BEGIN_NAMESPACE + #ifndef GL_BGRA #define GL_BGRA 0x80E1 #endif @@ -89,11 +92,15 @@ static int qsg_envInt(const char *name, int defaultValue) Manager::Manager() : m_atlas(0) { - QSize screenSize = QGuiApplication::primaryScreen()->geometry().size(); + QOpenGLContext *gl = QOpenGLContext::currentContext(); + Q_ASSERT(gl); + QSurface *surface = gl->surface(); + QSize surfaceSize = surface->size(); int max; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); - int w = qMin(max, qsg_envInt("QSG_ATLAS_WIDTH", qsg_powerOfTwo(screenSize.width()))); - int h = qMin(max, qsg_envInt("QSG_ATLAS_HEIGHT", qsg_powerOfTwo(screenSize.height()))); + + int w = qMin(max, qsg_envInt("QSG_ATLAS_WIDTH", qMax(512, qsg_powerOfTwo(surfaceSize.width())))); + int h = qMin(max, qsg_envInt("QSG_ATLAS_HEIGHT", qMax(512, qsg_powerOfTwo(surfaceSize.height())))); m_atlas_size_limit = qsg_envInt("QSG_ATLAS_SIZE_LIMIT", qMax(w, h) / 2); m_atlas_size = QSize(w, h); @@ -102,13 +109,16 @@ Manager::Manager() Manager::~Manager() { - invalidate(); + Q_ASSERT(m_atlas == 0); } void Manager::invalidate() { - delete m_atlas; - m_atlas = 0; + if (m_atlas) { + m_atlas->invalidate(); + m_atlas->deleteLater(); + m_atlas = 0; + } } QSGTexture *Manager::create(const QImage &image) @@ -118,10 +128,7 @@ QSGTexture *Manager::create(const QImage &image) if (!m_atlas) m_atlas = new Atlas(m_atlas_size); t = m_atlas->create(image); - if (t) - return t; } - return t; } @@ -153,13 +160,21 @@ Atlas::Atlas(const QSize &size) Atlas::~Atlas() { - if (m_texture_id) - glDeleteTextures(1, &m_texture_id); + Q_ASSERT(!m_texture_id); } +void Atlas::invalidate() +{ + Q_ASSERT(QOpenGLContext::currentContext()); + if (m_texture_id) { + glDeleteTextures(1, &m_texture_id); + m_texture_id = 0; + } +} Texture *Atlas::create(const QImage &image) { + // No need to lock, as manager already locked it. QRect rect = m_allocator.allocate(QSize(image.width() + 2, image.height() + 2)); if (rect.width() > 0 && rect.height() > 0) { Texture *t = new Texture(this, rect, image); @@ -386,7 +401,6 @@ void Atlas::remove(Texture *t) { QRect atlasRect = t->atlasSubRect(); m_allocator.deallocate(atlasRect); - m_pending_uploads.removeOne(t); } @@ -431,3 +445,5 @@ QSGTexture *Texture::removedFromAtlas() const } } + +QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgatlastexture_p.h b/src/quick/scenegraph/util/qsgatlastexture_p.h index f8edd96f47..ade7b8f00e 100644 --- a/src/quick/scenegraph/util/qsgatlastexture_p.h +++ b/src/quick/scenegraph/util/qsgatlastexture_p.h @@ -50,6 +50,8 @@ #include <QtQuick/private/qsgtexture_p.h> #include <QtQuick/private/qsgareaallocator_p.h> +QT_BEGIN_NAMESPACE + namespace QSGAtlasTexture { @@ -69,19 +71,18 @@ public: private: Atlas *m_atlas; - Atlas *m_secondary_atlas; QSize m_atlas_size; int m_atlas_size_limit; }; -class Atlas +class Atlas : public QObject { public: Atlas(const QSize &size); ~Atlas(); - void initialize(); + void invalidate(); int textureId() const; bool bind(QSGTexture::Filtering filteing); @@ -95,7 +96,6 @@ public: QSize size() const { return m_size; } private: - QSGAreaAllocator m_allocator; GLuint m_texture_id; QSize m_size; @@ -153,4 +153,6 @@ private: } +QT_END_NAMESPACE + #endif diff --git a/src/quick/scenegraph/util/qsgpainternode.cpp b/src/quick/scenegraph/util/qsgpainternode.cpp index d6bec550d3..797fc4d145 100644 --- a/src/quick/scenegraph/util/qsgpainternode.cpp +++ b/src/quick/scenegraph/util/qsgpainternode.cpp @@ -111,7 +111,7 @@ QSGPainterNode::QSGPainterNode(QQuickPaintedItem *item) , m_dirtyRenderTarget(false) , m_dirtyTexture(false) { - m_context = static_cast<QQuickPaintedItemPrivate *>(QObjectPrivate::get(item))->sceneGraphContext(); + m_context = static_cast<QQuickPaintedItemPrivate *>(QObjectPrivate::get(item))->sceneGraphRenderContext(); setMaterial(&m_materialO); setOpaqueMaterial(&m_material); @@ -260,7 +260,7 @@ void QSGPainterNode::updateRenderTarget() if (m_actualRenderTarget == QQuickPaintedItem::FramebufferObject || m_actualRenderTarget == QQuickPaintedItem::InvertedYFramebufferObject) { - const QOpenGLContext *ctx = m_context->glContext(); + const QOpenGLContext *ctx = m_context->openglContext(); if (m_fbo && !m_dirtyGeometry && (!ctx->format().samples() || !m_multisamplingSupported)) return; @@ -323,7 +323,7 @@ void QSGPainterNode::updateFBOSize() fboWidth = qMax(QT_MINIMUM_DYNAMIC_FBO_SIZE, qt_next_power_of_two(m_size.width())); fboHeight = qMax(QT_MINIMUM_DYNAMIC_FBO_SIZE, qt_next_power_of_two(m_size.height())); } else { - QSize minimumFBOSize = m_context->minimumFBOSize(); + QSize minimumFBOSize = m_context->sceneGraphContext()->minimumFBOSize(); fboWidth = qMax(minimumFBOSize.width(), m_size.width()); fboHeight = qMax(minimumFBOSize.height(), m_size.height()); } diff --git a/src/quick/scenegraph/util/qsgpainternode_p.h b/src/quick/scenegraph/util/qsgpainternode_p.h index bc1556672c..df0943d38e 100644 --- a/src/quick/scenegraph/util/qsgpainternode_p.h +++ b/src/quick/scenegraph/util/qsgpainternode_p.h @@ -113,7 +113,7 @@ private: void updateRenderTarget(); void updateFBOSize(); - QSGContext *m_context; + QSGRenderContext *m_context; QQuickPaintedItem::RenderTarget m_preferredRenderTarget; QQuickPaintedItem::RenderTarget m_actualRenderTarget; |