Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgsoftwarerenderer.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
10
11#include <QtGui/QPaintDevice>
12#include <QtGui/QBackingStore>
13#include <QElapsedTimer>
14
15Q_LOGGING_CATEGORY(lcRenderer, "qt.scenegraph.softwarecontext.renderer")
16
18
21 , m_paintDevice(nullptr)
22 , m_backingStore(nullptr)
23{
24}
25
29
31{
32 m_paintDevice = device;
33 m_backingStore = nullptr;
34}
35
37{
38 return m_paintDevice;
39}
40
42{
43 m_backingStore = backingStore;
44 m_paintDevice = nullptr;
45}
46
48{
49 return m_flushRegion;
50}
51
56
58{
59 if (!m_paintDevice && !m_backingStore && !m_rt.paintDevice)
60 return;
61
62 QPaintDevice *paintDevice = m_paintDevice ? m_paintDevice : m_rt.paintDevice;
63 QBackingStore *backingStore = nullptr;
64 // If no paint device and there is a backingstore, set the current paint device
65 if (!paintDevice && m_backingStore) {
66 // For HiDPI QBackingStores, the paint device is not valid
67 // until begin() has been called. See: QTBUG-55875
68 m_backingStore->beginPaint(QRegion());
69 paintDevice = m_backingStore->paintDevice();
70 m_backingStore->endPaint();
71 backingStore = m_backingStore;
72 }
73
74 QElapsedTimer renderTimer;
75
78 paintDevice->width() / paintDevice->devicePixelRatio(),
79 paintDevice->height() / paintDevice->devicePixelRatio()),
80 paintDevice->devicePixelRatio());
81
82 // Build Renderlist
83 // The renderlist is created by visiting each node in the tree and when a
84 // renderable node is reach, we find the coorosponding RenderableNode object
85 // and append it to the renderlist. At this point the RenderableNode object
86 // should not need any further updating so it is just a matter of appending
87 // RenderableNodes
88 renderTimer.start();
90 qint64 buildRenderListTime = renderTimer.restart();
91
92 // Optimize Renderlist
93 // This is a pass through the renderlist to determine what actually needs to
94 // be painted. Without this pass the renderlist will simply render each item
95 // from back to front, with a high potential for overdraw. It would also lead
96 // to the entire window being flushed every frame. The objective of the
97 // optimization pass is to only paint dirty nodes that are not occuluded. A
98 // side effect of this is that additional nodes may need to be marked dirty to
99 // force a repaint. It is also important that any item that needs to be
100 // repainted only paints what is needed, via the use of clip regions.
101 const QRegion updateRegion = optimizeRenderList();
102 qint64 optimizeRenderListTime = renderTimer.restart();
103
104 // If Rendering to a backingstore, prepare it to be updated
105 if (backingStore != nullptr) {
106 backingStore->beginPaint(updateRegion);
107 // It is possible that a QBackingStore's paintDevice() will change
108 // when begin() is called.
109 paintDevice = backingStore->paintDevice();
110 }
111
112 QPainter painter(paintDevice);
114 auto rc = static_cast<QSGSoftwareRenderContext *>(context());
115 QPainter *prevPainter = rc->m_activePainter;
116 rc->m_activePainter = &painter;
117
118 // Render the contents Renderlist
119 m_flushRegion = renderNodes(&painter);
120 qint64 renderTime = renderTimer.elapsed();
121
122 painter.end();
123 if (backingStore != nullptr)
124 backingStore->endPaint();
125
126 rc->m_activePainter = prevPainter;
127 qCDebug(lcRenderer) << "render" << m_flushRegion << buildRenderListTime << optimizeRenderListTime << renderTime;
128}
129
IOBluetoothDevice * device
The QBackingStore class provides a drawing area for QWindow.
QPaintDevice * paintDevice()
Returns the paint device for this surface.
void beginPaint(const QRegion &)
Begins painting on the backing store surface in the given region.
void endPaint()
Ends painting.
\inmodule QtCore
qreal devicePixelRatio() const
int width() const
int height() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
@ Antialiasing
Definition qpainter.h:52
bool end()
Ends painting.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QColor clearColor() const
Returns the color that clears the framebuffer at the beginning of the rendering.
void setBackgroundColor(const QColor &color)
void setBackgroundRect(const QRect &rect, qreal devicePixelRatio)
QPaintDevice * paintDevice
QSGRenderContext * context() const
void renderScene() override
Renders the scene.
QSGRenderTarget m_rt
QPaintDevice * currentPaintDevice() const
void setCurrentPaintDevice(QPaintDevice *device)
void setBackingStore(QBackingStore *backingStore)
void renderScene() final
Renders the scene.
Combined button and popup list for selecting options.
static void * context
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
long long qint64
Definition qtypes.h:60
QPainter painter(this)
[7]