1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKCONTEXT2DCOMMANDBUFFER_P_H
43 #define QQUICKCONTEXT2DCOMMANDBUFFER_P_H
45 #include "qquickcontext2d_p.h"
46 #include <QtQuick/private/qdeclarativepixmapcache_p.h>
53 class QQuickCanvasItem;
56 class QQuickContext2DCommandBuffer
59 QQuickContext2DCommandBuffer();
60 ~QQuickContext2DCommandBuffer();
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++]; }
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(); }
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(); }
78 inline void setGlobalAlpha( qreal alpha)
80 commands << QQuickContext2D::GlobalAlpha;
84 inline void setGlobalCompositeOperation(QPainter::CompositionMode cm)
86 commands << QQuickContext2D::GlobalCompositeOperation;
90 inline void setStrokeStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
92 commands << QQuickContext2D::StrokeStyle;
94 bools << repeatX << repeatY;
97 inline void drawImage(const QImage& image, qreal sx, qreal sy, qreal sw, qreal sh, qreal dx, qreal dy, qreal dw, qreal dh)
99 commands << QQuickContext2D::DrawImage;
101 reals << sx << sy << sw << sh << dx << dy << dw << dh;
104 inline qreal takeShadowOffsetX() { return takeReal(); }
105 inline qreal takeShadowOffsetY() { return takeReal(); }
106 inline qreal takeShadowBlur() { return takeReal(); }
107 inline QColor takeShadowColor() { return takeColor(); }
110 inline void updateMatrix(const QTransform& matrix)
112 commands << QQuickContext2D::UpdateMatrix;
116 inline void clearRect(qreal x, qreal y, qreal w, qreal h)
118 commands << QQuickContext2D::ClearRect;
119 reals << x << y << w << h;
122 inline void fillRect(qreal x, qreal y, qreal w, qreal h)
124 commands << QQuickContext2D::FillRect;
125 reals << x << y << w << h;
128 inline void strokeRect(qreal x, qreal y, qreal w, qreal h)
131 p.addRect(x, y, w, h);
133 commands << QQuickContext2D::Stroke;
138 inline void fill(const QPainterPath& path)
140 commands << QQuickContext2D::Fill;
145 inline void stroke(const QPainterPath& path)
147 commands << QQuickContext2D::Stroke;
151 inline void clip(const QPainterPath& path)
153 commands << QQuickContext2D::Clip;
159 inline void setFillStyle(const QBrush &style, bool repeatX = false, bool repeatY = false)
161 commands << QQuickContext2D::FillStyle;
163 bools << repeatX << repeatY;
167 inline void setLineWidth( qreal w)
169 commands << QQuickContext2D::LineWidth;
173 inline void setLineCap(Qt::PenCapStyle cap)
175 commands << QQuickContext2D::LineCap;
179 inline void setLineJoin(Qt::PenJoinStyle join)
181 commands << QQuickContext2D::LineJoin;
185 inline void setMiterLimit( qreal limit)
187 commands << QQuickContext2D::MiterLimit;
191 inline void setShadowOffsetX( qreal x)
193 commands << QQuickContext2D::ShadowOffsetX;
197 inline void setShadowOffsetY( qreal y)
199 commands << QQuickContext2D::ShadowOffsetY;
203 inline void setShadowBlur( qreal b)
205 commands << QQuickContext2D::ShadowBlur;
209 inline void setShadowColor(const QColor &color)
211 commands << QQuickContext2D::ShadowColor;
215 inline QTransform takeMatrix() { return matrixes[matrixIdx++]; }
218 inline QRectF takeRect() {
224 return QRectF(x, y, w ,h);
227 inline QPainterPath takePath() { return pathes[pathIdx++]; }
229 inline const QImage& takeImage() { return images[imageIdx++]; }
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++]; }
237 void replay(QPainter* painter, QQuickContext2D::State& state);
239 QPen makePen(const QQuickContext2D::State& state);
240 void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen);
250 QVector<QQuickContext2D::PaintCommand> commands;
254 QVector<qreal> reals;
255 QVector<QColor> colors;
256 QVector<QTransform> matrixes;
257 QVector<QBrush> brushes;
258 QVector<QPainterPath> pathes;
259 QVector<QImage> images;
266 #endif // QQUICKCONTEXT2DCOMMANDBUFFER_P_H