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#ifndef QSGDEFAULTPAINTERNODE_P_H
41#define QSGDEFAULTPAINTERNODE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <private/qsgadaptationlayer_p.h>
55#include "qsgtexturematerial.h"
56#include "qsgplaintexture_p.h"
57
58#include <QtQuick/qquickpainteditem.h>
59
60#include <QtGui/qcolor.h>
61
62QT_BEGIN_NAMESPACE
63
64class QOpenGLFramebufferObject;
65class QOpenGLPaintDevice;
66class QSGDefaultRenderContext;
67class QSGPainterTexturePrivate;
68
69class Q_QUICK_PRIVATE_EXPORT QSGPainterTexture : public QSGPlainTexture
70{
71 Q_DECLARE_PRIVATE(QSGPainterTexture)
72public:
73 QSGPainterTexture();
74
75 void setDirtyRect(const QRect &rect) { m_dirty_rect = rect; }
76
77 void bind() override;
78
79private:
80 QRect m_dirty_rect;
81};
82
83class QSGPainterTexturePrivate : public QSGPlainTexturePrivate
84{
85 Q_DECLARE_PUBLIC(QSGPainterTexture)
86public:
87 void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
88};
89
90class Q_QUICK_PRIVATE_EXPORT QSGDefaultPainterNode : public QSGPainterNode
91{
92public:
93 QSGDefaultPainterNode(QQuickPaintedItem *item);
94 virtual ~QSGDefaultPainterNode();
95
96 void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override;
97
98 void setSize(const QSize &size) override;
99 QSize size() const { return m_size; }
100
101 void setDirty(const QRect &dirtyRect = QRect()) override;
102
103 void setOpaquePainting(bool opaque) override;
104 bool opaquePainting() const { return m_opaquePainting; }
105
106 void setLinearFiltering(bool linearFiltering) override;
107 bool linearFiltering() const { return m_linear_filtering; }
108
109 void setMipmapping(bool mipmapping) override;
110 bool mipmapping() const { return m_mipmapping; }
111
112 void setSmoothPainting(bool s) override;
113 bool smoothPainting() const { return m_smoothPainting; }
114
115 void setFillColor(const QColor &c) override;
116 QColor fillColor() const { return m_fillColor; }
117
118 void setContentsScale(qreal s) override;
119 qreal contentsScale() const { return m_contentsScale; }
120
121 void setFastFBOResizing(bool fastResizing) override;
122 bool fastFBOResizing() const { return m_fastFBOResizing; }
123
124 void setTextureSize(const QSize &textureSize) override;
125 QSize textureSize() const { return m_textureSize; }
126
127 QImage toImage() const override;
128 void update() override;
129
130 void paint();
131
132 QSGTexture *texture() const override { return m_texture; }
133
134private:
135 void updateTexture();
136 void updateGeometry();
137 void updateRenderTarget();
138 void updateFBOSize();
139
140 QSGDefaultRenderContext *m_context;
141
142 QQuickPaintedItem::RenderTarget m_preferredRenderTarget;
143 QQuickPaintedItem::RenderTarget m_actualRenderTarget;
144
145 QQuickPaintedItem *m_item;
146
147 QOpenGLFramebufferObject *m_fbo;
148 QOpenGLFramebufferObject *m_multisampledFbo;
149 QImage m_image;
150
151 QSGOpaqueTextureMaterial m_material;
152 QSGTextureMaterial m_materialO;
153 QSGGeometry m_geometry;
154 QSGPainterTexture *m_texture;
155 QOpenGLPaintDevice *m_gl_device;
156
157 QSize m_size;
158 QSize m_fboSize;
159 QSize m_textureSize;
160 QRect m_dirtyRect;
161 QColor m_fillColor;
162#if QT_VERSION >= 0x060000
163#warning "Remove m_contentsScale and assume 1 everywhere"
164#endif
165 qreal m_contentsScale;
166
167 bool m_dirtyContents : 1;
168 bool m_opaquePainting : 1;
169 bool m_linear_filtering : 1;
170 bool m_mipmapping : 1;
171 bool m_smoothPainting : 1;
172 bool m_extensionsChecked : 1;
173 bool m_multisamplingSupported : 1;
174 bool m_fastFBOResizing : 1;
175 bool m_dirtyGeometry : 1;
176 bool m_dirtyRenderTarget : 1;
177 bool m_dirtyTexture : 1;
178};
179
180QT_END_NAMESPACE
181
182#endif // QSGDEFAULTPAINTERNODE_P_H
183

source code of qtdeclarative/src/quick/scenegraph/util/qsgdefaultpainternode_p.h