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
qquickcanvasitem_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 QQUICKCANVASITEM_P_H
5#define QQUICKCANVASITEM_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 <QtQuick/qquickitem.h>
23#include <private/qqmlrefcount_p.h>
24#include <QtCore/QThread>
25#include <QtCore/qmutex.h>
26#include <QtGui/QImage>
27
29
31
33class QQuickPixmap;
34
35class QQuickCanvasPixmap final : public QQmlRefCounted<QQuickCanvasPixmap>
36{
37public:
41
42 QImage image();
43
44 qreal width() const;
45 qreal height() const;
46 bool isValid() const;
47 QQuickPixmap *pixmap() const { return m_pixmap;}
48
49private:
50 QQuickPixmap *m_pixmap;
51 QImage m_image;
52};
53
55{
57
66 QML_NAMED_ELEMENT(Canvas)
68
69public:
75
82
85
86 bool isAvailable() const;
87
88 QString contextType() const;
90
91 QJSValue context() const;
92
93 QSizeF canvasSize() const;
94 void setCanvasSize(const QSizeF &);
95
96 QSize tileSize() const;
97 void setTileSize(const QSize &);
98
99 QRectF canvasWindow() const;
100 void setCanvasWindow(const QRectF& rect);
101
104
106 void setRenderStrategy(RenderStrategy strategy);
107
109
110 QImage toImage(const QRectF& rect = QRectF()) const;
111
113
116
118 Q_INVOKABLE void markDirty(const QRectF& dirtyRect = QRectF());
119
120 Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize = QSizeF()) const;
121 Q_INVOKABLE QString toDataURL(const QString& type = QLatin1String("image/png")) const;
122 QQmlRefPointer<QQuickCanvasPixmap> loadedPixmap(const QUrl& url, QSizeF sourceSize = QSizeF());
123
124 bool isTextureProvider() const override;
125 QSGTextureProvider *textureProvider() const override;
126
128 void paint(const QRect &region);
129 void painted();
139
140public Q_SLOTS:
141 void loadImage(const QUrl& url, QSizeF sourceSize = QSizeF());
142 void unloadImage(const QUrl& url);
143 bool isImageLoaded(const QUrl& url) const;
144 bool isImageLoading(const QUrl& url) const;
145 bool isImageError(const QUrl& url) const;
146
147private Q_SLOTS:
148 void sceneGraphInitialized();
149 void checkAnimationCallbacks();
150 void invalidateSceneGraph();
151 void schedulePolish();
152
153protected:
154 void componentComplete() override;
156 void updatePolish() override;
158 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
159 void releaseResources() override;
160 bool event(QEvent *event) override;
161private:
162 Q_DECLARE_PRIVATE(QQuickCanvasItem)
163 Q_INVOKABLE void delayedCreate();
164 bool createContext(const QString &contextType);
165 void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap());
166 static QRect tiledRect(const QRectF &window, const QSize &tileSize);
167 bool isPaintConnected();
168};
169
171{
173public:
176
178
179private:
180 QQmlEngine *m_engine;
181 QObject *m_eventLoopQuitHack;
182 static QHash<QQmlEngine *,QQuickContext2DRenderThread*> renderThreads;
183 static QMutex renderThreadsMutex;
184};
185
187
188#endif //QQUICKCANVASITEM_P_H
\inmodule QtCore
Definition qcoreevent.h:45
\inmodule QtGui
Definition qimage.h:37
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void setTileSize(const QSize &)
void renderStrategyChanged()
void renderTargetChanged()
void setCanvasWindow(const QRectF &rect)
Q_INVOKABLE QString toDataURL(const QString &type=QLatin1String("image/png")) const
\qmlmethod string QtQuick::Canvas::toDataURL(string mimeType)
bool isTextureProvider() const override
Returns true if this item is a texture provider.
void paint(const QRect &region)
bool isImageLoaded(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoaded(url image) Returns true if the image is successfully loaded...
void setCanvasSize(const QSizeF &)
void setRenderStrategy(RenderStrategy strategy)
RenderStrategy renderStrategy
QQmlRefPointer< QQuickCanvasPixmap > loadedPixmap(const QUrl &url, QSizeF sourceSize=QSizeF())
Q_INVOKABLE void requestAnimationFrame(QQmlV4FunctionPtr args)
\qmlmethod int QtQuick::Canvas::requestAnimationFrame(callback)
void updatePolish() override
This function should perform any layout as required for this item.
QQuickCanvasContext * rawContext() const
QSGTextureProvider * textureProvider() const override
Returns the texture provider for an item.
void setContextType(const QString &contextType)
bool isAvailable() const
\qmlproperty bool QtQuick::Canvas::available
Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize=QSizeF()) const
\qmlmethod bool QtQuick::Canvas::save(string filename, size imageSize = undefined)
void availableChanged()
void unloadImage(const QUrl &url)
\qmlmethod QtQuick::Canvas::unloadImage(url image)
bool isImageError(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageError(url image)
void contextTypeChanged()
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QQuickCanvasItem(QQuickItem *parent=nullptr)
\qmltype Canvas \instantiates QQuickCanvasItem \inqmlmodule QtQuick
QImage toImage(const QRectF &rect=QRectF()) const
void tileSizeChanged()
void canvasSizeChanged()
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void canvasWindowChanged()
void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override
Called when change occurs for this item.
void releaseResources() override
This function is called when an item should release graphics resources which are not already managed ...
Q_INVOKABLE void cancelRequestAnimationFrame(QQmlV4FunctionPtr args)
\qmlmethod QtQuick::Canvas::cancelRequestAnimationFrame(int handle)
Q_INVOKABLE void getContext(QQmlV4FunctionPtr args)
\qmlmethod object QtQuick::Canvas::getContext(string contextId, ... args)
bool isImageLoading(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoading(url image) Returns true if the image is currently loading.
RenderTarget renderTarget
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Q_INVOKABLE void markDirty(const QRectF &dirtyRect=QRectF())
\qmlmethod QtQuick::Canvas::markDirty(rect area)
void setRenderTarget(RenderTarget target)
void loadImage(const QUrl &url, QSizeF sourceSize=QSizeF())
\qmlsignal QtQuick::Canvas::imageLoaded()
Q_INVOKABLE void requestPaint()
\qmlmethod QtQuick::Canvas::requestPaint()
QQuickCanvasPixmap(const QImage &image)
QQuickPixmap * pixmap() const
QQuickContext2DRenderThread(QQmlEngine *eng)
static QQuickContext2DRenderThread * instance(QQmlEngine *engine)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickWindow * window() const
Returns the window in which this item is rendered.
QQuickItem * parent
\qmlproperty Item QtQuick::Item::parent This property holds the visual parent of the item.
Definition qquickitem.h:67
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:144
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
The QSGTextureProvider class encapsulates texture based entities in QML.
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
rect
[4]
Combined button and popup list for selecting options.
Definition image.cpp:4
QMap< QString, QVariant > QVariantMap
GLenum type
GLenum target
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
struct _cl_event * event
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:187
QUrl url("example.com")
[constructor-url-reference]
QJSValueList args
QJSEngine engine
[0]
\inmodule QtQuick
Definition qquickitem.h:159