1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 QQuickCanvasItem::RenderTarget renderTarget() const = 0;
74 static QRect tiledRect(const QRectF& window, const QSize& tileSize);
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();
85 void textureChanged();
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;
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;
102 virtual QSize adjustedTileSize(const QSize &ts);
103 QRect createTiles(const QRect& window);
105 QList<QQuickContext2DTile*> m_tiles;
106 QQuickContext2D* m_context;
108 QQuickContext2D::State m_state;
110 QQuickCanvasItem* m_item;
113 QRect m_canvasWindow;
115 uint m_dirtyCanvas : 1;
116 uint m_canvasWindowChanged : 1;
117 uint m_dirtyTexture : 1;
119 uint m_antialiasing : 1;
120 uint m_tiledCanvas : 1;
124 class QQuickContext2DFBOTexture : public QQuickContext2DTexture
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);
140 QSize adjustedTileSize(const QSize &ts);
143 virtual void grabImage(const QRectF& region = QRectF());
146 bool doMultisampling() const;
147 QOpenGLFramebufferObject *m_fbo;
148 QOpenGLFramebufferObject *m_multisampledFbo;
150 QWaitCondition m_condition;
152 QPaintDevice *m_paint_device;
155 class QSGPlainTexture;
156 class QQuickContext2DImageTexture : public QQuickContext2DTexture
161 QQuickContext2DImageTexture();
162 ~QQuickContext2DImageTexture();
163 virtual int textureId() const;
166 virtual QQuickCanvasItem::RenderTarget renderTarget() const;
168 virtual bool updateTexture();
169 virtual QQuickContext2DTile* createTile() const;
170 virtual QPaintDevice* beginPainting();
171 virtual void compositeTile(QQuickContext2DTile* tile);
174 virtual void grabImage(const QRectF& region = QRectF());
177 QSGPlainTexture *imageTexture() const;
180 QSGPlainTexture* m_texture;
187 #endif // QQUICKCONTEXT2DTEXTURE_P_H