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;
67void QSGSoftwareRenderer::render()
69 if (!m_paintDevice && !m_backingStore && !m_rt.paintDevice)
72 QPaintDevice *paintDevice = m_paintDevice ? m_paintDevice : m_rt.paintDevice;
74 qreal paintDevicePixelRatio = 1.0;
77 paintSize = QSize(paintDevice->width(), paintDevice->height());
78 paintDevicePixelRatio = paintDevice->devicePixelRatio();
83 m_backingStore->beginPaint(QRegion());
85 const QPaintDevice *backingStorePaintDevice = m_backingStore->paintDevice();
86 paintSize = QSize(backingStorePaintDevice->width(), backingStorePaintDevice->height());
87 paintDevicePixelRatio = backingStorePaintDevice->devicePixelRatio();
89 m_backingStore->endPaint();
92 QElapsedTimer renderTimer;
94 setBackgroundColor(clearColor());
95 setBackgroundRect(QRect(0, 0,
96 paintSize.width() / paintDevicePixelRatio,
97 paintSize.height() / paintDevicePixelRatio),
98 paintDevicePixelRatio);
100 const bool nonIntegerRatio = !qFuzzyIsNull(paintDevicePixelRatio - qFloor(paintDevicePixelRatio));
101 bool disablePartialUpdates = m_partialUpdateMode == DisablePartialUpdate || nonIntegerRatio;
102 if (m_partialUpdateMode == ForcePartialUpdate)
103 disablePartialUpdates =
false;
106 if (disablePartialUpdates)
117 qint64 buildRenderListTime = renderTimer.restart();
128 const QRegion updateRegion = optimizeRenderList();
129 qint64 optimizeRenderListTime = renderTimer.restart();
132 bool usingBackingStore =
false;
134 m_backingStore->beginPaint(updateRegion);
135 paintDevice = m_backingStore->paintDevice();
136 usingBackingStore =
true;
139 QPainter painter(paintDevice);
140 painter.setRenderHint(QPainter::Antialiasing);
141 auto rc =
static_cast<QSGSoftwareRenderContext *>(context());
142 QPainter *prevPainter = rc->m_activePainter;
143 rc->m_activePainter = &painter;
146 m_flushRegion = renderNodes(&painter);
147 qint64 renderTime = renderTimer.elapsed();
150 if (usingBackingStore)
151 m_backingStore->endPaint();
153 rc->m_activePainter = prevPainter;
154 qCDebug(lcRenderer) <<
"render" << m_flushRegion << buildRenderListTime << optimizeRenderListTime << renderTime;