Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / context2d / qquickcontext2dcommandbuffer_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 QQUICKCONTEXT2DCOMMANDBUFFER_P_H
43 #define QQUICKCONTEXT2DCOMMANDBUFFER_P_H
44
45 #include "qquickcontext2d_p.h"
46 #include <QtQuick/private/qdeclarativepixmapcache_p.h>
47
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickCanvasItem;
54 class QMutex;
55
56 class QQuickContext2DCommandBuffer
57 {
58 public:
59     QQuickContext2DCommandBuffer();
60     ~QQuickContext2DCommandBuffer();
61     void reset();
62     void clear();
63     inline int size() {return commands.size();}
64     inline bool isEmpty() const {return commands.isEmpty(); }
65     inline bool hasNext() const {return cmdIdx < commands.size(); }
66     inline QQuickContext2D::PaintCommand takeNextCommand() { return commands[cmdIdx++]; }
67
68     inline qreal takeGlobalAlpha() { return takeReal(); }
69     inline QPainter::CompositionMode takeGlobalCompositeOperation(){ return static_cast<QPainter::CompositionMode>(takeInt()); }
70     inline QBrush takeStrokeStyle() { return takeBrush(); }
71     inline QBrush takeFillStyle() { return takeBrush(); }
72
73     inline qreal takeLineWidth() { return takeReal(); }
74     inline Qt::PenCapStyle takeLineCap() { return static_cast<Qt::PenCapStyle>(takeInt());}
75     inline Qt::PenJoinStyle takeLineJoin(){ return static_cast<Qt::PenJoinStyle>(takeInt());}
76     inline qreal takeMiterLimit() { return takeReal(); }
77
78     inline void setGlobalAlpha( qreal alpha)
79     {
80         commands << QQuickContext2D::GlobalAlpha;
81         reals << alpha;
82     }
83
84     inline void setGlobalCompositeOperation(QPainter::CompositionMode cm)
85     {
86         commands << QQuickContext2D::GlobalCompositeOperation;
87         ints << cm;
88     }
89
90     inline void setStrokeStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
91     {
92         commands << QQuickContext2D::StrokeStyle;
93         brushes << style;
94         bools << repeatX << repeatY;
95     }
96
97     inline void drawImage(const QImage& image, qreal sx, qreal sy, qreal sw, qreal sh, qreal dx, qreal dy, qreal dw, qreal dh)
98     {
99         commands << QQuickContext2D::DrawImage;
100         images << image;
101         reals << sx << sy << sw << sh << dx << dy << dw << dh;
102     }
103
104     inline qreal takeShadowOffsetX() { return takeReal(); }
105     inline qreal takeShadowOffsetY() { return takeReal(); }
106     inline qreal takeShadowBlur() { return takeReal(); }
107     inline QColor takeShadowColor() { return takeColor(); }
108
109
110     inline void updateMatrix(const QTransform& matrix)
111     {
112         commands << QQuickContext2D::UpdateMatrix;
113         matrixes << matrix;
114     }
115
116     inline void clearRect(qreal x, qreal y, qreal w, qreal h)
117     {
118         commands << QQuickContext2D::ClearRect;
119         reals << x << y << w << h;
120     }
121
122     inline void fillRect(qreal x, qreal y, qreal w, qreal h)
123     {
124         commands << QQuickContext2D::FillRect;
125         reals << x << y << w << h;
126     }
127
128     inline void strokeRect(qreal x, qreal y, qreal w, qreal h)
129     {
130         QPainterPath p;
131         p.addRect(x, y, w, h);
132
133         commands << QQuickContext2D::Stroke;
134         pathes << p;
135     }
136
137
138     inline void fill(const QPainterPath& path)
139     {
140         commands << QQuickContext2D::Fill;
141         pathes << path;
142
143     }
144
145     inline void stroke(const QPainterPath& path)
146     {
147         commands << QQuickContext2D::Stroke;
148         pathes << path;
149     }
150
151     inline void clip(const QPainterPath& path)
152     {
153         commands << QQuickContext2D::Clip;
154         pathes << path;
155     }
156
157
158
159     inline void setFillStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
160     {
161         commands << QQuickContext2D::FillStyle;
162         brushes << style;
163         bools << repeatX << repeatY;
164     }
165
166
167     inline void setLineWidth( qreal w)
168     {
169         commands << QQuickContext2D::LineWidth;
170         reals << w;
171     }
172
173     inline void setLineCap(Qt::PenCapStyle  cap)
174     {
175         commands << QQuickContext2D::LineCap;
176         ints << cap;
177     }
178
179     inline void setLineJoin(Qt::PenJoinStyle join)
180     {
181         commands << QQuickContext2D::LineJoin;
182         ints << join;
183     }
184
185     inline void setMiterLimit( qreal limit)
186     {
187         commands << QQuickContext2D::MiterLimit;
188         reals << limit;
189     }
190
191     inline void setShadowOffsetX( qreal x)
192     {
193         commands << QQuickContext2D::ShadowOffsetX;
194         reals << x;
195     }
196
197     inline void setShadowOffsetY( qreal y)
198     {
199         commands << QQuickContext2D::ShadowOffsetY;
200         reals << y;
201     }
202
203     inline void setShadowBlur( qreal b)
204     {
205         commands << QQuickContext2D::ShadowBlur;
206         reals << b;
207     }
208
209     inline void setShadowColor(const QColor &color)
210     {
211         commands << QQuickContext2D::ShadowColor;
212         colors << color;
213     }
214
215     inline QTransform takeMatrix() { return matrixes[matrixIdx++]; }
216
217     // rects
218     inline QRectF takeRect() {
219         qreal x, y, w, h;
220         x = takeReal();
221         y = takeReal();
222         w = takeReal();
223         h = takeReal();
224         return QRectF(x, y, w ,h);
225     }
226
227     inline QPainterPath takePath() { return pathes[pathIdx++]; }
228
229     inline const QImage& takeImage() { return images[imageIdx++]; }
230
231     inline int takeInt() { return ints[intIdx++]; }
232     inline bool takeBool() {return bools[boolIdx++]; }
233     inline qreal takeReal() { return reals[realIdx++]; }
234     inline QColor takeColor() { return colors[colorIdx++]; }
235     inline QBrush takeBrush() { return brushes[brushIdx++]; }
236
237     void replay(QPainter* painter, QQuickContext2D::State& state);
238 private:
239     QPen makePen(const QQuickContext2D::State& state);
240     void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen);
241     int cmdIdx;
242     int intIdx;
243     int boolIdx;
244     int realIdx;
245     int colorIdx;
246     int matrixIdx;
247     int brushIdx;
248     int pathIdx;
249     int imageIdx;
250     QVector<QQuickContext2D::PaintCommand> commands;
251
252     QVector<int> ints;
253     QVector<bool> bools;
254     QVector<qreal> reals;
255     QVector<QColor> colors;
256     QVector<QTransform> matrixes;
257     QVector<QBrush> brushes;
258     QVector<QPainterPath> pathes;
259     QVector<QImage> images;
260 };
261
262 QT_END_HEADER
263
264 QT_END_NAMESPACE
265
266 #endif // QQUICKCONTEXT2DCOMMANDBUFFER_P_H