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().toAlignedRect(), 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 if (m_projectionRect.width() == 0 || m_projectionRect.height() == 0)
64 return;
65
66 QPainter painter(target);
67 painter.setRenderHint(QPainter::Antialiasing);
68 // Not setWindow(), which would round the projection rect
69 const qreal dpr = target->devicePixelRatio();
70 QTransform projection;
71 projection.scale(target->width() / dpr / m_projectionRect.width(),
72 target->height() / dpr / m_projectionRect.height());
73 projection.translate(-m_projectionRect.x(), -m_projectionRect.y());
74 painter.setWorldTransform(projection);
75 auto rc = static_cast<QSGSoftwareRenderContext *>(context());
76 QPainter *prevPainter = rc->m_activePainter;
77 rc->m_activePainter = &painter;
78
79 QRegion paintedRegion = renderNodes(&painter);
80 qint64 renderTime = renderTimer.elapsed();
81
82 rc->m_activePainter = prevPainter;
83 qCDebug(lcPixmapRenderer) << "pixmapRender" << paintedRegion << buildRenderListTime << optimizeRenderListTime << renderTime;
84}
85
86void QSGSoftwarePixmapRenderer::setProjectionRect(const QRectF &projectionRect)
87{
88 m_projectionRect = projectionRect;
89}
90
91QT_END_NAMESPACE
void renderScene() final
Renders the scene.
void render(QPaintDevice *target)
void setProjectionRect(const QRectF &projectionRect)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)