Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKCANVASITEM_P_H
6#define QQUICKCANVASITEM_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20
22
23#include <QtQuick/qquickitem.h>
24#include <private/qqmlrefcount_p.h>
25#include <QtCore/QThread>
26#include <QtCore/qmutex.h>
27#include <QtCore/qvariantmap.h>
28#include <QtGui/QImage>
29
30QT_BEGIN_NAMESPACE
31
32class QQuickCanvasContext;
33
35class QQuickPixmap;
36class QQmlEngine;
37
38class QQuickCanvasPixmap final : public QQmlRefCounted<QQuickCanvasPixmap>
39{
40public:
41 QQuickCanvasPixmap(const QImage& image);
42 QQuickCanvasPixmap(QQuickPixmap *pixmap);
44
45 QImage image();
46
47 qreal width() const;
48 qreal height() const;
49 bool isValid() const;
50 QQuickPixmap *pixmap() const { return m_pixmap;}
51
52private:
53 QQuickPixmap *m_pixmap;
54 QImage m_image;
55};
56
58{
59 Q_OBJECT
60
61 Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
71
72public:
77 Q_ENUM(RenderTarget)
78
84 Q_ENUM(RenderStrategy)
85
88
89 bool isAvailable() const;
90
91 QString contextType() const;
92 void setContextType(const QString &contextType);
93
94 QJSValue context() const;
95
96 QSizeF canvasSize() const;
97 void setCanvasSize(const QSizeF &);
98
99 QSize tileSize() const;
100 void setTileSize(const QSize &);
101
102 QRectF canvasWindow() const;
103 void setCanvasWindow(const QRectF& rect);
104
106 void setRenderTarget(RenderTarget target);
107
109 void setRenderStrategy(RenderStrategy strategy);
110
112
113 QImage toImage(const QRectF& rect = QRectF()) const;
114
115 Q_INVOKABLE void getContext(QQmlV4FunctionPtr args);
116
117 Q_INVOKABLE void requestAnimationFrame(QQmlV4FunctionPtr args);
118 Q_INVOKABLE void cancelRequestAnimationFrame(QQmlV4FunctionPtr args);
119
121 Q_INVOKABLE void markDirty(const QRectF& dirtyRect = QRectF());
122
123 Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize = QSizeF()) const;
124 Q_INVOKABLE QString toDataURL(const QString& type = QLatin1String("image/png")) const;
125 QQmlRefPointer<QQuickCanvasPixmap> loadedPixmap(const QUrl& url, QSizeF sourceSize = QSizeF());
126
127 bool isTextureProvider() const override;
128 QSGTextureProvider *textureProvider() const override;
129
131 void paint(const QRect &region);
132 void painted();
142
143public Q_SLOTS:
144 void loadImage(const QUrl& url, QSizeF sourceSize = QSizeF());
145 void unloadImage(const QUrl& url);
146 bool isImageLoaded(const QUrl& url) const;
147 bool isImageLoading(const QUrl& url) const;
148 bool isImageError(const QUrl& url) const;
149
150private Q_SLOTS:
152 void checkAnimationCallbacks();
153 void invalidateSceneGraph();
154 void schedulePolish();
155
156protected:
158 void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override;
159 void updatePolish() override;
160 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
161 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
163 bool event(QEvent *event) override;
164private:
167 bool createContext(const QString &contextType);
168 void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap());
169 static QRect tiledRect(const QRectF &window, const QSize &tileSize);
170 bool isPaintConnected();
171};
172
174{
176public:
179
180 static QQuickContext2DRenderThread *instance(QQmlEngine *engine);
181
182private:
183 QQmlEngine *m_engine;
184 QObject *m_eventLoopQuitHack;
185 static QHash<QQmlEngine *,QQuickContext2DRenderThread*> renderThreads;
186 static QMutex renderThreadsMutex;
187};
188
189QT_END_NAMESPACE
190
191#endif //QQUICKCANVASITEM_P_H
QSGInternalImageNode * node
QQuickCanvasItem::RenderTarget renderTarget
QMap< int, QV4::PersistentValue > animationCallbacks
QQuickCanvasItem::RenderStrategy renderStrategy
QQuickCanvasContext * context
QQuickCanvasTextureProvider * textureProvider
void setTileSize(const QSize &)
void renderStrategyChanged()
void renderTargetChanged()
void setCanvasWindow(const QRectF &rect)
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
bool isTextureProvider() const override
Returns true if this item is a texture provider.
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)
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
RenderStrategy renderStrategy() const
\qmlproperty enumeration QtQuick::Canvas::renderStrategy Holds the current canvas rendering strategy.
QSGTextureProvider * textureProvider() const override
Returns the texture provider for an item.
RenderTarget renderTarget() const
\qmlproperty enumeration QtQuick::Canvas::renderTarget Holds the current canvas render target.
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()
QRectF canvasWindow() const
\qmlproperty rect QtQuick::Canvas::canvasWindow Holds the current canvas visible window.
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
QJSValue context() const
\qmlproperty object QtQuick::Canvas::context Holds the active drawing context.
QImage toImage(const QRectF &rect=QRectF()) const
QSize tileSize() const
\qmlproperty size QtQuick::Canvas::tileSize Holds the canvas rendering tile size.
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.
QSizeF canvasSize() const
\qmlproperty size QtQuick::Canvas::canvasSize Holds the logical canvas size that the context paints o...
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.
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)
QString contextType() const
\qmlproperty string QtQuick::Canvas::contextType The type of drawing context to use.
Q_INVOKABLE void requestPaint()
\qmlmethod QtQuick::Canvas::requestPaint()
QQuickCanvasPixmap(const QImage &image)
QQuickPixmap * pixmap() const
QQuickCanvasPixmap(QQuickPixmap *pixmap)
QSGTexture * texture() const override
Returns a pointer to the texture object.
static QQuickContext2DRenderThread * instance(QQmlEngine *engine)
static const char * mimeToType(const QString &mime)
QT_REQUIRE_CONFIG(quick_canvas)