Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgsoftwarepixmaprenderer.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// Qt-Security score:significant reason:default
4
7
8#include <QtQuick/QSGSimpleRectNode>
9
10#include <QElapsedTimer>
11
12Q_STATIC_LOGGING_CATEGORY(lcPixmapRenderer, "qt.scenegraph.softwarecontext.pixmapRenderer")
13
14QT_BEGIN_NAMESPACE
15
16QSGSoftwarePixmapRenderer::QSGSoftwarePixmapRenderer(QSGRenderContext *context)
17 : QSGAbstractSoftwareRenderer(context)
18{
19
20}
21
26
28{
29 QSGRenderer::renderScene();
30}
31
36
37void QSGSoftwarePixmapRenderer::render(QPaintDevice *target)
38{
39 QElapsedTimer renderTimer;
40
41 // Setup background item
42 setBackgroundRect(m_projectionRect.normalized(), qreal(1));
43 setBackgroundColor(clearColor());
44
45 renderTimer.start();
46 buildRenderList();
47 qint64 buildRenderListTime = renderTimer.restart();
48
49 // Optimize Renderlist
50 // Right now there is an assumption that when possible the same pixmap will
51 // be reused. So we can treat it like a backing store in that we can assume
52 // that when the pixmap is not being resized, the data can be reused. What is
53 // different though is that everything should be marked as dirty on a resize.
54 optimizeRenderList();
55 qint64 optimizeRenderListTime = renderTimer.restart();
56
57 if (!isOpaque() && target->devType() == QInternal::Pixmap) {
58 // This fill here is wasteful, but necessary because it is the only way
59 // to force a QImage based pixmap to have an alpha channel.
60 static_cast<QPixmap *>(target)->fill(Qt::transparent);
61 }
62
63 QPainter painter(target);
64 painter.setRenderHint(QPainter::Antialiasing);
65 painter.setWindow(m_projectionRect);
66 auto rc = static_cast<QSGSoftwareRenderContext *>(context());
67 QPainter *prevPainter = rc->m_activePainter;
68 rc->m_activePainter = &painter;
69
70 QRegion paintedRegion = renderNodes(&painter);
71 qint64 renderTime = renderTimer.elapsed();
72
73 rc->m_activePainter = prevPainter;
74 qCDebug(lcPixmapRenderer) << "pixmapRender" << paintedRegion << buildRenderListTime << optimizeRenderListTime << renderTime;
75}
76
77void QSGSoftwarePixmapRenderer::setProjectionRect(const QRect &projectionRect)
78{
79 m_projectionRect = projectionRect;
80}
81
82QT_END_NAMESPACE
void renderScene() final
Renders the scene.
void render(QPaintDevice *target)
void setProjectionRect(const QRect &projectionRect)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)