1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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 virtual bool setCanvasSize(const QSize &size);
85 virtual bool setTileSize(const QSize &size);
86 virtual 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 QRect createTiles(const QRect& window);
109 QList<QQuickContext2DTile*> m_tiles;
110 QQuickContext2D* m_context;
112 QQuickContext2D::State m_state;
114 QQuickCanvasItem* m_item;
117 QRect m_canvasWindow;
119 uint m_dirtyCanvas : 1;
120 uint m_dirtyTexture : 1;
121 uint m_threadRendering : 1;
123 uint m_tiledCanvas : 1;
124 uint m_doGrabImage : 1;
128 class QQuickContext2DFBOTexture : public QQuickContext2DTexture
133 QQuickContext2DFBOTexture();
134 ~QQuickContext2DFBOTexture();
135 virtual int textureId() const;
136 virtual bool updateTexture();
137 virtual QQuickContext2DTile* createTile() const;
138 virtual QImage toImage(const QRectF& region = QRectF());
139 virtual QPaintDevice* beginPainting();
140 virtual void endPainting();
141 QRectF textureSubRect() const;
142 virtual bool supportThreadRendering() const {return false;}
143 virtual bool supportDirectRendering() const {return false;}
144 virtual QQuickCanvasItem::RenderTarget renderTarget() const;
145 virtual void compositeTile(QQuickContext2DTile* tile);
147 virtual bool setCanvasSize(const QSize &size);
148 virtual bool setTileSize(const QSize &size);
149 virtual bool setCanvasWindow(const QRect& canvasWindow);
154 bool doMultisampling() const;
155 QImage m_grabedImage;
156 QOpenGLFramebufferObject *m_fbo;
157 QOpenGLFramebufferObject *m_multisampledFbo;
159 QWaitCondition m_condition;
161 QPaintDevice *m_paint_device;
164 class QSGPlainTexture;
165 class QQuickContext2DImageTexture : public QQuickContext2DTexture
170 QQuickContext2DImageTexture(bool threadRendering = true);
171 ~QQuickContext2DImageTexture();
172 virtual int textureId() const;
174 virtual bool supportThreadRendering() const {return true;}
175 virtual bool supportDirectRendering() const;
176 virtual QQuickCanvasItem::RenderTarget renderTarget() const;
178 virtual void unlock();
182 virtual bool updateTexture();
183 virtual QQuickContext2DTile* createTile() const;
184 virtual QImage toImage(const QRectF& region = QRectF());
185 virtual QPaintDevice* beginPainting();
186 virtual void compositeTile(QQuickContext2DTile* tile);
189 void grabImage(const QRect& r);
192 QImage m_grabedImage;
194 QWaitCondition m_waitCondition;
196 QSGPlainTexture* m_texture;
203 #endif // QQUICKCONTEXT2DTEXTURE_P_H