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
qquickcontext2d_p.h
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
4#ifndef QQUICKCONTEXT2D_P_H
5#define QQUICKCONTEXT2D_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_canvas);
21
22#include <QtQml/qqml.h>
23#include <QtQml/qqmlcomponent.h>
24#include <private/qquickcanvascontext_p.h>
25#include <private/qquickcanvasitem_p.h>
26#include <QtGui/qpainter.h>
27#include <QtGui/qpainterpath.h>
28#include <QtGui/qoffscreensurface.h>
29#include <QtCore/qstring.h>
30#include <QtCore/qstack.h>
31#include <QtCore/qqueue.h>
32#include <QtCore/QWaitCondition>
33
34#include <private/qv4persistent_p.h>
35
36//#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
37
38#ifdef QQUICKCONTEXT2D_DEBUG
39#include <QElapsedTimer>
40#endif
41
43
44namespace QV4 {
45 struct ExecutionEngine;
46}
47
50class QQuickPixmap;
51class QSGTexture;
52class QSurface;
53
55{
57
58public:
59 Q_DISABLE_COPY(QQuickContext2D)
60
96
97 struct State {
105 , invertibleCTM(true)
106 , clip(false)
107 , fillRule(Qt::WindingFill)
108 , globalAlpha(1.0)
109 , lineWidth(1)
110 , lineCap(Qt::FlatCap)
111 , lineJoin(Qt::MiterJoin)
112 , lineDashOffset(0)
113 , miterLimit(10)
114 , shadowOffsetX(0)
115 , shadowOffsetY(0)
116 , shadowBlur(0)
117 , shadowColor(qRgba(0, 0, 0, 0))
118 , globalCompositeOperation(QPainter::CompositionMode_SourceOver)
119 , font(QFont(QLatin1String("sans-serif")))
122 {
123 font.setPixelSize(10);
124 }
125
135 bool clip:1;
141 QVector<qreal> lineDash;
152 };
153
154 QQuickContext2D(QObject *parent = nullptr);
156
157 QStringList contextNames() const override;
158 void init(QQuickCanvasItem *canvasItem, const QVariantMap &args) override;
159 void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth, bool antialiasing) override;
160 void flush() override;
161 void sync();
162 QThread *thread() const { return m_thread; }
164 QImage toImage(const QRectF& bounds) override;
165
166 QV4::ReturnedValue v4value() const override;
167 QV4::ExecutionEngine *v4Engine() const override;
168 void setV4Engine(QV4::ExecutionEngine *eng) override;
169
170 QQuickCanvasItem* canvas() const { return m_canvas; }
172
173 bool bufferValid() const { return m_buffer != nullptr; }
174 void popState();
175 void pushState();
176 void reset();
177
178 void fill();
179 void clip();
180 void stroke();
181 void fillRect(qreal x, qreal y, qreal w, qreal h);
182 void strokeRect(qreal x, qreal y, qreal w, qreal h);
183 void clearRect(qreal x, qreal y, qreal w, qreal h);
184 void drawText(const QString& text, qreal x, qreal y, bool fill);
185
186 //Transform APIs
187 void scale(qreal x, qreal y);
188 void rotate(qreal angle);
189 void shear(qreal h, qreal v);
190 void translate(qreal x, qreal y);
191 void transform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f);
193
194 // Path APIs
195 void beginPath();
196 void closePath();
197 void moveTo(qreal x, qreal y);
198 void lineTo(qreal x, qreal y);
199 void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y);
200 void bezierCurveTo(qreal cp1x, qreal cp1y,
201 qreal cp2x, qreal cp2y, qreal x, qreal y);
202 void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius);
203 void rect(qreal x, qreal y, qreal w, qreal h);
204 void roundedRect(qreal x, qreal y,qreal w, qreal h, qreal xr, qreal yr);
205 void ellipse(qreal x, qreal y,qreal w, qreal h);
206 void text(const QString& str, qreal x, qreal y);
207 void arc(qreal x, qreal y, qreal radius,
208 qreal startAngle, qreal endAngle,
209 bool anticlockwise);
210 void addArcTo(const QPointF& p1, const QPointF& p2, qreal radius);
211
212 bool isPointInPath(qreal x, qreal y) const;
213
215 QQmlRefPointer<QQuickCanvasPixmap> createPixmap(const QUrl& url, QSizeF sourceSize = QSizeF());
216
217 QSurface *surface() const { return m_surface.data(); }
218 void setGrabbedImage(const QImage& grab);
219
221 QStack<QQuickContext2D::State> m_stateStack;
229 QScopedPointer<QOffscreenSurface> m_surface;
234 QQueue<QQuickContext2DCommandBuffer*> m_bufferQueue;
237 bool m_grabbed:1;
238
239 static QMutex mutex;
240};
241
243
244#endif // QQUICKCONTEXT2D_P_H
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\reentrant
Definition qfont.h:22
void setPixelSize(int)
Sets the font size to pixelSize pixels, with a maxiumum size of an unsigned 16-bit integer.
Definition qfont.cpp:1049
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:97
\inmodule QtCore\reentrant
Definition qpoint.h:217
QPainterPath createTextGlyphs(qreal x, qreal y, const QString &text)
bool isPointInPath(qreal x, qreal y) const
void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius)
QV4::PersistentValue m_v4path
void translate(qreal x, qreal y)
QQuickContext2DTexture * texture() const
QV4::ExecutionEngine * v4Engine() const override
void strokeRect(qreal x, qreal y, qreal w, qreal h)
QQueue< QQuickContext2DCommandBuffer * > m_bufferQueue
QV4::ExecutionEngine * m_v4engine
void flush() override
QV4::PersistentValue m_fillStyle
QV4::PersistentValue m_strokeStyle
QQuickCanvasItem * canvas() const
QV4::ReturnedValue v4value() const override
void setTransform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f)
QImage toImage(const QRectF &bounds) override
QSurface * surface() const
void arc(qreal x, qreal y, qreal radius, qreal startAngle, qreal endAngle, bool anticlockwise)
QScopedPointer< QOffscreenSurface > m_surface
QStringList contextNames() const override
void setGrabbedImage(const QImage &grab)
void lineTo(qreal x, qreal y)
QQuickContext2D(QObject *parent=nullptr)
void init(QQuickCanvasItem *canvasItem, const QVariantMap &args) override
QQuickContext2DCommandBuffer * buffer() const
void bezierCurveTo(qreal cp1x, qreal cp1y, qreal cp2x, qreal cp2y, qreal x, qreal y)
void prepare(const QSize &canvasSize, const QSize &tileSize, const QRect &canvasWindow, const QRect &dirtyRect, bool smooth, bool antialiasing) override
QQuickContext2DTexture * m_texture
QQuickCanvasItem * m_canvas
void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y)
void rotate(qreal angle)
QQuickCanvasItem::RenderStrategy m_renderStrategy
void drawText(const QString &text, qreal x, qreal y, bool fill)
void roundedRect(qreal x, qreal y, qreal w, qreal h, qreal xr, qreal yr)
static QMutex mutex
QQuickCanvasItem::RenderTarget m_renderTarget
QQmlRefPointer< QQuickCanvasPixmap > createPixmap(const QUrl &url, QSizeF sourceSize=QSizeF())
void setV4Engine(QV4::ExecutionEngine *eng) override
bool bufferValid() const
void shear(qreal h, qreal v)
QQuickContext2DCommandBuffer * m_buffer
void clearRect(qreal x, qreal y, qreal w, qreal h)
void addArcTo(const QPointF &p1, const QPointF &p2, qreal radius)
QV4::PersistentValue m_v4value
QThread * thread() const
void moveTo(qreal x, qreal y)
void fillRect(qreal x, qreal y, qreal w, qreal h)
QStack< QQuickContext2D::State > m_stateStack
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtQuick
Definition qsgtexture.h:20
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtGui
Definition qsurface.h:21
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
\inmodule QtCore
Definition qurl.h:94
QString str
[2]
QPixmap p2
QPixmap p1
[0]
QString text
rect
[4]
Combined button and popup list for selecting options.
quint64 ReturnedValue
Definition qcompare.h:63
PenJoinStyle
PenCapStyle
static QT_BEGIN_NAMESPACE const int tileSize
Definition qmemrotate.cpp:9
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLfloat GLfloat f
GLfloat angle
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum GLenum transform
const GLubyte * c
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
GLenum GLenum GLenum GLenum GLenum scale
constexpr QRgb qRgba(int r, int g, int b, int a)
Definition qrgb.h:33
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
double qreal
Definition qtypes.h:187
QUrl url("example.com")
[constructor-url-reference]
QGraphicsEllipseItem * ellipse
QJSValueList args
QGraphicsSvgItem * black
QPainter::CompositionMode globalCompositeOperation
QQuickContext2D::TextAlignType textAlign
QQuickContext2D::TextBaseLineType textBaseline