1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qsgsoftwarepixmaprenderer_p.h"
41#include "qsgsoftwarecontext_p.h"
42
43#include <QtQuick/QSGSimpleRectNode>
44
45#include <QElapsedTimer>
46
47Q_LOGGING_CATEGORY(lcPixmapRenderer, "qt.scenegraph.softwarecontext.pixmapRenderer")
48
49QT_BEGIN_NAMESPACE
50
51QSGSoftwarePixmapRenderer::QSGSoftwarePixmapRenderer(QSGRenderContext *context)
52 : QSGAbstractSoftwareRenderer(context)
53{
54
55}
56
57QSGSoftwarePixmapRenderer::~QSGSoftwarePixmapRenderer()
58{
59
60}
61
62void QSGSoftwarePixmapRenderer::renderScene(uint)
63{
64 class B : public QSGBindable
65 {
66 public:
67 void bind() const override { }
68 } bindable;
69 QSGRenderer::renderScene(bindable);
70}
71
72void QSGSoftwarePixmapRenderer::render()
73{
74
75}
76
77void QSGSoftwarePixmapRenderer::render(QPaintDevice *target)
78{
79 QElapsedTimer renderTimer;
80
81 // Setup background item
82 setBackgroundRect(rect: m_projectionRect.normalized(), devicePixelRatio: qreal(1));
83 setBackgroundColor(clearColor());
84
85 renderTimer.start();
86 buildRenderList();
87 qint64 buildRenderListTime = renderTimer.restart();
88
89 // Optimize Renderlist
90 // Right now there is an assumption that when possible the same pixmap will
91 // be reused. So we can treat it like a backing store in that we can assume
92 // that when the pixmap is not being resized, the data can be reused. What is
93 // different though is that everything should be marked as dirty on a resize.
94 optimizeRenderList();
95 qint64 optimizeRenderListTime = renderTimer.restart();
96
97 if (!isOpaque() && target->devType() == QInternal::Pixmap) {
98 // This fill here is wasteful, but necessary because it is the only way
99 // to force a QImage based pixmap to have an alpha channel.
100 static_cast<QPixmap *>(target)->fill(fillColor: Qt::transparent);
101 }
102
103 QPainter painter(target);
104 painter.setRenderHint(hint: QPainter::Antialiasing);
105 painter.setWindow(m_projectionRect);
106 auto rc = static_cast<QSGSoftwareRenderContext *>(context());
107 QPainter *prevPainter = rc->m_activePainter;
108 rc->m_activePainter = &painter;
109
110 QRegion paintedRegion = renderNodes(painter: &painter);
111 qint64 renderTime = renderTimer.elapsed();
112
113 rc->m_activePainter = prevPainter;
114 qCDebug(lcPixmapRenderer) << "pixmapRender" << paintedRegion << buildRenderListTime << optimizeRenderListTime << renderTime;
115}
116
117void QSGSoftwarePixmapRenderer::setProjectionRect(const QRect &projectionRect)
118{
119 m_projectionRect = projectionRect;
120}
121
122QT_END_NAMESPACE
123

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