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 | |
11 | Q_LOGGING_CATEGORY(lcPixmapRenderer, "qt.scenegraph.softwarecontext.pixmapRenderer") |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | QSGSoftwarePixmapRenderer::QSGSoftwarePixmapRenderer(QSGRenderContext *context) |
16 | : QSGAbstractSoftwareRenderer(context) |
17 | { |
18 | |
19 | } |
20 | |
21 | QSGSoftwarePixmapRenderer::~QSGSoftwarePixmapRenderer() |
22 | { |
23 | |
24 | } |
25 | |
26 | void QSGSoftwarePixmapRenderer::renderScene() |
27 | { |
28 | QSGRenderer::renderScene(); |
29 | } |
30 | |
31 | void QSGSoftwarePixmapRenderer::render() |
32 | { |
33 | |
34 | } |
35 | |
36 | void 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 | |
76 | void QSGSoftwarePixmapRenderer::setProjectionRect(const QRect &projectionRect) |
77 | { |
78 | m_projectionRect = projectionRect; |
79 | } |
80 | |
81 | QT_END_NAMESPACE |
82 |