Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsgopenvgpainternode.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
4
#
include
"qsgopenvgpainternode.h"
5
#
include
"qsgopenvgtexture.h"
6
#
include
<
private
/
qsgcontext_p
.
h
>
7
#
include
<
qmath
.
h
>
8
9
#
include
<
QtGui
/
QPainter
>
10
11
QT_BEGIN_NAMESPACE
12
13
QSGOpenVGPainterNode
::
QSGOpenVGPainterNode
(
QQuickPaintedItem
*
item
)
14
: m_preferredRenderTarget(QQuickPaintedItem::Image)
15
, m_item(item)
16
, m_texture(
nullptr
)
17
, m_dirtyContents(
false
)
18
, m_opaquePainting(
false
)
19
, m_linear_filtering(
false
)
20
, m_smoothPainting(
false
)
21
, m_fillColor(Qt::transparent)
22
, m_contentsScale(1.0)
23
, m_dirtyGeometry(
false
)
24
{
25
// Set Dummy material and geometry to avoid asserts
26
setMaterial((QSGMaterial*)1);
27
setGeometry((QSGGeometry*)1);
28
}
29
30
QSGOpenVGPainterNode
::~
QSGOpenVGPainterNode
()
31
{
32
delete
m_texture;
33
}
34
35
void
QSGOpenVGPainterNode
::
setPreferredRenderTarget
(
QQuickPaintedItem
::
RenderTarget
)
36
{
37
}
38
39
void
QSGOpenVGPainterNode
::
setSize
(
const
QSize &size)
40
{
41
if
(size == m_size)
42
return
;
43
44
m_size = size;
45
46
m_dirtyGeometry =
true
;
47
}
48
49
void
QSGOpenVGPainterNode
::
setDirty
(
const
QRect &dirtyRect)
50
{
51
m_dirtyContents =
true
;
52
m_dirtyRect = dirtyRect;
53
markDirty(DirtyMaterial);
54
}
55
56
void
QSGOpenVGPainterNode
::
setOpaquePainting
(
bool
opaque)
57
{
58
if
(opaque == m_opaquePainting)
59
return
;
60
61
m_opaquePainting = opaque;
62
}
63
64
void
QSGOpenVGPainterNode
::
setLinearFiltering
(
bool
linearFiltering)
65
{
66
if
(linearFiltering == m_linear_filtering)
67
return
;
68
69
m_linear_filtering = linearFiltering;
70
}
71
72
void
QSGOpenVGPainterNode
::
setMipmapping
(
bool
)
73
{
74
75
}
76
77
void
QSGOpenVGPainterNode
::
setSmoothPainting
(
bool
s)
78
{
79
if
(s == m_smoothPainting)
80
return
;
81
82
m_smoothPainting = s;
83
}
84
85
void
QSGOpenVGPainterNode
::
setFillColor
(
const
QColor &c)
86
{
87
if
(c == m_fillColor)
88
return
;
89
90
m_fillColor = c;
91
markDirty(DirtyMaterial);
92
}
93
94
void
QSGOpenVGPainterNode
::
setContentsScale
(qreal s)
95
{
96
if
(s == m_contentsScale)
97
return
;
98
99
m_contentsScale = s;
100
markDirty(DirtyMaterial);
101
}
102
103
void
QSGOpenVGPainterNode
::
setFastFBOResizing
(
bool
)
104
{
105
}
106
107
void
QSGOpenVGPainterNode
::
setTextureSize
(
const
QSize &size)
108
{
109
if
(size == m_textureSize)
110
return
;
111
112
m_textureSize = size;
113
m_dirtyGeometry =
true
;
114
}
115
116
QImage
QSGOpenVGPainterNode
::
toImage
()
const
117
{
118
return
m_image;
119
}
120
121
void
QSGOpenVGPainterNode
::
update
()
122
{
123
if
(m_dirtyGeometry) {
124
if
(!m_opaquePainting)
125
m_image = QImage(m_size, QImage::Format_ARGB32_Premultiplied);
126
else
127
m_image = QImage(m_size, QImage::Format_RGB32);
128
}
129
130
if
(m_dirtyContents)
131
paint
(
)
;
132
133
m_dirtyGeometry =
false
;
134
m_dirtyContents =
false
;
135
}
136
137
QSGTexture
*
QSGOpenVGPainterNode
::
texture
()
const
138
{
139
return
m_texture;
140
}
141
142
void
QSGOpenVGPainterNode
::
render
()
143
{
144
if
(!m_texture)
145
return
;
146
147
// Set Draw Mode
148
if
(
opacity
() < 1.0) {
149
//Transparent
150
vgSetPaint(opacityPaint(), VG_FILL_PATH);
151
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
152
}
else
{
153
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
154
}
155
156
if
(m_linear_filtering)
157
vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
158
else
159
vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
160
161
// Set Transform
162
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
163
vgLoadMatrix(
transform
().constData());
164
165
vgDrawImage(
static_cast
<VGImage>(m_texture->comparisonKey()));
166
}
167
168
void
QSGOpenVGPainterNode
::
paint
()
169
{
170
QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;
171
172
QPainter painter;
173
174
painter.begin(&m_image);
175
if
(m_smoothPainting) {
176
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
177
}
178
179
QRect clipRect;
180
181
if
(m_contentsScale == 1) {
182
qreal scaleX = m_textureSize.width() / (qreal) m_size.width();
183
qreal scaleY = m_textureSize.height() / (qreal) m_size.height();
184
painter.scale(scaleX, scaleY);
185
clipRect = dirtyRect;
186
}
else
{
187
painter.scale(m_contentsScale, m_contentsScale);
188
189
QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
190
qFloor(dirtyRect.y()/m_contentsScale),
191
qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
192
qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));
193
194
clipRect = sclip;
195
}
196
197
if
(!m_dirtyRect.isNull())
198
painter.setClipRect(clipRect);
199
200
painter.setCompositionMode(QPainter::CompositionMode_Source);
201
painter.fillRect(clipRect, m_fillColor);
202
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
203
204
m_item->paint(&painter);
205
painter.end();
206
207
m_dirtyRect = QRect();
208
209
if
(m_texture)
210
delete
m_texture;
211
212
uint textureFlags = m_opaquePainting ? 0 : QSGRenderContext::CreateTexture_Alpha;
213
m_texture =
new
QSGOpenVGTexture(m_image, textureFlags);
214
}
215
216
QT_END_NAMESPACE
QQuickPaintedItem
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
Definition
qquickpainteditem.h:17
QSGOpenVGPainterNode
Definition
qsgopenvgpainternode.h:16
QSGOpenVGPainterNode::setTextureSize
void setTextureSize(const QSize &size) override
Definition
qsgopenvgpainternode.cpp:107
QSGOpenVGPainterNode::texture
QSGTexture * texture() const override
Definition
qsgopenvgpainternode.cpp:137
QSGOpenVGPainterNode::setFillColor
void setFillColor(const QColor &c) override
Definition
qsgopenvgpainternode.cpp:85
QSGOpenVGPainterNode::paint
void paint()
Definition
qsgopenvgpainternode.cpp:168
QSGOpenVGPainterNode::setOpaquePainting
void setOpaquePainting(bool opaque) override
Definition
qsgopenvgpainternode.cpp:56
QSGOpenVGPainterNode::setDirty
void setDirty(const QRect &dirtyRect) override
Definition
qsgopenvgpainternode.cpp:49
QSGOpenVGPainterNode::~QSGOpenVGPainterNode
~QSGOpenVGPainterNode()
Definition
qsgopenvgpainternode.cpp:30
QSGOpenVGPainterNode::setMipmapping
void setMipmapping(bool mipmapping) override
Definition
qsgopenvgpainternode.cpp:72
QSGOpenVGPainterNode::setSmoothPainting
void setSmoothPainting(bool s) override
Definition
qsgopenvgpainternode.cpp:77
QSGOpenVGPainterNode::render
void render() override
Definition
qsgopenvgpainternode.cpp:142
QSGOpenVGPainterNode::setPreferredRenderTarget
void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override
Definition
qsgopenvgpainternode.cpp:35
QSGOpenVGPainterNode::setLinearFiltering
void setLinearFiltering(bool linearFiltering) override
Definition
qsgopenvgpainternode.cpp:64
QSGOpenVGPainterNode::setContentsScale
void setContentsScale(qreal s) override
Definition
qsgopenvgpainternode.cpp:94
QSGOpenVGPainterNode::toImage
QImage toImage() const override
Definition
qsgopenvgpainternode.cpp:116
QSGOpenVGPainterNode::setSize
void setSize(const QSize &size) override
Definition
qsgopenvgpainternode.cpp:39
QSGOpenVGPainterNode::update
void update() override
Definition
qsgopenvgpainternode.cpp:121
QSGOpenVGPainterNode::setFastFBOResizing
void setFastFBOResizing(bool dynamic) override
Definition
qsgopenvgpainternode.cpp:103
QSGOpenVGRenderable::opacity
float opacity() const
Definition
qsgopenvgrenderable.cpp:31
QSGOpenVGRenderable::transform
const QOpenVGMatrix & transform() const
Definition
qsgopenvgrenderable.cpp:46
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
plugins
scenegraph
openvg
qsgopenvgpainternode.cpp
Generated on
for Qt by
1.18.0