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
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
5#include "qsgopenvgtexture.h"
6#include <private/qsgcontext_p.h>
7#include <qmath.h>
8
9#include <QtGui/QPainter>
10
12
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
28}
29
31{
32 delete m_texture;
33}
34
38
40{
41 if (size == m_size)
42 return;
43
44 m_size = size;
45
46 m_dirtyGeometry = true;
47}
48
50{
51 m_dirtyContents = true;
52 m_dirtyRect = dirtyRect;
54}
55
57{
58 if (opaque == m_opaquePainting)
59 return;
60
61 m_opaquePainting = opaque;
62}
63
65{
66 if (linearFiltering == m_linear_filtering)
67 return;
68
69 m_linear_filtering = linearFiltering;
70}
71
76
78{
79 if (s == m_smoothPainting)
80 return;
81
82 m_smoothPainting = s;
83}
84
86{
87 if (c == m_fillColor)
88 return;
89
90 m_fillColor = c;
92}
93
95{
96 if (s == m_contentsScale)
97 return;
98
99 m_contentsScale = s;
101}
102
106
108{
109 if (size == m_textureSize)
110 return;
111
112 m_textureSize = size;
113 m_dirtyGeometry = true;
114}
115
117{
118 return m_image;
119}
120
122{
123 if (m_dirtyGeometry) {
124 if (!m_opaquePainting)
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
138{
139 return m_texture;
140}
141
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
169{
170 QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;
171
173
174 painter.begin(&m_image);
175 if (m_smoothPainting) {
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
201 painter.fillRect(clipRect, m_fillColor);
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
217
218
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
Definition qimage.h:37
@ Format_RGB32
Definition qimage.h:46
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation.
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false.
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
@ SmoothPixmapTransform
Definition qpainter.h:54
@ Antialiasing
Definition qpainter.h:52
@ TextAntialiasing
Definition qpainter.h:53
bool end()
Ends painting.
@ CompositionMode_SourceOver
Definition qpainter.h:98
@ CompositionMode_Source
Definition qpainter.h:101
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
virtual void paint(QPainter *painter)=0
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
RenderTarget
This enum describes QQuickPaintedItem's render targets.
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
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
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setTextureSize(const QSize &size) override
QSGTexture * texture() const override
void setFillColor(const QColor &c) override
void setOpaquePainting(bool opaque) override
void setDirty(const QRect &dirtyRect) override
void setMipmapping(bool mipmapping) override
void setSmoothPainting(bool s) override
void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override
void setLinearFiltering(bool linearFiltering) override
void setContentsScale(qreal s) override
QImage toImage() const override
void setSize(const QSize &size) override
QSGOpenVGPainterNode(QQuickPaintedItem *item)
void setFastFBOResizing(bool dynamic) override
const QOpenVGMatrix & transform() const
qint64 comparisonKey() const override
Returns a key suitable for comparing textures.
\inmodule QtQuick
Definition qsgtexture.h:20
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
Combined button and popup list for selecting options.
Definition qcompare.h:63
int qFloor(T v)
Definition qmath.h:42
int qCeil(T v)
Definition qmath.h:36
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QGraphicsItem * item
QPainter painter(this)
[7]