19QSGSoftwareRenderer::QSGSoftwareRenderer(QSGRenderContext *context)
20 : QSGAbstractSoftwareRenderer(context)
21 , m_paintDevice(
nullptr)
22 , m_backingStore(
nullptr)
25 static bool partialUpdateOverrideSet =
false;
26 static const int forcePartialUpdates = qEnvironmentVariableIntValue(
"QSG_SOFTWARE_RENDERER_FORCE_PARTIAL_UPDATES", &partialUpdateOverrideSet);
27 if (partialUpdateOverrideSet) {
28 if (forcePartialUpdates == 0)
29 m_partialUpdateMode = DisablePartialUpdate;
31 m_partialUpdateMode = ForcePartialUpdate;
66void QSGSoftwareRenderer::render()
68 if (!m_paintDevice && !m_backingStore && !m_rt.paintDevice)
71 QPaintDevice *paintDevice = m_paintDevice ? m_paintDevice : m_rt.paintDevice;
73 qreal paintDevicePixelRatio = 1.0;
76 paintSize = QSize(paintDevice->width(), paintDevice->height());
77 paintDevicePixelRatio = paintDevice->devicePixelRatio();
82 m_backingStore->beginPaint(QRegion());
84 const QPaintDevice *backingStorePaintDevice = m_backingStore->paintDevice();
85 paintSize = QSize(backingStorePaintDevice->width(), backingStorePaintDevice->height());
86 paintDevicePixelRatio = backingStorePaintDevice->devicePixelRatio();
88 m_backingStore->endPaint();
91 QElapsedTimer renderTimer;
93 setBackgroundColor(clearColor());
94 setBackgroundRect(QRect(0, 0,
95 paintSize.width() / paintDevicePixelRatio,
96 paintSize.height() / paintDevicePixelRatio),
97 paintDevicePixelRatio);
99 const bool nonIntegerRatio = !qFuzzyIsNull(paintDevicePixelRatio - qFloor(paintDevicePixelRatio));
100 bool disablePartialUpdates = m_partialUpdateMode == DisablePartialUpdate || nonIntegerRatio;
101 if (m_partialUpdateMode == ForcePartialUpdate)
102 disablePartialUpdates =
false;
105 if (disablePartialUpdates)
116 qint64 buildRenderListTime = renderTimer.restart();
127 const QRegion updateRegion = optimizeRenderList();
128 qint64 optimizeRenderListTime = renderTimer.restart();
131 bool usingBackingStore =
false;
133 m_backingStore->beginPaint(updateRegion);
134 paintDevice = m_backingStore->paintDevice();
135 usingBackingStore =
true;
138 QPainter painter(paintDevice);
139 painter.setRenderHint(QPainter::Antialiasing);
140 auto rc =
static_cast<QSGSoftwareRenderContext *>(context());
141 QPainter *prevPainter = rc->m_activePainter;
142 rc->m_activePainter = &painter;
145 m_flushRegion = renderNodes(&painter);
146 qint64 renderTime = renderTimer.elapsed();
149 if (usingBackingStore)
150 m_backingStore->endPaint();
152 rc->m_activePainter = prevPainter;
153 qCDebug(lcRenderer) <<
"render" << m_flushRegion << buildRenderListTime << optimizeRenderListTime << renderTime;