2016-01-13 09:14:13 +00:00
|
|
|
/****************************************************************************
|
2014-08-11 13:04:41 +00:00
|
|
|
**
|
2016-01-13 09:14:13 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-08-11 13:04:41 +00:00
|
|
|
**
|
2016-03-08 15:28:47 +00:00
|
|
|
** This file is part of the QtQuick module of the Qt Toolkit.
|
2014-08-11 13:04:41 +00:00
|
|
|
**
|
2016-03-08 15:28:47 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2015-08-11 10:03:16 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-08-11 13:04:41 +00:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-08-11 10:03:16 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-13 09:14:13 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
2016-03-08 15:28:47 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
|
|
|
**
|
2016-01-13 09:14:13 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-03-08 15:28:47 +00:00
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
2016-01-13 09:14:13 +00:00
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
2016-03-08 15:28:47 +00:00
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-11-23 11:42:31 +00:00
|
|
|
**
|
2014-08-11 13:04:41 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
2016-01-13 09:14:13 +00:00
|
|
|
****************************************************************************/
|
2015-08-11 10:03:16 +00:00
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
#include "qsgsoftwarerenderloop_p.h"
|
2014-08-07 13:15:38 +00:00
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
#include "qsgsoftwarecontext_p.h"
|
2015-10-14 15:12:58 +00:00
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
2014-08-07 13:15:38 +00:00
|
|
|
#include <private/qquickwindow_p.h>
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <private/qquickprofiler_p.h>
|
|
|
|
|
2016-03-04 12:54:34 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
QSGSoftwareRenderLoop::QSGSoftwareRenderLoop()
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
sg = QSGContext::createDefaultContext();
|
|
|
|
rc = sg->createRenderContext();
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
QSGSoftwareRenderLoop::~QSGSoftwareRenderLoop()
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
delete rc;
|
|
|
|
delete sg;
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::show(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
WindowData data;
|
|
|
|
data.updatePending = false;
|
|
|
|
data.grabOnly = false;
|
|
|
|
m_windows[window] = data;
|
|
|
|
|
|
|
|
maybeUpdate(window);
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::hide(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
|
|
|
|
cd->fireAboutToStop();
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::windowDestroyed(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
2015-08-10 12:57:09 +00:00
|
|
|
m_windows.remove(window);
|
2014-08-07 13:15:38 +00:00
|
|
|
hide(window);
|
2015-08-10 12:57:09 +00:00
|
|
|
|
|
|
|
QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
|
|
|
|
d->cleanupNodesOnShutdown();
|
|
|
|
|
2014-08-07 13:15:38 +00:00
|
|
|
if (m_windows.size() == 0) {
|
|
|
|
rc->invalidate();
|
|
|
|
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::renderWindow(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
|
|
|
|
if (!cd->isRenderable() || !m_windows.contains(window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WindowData &data = const_cast<WindowData &>(m_windows[window]);
|
|
|
|
|
|
|
|
// ### create QPainter and set up pointer to current window/painter
|
2016-03-08 16:33:44 +00:00
|
|
|
QSGSoftwareRenderContext *ctx = static_cast<QSGSoftwareRenderContext*>(cd->context);
|
2014-08-14 10:41:26 +00:00
|
|
|
ctx->currentWindow = window;
|
|
|
|
ctx->initializeIfNeeded();
|
2014-08-07 13:15:38 +00:00
|
|
|
|
|
|
|
bool alsoSwap = data.updatePending;
|
|
|
|
data.updatePending = false;
|
|
|
|
|
|
|
|
if (!data.grabOnly) {
|
|
|
|
cd->flushDelayedTouchEvent();
|
|
|
|
// Event delivery/processing triggered the window to be deleted or stop rendering.
|
|
|
|
if (!m_windows.contains(window))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QElapsedTimer renderTimer;
|
|
|
|
qint64 renderTime = 0, syncTime = 0, polishTime = 0;
|
2015-08-10 12:57:09 +00:00
|
|
|
bool profileFrames = QSG_RASTER_LOG_TIME_RENDERLOOP().isDebugEnabled();
|
2014-08-07 13:15:38 +00:00
|
|
|
if (profileFrames)
|
|
|
|
renderTimer.start();
|
2015-08-10 12:57:09 +00:00
|
|
|
Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphPolishFrame);
|
2014-08-07 13:15:38 +00:00
|
|
|
|
|
|
|
cd->polishItems();
|
|
|
|
|
2015-08-10 12:57:09 +00:00
|
|
|
if (profileFrames)
|
2014-08-07 13:15:38 +00:00
|
|
|
polishTime = renderTimer.nsecsElapsed();
|
2015-08-10 12:57:09 +00:00
|
|
|
Q_QUICK_SG_PROFILE_SWITCH(QQuickProfiler::SceneGraphPolishFrame,
|
|
|
|
QQuickProfiler::SceneGraphRenderLoopFrame);
|
2014-08-07 13:15:38 +00:00
|
|
|
|
|
|
|
emit window->afterAnimating();
|
|
|
|
|
|
|
|
cd->syncSceneGraph();
|
|
|
|
|
|
|
|
if (profileFrames)
|
|
|
|
syncTime = renderTimer.nsecsElapsed();
|
2015-08-10 12:57:09 +00:00
|
|
|
Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame);
|
2014-08-07 13:15:38 +00:00
|
|
|
|
|
|
|
cd->renderSceneGraph(window->size());
|
|
|
|
|
|
|
|
if (profileFrames)
|
|
|
|
renderTime = renderTimer.nsecsElapsed();
|
2015-08-10 12:57:09 +00:00
|
|
|
Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame);
|
2014-08-07 13:15:38 +00:00
|
|
|
|
|
|
|
if (data.grabOnly) {
|
2015-08-10 12:57:09 +00:00
|
|
|
// #### grabContent = qt_gl_read_framebuffer(window->size() * window->effectiveDevicePixelRatio(), false, false);
|
2014-08-07 13:15:38 +00:00
|
|
|
data.grabOnly = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alsoSwap && window->isVisible()) {
|
|
|
|
// ### gl->swapBuffers(window);
|
|
|
|
cd->fireFrameSwapped();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 swapTime = 0;
|
|
|
|
if (profileFrames)
|
|
|
|
swapTime = renderTimer.nsecsElapsed();
|
2015-08-10 12:57:09 +00:00
|
|
|
Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRenderLoopFrame);
|
2014-08-07 13:15:38 +00:00
|
|
|
|
2014-11-17 11:25:41 +00:00
|
|
|
if (QSG_RASTER_LOG_TIME_RENDERLOOP().isDebugEnabled()) {
|
2014-08-07 13:15:38 +00:00
|
|
|
static QTime lastFrameTime = QTime::currentTime();
|
2014-11-17 11:25:41 +00:00
|
|
|
qCDebug(QSG_RASTER_LOG_TIME_RENDERLOOP,
|
2014-08-07 13:15:38 +00:00
|
|
|
"Frame rendered with 'basic' renderloop in %dms, polish=%d, sync=%d, render=%d, swap=%d, frameDelta=%d",
|
|
|
|
int(swapTime / 1000000),
|
|
|
|
int(polishTime / 1000000),
|
|
|
|
int((syncTime - polishTime) / 1000000),
|
|
|
|
int((renderTime - syncTime) / 1000000),
|
|
|
|
int((swapTime - renderTime) / 10000000),
|
|
|
|
int(lastFrameTime.msecsTo(QTime::currentTime())));
|
|
|
|
lastFrameTime = QTime::currentTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Might have been set during syncSceneGraph()
|
|
|
|
if (data.updatePending)
|
|
|
|
maybeUpdate(window);
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::exposureChanged(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
if (window->isExposed()) {
|
|
|
|
m_windows[window].updatePending = true;
|
|
|
|
renderWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
QImage QSGSoftwareRenderLoop::grab(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
if (!m_windows.contains(window))
|
|
|
|
return QImage();
|
|
|
|
|
|
|
|
m_windows[window].grabOnly = true;
|
|
|
|
|
|
|
|
renderWindow(window);
|
|
|
|
|
|
|
|
QImage grabbed = grabContent;
|
|
|
|
grabContent = QImage();
|
|
|
|
return grabbed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::maybeUpdate(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
if (!m_windows.contains(window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_windows[window].updatePending = true;
|
2016-01-13 21:42:31 +00:00
|
|
|
window->requestUpdate();
|
2014-08-07 13:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
QSurface::SurfaceType QSGSoftwareRenderLoop::windowSurfaceType() const
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
return QSurface::RasterSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
QSGContext *QSGSoftwareRenderLoop::sceneGraphContext() const
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-08 16:14:39 +00:00
|
|
|
void QSGSoftwareRenderLoop::handleUpdateRequest(QQuickWindow *window)
|
2014-08-07 13:15:38 +00:00
|
|
|
{
|
2016-01-13 21:42:31 +00:00
|
|
|
renderWindow(window);
|
2014-08-07 13:15:38 +00:00
|
|
|
}
|
2016-03-04 12:54:34 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|