Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgopenvginternalimagenode.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
6
7#include <VG/openvg.h>
8
10
11QSGOpenVGInternalImageNode::QSGOpenVGInternalImageNode()
12{
13 // Set Dummy material and geometry to avoid asserts
14 setMaterial((QSGMaterial*)1);
15 setGeometry((QSGGeometry*)1);
16}
17
19{
20 if (m_subSourceRectImage != 0)
21 vgDestroyImage(m_subSourceRectImage);
22}
23
25{
26 if (!m_texture) {
27 return;
28 }
29
30 // Set Draw Mode
31 if (opacity() < 1.0) {
32 //Transparent
33 vgSetPaint(opacityPaint(), VG_FILL_PATH);
34 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
35 } else {
36 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
37 }
38
39 // Set Transform
40 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
41 vgLoadMatrix(transform().constData());
42
43 VGImage image = static_cast<VGImage>(m_texture->comparisonKey());
44 QSize textureSize = m_texture->textureSize();
45
46 if (image == VG_INVALID_HANDLE || !textureSize.isValid())
47 return;
48
49
50 // If Mirrored
51 if (m_mirror) {
52 vgTranslate(m_targetRect.width(), 0.0f);
53 vgScale(-1.0, 1.0);
54 }
55
56 if (m_smooth)
57 vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
58 else
59 vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
60
61
62 if (m_innerTargetRect != m_targetRect) {
63 // border image
64 QSGOpenVGHelpers::qDrawBorderImage(image, textureSize, m_targetRect, m_innerTargetRect, m_subSourceRect);
65 } else if (m_tileHorizontal || m_tileVertical) {
66 // Tilled Image
67
68 float sx = m_targetRect.width() / (m_subSourceRect.width() * textureSize.width());
69 float sy = m_targetRect.height() / (m_subSourceRect.height() * textureSize.height());
70 QPointF offset(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height());
71
72 QSGOpenVGHelpers::qDrawTiled(image, textureSize, m_targetRect, offset, sx, sy);
73
74 } else {
75 // Regular BLIT
76
77 QRectF sr(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height(),
78 m_subSourceRect.width() * textureSize.width(), m_subSourceRect.height() * textureSize.height());
79
80 if (m_subSourceRectImageDirty) {
81 if (m_subSourceRectImage != 0)
82 vgDestroyImage(m_subSourceRectImage);
83 m_subSourceRectImage = vgChildImage(image, sr.x(), sr.y(), sr.width(), sr.height());
84 m_subSourceRectImageDirty = false;
85 }
86
87 // If the the source rect is the same as the target rect
88 if (sr == m_targetRect) {
89 vgDrawImage(image);
90 } else {
91 // Scale
92 float scaleX = m_targetRect.width() / sr.width();
93 float scaleY = m_targetRect.height() / sr.height();
94 vgTranslate(m_targetRect.x(), m_targetRect.y());
95 vgScale(scaleX, scaleY);
96 vgDrawImage(m_subSourceRectImage);
97 }
98 }
99}
100
102{
103 if (rect == m_targetRect)
104 return;
105 m_targetRect = rect;
106 markDirty(DirtyGeometry);
107}
108
110{
111 if (rect == m_innerTargetRect)
112 return;
113 m_innerTargetRect = rect;
114 markDirty(DirtyGeometry);
115}
116
118{
119 if (rect == m_innerSourceRect)
120 return;
121 m_innerSourceRect = rect;
122 markDirty(DirtyGeometry);
123}
124
126{
127 if (rect == m_subSourceRect)
128 return;
129 m_subSourceRect = rect;
130 m_subSourceRectImageDirty = true;
131 markDirty(DirtyGeometry);
132}
133
134void QSGOpenVGInternalImageNode::setTexture(QSGTexture *texture)
135{
136 m_texture = texture;
137 m_subSourceRectImageDirty = true;
138 markDirty(DirtyMaterial);
139}
140
142{
143 if (m_mirror != mirror) {
144 m_mirror = mirror;
145 markDirty(DirtyMaterial);
146 }
147}
148
152
153void QSGOpenVGInternalImageNode::setFiltering(QSGTexture::Filtering filtering)
154{
155 bool smooth = (filtering == QSGTexture::Linear);
156 if (smooth == m_smooth)
157 return;
158
159 m_smooth = smooth;
160 markDirty(DirtyMaterial);
161}
162
163void QSGOpenVGInternalImageNode::setHorizontalWrapMode(QSGTexture::WrapMode wrapMode)
164{
165 bool tileHorizontal = (wrapMode == QSGTexture::Repeat);
166 if (tileHorizontal == m_tileHorizontal)
167 return;
168
169 m_tileHorizontal = tileHorizontal;
170 markDirty(DirtyMaterial);
171}
172
173void QSGOpenVGInternalImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode)
174{
175 bool tileVertical = (wrapMode == QSGTexture::Repeat);
176 if (tileVertical == m_tileVertical)
177 return;
178
179 m_tileVertical = (wrapMode == QSGTexture::Repeat);
180 markDirty(DirtyMaterial);
181}
182
186
188{
189 bool doDirty = false;
190 QSGLayer *t = qobject_cast<QSGLayer *>(m_texture);
191 if (t) {
192 doDirty = t->updateTexture();
193 markDirty(DirtyGeometry);
194 }
195 if (doDirty)
196 markDirty(DirtyMaterial);
197}
198
199QT_END_NAMESPACE
void setInnerTargetRect(const QRectF &rect) override
void setSubSourceRect(const QRectF &rect) override
void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) override
void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) override
void setTexture(QSGTexture *texture) override
void setMipmapFiltering(QSGTexture::Filtering filtering) override
void setFiltering(QSGTexture::Filtering filtering) override
void setTargetRect(const QRectF &rect) override
void setInnerSourceRect(const QRectF &rect) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
const QOpenVGMatrix & transform() const