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
qsgsoftwarepublicnodes.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
8#include <private/qsgplaintexture_p.h>
9
11
18
23
25 : m_texture(nullptr),
26 m_owns(false),
27 m_filtering(QSGTexture::None),
28 m_transformMode(NoTransform),
29 m_cachedMirroredPixmapIsDirty(false)
30{
33}
34
36{
37 if (m_owns)
38 delete m_texture;
39}
40
42{
43 if (m_owns)
44 delete m_texture;
45
46 m_texture = texture; markDirty(DirtyMaterial);
47 m_cachedMirroredPixmapIsDirty = true;
48}
49
50void QSGSoftwareImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
51{
52 if (m_transformMode == transformNode)
53 return;
54
55 m_transformMode = transformNode;
56 m_cachedMirroredPixmapIsDirty = true;
57
59}
60
62{
63 if (m_cachedMirroredPixmapIsDirty)
64 updateCachedMirroredPixmap();
65
67 // Disable antialiased clipping. It causes transformed tiles to have gaps.
69
70 if (!m_cachedPixmap.isNull()) {
71 painter->drawPixmap(m_rect, m_cachedPixmap, m_sourceRect);
72 } else if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
73 const QPixmap &pm = pt->pixmap();
74 painter->drawPixmap(m_rect, pm, m_sourceRect);
75 } else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
76 const QPixmap &pm = pt->pixmap();
77 painter->drawPixmap(m_rect, pm, m_sourceRect);
78 } else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
79 const QImage &im = pt->image();
80 painter->drawImage(m_rect, im, m_sourceRect);
81 }
82}
83
84void QSGSoftwareImageNode::updateCachedMirroredPixmap()
85{
86 if (m_transformMode == NoTransform) {
87 m_cachedPixmap = QPixmap();
88 } else {
89 if (QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture *>(m_texture)) {
90 QTransform mirrorTransform;
91 if (m_transformMode.testFlag(MirrorVertically))
92 mirrorTransform = mirrorTransform.scale(1, -1);
93 if (m_transformMode.testFlag(MirrorHorizontally))
94 mirrorTransform = mirrorTransform.scale(-1, 1);
95 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
96 } else if (QSGSoftwareLayer *pt = qobject_cast<QSGSoftwareLayer *>(m_texture)) {
97 QTransform mirrorTransform;
98 if (m_transformMode.testFlag(MirrorVertically))
99 mirrorTransform = mirrorTransform.scale(1, -1);
100 if (m_transformMode.testFlag(MirrorHorizontally))
101 mirrorTransform = mirrorTransform.scale(-1, 1);
102 m_cachedPixmap = pt->pixmap().transformed(mirrorTransform);
103 } else if (QSGPlainTexture *pt = qobject_cast<QSGPlainTexture *>(m_texture)) {
104 m_cachedPixmap = QPixmap::fromImage(pt->image().mirrored(m_transformMode.testFlag(MirrorHorizontally), m_transformMode.testFlag(MirrorVertically)));
105 } else {
106 m_cachedPixmap = QPixmap();
107 }
108 }
109
110 m_cachedMirroredPixmapIsDirty = false;
111}
112
118
120{
121 QSGSoftwarePixmapTexture *pt = qobject_cast<QSGSoftwarePixmapTexture*>(texture);
122 if (!pt) {
123 qWarning() << "Image used with invalid texture format.";
124 } else {
125 m_pixmap = pt->pixmap();
127 }
128 delete texture;
129}
130
132{
133 if (m_bounds == bounds)
134 return;
135
136 m_bounds = bounds;
138}
139
141{
142 if (m_pixelRatio == ratio)
143 return;
144
145 m_pixelRatio = ratio;
147}
148
150{
152 if (m_margins == margins)
153 return;
154
155 m_margins = QMargins(qRound(left), qRound(top), qRound(right), qRound(bottom));
157}
158
162
164{
165 // Disable antialiased clipping. It causes transformed tiles to have gaps.
167
168 if (m_margins.isNull())
169 painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height()));
170 else
171 QSGSoftwareHelpers::qDrawBorderPixmap(painter, m_bounds.toRect(), m_margins, m_pixmap, QRect(0, 0, m_pixmap.width(), m_pixmap.height()),
172 m_margins, Qt::StretchTile, QSGSoftwareHelpers::QDrawBorderPixmap::DrawingHints{});
173}
174
176{
177 return m_bounds;
178}
179
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qmargins.h:24
constexpr bool isNull() const noexcept
Returns true if all margins are is 0; otherwise returns false.
Definition qmargins.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
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
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.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
int height() const
Returns the height of the pixmap.
Definition qpixmap.cpp:480
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition qpixmap.cpp:456
int width() const
Returns the width of the pixmap.
Definition qpixmap.cpp:468
QPixmap transformed(const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:859
\inmodule QtCore\reentrant
Definition qrect.h:30
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 paint(QPainter *painter)
void setTexture(QSGTexture *texture) override
Sets the texture of this image node to texture.
QSGTexture * texture() const override
Returns the texture for this image node.
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode transformNode) override
Sets the method used to generate texture coordinates to mode.
void setDevicePixelRatio(qreal ratio) override
void setTexture(QSGTexture *texture) override
void setPadding(qreal left, qreal top, qreal right, qreal bottom) override
void setBounds(const QRectF &bounds) override
void paint(QPainter *painter)
\inmodule QtQuick
Definition qsgtexture.h:20
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMarginsIn, const QPixmap &pixmap, const QRect &sourceRect, const QMargins &sourceMarginsIn, const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
Combined button and popup list for selecting options.
@ StretchTile
Definition qnamespace.h:134
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
@ None
Definition qhash.cpp:531
#define qWarning
Definition qlogging.h:166
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLenum GLuint texture
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QPainter painter(this)
[7]