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
4#include "qsgsoftwarepixmaprenderer_p.h"
5#include "qsgsoftwarecontext_p.h"
6
7#include <QtQuick/QSGSimpleRectNode>
8
9#include <QElapsedTimer>
10
11Q_LOGGING_CATEGORY(lcPixmapRenderer, "qt.scenegraph.softwarecontext.pixmapRenderer")
12
13QT_BEGIN_NAMESPACE
14
15QSGSoftwarePixmapRenderer::QSGSoftwarePixmapRenderer(QSGRenderContext *context)
16 : QSGAbstractSoftwareRenderer(context)
17{
18
19}
20
21QSGSoftwarePixmapRenderer::~QSGSoftwarePixmapRenderer()
22{
23
24}
25
26void QSGSoftwarePixmapRenderer::renderScene()
27{
28 QSGRenderer::renderScene();
29}
30
31void QSGSoftwarePixmapRenderer::render()
32{
33
34}
35
36void QSGSoftwarePixmapRenderer::render(QPaintDevice *target)
37{
38 QElapsedTimer renderTimer;
39
40 // Setup background item
41 setBackgroundRect(rect: m_projectionRect.normalized(), devicePixelRatio: qreal(1));
42 setBackgroundColor(clearColor());
43
44 renderTimer.start();
45 buildRenderList();
46 qint64 buildRenderListTime = renderTimer.restart();
47
48 // Optimize Renderlist
49 // Right now there is an assumption that when possible the same pixmap will
50 // be reused. So we can treat it like a backing store in that we can assume
51 // that when the pixmap is not being resized, the data can be reused. What is
52 // different though is that everything should be marked as dirty on a resize.
53 optimizeRenderList();
54 qint64 optimizeRenderListTime = renderTimer.restart();
55
56 if (!isOpaque() && target->devType() == QInternal::Pixmap) {
57 // This fill here is wasteful, but necessary because it is the only way
58 // to force a QImage based pixmap to have an alpha channel.
59 static_cast<QPixmap *>(target)->fill(fillColor: Qt::transparent);
60 }
61
62 QPainter painter(target);
63 painter.setRenderHint(hint: QPainter::Antialiasing);
64 painter.setWindow(m_projectionRect);
65 auto rc = static_cast<QSGSoftwareRenderContext *>(context());
66 QPainter *prevPainter = rc->m_activePainter;
67 rc->m_activePainter = &painter;
68
69 QRegion paintedRegion = renderNodes(painter: &painter);
70 qint64 renderTime = renderTimer.elapsed();
71
72 rc->m_activePainter = prevPainter;
73 qCDebug(lcPixmapRenderer) << "pixmapRender" << paintedRegion << buildRenderListTime << optimizeRenderListTime << renderTime;
74}
75
76void QSGSoftwarePixmapRenderer::setProjectionRect(const QRect &projectionRect)
77{
78 m_projectionRect = projectionRect;
79}
80
81QT_END_NAMESPACE
82

source code of qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaprenderer.cpp