61QSGRenderer::QSGRenderer(QSGRenderContext *context)
62 : m_current_opacity(1)
63 , m_current_determinant(1)
64 , m_device_pixel_ratio(1)
66 , m_current_uniform_data(
nullptr)
67 , m_current_resource_update_batch(
nullptr)
69 , m_node_updater(
nullptr)
70 , m_changed_emitted(
false)
71 , m_is_rendering(
false)
72 , m_is_preprocessing(
false)
74 m_current_projection_matrix.resize(1);
75 m_current_projection_matrix_native_ndc.resize(1);
113bool QSGRenderer::isMirrored()
const
115 QMatrix4x4 matrix = projectionMatrix(0);
117 return matrix(0, 0) * matrix(1, 1) - matrix(0, 1) * matrix(1, 0) > 0;
120void QSGRenderer::renderScene()
125 Q_TRACE_SCOPE(QSG_renderScene);
126 m_is_rendering =
true;
128 bool profileFrames = QSG_LOG_TIME_RENDERER().isDebugEnabled();
131 Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphRendererFrame);
137 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
138 QQuickProfiler::SceneGraphRendererBinding);
140 qint64 renderTime = 0;
144 Q_TRACE(QSG_render_entry);
147 renderTime = frameTimer.nsecsElapsed();
148 Q_TRACE(QSG_render_exit);
149 Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRendererFrame,
150 QQuickProfiler::SceneGraphRendererRender);
152 m_is_rendering =
false;
153 m_changed_emitted =
false;
155 qCDebug(QSG_LOG_TIME_RENDERER,
156 "time in renderer: total=%dms, preprocess=%d, updates=%d, rendering=%d",
157 int(renderTime / 1000000),
158 int(preprocessTime / 1000000),
159 int((updatePassTime - preprocessTime) / 1000000),
160 int((renderTime - updatePassTime) / 1000000));
194void QSGRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
196 if (state & QSGNode::DirtyNodeAdded)
197 addNodesToPreprocess(node);
198 if (state & QSGNode::DirtyNodeRemoved)
199 removeNodesToPreprocess(node);
200 if (state & QSGNode::DirtyUsePreprocess) {
201 if (node->flags() & QSGNode::UsePreprocess)
202 m_nodes_to_preprocess.insert(node);
204 m_nodes_to_preprocess.remove(node);
207 if (!m_changed_emitted && !m_is_rendering) {
209 m_changed_emitted =
true;
210 emit sceneGraphChanged();
214void QSGRenderer::preprocess()
216 Q_TRACE(QSG_preprocess_entry);
218 m_is_preprocessing =
true;
220 QSGRootNode *root = rootNode();
226 QSet<QSGNode *> items = m_nodes_to_preprocess;
228 m_context->preprocess();
230 for (QSet<QSGNode *>::const_iterator it = items.constBegin();
231 it != items.constEnd(); ++it) {
236 if (m_nodes_dont_preprocess.contains(n))
238 if (!nodeUpdater()->isNodeBlocked(n, root)) {
243 bool profileFrames = QSG_LOG_TIME_RENDERER().isDebugEnabled();
245 preprocessTime = frameTimer.nsecsElapsed();
246 Q_TRACE(QSG_preprocess_exit);
247 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
248 QQuickProfiler::SceneGraphRendererPreprocess);
249 Q_TRACE(QSG_update_entry);
251 nodeUpdater()->updateStates(root);
254 updatePassTime = frameTimer.nsecsElapsed();
255 Q_TRACE(QSG_update_exit);
256 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
257 QQuickProfiler::SceneGraphRendererUpdate);
259 m_is_preprocessing =
false;
260 m_nodes_dont_preprocess.clear();
273void QSGRenderer::removeNodesToPreprocess(QSGNode *node)
275 for (QSGNode *c = node->firstChild(); c; c = c->nextSibling())
276 removeNodesToPreprocess(c);
277 if (node->flags() & QSGNode::UsePreprocess) {
278 m_nodes_to_preprocess.remove(node);
281 if (m_is_preprocessing)
282 m_nodes_dont_preprocess.insert(node);