From 1dcfa8aa2ae6460f26d9843c197532024447e43b Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Mon, 4 Jun 2012 16:34:17 +1000 Subject: Introduce QQuickCanvasPixmap 1. QQuickPixmap now only store textures instead of QImage data, however context2d still need to access the QImage in some places, so cache the loaded images to avoid the expensive GL readback operations. 2. Use texture directly if the render target is FBO. Change-Id: I6228011e5698fa00f2e3420a3a4a305995b8a238 Reviewed-by: Yunqiao Yin --- src/quick/items/context2d/qquickcanvasitem_p.h | 37 +++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/quick/items/context2d/qquickcanvasitem_p.h') diff --git a/src/quick/items/context2d/qquickcanvasitem_p.h b/src/quick/items/context2d/qquickcanvasitem_p.h index 8e7b992387..090c763e46 100644 --- a/src/quick/items/context2d/qquickcanvasitem_p.h +++ b/src/quick/items/context2d/qquickcanvasitem_p.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -53,15 +54,40 @@ QT_BEGIN_NAMESPACE class QQuickCanvasContext; class QQuickCanvasItemPrivate; +class QSGTexture; +class QQuickPixmap; + +class QQuickCanvasPixmap : public QQmlRefCount +{ +public: + QQuickCanvasPixmap(const QImage& image, QQuickCanvas *canvas); + QQuickCanvasPixmap(QQuickPixmap *pixmap, QQuickCanvas *canvas); + ~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; + QQuickCanvas *m_canvas; +}; + 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) @@ -105,7 +131,7 @@ public: RenderStrategy renderStrategy() const; void setRenderStrategy(RenderStrategy strategy); - QQuickCanvasContext* rawContext() const; + QQuickCanvasContext *rawContext() const; QImage toImage(const QRectF& rect = QRectF()) const; @@ -119,7 +145,7 @@ public: 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 loadedPixmap(const QUrl& url); Q_SIGNALS: void paint(const QRect ®ion); @@ -154,7 +180,6 @@ protected: private: Q_DECLARE_PRIVATE(QQuickCanvasItem) - Q_INVOKABLE void delayedCreate(); bool createContext(const QString &contextType); void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap()); @@ -184,4 +209,4 @@ QML_DECLARE_TYPE(QQuickCanvasItem) QT_END_HEADER -#endif //QQUICKCANVASITEM_P_H +#endif //QQUICKCANVASITEM_P_H \ No newline at end of file -- cgit v1.2.3