20QSGSoftwareRenderer::QSGSoftwareRenderer(QSGRenderContext *context)
21 : QSGAbstractSoftwareRenderer(context)
22 , m_paintDevice(
nullptr)
23 , m_backingStore(
nullptr)
26 static bool partialUpdateOverrideSet =
false;
27 static const int forcePartialUpdates = qEnvironmentVariableIntValue(
"QSG_SOFTWARE_RENDERER_FORCE_PARTIAL_UPDATES", &partialUpdateOverrideSet);
28 if (partialUpdateOverrideSet) {
29 if (forcePartialUpdates == 0)
30 m_partialUpdateMode = DisablePartialUpdate;
32 m_partialUpdateMode = ForcePartialUpdate;
69void QSGSoftwareRenderer::render()
71 if (!m_paintDevice && !m_backingStore && !m_rt.paintDevice)
74 QPaintDevice *paintDevice = m_paintDevice ? m_paintDevice : m_rt.paintDevice;
76 qreal paintDevicePixelRatio = 1.0;
79 paintSize = QSize(paintDevice->width(), paintDevice->height());
80 paintDevicePixelRatio = paintDevice->devicePixelRatio();
84 const QSize size = m_backingStore->size();
85 const qreal windowDpr = m_backingStore->window()->devicePixelRatio();
86 if (size != m_backingStoreSize || windowDpr != m_windowDevicePixelRatio) {
87 m_backingStore->beginPaint(QRegion());
89 const QPaintDevice *backingStorePaintDevice = m_backingStore->paintDevice();
90 m_backingStorePaintSize = QSize(backingStorePaintDevice->width(),
91 backingStorePaintDevice->height());
92 m_backingStorePaintDevicePixelRatio = backingStorePaintDevice->devicePixelRatio();
94 m_backingStore->endPaint();
95 m_backingStoreSize = size;
96 m_windowDevicePixelRatio = windowDpr;
98 paintSize = m_backingStorePaintSize;
99 paintDevicePixelRatio = m_backingStorePaintDevicePixelRatio;
102 QElapsedTimer renderTimer;
104 setBackgroundColor(clearColor());
105 const QRect backgroundRect =
106 QRectF(QPointF(), QSizeF(paintSize) / paintDevicePixelRatio).toAlignedRect();
107 setBackgroundRect(backgroundRect, paintDevicePixelRatio);
108 const bool disablePartialUpdates = m_partialUpdateMode == DisablePartialUpdate;
111 if (disablePartialUpdates)
122 qint64 buildRenderListTime = renderTimer.restart();
133 const QRegion updateRegion = optimizeRenderList();
134 qint64 optimizeRenderListTime = renderTimer.restart();
137 const auto &nodes = renderableNodes();
138 if (updateRegion.isEmpty() && std::none_of(nodes.cbegin(), nodes.cend(), [](
auto *node) {
139 return node->type() == QSGSoftwareRenderableNode::RenderNode && node->isDirty();
141 for (
auto *node : nodes)
143 m_flushRegion = QRegion();
144 qCDebug(lcRenderer) <<
"render: nothing to paint" << buildRenderListTime << optimizeRenderListTime;
149 bool usingBackingStore =
false;
151 m_backingStore->beginPaint(updateRegion);
152 paintDevice = m_backingStore->paintDevice();
153 usingBackingStore =
true;
156 QPainter painter(paintDevice);
157 painter.setRenderHint(QPainter::Antialiasing);
158 auto rc =
static_cast<QSGSoftwareRenderContext *>(context());
159 QPainter *prevPainter = rc->m_activePainter;
160 rc->m_activePainter = &painter;
163 m_flushRegion = renderNodes(&painter);
164 qint64 renderTime = renderTimer.elapsed();
167 if (usingBackingStore)
168 m_backingStore->endPaint();
170 rc->m_activePainter = prevPainter;
171 qCDebug(lcRenderer) <<
"render" << m_flushRegion << buildRenderListTime << optimizeRenderListTime << renderTime;