1 /****************************************************************************
3 ** Copyright (C) 2010 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 QSGCONTEXT2DTEXTURE_P_H
43 #define QSGCONTEXT2DTEXTURE_P_H
45 #include "qsgtexture.h"
46 #include "qsgcanvasitem_p.h"
47 #include "qsgcontext2d_p.h"
49 #include <QOpenGLContext>
50 #include <QOpenGLFramebufferObject>
52 #include <QtCore/QMutex>
53 #include <QtCore/QWaitCondition>
54 #include <QtCore/QThread>
60 QT_MODULE(Declarative)
62 class QSGContext2DTile;
63 class QSGContext2DCommandBuffer;
65 class QSGContext2DTexture : public QSGDynamicTexture
69 QSGContext2DTexture();
70 ~QSGContext2DTexture();
72 virtual bool hasAlphaChannel() const {return true;}
73 virtual bool hasMipmaps() const {return false;}
74 virtual QSize textureSize() const;
75 virtual void lock() {}
76 virtual void unlock() {}
77 virtual void wait() {}
78 virtual void wake() {}
79 bool threadRendering() const {return m_threadRendering;}
80 virtual bool supportThreadRendering() const = 0;
81 virtual bool supportDirectRendering() const = 0;
82 virtual QSGCanvasItem::RenderTarget renderTarget() const = 0;
83 virtual QImage toImage(const QRectF& region = QRectF()) = 0;
84 static QRect tiledRect(const QRectF& window, const QSize& tileSize);
86 virtual bool setCanvasSize(const QSize &size);
87 virtual bool setTileSize(const QSize &size);
88 virtual bool setCanvasWindow(const QRect& canvasWindow);
89 void setSmooth(bool smooth);
90 bool setDirtyRect(const QRect &dirtyRect);
91 virtual void canvasChanged(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth);
92 bool canvasDestroyed();
94 void textureChanged();
97 void markDirtyTexture();
98 void setItem(QSGCanvasItem* item);
102 void paintWithoutTiles();
103 virtual QPaintDevice* beginPainting() {m_painting = true; return 0; }
104 virtual void endPainting() {m_painting = false;}
105 virtual QSGContext2DTile* createTile() const = 0;
106 virtual void compositeTile(QSGContext2DTile* tile) = 0;
109 QRect createTiles(const QRect& window);
111 QList<QSGContext2DTile*> m_tiles;
112 QSGContext2D* m_context;
114 QSGContext2D::State m_state;
116 QSGCanvasItem* m_item;
119 QRect m_canvasWindow;
121 uint m_dirtyCanvas : 1;
122 uint m_dirtyTexture : 1;
123 uint m_threadRendering : 1;
125 uint m_tiledCanvas : 1;
126 uint m_doGrabImage : 1;
130 class QSGContext2DFBOTexture : public QSGContext2DTexture
135 QSGContext2DFBOTexture();
136 virtual int textureId() const;
137 virtual bool updateTexture();
138 virtual QSGContext2DTile* createTile() const;
139 virtual QImage toImage(const QRectF& region = QRectF());
140 virtual QPaintDevice* beginPainting();
141 virtual void endPainting();
142 QRectF textureSubRect() const;
143 virtual bool supportThreadRendering() const {return false;}
144 virtual bool supportDirectRendering() const {return false;}
145 virtual QSGCanvasItem::RenderTarget renderTarget() const;
146 virtual void compositeTile(QSGContext2DTile* tile);
148 virtual bool setCanvasSize(const QSize &size);
149 virtual bool setTileSize(const QSize &size);
150 virtual bool setCanvasWindow(const QRect& canvasWindow);
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 QSGContext2DImageTexture : public QSGContext2DTexture
171 QSGContext2DImageTexture(bool threadRendering = true);
172 ~QSGContext2DImageTexture();
173 virtual int textureId() const;
175 virtual bool supportThreadRendering() const {return true;}
176 virtual bool supportDirectRendering() const;
177 virtual QSGCanvasItem::RenderTarget renderTarget() const;
179 virtual void unlock();
183 virtual bool updateTexture();
184 virtual QSGContext2DTile* createTile() const;
185 virtual QImage toImage(const QRectF& region = QRectF());
186 virtual QPaintDevice* beginPainting();
187 virtual void compositeTile(QSGContext2DTile* tile);
190 void grabImage(const QRect& r);
193 QImage m_grabedImage;
195 QWaitCondition m_waitCondition;
197 QSGPlainTexture* m_texture;
204 #endif // QSGCONTEXT2DTEXTURE_P_H