1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKCONTEXT2DTEXTURE_P_H
43 #define QQUICKCONTEXT2DTEXTURE_P_H
45 #include <QtQuick/qsgtexture.h>
46 #include "qquickcanvasitem_p.h"
47 #include "qquickcontext2d_p.h"
49 #include <QOpenGLContext>
50 #include <QOpenGLFramebufferObject>
52 #include <QtCore/QMutex>
53 #include <QtCore/QWaitCondition>
54 #include <QtCore/QThread>
60 class QQuickContext2DTile;
61 class QQuickContext2DCommandBuffer;
63 class QQuickContext2DTexture : public QSGDynamicTexture
67 QQuickContext2DTexture();
68 ~QQuickContext2DTexture();
70 virtual bool hasAlphaChannel() const {return true;}
71 virtual bool hasMipmaps() const {return false;}
72 virtual QSize textureSize() const;
73 virtual void lock() {}
74 virtual void unlock() {}
75 virtual void wait() {}
76 virtual void wake() {}
77 bool threadRendering() const {return m_threadRendering;}
78 virtual bool supportThreadRendering() const = 0;
79 virtual bool supportDirectRendering() const = 0;
80 virtual QQuickCanvasItem::RenderTarget renderTarget() const = 0;
81 virtual QImage toImage(const QRectF& region = QRectF()) = 0;
82 static QRect tiledRect(const QRectF& window, const QSize& tileSize);
84 bool setCanvasSize(const QSize &size);
85 bool setTileSize(const QSize &size);
86 bool setCanvasWindow(const QRect& canvasWindow);
87 void setSmooth(bool smooth);
88 bool setDirtyRect(const QRect &dirtyRect);
89 virtual void canvasChanged(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth);
90 bool canvasDestroyed();
92 void textureChanged();
95 void markDirtyTexture();
96 void setItem(QQuickCanvasItem* item);
100 void paintWithoutTiles();
101 virtual QPaintDevice* beginPainting() {m_painting = true; return 0; }
102 virtual void endPainting() {m_painting = false;}
103 virtual QQuickContext2DTile* createTile() const = 0;
104 virtual void compositeTile(QQuickContext2DTile* tile) = 0;
107 virtual QSize adjustedTileSize(const QSize &ts);
108 QRect createTiles(const QRect& window);
110 QList<QQuickContext2DTile*> m_tiles;
111 QQuickContext2D* m_context;
113 QQuickContext2D::State m_state;
115 QQuickCanvasItem* m_item;
118 QRect m_canvasWindow;
120 uint m_dirtyCanvas : 1;
121 uint m_canvasWindowChanged : 1;
122 uint m_dirtyTexture : 1;
123 uint m_threadRendering : 1;
125 uint m_tiledCanvas : 1;
126 uint m_doGrabImage : 1;
130 class QQuickContext2DFBOTexture : public QQuickContext2DTexture
135 QQuickContext2DFBOTexture();
136 ~QQuickContext2DFBOTexture();
137 virtual int textureId() const;
138 virtual bool updateTexture();
139 virtual QQuickContext2DTile* createTile() const;
140 virtual QImage toImage(const QRectF& region = QRectF());
141 virtual QPaintDevice* beginPainting();
142 virtual void endPainting();
143 QRectF normalizedTextureSubRect() const;
144 virtual bool supportThreadRendering() const {return false;}
145 virtual bool supportDirectRendering() const {return false;}
146 virtual QQuickCanvasItem::RenderTarget renderTarget() const;
147 virtual void compositeTile(QQuickContext2DTile* tile);
149 QSize adjustedTileSize(const QSize &ts);
155 bool doMultisampling() const;
156 QImage m_grabedImage;
157 QOpenGLFramebufferObject *m_fbo;
158 QOpenGLFramebufferObject *m_multisampledFbo;
160 QWaitCondition m_condition;
162 QPaintDevice *m_paint_device;
165 class QSGPlainTexture;
166 class QQuickContext2DImageTexture : public QQuickContext2DTexture
171 QQuickContext2DImageTexture(bool threadRendering = true);
172 ~QQuickContext2DImageTexture();
173 virtual int textureId() const;
175 virtual bool supportThreadRendering() const {return true;}
176 virtual bool supportDirectRendering() const;
177 virtual QQuickCanvasItem::RenderTarget renderTarget() const;
179 virtual void unlock();
183 virtual bool updateTexture();
184 virtual QQuickContext2DTile* createTile() const;
185 virtual QImage toImage(const QRectF& region = QRectF());
186 virtual QPaintDevice* beginPainting();
187 virtual void compositeTile(QQuickContext2DTile* tile);
190 void grabImage(const QRect& r);
193 QImage m_grabedImage;
195 QWaitCondition m_waitCondition;
197 QSGPlainTexture* m_texture;
204 #endif // QQUICKCONTEXT2DTEXTURE_P_H