fix declarative to work after broken refactor
[profile/ivi/qtdeclarative.git] / src / declarative / items / context2d / qsgcontext2dtexture_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSGCONTEXT2DTEXTURE_P_H
43 #define QSGCONTEXT2DTEXTURE_P_H
44
45 #include "qsgtexture.h"
46 #include "qsgcanvasitem_p.h"
47 #include "qsgcontext2d_p.h"
48
49 #include <QOpenGLContext>
50 #include <QOpenGLFramebufferObject>
51
52 #include <QtCore/QMutex>
53 #include <QtCore/QWaitCondition>
54 #include <QtCore/QThread>
55
56 QT_BEGIN_HEADER
57
58 QT_BEGIN_NAMESPACE
59
60 QT_MODULE(Declarative)
61
62 class QSGContext2DTile;
63 class QSGContext2DCommandBuffer;
64
65 class QSGContext2DTexture : public QSGDynamicTexture
66 {
67     Q_OBJECT
68 public:
69     QSGContext2DTexture();
70     ~QSGContext2DTexture();
71
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);
85
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();
93 Q_SIGNALS:
94     void textureChanged();
95
96 public Q_SLOTS:
97     void markDirtyTexture();
98     void setItem(QSGCanvasItem* item);
99     void paint();
100
101 protected:
102     void paintWithoutTiles();
103     virtual QPaintDevice* beginPainting() {m_painting = true;}
104     virtual void endPainting() {m_painting = false;}
105     virtual QSGContext2DTile* createTile() const = 0;
106     virtual void compositeTile(QSGContext2DTile* tile) = 0;
107
108     void clearTiles();
109     QRect createTiles(const QRect& window);
110
111     QList<QSGContext2DTile*> m_tiles;
112     QSGContext2D* m_context;
113
114     QSGContext2D::State m_state;
115
116     QSGCanvasItem* m_item;
117     QSize m_canvasSize;
118     QSize m_tileSize;
119     QRect m_canvasWindow;
120
121     uint m_dirtyCanvas : 1;
122     uint m_dirtyTexture : 1;
123     uint m_threadRendering : 1;
124     uint m_smooth : 1;
125     uint m_tiledCanvas : 1;
126     uint m_doGrabImage : 1;
127     uint m_painting : 1;
128 };
129
130 class QSGContext2DFBOTexture : public QSGContext2DTexture
131 {
132     Q_OBJECT
133
134 public:
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     QRectF textureSubRect() const;
142     virtual bool supportThreadRendering() const {return false;}
143     virtual bool supportDirectRendering() const {return false;}
144     virtual QSGCanvasItem::RenderTarget renderTarget() const;
145     virtual void compositeTile(QSGContext2DTile* tile);
146     virtual void bind();
147     virtual bool setCanvasSize(const QSize &size);
148     virtual bool setTileSize(const QSize &size);
149     virtual bool setCanvasWindow(const QRect& canvasWindow);
150 private Q_SLOTS:
151     void grabImage();
152
153 private:
154     QImage m_grabedImage;
155     QOpenGLFramebufferObject *m_fbo;
156     QMutex m_mutex;
157     QWaitCondition m_condition;
158     QSize m_fboSize;
159     QPaintDevice *m_paint_device;
160 };
161
162 class QSGPlainTexture;
163 class QSGContext2DImageTexture : public QSGContext2DTexture
164 {
165     Q_OBJECT
166
167 public:
168     QSGContext2DImageTexture(bool threadRendering = true);
169     ~QSGContext2DImageTexture();
170     virtual int textureId() const;
171     virtual void bind();
172     virtual bool supportThreadRendering() const {return true;}
173     virtual bool supportDirectRendering() const;
174     virtual QSGCanvasItem::RenderTarget renderTarget() const;
175     virtual void lock();
176     virtual void unlock();
177     virtual void wait();
178     virtual void wake();
179
180     virtual bool updateTexture();
181     virtual QSGContext2DTile* createTile() const;
182     virtual QImage toImage(const QRectF& region = QRectF());
183     virtual QPaintDevice* beginPainting();
184     virtual void compositeTile(QSGContext2DTile* tile);
185
186 private Q_SLOTS:
187     void grabImage(const QRect& r);
188 private:
189     QImage m_image;
190     QImage m_grabedImage;
191     QMutex m_mutex;
192     QWaitCondition m_waitCondition;
193     QPainter m_painter;
194     QSGPlainTexture*  m_texture;
195 };
196
197 QT_END_HEADER
198
199 QT_END_NAMESPACE
200
201 #endif // QSGCONTEXT2DTEXTURE_P_H