1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKCONTEXT2DCOMMANDBUFFER_P_H
43 #define QQUICKCONTEXT2DCOMMANDBUFFER_P_H
45 #include <QtCore/qmutex.h>
46 #include "qquickcontext2d_p.h"
52 class QQuickCanvasItem;
55 class QQuickContext2DCommandBuffer
58 QQuickContext2DCommandBuffer();
59 ~QQuickContext2DCommandBuffer();
63 void lockQueue() { queueLock.lock(); }
64 void unlockQueue() { queueLock.unlock(); }
65 inline int size() {return commands.size();}
66 inline bool isEmpty() const {return commands.isEmpty(); }
67 inline bool hasNext() const {return cmdIdx < commands.size(); }
68 inline QQuickContext2D::PaintCommand takeNextCommand() { return commands[cmdIdx++]; }
70 inline qreal takeGlobalAlpha() { return takeReal(); }
71 inline QPainter::CompositionMode takeGlobalCompositeOperation(){ return static_cast<QPainter::CompositionMode>(takeInt()); }
72 inline QBrush takeStrokeStyle() { return takeBrush(); }
73 inline QBrush takeFillStyle() { return takeBrush(); }
75 inline qreal takeLineWidth() { return takeReal(); }
76 inline Qt::PenCapStyle takeLineCap() { return static_cast<Qt::PenCapStyle>(takeInt());}
77 inline Qt::PenJoinStyle takeLineJoin(){ return static_cast<Qt::PenJoinStyle>(takeInt());}
78 inline qreal takeMiterLimit() { return takeReal(); }
80 inline void setGlobalAlpha( qreal alpha)
82 commands << QQuickContext2D::GlobalAlpha;
86 inline void setGlobalCompositeOperation(QPainter::CompositionMode cm)
88 commands << QQuickContext2D::GlobalCompositeOperation;
92 inline void setStrokeStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
94 commands << QQuickContext2D::StrokeStyle;
96 bools << repeatX << repeatY;
99 inline void drawImage(const QImage& image, const QRectF& sr, const QRectF& dr)
101 commands << QQuickContext2D::DrawImage;
106 inline void drawPixmap(QQmlRefPointer<QQuickCanvasPixmap> pixmap, const QRectF& sr, const QRectF& dr)
108 commands << QQuickContext2D::DrawPixmap;
113 inline qreal takeShadowOffsetX() { return takeReal(); }
114 inline qreal takeShadowOffsetY() { return takeReal(); }
115 inline qreal takeShadowBlur() { return takeReal(); }
116 inline QColor takeShadowColor() { return takeColor(); }
119 inline void updateMatrix(const QTransform& matrix)
121 commands << QQuickContext2D::UpdateMatrix;
125 inline void clearRect(const QRectF& r)
127 commands << QQuickContext2D::ClearRect;
131 inline void fillRect(const QRectF& r)
133 commands << QQuickContext2D::FillRect;
137 inline void strokeRect(const QRectF& r)
142 commands << QQuickContext2D::Stroke;
147 inline void fill(const QPainterPath& path)
149 commands << QQuickContext2D::Fill;
154 inline void stroke(const QPainterPath& path)
156 commands << QQuickContext2D::Stroke;
160 inline void clip(const QPainterPath& path)
162 commands << QQuickContext2D::Clip;
168 inline void setFillStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
170 commands << QQuickContext2D::FillStyle;
172 bools << repeatX << repeatY;
176 inline void setLineWidth( qreal w)
178 commands << QQuickContext2D::LineWidth;
182 inline void setLineCap(Qt::PenCapStyle cap)
184 commands << QQuickContext2D::LineCap;
188 inline void setLineJoin(Qt::PenJoinStyle join)
190 commands << QQuickContext2D::LineJoin;
194 inline void setMiterLimit( qreal limit)
196 commands << QQuickContext2D::MiterLimit;
200 inline void setShadowOffsetX( qreal x)
202 commands << QQuickContext2D::ShadowOffsetX;
206 inline void setShadowOffsetY( qreal y)
208 commands << QQuickContext2D::ShadowOffsetY;
212 inline void setShadowBlur( qreal b)
214 commands << QQuickContext2D::ShadowBlur;
218 inline void setShadowColor(const QColor &color)
220 commands << QQuickContext2D::ShadowColor;
224 inline QTransform takeMatrix() { return matrixes[matrixIdx++]; }
226 inline QRectF takeRect() { return rects[rectIdx++]; }
228 inline QPainterPath takePath() { return pathes[pathIdx++]; }
230 inline const QImage& takeImage() { return images[imageIdx++]; }
231 inline QQmlRefPointer<QQuickCanvasPixmap> takePixmap() { return pixmaps[pixmapIdx++]; }
233 inline int takeInt() { return ints[intIdx++]; }
234 inline bool takeBool() {return bools[boolIdx++]; }
235 inline qreal takeReal() { return reals[realIdx++]; }
236 inline QColor takeColor() { return colors[colorIdx++]; }
237 inline QBrush takeBrush() { return brushes[brushIdx++]; }
239 void replay(QPainter* painter, QQuickContext2D::State& state);
241 QPen makePen(const QQuickContext2D::State& state);
242 void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen);
254 QVector<QQuickContext2D::PaintCommand> commands;
258 QVector<qreal> reals;
259 QVector<QRectF> rects;
260 QVector<QColor> colors;
261 QVector<QTransform> matrixes;
262 QVector<QBrush> brushes;
263 QVector<QPainterPath> pathes;
264 QVector<QImage> images;
265 QVector<QQmlRefPointer<QQuickCanvasPixmap> > pixmaps;
273 #endif // QQUICKCONTEXT2DCOMMANDBUFFER_P_H