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
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
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
28QT_BEGIN_NAMESPACE
29
30class QQuickCanvasContext;
31
33class QQuickPixmap;
34
35class QQuickCanvasPixmap final : public QQmlRefCounted<QQuickCanvasPixmap>
36{
37public:
38 QQuickCanvasPixmap(const QImage& image);
39 QQuickCanvasPixmap(QQuickPixmap *pixmap);
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{
56 Q_OBJECT
57
58 Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
68
69public:
74 Q_ENUM(RenderTarget)
75
81 Q_ENUM(RenderStrategy)
82
85
86 bool isAvailable() const;
87
88 QString contextType() const;
89 void setContextType(const QString &contextType);
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
103 void setRenderTarget(RenderTarget target);
104
106 void setRenderStrategy(RenderStrategy strategy);
107
109
110 QImage toImage(const QRectF& rect = QRectF()) const;
111
112 Q_INVOKABLE void getContext(QQmlV4FunctionPtr args);
113
114 Q_INVOKABLE void requestAnimationFrame(QQmlV4FunctionPtr args);
115 Q_INVOKABLE void cancelRequestAnimationFrame(QQmlV4FunctionPtr args);
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:
149 void checkAnimationCallbacks();
150 void invalidateSceneGraph();
151 void schedulePolish();
152
153protected:
155 void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override;
156 void updatePolish() override;
157 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
158 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
160 bool event(QEvent *event) override;
161private:
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
177 static QQuickContext2DRenderThread *instance(QQmlEngine *engine);
178
179private:
180 QQmlEngine *m_engine;
181 QObject *m_eventLoopQuitHack;
182 static QHash<QQmlEngine *,QQuickContext2DRenderThread*> renderThreads;
183 static QMutex renderThreadsMutex;
184};
185
186QT_END_NAMESPACE
187
188#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)
Combined button and popup list for selecting options.
static const char * mimeToType(const QString &mime)
QT_REQUIRE_CONFIG(quick_canvas)