~saviq/ubuntu/saucy/qtdeclarative-opensource-src/add-qtquick-delegate-range

« back to all changes in this revision

Viewing changes to src/quick/items/context2d/qquickcontext2dtexture_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
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