62QSGRenderer::QSGRenderer(QSGRenderContext *context)
63 : m_current_opacity(1)
64 , m_current_determinant(1)
65 , m_device_pixel_ratio(1)
67 , m_current_uniform_data(
nullptr)
68 , m_current_resource_update_batch(
nullptr)
70 , m_node_updater(
nullptr)
71 , m_changed_emitted(
false)
72 , m_is_rendering(
false)
73 , m_is_preprocessing(
false)
75 m_current_projection_matrix.resize(1);
76 m_current_projection_matrix_native_ndc.resize(1);
114bool QSGRenderer::isMirrored()
const
116 QMatrix4x4 matrix = projectionMatrix(0);
118 return matrix(0, 0) * matrix(1, 1) - matrix(0, 1) * matrix(1, 0) > 0;
121void QSGRenderer::renderScene()
126 Q_TRACE_SCOPE(QSG_renderScene);
127 m_is_rendering =
true;
129 bool profileFrames = QSG_LOG_TIME_RENDERER().isDebugEnabled();
132 Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphRendererFrame);
138 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
139 QQuickProfiler::SceneGraphRendererBinding);
141 qint64 renderTime = 0;
145 Q_TRACE(QSG_render_entry);
148 renderTime = frameTimer.nsecsElapsed();
149 Q_TRACE(QSG_render_exit);
150 Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRendererFrame,
151 QQuickProfiler::SceneGraphRendererRender);
153 m_is_rendering =
false;
154 m_changed_emitted =
false;
156 qCDebug(QSG_LOG_TIME_RENDERER,
157 "time in renderer: total=%dms, preprocess=%d, updates=%d, rendering=%d",
158 int(renderTime / 1000000),
159 int(preprocessTime / 1000000),
160 int((updatePassTime - preprocessTime) / 1000000),
161 int((renderTime - updatePassTime) / 1000000));
195void QSGRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
197 if (state & QSGNode::DirtyNodeAdded)
198 addNodesToPreprocess(node);
199 if (state & QSGNode::DirtyNodeRemoved)
200 removeNodesToPreprocess(node);
201 if (state & QSGNode::DirtyUsePreprocess) {
202 if (node->flags() & QSGNode::UsePreprocess)
203 m_nodes_to_preprocess.insert(node);
205 m_nodes_to_preprocess.remove(node);
208 if (!m_changed_emitted && !m_is_rendering) {
210 m_changed_emitted =
true;
211 emit sceneGraphChanged();
215void QSGRenderer::preprocess()
217 Q_TRACE(QSG_preprocess_entry);
219 m_is_preprocessing =
true;
221 QSGRootNode *root = rootNode();
227 QSet<QSGNode *> items = m_nodes_to_preprocess;
229 m_context->preprocess();
231 for (QSet<QSGNode *>::const_iterator it = items.constBegin();
232 it != items.constEnd(); ++it) {
237 if (m_nodes_dont_preprocess.contains(n))
239 if (!nodeUpdater()->isNodeBlocked(n, root)) {
244 bool profileFrames = QSG_LOG_TIME_RENDERER().isDebugEnabled();
246 preprocessTime = frameTimer.nsecsElapsed();
247 Q_TRACE(QSG_preprocess_exit);
248 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
249 QQuickProfiler::SceneGraphRendererPreprocess);
250 Q_TRACE(QSG_update_entry);
252 nodeUpdater()->updateStates(root);
255 updatePassTime = frameTimer.nsecsElapsed();
256 Q_TRACE(QSG_update_exit);
257 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRendererFrame,
258 QQuickProfiler::SceneGraphRendererUpdate);
260 m_is_preprocessing =
false;
261 m_nodes_dont_preprocess.clear();
274void QSGRenderer::removeNodesToPreprocess(QSGNode *node)
276 for (QSGNode *c = node->firstChild(); c; c = c->nextSibling())
277 removeNodesToPreprocess(c);
278 if (node->flags() & QSGNode::UsePreprocess) {
279 m_nodes_to_preprocess.remove(node);
282 if (m_is_preprocessing)
283 m_nodes_dont_preprocess.insert(node);