#include <QtQuick/qquickitem.h>
#include <private/qv8engine_p.h>
+#include <QtCore/QThread>
+#include <QtGui/QImage>
QT_BEGIN_HEADER
class QQuickCanvasContext;
class QQuickCanvasItemPrivate;
-class Q_QUICK_EXPORT QQuickCanvasItem : public QQuickItem
+class QSGTexture;
+class QQuickPixmap;
+
+class QQuickCanvasPixmap : public QQmlRefCount
+{
+public:
+ QQuickCanvasPixmap(const QImage& image, QQuickWindow *window);
+ QQuickCanvasPixmap(QQuickPixmap *pixmap, QQuickWindow *window);
+ ~QQuickCanvasPixmap();
+
+ QSGTexture *texture();
+ QImage image();
+
+ qreal width() const;
+ qreal height() const;
+ bool isValid() const;
+ QQuickPixmap *pixmap() const { return m_pixmap;}
+
+private:
+ QQuickPixmap *m_pixmap;
+ QImage m_image;
+ QSGTexture *m_texture;
+ QQuickWindow *m_window;
+};
+
+class QQuickCanvasItem : public QQuickItem
{
Q_OBJECT
Q_ENUMS(RenderTarget)
Q_ENUMS(RenderStrategy)
- Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged);
+ Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
Q_PROPERTY(QString contextType READ contextType WRITE setContextType NOTIFY contextTypeChanged)
- Q_PROPERTY(QQmlV8Handle context READ context NOTIFY contextChanged);
+ Q_PROPERTY(QQmlV8Handle context READ context NOTIFY contextChanged)
Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged)
Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged)
Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged)
RenderStrategy renderStrategy() const;
void setRenderStrategy(RenderStrategy strategy);
- QQuickCanvasContext* rawContext() const;
+ QQuickCanvasContext *rawContext() const;
QImage toImage(const QRectF& rect = QRectF()) const;
Q_INVOKABLE bool save(const QString &filename) const;
Q_INVOKABLE QString toDataURL(const QString& type = QLatin1String("image/png")) const;
- QImage loadedImage(const QUrl& url);
+ QQmlRefPointer<QQuickCanvasPixmap> loadedPixmap(const QUrl& url);
Q_SIGNALS:
void paint(const QRect ®ion);
private:
Q_DECLARE_PRIVATE(QQuickCanvasItem)
-
Q_INVOKABLE void delayedCreate();
bool createContext(const QString &contextType);
void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap());
QRect tiledRect(const QRectF &window, const QSize &tileSize);
+ bool isPaintConnected();
+};
+
+class QQuickContext2DRenderThread : public QThread
+{
+ Q_OBJECT
+public:
+ QQuickContext2DRenderThread(QQmlEngine *eng);
+ ~QQuickContext2DRenderThread();
+
+ static QQuickContext2DRenderThread *instance(QQmlEngine *engine);
+
+private:
+ QQmlEngine *m_engine;
+ QObject *m_eventLoopQuitHack;
+ static QHash<QQmlEngine *,QQuickContext2DRenderThread*> renderThreads;
+ static QMutex renderThreadsMutex;
};
QT_END_NAMESPACE