Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickshadereffectsource_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKSHADEREFFECTSOURCE_P_H
43 #define QQUICKSHADEREFFECTSOURCE_P_H
44
45 #include "qquickitem.h"
46 #include <QtQuick/qsgtextureprovider.h>
47 #include <private/qsgadaptationlayer_p.h>
48 #include <QtQuick/private/qsgcontext_p.h>
49 #include <private/qsgdefaultimagenode_p.h>
50 #include <private/qquickitemchangelistener_p.h>
51
52 #include "qpointer.h"
53 #include "qsize.h"
54 #include "qrect.h"
55
56 #define QSG_DEBUG_FBO_OVERLAY
57
58 QT_BEGIN_HEADER
59
60 QT_BEGIN_NAMESPACE
61
62 class QSGNode;
63 class UpdatePaintNodeData;
64 class QOpenGLFramebufferObject;
65
66 class QQuickShaderEffectSourceTextureProvider;
67
68 class QQuickShaderEffectSourceNode : public QObject, public QSGDefaultImageNode
69 {
70     Q_OBJECT
71
72 public:
73     QQuickShaderEffectSourceNode();
74
75 private Q_SLOTS:
76     void markDirtyTexture();
77 };
78
79 class Q_QUICK_EXPORT QQuickShaderEffectTexture : public QSGDynamicTexture
80 {
81     Q_OBJECT
82 public:
83     QQuickShaderEffectTexture(QQuickItem *shaderSource);
84     ~QQuickShaderEffectTexture();
85
86     virtual bool updateTexture();
87
88     // The item's "paint node", not effect node.
89     QSGNode *item() const { return m_item; }
90     void setItem(QSGNode *item);
91
92     QRectF rect() const { return m_rect; }
93     void setRect(const QRectF &rect);
94
95     QSize size() const { return m_size; }
96     void setSize(const QSize &size);
97
98     void setHasMipmaps(bool mipmap);
99
100     void bind();
101
102     bool hasAlphaChannel() const;
103     bool hasMipmaps() const;
104     int textureId() const;
105     QSize textureSize() const { return m_size; }
106
107     GLenum format() const { return m_format; }
108     void setFormat(GLenum format);
109
110     bool live() const { return bool(m_live); }
111     void setLive(bool live);
112
113     bool recursive() const { return bool(m_recursive); }
114     void setRecursive(bool recursive);
115
116     void scheduleUpdate();
117
118     QImage toImage() const;
119
120 Q_SIGNALS:
121     void updateRequested();
122     void scheduledUpdateCompleted();
123
124 public Q_SLOTS:
125     void markDirtyTexture();
126
127 private:
128     void grab();
129
130     QSGNode *m_item;
131     QRectF m_rect;
132     QSize m_size;
133     GLenum m_format;
134
135     QQuickItem *m_shaderSource;
136     QSGRenderer *m_renderer;
137     QOpenGLFramebufferObject *m_fbo;
138     QOpenGLFramebufferObject *m_secondaryFbo;
139
140 #ifdef QSG_DEBUG_FBO_OVERLAY
141     QSGRectangleNode *m_debugOverlay;
142 #endif
143
144     QSGContext *m_context;
145
146     uint m_mipmap : 1;
147     uint m_live : 1;
148     uint m_recursive : 1;
149     uint m_dirtyTexture : 1;
150     uint m_multisamplingSupportChecked : 1;
151     uint m_multisampling : 1;
152     uint m_grab : 1;
153 };
154
155 class Q_QUICK_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener
156 {
157     Q_OBJECT
158     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
159     Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
160     Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
161     Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
162     Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged)
163     Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
164     Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
165     Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
166     Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
167
168     Q_ENUMS(Format WrapMode)
169 public:
170     enum WrapMode {
171         ClampToEdge,
172         RepeatHorizontally,
173         RepeatVertically,
174         Repeat
175     };
176
177     enum Format {
178         Alpha = GL_ALPHA,
179         RGB = GL_RGB,
180         RGBA = GL_RGBA
181     };
182
183     QQuickShaderEffectSource(QQuickItem *parent = 0);
184     ~QQuickShaderEffectSource();
185
186     WrapMode wrapMode() const;
187     void setWrapMode(WrapMode mode);
188
189     QQuickItem *sourceItem() const;
190     void setSourceItem(QQuickItem *item);
191
192     QRectF sourceRect() const;
193     void setSourceRect(const QRectF &rect);
194
195     QSize textureSize() const;
196     void setTextureSize(const QSize &size);
197
198     Format format() const;
199     void setFormat(Format format);
200
201     bool live() const;
202     void setLive(bool live);
203
204     bool hideSource() const;
205     void setHideSource(bool hide);
206
207     bool mipmap() const;
208     void setMipmap(bool enabled);
209
210     bool recursive() const;
211     void setRecursive(bool enabled);
212
213     bool isTextureProvider() const { return true; }
214     QSGTextureProvider *textureProvider() const;
215
216     Q_INVOKABLE void scheduleUpdate();
217
218 Q_SIGNALS:
219     void wrapModeChanged();
220     void sourceItemChanged();
221     void sourceRectChanged();
222     void textureSizeChanged();
223     void formatChanged();
224     void liveChanged();
225     void hideSourceChanged();
226     void mipmapChanged();
227     void recursiveChanged();
228
229     void scheduledUpdateCompleted();
230
231 protected:
232     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
233
234     virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect);
235     virtual void itemChange(ItemChange change, const ItemChangeData &value);
236
237 private:
238     void ensureTexture();
239
240     QQuickShaderEffectSourceTextureProvider *m_provider;
241     QQuickShaderEffectTexture *m_texture;
242     WrapMode m_wrapMode;
243     QPointer<QQuickItem> m_sourceItem;
244     QRectF m_sourceRect;
245     QSize m_textureSize;
246     Format m_format;
247     uint m_live : 1;
248     uint m_hideSource : 1;
249     uint m_mipmap : 1;
250     uint m_recursive : 1;
251     uint m_grab : 1;
252 };
253
254 QT_END_NAMESPACE
255
256 QT_END_HEADER
257
258 #endif // QQUICKSHADEREFFECTSOURCE_P_H