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
qsgsoftwarepainternode.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#include <qmath.h>
7
9
12 , m_preferredRenderTarget(QQuickPaintedItem::Image)
13 , m_item(item)
14 , m_texture(nullptr)
15 , m_dirtyContents(false)
16 , m_opaquePainting(false)
17 , m_linear_filtering(false)
18 , m_mipmapping(false)
19 , m_smoothPainting(false)
20 , m_fastFBOResizing(false)
21 , m_fillColor(Qt::transparent)
22 , m_contentsScale(1.0)
23 , m_dirtyGeometry(false)
24{
27}
28
33
35{
36 if (m_preferredRenderTarget == target)
37 return;
38
39 m_preferredRenderTarget = target;
40}
41
43{
44 if (size == m_size)
45 return;
46
47 m_size = size;
48
49 m_dirtyGeometry = true;
50}
51
53{
54 m_dirtyContents = true;
55 m_dirtyRect = dirtyRect;
57}
58
60{
61 if (opaque == m_opaquePainting)
62 return;
63
64 m_opaquePainting = opaque;
65}
66
68{
69 if (linearFiltering == m_linear_filtering)
70 return;
71
72 m_linear_filtering = linearFiltering;
73}
74
76{
77 if (mipmapping == m_mipmapping)
78 return;
79
80 m_mipmapping = mipmapping;
81}
82
84{
85 if (s == m_smoothPainting)
86 return;
87
88 m_smoothPainting = s;
89}
90
92{
93 if (c == m_fillColor)
94 return;
95
96 m_fillColor = c;
98}
99
101{
102 if (s == m_contentsScale)
103 return;
104
105 m_contentsScale = s;
107}
108
110{
111 m_fastFBOResizing = dynamic;
112}
113
115{
116 return m_pixmap.toImage();
117}
118
120{
121 if (m_dirtyGeometry) {
122 m_pixmap = QPixmap(m_textureSize);
123 if (!m_opaquePainting)
124 m_pixmap.fill(Qt::transparent);
125
126 if (m_texture)
127 delete m_texture;
128 m_texture = new QSGSoftwarePixmapTexture(m_pixmap);
129 }
130
131 if (m_dirtyContents)
132 paint();
133
134 m_dirtyGeometry = false;
135 m_dirtyContents = false;
136}
137
145
147{
148 QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;
149
151
152 painter.begin(&m_pixmap);
153 if (m_smoothPainting) {
155 }
156
157 QRect clipRect;
158
159 if (m_contentsScale == 1) {
160 qreal scaleX = m_textureSize.width() / (qreal) m_size.width();
161 qreal scaleY = m_textureSize.height() / (qreal) m_size.height();
162 painter.scale(scaleX, scaleY);
163 clipRect = dirtyRect;
164 } else {
165 painter.scale(m_contentsScale, m_contentsScale);
166
167 QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
168 qFloor(dirtyRect.y()/m_contentsScale),
169 qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
170 qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));
171
172 clipRect = sclip;
173 }
174
175 if (!m_dirtyRect.isNull())
176 painter.setClipRect(clipRect);
177
179 painter.fillRect(clipRect, m_fillColor);
181
182 m_item->paint(&painter);
183 painter.end();
184
185 m_dirtyRect = QRect();
186}
187
188
190{
191 if (size == m_textureSize)
192 return;
193
194 m_textureSize = size;
195 m_dirtyGeometry = true;
196}
197
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
Definition qimage.h:37
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.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
@ 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.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
bool testRenderHint(RenderHint hint) const
Definition qpainter.h:407
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
QImage toImage() const
Converts the pixmap to a QImage.
Definition qpixmap.cpp:408
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition qpixmap.cpp:850
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 setDirty(const QRect &dirtyRect=QRect()) override
void setTextureSize(const QSize &size) override
void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override
void setOpaquePainting(bool opaque) override
void setSmoothPainting(bool s) override
void setMipmapping(bool mipmapping) override
QImage toImage() const override
void setContentsScale(qreal s) override
void setFillColor(const QColor &c) override
void setLinearFiltering(bool linearFiltering) override
void setFastFBOResizing(bool dynamic) override
QSGSoftwarePainterNode(QQuickPaintedItem *item)
void setSize(const QSize &size) override
\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
@ transparent
Definition qnamespace.h:47
int qFloor(T v)
Definition qmath.h:42
int qCeil(T v)
Definition qmath.h:36
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum target
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QGraphicsItem * item
QPainter painter(this)
[7]