Use the new antialiasing property for canvas painting
[profile/ivi/qtdeclarative.git] / src / quick / items / context2d / qquickcontext2dtexture_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 QtQml 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 QQUICKCONTEXT2DTEXTURE_P_H
43 #define QQUICKCONTEXT2DTEXTURE_P_H
44
45 #include <QtQuick/qsgtexture.h>
46 #include "qquickcanvasitem_p.h"
47 #include "qquickcontext2d_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 class QQuickContext2DTile;
61 class QQuickContext2DCommandBuffer;
62
63 class QQuickContext2DTexture : public QSGDynamicTexture
64 {
65     Q_OBJECT
66 public:
67     QQuickContext2DTexture();
68     ~QQuickContext2DTexture();
69
70     virtual bool hasAlphaChannel() const {return true;}
71     virtual bool hasMipmaps() const {return false;}
72     virtual QSize textureSize() const;
73     virtual QQuickCanvasItem::RenderTarget renderTarget() const = 0;
74     static QRect tiledRect(const QRectF& window, const QSize& tileSize);
75
76     bool setCanvasSize(const QSize &size);
77     bool setTileSize(const QSize &size);
78     bool setCanvasWindow(const QRect& canvasWindow);
79     void setSmooth(bool smooth);
80     void setAntialiasing(bool antialiasing);
81     bool setDirtyRect(const QRect &dirtyRect);
82     bool canvasDestroyed();
83
84 Q_SIGNALS:
85     void textureChanged();
86
87 public Q_SLOTS:
88     void markDirtyTexture();
89     void setItem(QQuickCanvasItem* item);
90     void canvasChanged(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth, bool antialiasing);
91     void paint(QQuickContext2DCommandBuffer *ccb);
92     virtual void grabImage(const QRectF& region = QRectF()) = 0;
93
94 protected:
95     void paintWithoutTiles(QQuickContext2DCommandBuffer *ccb);
96     virtual QPaintDevice* beginPainting() {m_painting = true; return 0; }
97     virtual void endPainting() {m_painting = false;}
98     virtual QQuickContext2DTile* createTile() const = 0;
99     virtual void compositeTile(QQuickContext2DTile* tile) = 0;
100
101     void clearTiles();
102     virtual QSize adjustedTileSize(const QSize &ts);
103     QRect createTiles(const QRect& window);
104
105     QList<QQuickContext2DTile*> m_tiles;
106     QQuickContext2D* m_context;
107
108     QQuickContext2D::State m_state;
109
110     QQuickCanvasItem* m_item;
111     QSize m_canvasSize;
112     QSize m_tileSize;
113     QRect m_canvasWindow;
114
115     uint m_dirtyCanvas : 1;
116     uint m_canvasWindowChanged : 1;
117     uint m_dirtyTexture : 1;
118     uint m_smooth : 1;
119     uint m_antialiasing : 1;
120     uint m_tiledCanvas : 1;
121     uint m_painting : 1;
122 };
123
124 class QQuickContext2DFBOTexture : public QQuickContext2DTexture
125 {
126     Q_OBJECT
127
128 public:
129     QQuickContext2DFBOTexture();
130     ~QQuickContext2DFBOTexture();
131     virtual int textureId() const;
132     virtual bool updateTexture();
133     virtual QQuickContext2DTile* createTile() const;
134     virtual QPaintDevice* beginPainting();
135     virtual void endPainting();
136     QRectF normalizedTextureSubRect() const;
137     virtual QQuickCanvasItem::RenderTarget renderTarget() const;
138     virtual void compositeTile(QQuickContext2DTile* tile);
139     virtual void bind();
140     QSize adjustedTileSize(const QSize &ts);
141
142 public Q_SLOTS:
143     virtual void grabImage(const QRectF& region = QRectF());
144
145 private:
146     bool doMultisampling() const;
147     QOpenGLFramebufferObject *m_fbo;
148     QOpenGLFramebufferObject *m_multisampledFbo;
149     QMutex m_mutex;
150     QWaitCondition m_condition;
151     QSize m_fboSize;
152     QPaintDevice *m_paint_device;
153 };
154
155 class QSGPlainTexture;
156 class QQuickContext2DImageTexture : public QQuickContext2DTexture
157 {
158     Q_OBJECT
159
160 public:
161     QQuickContext2DImageTexture();
162     ~QQuickContext2DImageTexture();
163     virtual int textureId() const;
164     virtual void bind();
165
166     virtual QQuickCanvasItem::RenderTarget renderTarget() const;
167
168     virtual bool updateTexture();
169     virtual QQuickContext2DTile* createTile() const;
170     virtual QPaintDevice* beginPainting();
171     virtual void compositeTile(QQuickContext2DTile* tile);
172
173 public Q_SLOTS:
174     virtual void grabImage(const QRectF& region = QRectF());
175
176 private:
177     QSGPlainTexture *imageTexture() const;
178     QImage m_image;
179     QPainter m_painter;
180     QSGPlainTexture*  m_texture;
181 };
182
183 QT_END_HEADER
184
185 QT_END_NAMESPACE
186
187 #endif // QQUICKCONTEXT2DTEXTURE_P_H