From 75445c228476e4905cef3fb89a849f93f33e768f Mon Sep 17 00:00:00 2001 From: Balazs Kelemen Date: Thu, 27 Sep 2012 12:24:25 +0200 Subject: [PATCH] Allow grabbing windows rendered without showing for testing. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To make QQuickWindowPrivate::setRenderWithoutShowing more useful for autotesting we can allow grabbing such windows. This is safe if the platform window have been created and the window has a valid size. Change-Id: I8b9a2aaeb93935f662b75ef29651730b890441d5 Reviewed-by: Samuel Rødal Reviewed-by: Jocelyn Turcotte --- src/quick/items/qquickthreadedwindowmanager.cpp | 14 ++++++++------ src/quick/items/qquickthreadedwindowmanager_p.h | 10 ---------- src/quick/items/qquickwindow.cpp | 12 +++++++++--- src/quick/items/qquickwindow_p.h | 2 ++ src/quick/items/qquickwindowmanager.cpp | 7 +++++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/quick/items/qquickthreadedwindowmanager.cpp b/src/quick/items/qquickthreadedwindowmanager.cpp index 624efa5..50bd569 100644 --- a/src/quick/items/qquickthreadedwindowmanager.cpp +++ b/src/quick/items/qquickthreadedwindowmanager.cpp @@ -126,7 +126,12 @@ void QQuickRenderThreadSingleContextWindowManager::initialize() { Q_ASSERT(m_rendered_windows.size()); - QQuickWindow *win = masterWindow(); + QQuickWindow *win = 0; + for (QHash::const_iterator it = m_rendered_windows.constBegin(); + it != m_rendered_windows.constEnd() && !win; ++it) { + if (QQuickWindowPrivate::get(it.key())->isRenderable()) + win = it.key(); + } if (!win) return; @@ -391,12 +396,9 @@ void QQuickRenderThreadSingleContextWindowManager::run() WindowData *windowData = it.value(); QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(window); - Q_ASSERT(windowData->windowSize.width() > 0 && windowData->windowSize.height() > 0); + Q_ASSERT(windowPrivate->isRenderable()); - if (!windowData->isVisible) - gl->makeCurrent(masterWindow()); - else - gl->makeCurrent(window); + gl->makeCurrent(window); if (windowData->viewportSize != windowData->windowSize) { #ifdef THREAD_DEBUG diff --git a/src/quick/items/qquickthreadedwindowmanager_p.h b/src/quick/items/qquickthreadedwindowmanager_p.h index 48c9d10..9e28d87 100644 --- a/src/quick/items/qquickthreadedwindowmanager_p.h +++ b/src/quick/items/qquickthreadedwindowmanager_p.h @@ -118,16 +118,6 @@ public: void run(); - QQuickWindow *masterWindow() { - QQuickWindow *win = 0; - for (QHash::const_iterator it = m_rendered_windows.constBegin(); - it != m_rendered_windows.constEnd() && !win; ++it) { - if (it.value()->isVisible) - win = it.key(); - } - return win; - } - QAnimationDriver *animationDriver() const { return animDriver; } public slots: diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index b0e3db2..b657094 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -259,9 +259,8 @@ void QQuickWindowPrivate::polishItems() * This parameter enables that this window can be rendered without * being shown on screen. This feature is very limited in what it supports. * - * There needs to be another window actually showing that we can make current - * to get a surface to make current AND for this feature to be useful - * one needs to hook into beforeRender() and set the render tareget. + * For this feature to be useful one needs to hook into beforeRender() + * and set the render tareget. * */ void QQuickWindowPrivate::setRenderWithoutShowing(bool render) @@ -1996,6 +1995,13 @@ bool QQuickWindowPrivate::dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent return overThreshold; } +bool QQuickWindowPrivate::isRenderable() const +{ + if (geometry.width() <= 0 || geometry.height() <= 0) + return false; + return visible || (renderWithoutShowing && platformWindow); +} + /*! Propagates an event \a e to a QQuickItem \a item on the window. diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index fc8da0b..530e547 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -173,6 +173,8 @@ public: void syncSceneGraph(); void renderSceneGraph(const QSize &size); + bool isRenderable() const; + bool renderWithoutShowing; void setRenderWithoutShowing(bool enabled); diff --git a/src/quick/items/qquickwindowmanager.cpp b/src/quick/items/qquickwindowmanager.cpp index 4388766..6596343 100644 --- a/src/quick/items/qquickwindowmanager.cpp +++ b/src/quick/items/qquickwindowmanager.cpp @@ -198,13 +198,14 @@ void QQuickTrivialWindowManager::windowDestroyed(QQuickWindow *window) void QQuickTrivialWindowManager::renderWindow(QQuickWindow *window) { - if (!window->isExposed() || !m_windows.contains(window)) + bool renderWithoutShowing = QQuickWindowPrivate::get(window)->renderWithoutShowing; + if ((!window->isExposed() && !renderWithoutShowing) || !m_windows.contains(window)) return; WindowData &data = const_cast(m_windows[window]); QQuickWindow *masterWindow = 0; - if (!window->isVisible()) { + if (!window->isVisible() && !renderWithoutShowing) { // Find a "proper surface" to bind... for (QHash::const_iterator it = m_windows.constBegin(); it != m_windows.constEnd() && !masterWindow; ++it) { @@ -218,6 +219,8 @@ void QQuickTrivialWindowManager::renderWindow(QQuickWindow *window) if (!masterWindow) return; + Q_ASSERT(QQuickWindowPrivate::get(masterWindow)->isRenderable()); + if (!gl) { gl = new QOpenGLContext(); gl->setFormat(masterWindow->requestedFormat()); -- 1.7.2.5