Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgopenvgpublicnodes.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
5#include "qsgopenvghelpers.h"
6#include <VG/openvg.h>
7#include <QtGui/QPixmap>
8
10
12{
13 // Set Dummy material and geometry to avoid asserts
16
17 m_rectPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
18 VG_PATH_CAPABILITY_APPEND_TO);
19 m_rectPaint = vgCreatePaint();
20}
21
23{
24 vgDestroyPaint(m_rectPaint);
25 vgDestroyPath(m_rectPath);
26}
27
29{
30 m_rect = rect;
31 m_pathDirty = true;
33}
34
36{
37 return m_rect;
38}
39
41{
42 m_color = color;
43 m_paintDirty = true;
45}
46
48{
49 return m_color;
50}
51
53{
54 // if there transform matrix is not affine, regenerate the path
55 if (transform.isAffine())
56 m_pathDirty = true;
58
60}
61
63{
64 // Set Transform
65 if (transform().isAffine()) {
66 // Use current transform matrix
67 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
68 vgLoadMatrix(transform().constData());
69 } else {
70 // map the path's to handle the perspective matrix
71 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
72 vgLoadIdentity();
73 }
74
75 if (m_pathDirty) {
76 vgClearPath(m_rectPath, VG_PATH_CAPABILITY_APPEND_TO);
77
78 if (transform().isAffine()) {
79 // Create command list
80 static const VGubyte rectCommands[] = {
81 VG_MOVE_TO_ABS,
82 VG_HLINE_TO_REL,
83 VG_VLINE_TO_REL,
84 VG_HLINE_TO_REL,
85 VG_CLOSE_PATH
86 };
87
88 // Create command data
89 QVector<VGfloat> coordinates(5);
90 coordinates[0] = m_rect.x();
91 coordinates[1] = m_rect.y();
92 coordinates[2] = m_rect.width();
93 coordinates[3] = m_rect.height();
94 coordinates[4] = -m_rect.width();
95
96 vgAppendPathData(m_rectPath, 5, rectCommands, coordinates.constData());
97
98 } else {
99 // Pre-transform path
100 static const VGubyte rectCommands[] = {
101 VG_MOVE_TO_ABS,
102 VG_LINE_TO_ABS,
103 VG_LINE_TO_ABS,
104 VG_LINE_TO_ABS,
105 VG_CLOSE_PATH
106 };
107
108 QVector<VGfloat> coordinates(8);
109 const QPointF topLeft = transform().map(m_rect.topLeft());
110 const QPointF topRight = transform().map(m_rect.topRight());
111 const QPointF bottomLeft = transform().map(m_rect.bottomLeft());
112 const QPointF bottomRight = transform().map(m_rect.bottomRight());
113 coordinates[0] = bottomLeft.x();
114 coordinates[1] = bottomLeft.y();
115 coordinates[2] = bottomRight.x();
116 coordinates[3] = bottomRight.y();
117 coordinates[4] = topRight.x();
118 coordinates[5] = topRight.y();
119 coordinates[6] = topLeft.x();
120 coordinates[7] = topLeft.y();
121
122 vgAppendPathData(m_rectPath, 5, rectCommands, coordinates.constData());
123 }
124
125 m_pathDirty = false;
126 }
127
128 if (m_paintDirty) {
129 vgSetPaint(m_rectPaint, VG_FILL_PATH);
130 vgSetParameteri(m_rectPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
131 vgSetParameterfv(m_rectPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_color).constData());
132
133 m_paintDirty = false;
134 }
135
136 vgSetPaint(m_rectPaint, VG_FILL_PATH);
137 vgDrawPath(m_rectPath, VG_FILL_PATH);
138
139}
140
142{
143 // Set Dummy material and geometry to avoid asserts
146
147}
148
150{
151 if (m_owns)
152 delete m_texture;
153}
154
156{
157 m_rect = rect;
159}
160
162{
163 return m_rect;
164}
165
167{
168 m_sourceRect = r;
169}
170
172{
173 return m_sourceRect;
174}
175
177{
178 if (m_owns)
179 delete m_texture;
180 m_texture = texture;
182}
183
185{
186 return m_texture;
187}
188
194
196{
197 return m_filtering;
198}
199
203
208
212
217
218void QSGOpenVGImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
219{
220 if (m_transformMode == transformNode)
221 return;
222 m_transformMode = transformNode;
224}
225
226QSGImageNode::TextureCoordinatesTransformMode QSGOpenVGImageNode::textureCoordinatesTransform() const
227{
228 return m_transformMode;
229}
230
232{
233 m_owns = owns;
234}
235
237{
238 return m_owns;
239}
240
242{
243 if (!m_texture) {
244 return;
245 }
246
247 // Set Draw Mode
248 if (opacity() < 1.0) {
249 //Transparent
250 vgSetPaint(opacityPaint(), VG_FILL_PATH);
251 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
252 } else {
253 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
254 }
255
256 // Set Transform
257 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
258 vgLoadMatrix(transform().constData());
259
260 VGImage image = static_cast<VGImage>(m_texture->comparisonKey());
261
262 //Apply the TextureCoordinateTransform Flag
263 if (m_transformMode != QSGImageNode::NoTransform) {
264 float translateX = 0.0f;
265 float translateY = 0.0f;
266 float scaleX = 1.0f;
267 float scaleY = 1.0f;
268
269 if (m_transformMode & QSGImageNode::MirrorHorizontally) {
270 translateX = m_rect.width();
271 scaleX = -1.0;
272 }
273
274 if (m_transformMode & QSGImageNode::MirrorVertically) {
275 translateY = m_rect.height();
276 scaleY = -1.0;
277 }
278
279 vgTranslate(translateX, translateY);
280 vgScale(scaleX, scaleY);
281 }
282
283 // If the the source rect is the same as the target rect
284 if (m_sourceRect == m_rect) {
285 vgDrawImage(image);
286 } else {
287 // Scale
288 float scaleX = m_rect.width() / m_sourceRect.width();
289 float scaleY = m_rect.height() / m_sourceRect.height();
290 vgScale(scaleX, scaleY);
291 VGImage subImage = vgChildImage(image, m_sourceRect.x(), m_sourceRect.y(), m_sourceRect.width(), m_sourceRect.height());
292 vgDrawImage(subImage);
293 vgDestroyImage(subImage);
294 }
295
296}
297
299{
300 // Set Dummy material and geometry to avoid asserts
303
304}
305
307{
308 delete m_texture;
309}
310
312{
313 delete m_texture;
314 m_texture = texture;
316}
317
319{
320 if (m_bounds == bounds)
321 return;
322 m_bounds = bounds;
324}
325
327{
328 if (m_pixelRatio == ratio)
329 return;
330 m_pixelRatio = ratio;
332}
333
335{
336 QMarginsF margins(left, top, right, bottom);
337 if (m_margins == margins)
338 return;
339 m_margins = margins;
341}
342
347
349{
350 if (!m_texture)
351 return;
352
353 // Set Draw Mode
354 if (opacity() < 1.0) {
355 //Transparent
356 vgSetPaint(opacityPaint(), VG_FILL_PATH);
357 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
358 } else {
359 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
360 }
361
362 // Set Transform
363 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
364 vgLoadMatrix(transform().constData());
365
366 VGImage image = static_cast<VGImage>(m_texture->comparisonKey());
367
368 //Draw borderImage
369 QSGOpenVGHelpers::qDrawBorderImage(image, m_texture->textureSize(), m_bounds, m_bounds.marginsRemoved(m_margins), QRectF(0, 0, 1, 1));
370}
371
373{
374 return m_bounds;
375}
376
377
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qmargins.h:270
QPointF map(const QPointF &point) const
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:672
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:669
constexpr QRectF marginsRemoved(const QMarginsF &margins) const noexcept
Definition qrect.h:895
constexpr QPointF bottomLeft() const noexcept
Returns the position of the rectangle's bottom-left corner.
Definition qrect.h:514
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:511
constexpr QPointF bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:512
constexpr QPointF topRight() const noexcept
Returns the position of the rectangle's top-right corner.
Definition qrect.h:513
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
@ DirtyMaterial
Definition qsgnode.h:75
@ DirtyGeometry
Definition qsgnode.h:74
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setOwnsTexture(bool owns) override
Sets whether the node takes ownership of the texture to owns.
void setTexture(QSGTexture *texture) override
Sets the texture of this image node to texture.
QSGTexture::AnisotropyLevel anisotropyLevel() const override
Returns this image node's anistropy level.
bool ownsTexture() const override
void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) override
Sets this image node's anistropy level to level.
void setFiltering(QSGTexture::Filtering filtering) override
Sets the filtering to be used for this image node to filtering.
void setRect(const QRectF &rect) override
Sets the target rect of this image node to rect.
TextureCoordinatesTransformMode textureCoordinatesTransform() const override
Returns the mode used to generate texture coordinates for this node.
void setMipmapFiltering(QSGTexture::Filtering) override
Sets the mipmap filtering to be used for this image node to filtering.
QSGTexture::Filtering mipmapFiltering() const override
Returns the mipmap filtering for this image node.
QSGTexture::Filtering filtering() const override
Returns the filtering for this image node.
QRectF rect() const override
Returns the target rect of this image node.
QSGTexture * texture() const override
Returns the texture for this image node.
void setSourceRect(const QRectF &r) override
Sets the source rect of this image node to rect.
QRectF sourceRect() const override
Returns the source rect of this image node.
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode transformNode) override
Sets the method used to generate texture coordinates to mode.
void setTexture(QSGTexture *texture) override
void setBounds(const QRectF &bounds) override
void setDevicePixelRatio(qreal ratio) override
void setPadding(qreal left, qreal top, qreal right, qreal bottom) override
QRectF rect() const override
Returns the rectangle that this rect node covers.
QColor color() const override
Returns the color of this rectangle.
void setRect(const QRectF &rect) override
Sets the rectangle of this rect node to rect.
void setTransform(const QOpenVGMatrix &transform) override
void setColor(const QColor &color) override
Sets the color of this rectangle to color.
const QOpenVGMatrix & transform() const
virtual void setTransform(const QOpenVGMatrix &transform)
\inmodule QtQuick
Definition qsgtexture.h:20
virtual QSize textureSize() const =0
Returns the size of the texture in pixels.
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
Definition qsgtexture.h:34
AnisotropyLevel
Specifies the anisotropic filtering level to be used when the texture is not screen aligned.
Definition qsgtexture.h:40
virtual qint64 comparisonKey() const =0
Returns a key suitable for comparing textures.
rect
[4]
void qDrawBorderImage(VGImage image, const QSizeF &textureSize, const QRectF &targetRect, const QRectF &innerTargetRect, const QRectF &subSourceRect)
const QVector< VGfloat > qColorToVGColor(const QColor &color, float opacity)
Combined button and popup list for selecting options.
Definition image.cpp:4
GLboolean r
[2]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLuint color
[2]
GLint left
GLint GLint bottom
GLenum GLuint texture
GLuint GLenum GLenum transform
double qreal
Definition qtypes.h:187
QObject::connect nullptr