1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKSHAPESOFTWARERENDERER_P_H
5#define QQUICKSHAPESOFTWARERENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuickShapes/private/qquickshape_p_p.h>
20#include <qsgrendernode.h>
21#include <QPen>
22#include <QBrush>
23
24QT_BEGIN_NAMESPACE
25
26class QQuickShapeSoftwareRenderNode;
27
28class QQuickShapeSoftwareRenderer : public QQuickAbstractPathRenderer
29{
30public:
31 enum Dirty {
32 DirtyPath = 0x01,
33 DirtyPen = 0x02,
34 DirtyFillRule = 0x04,
35 DirtyBrush = 0x08,
36 DirtyList = 0x10
37 };
38
39 void beginSync(int totalCount, bool *countChanged) override;
40 void setPath(int index, const QQuickPath *path) override;
41 void setStrokeColor(int index, const QColor &color) override;
42 void setStrokeWidth(int index, qreal w) override;
43 void setFillColor(int index, const QColor &color) override;
44 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
45 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
46 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
47 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
48 qreal dashOffset, const QVector<qreal> &dashPattern) override;
49 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
50 void endSync(bool async) override;
51
52 void updateNode() override;
53
54 void setNode(QQuickShapeSoftwareRenderNode *node);
55
56private:
57 QQuickShapeSoftwareRenderNode *m_node = nullptr;
58 int m_accDirty = 0;
59 struct ShapePathGuiData {
60 int dirty = 0;
61 QPainterPath path;
62 QPen pen;
63 float strokeWidth;
64 QColor fillColor;
65 QBrush brush;
66 Qt::FillRule fillRule;
67 };
68 QVector<ShapePathGuiData> m_sp;
69};
70
71class QQuickShapeSoftwareRenderNode : public QSGRenderNode
72{
73public:
74 QQuickShapeSoftwareRenderNode(QQuickShape *item);
75 ~QQuickShapeSoftwareRenderNode();
76
77 void render(const RenderState *state) override;
78 void releaseResources() override;
79 StateFlags changedStates() const override;
80 RenderingFlags flags() const override;
81 QRectF rect() const override;
82
83private:
84 QQuickShape *m_item;
85
86 struct ShapePathRenderData {
87 QPainterPath path;
88 QPen pen;
89 float strokeWidth;
90 QBrush brush;
91 };
92 QVector<ShapePathRenderData> m_sp;
93 QRectF m_boundingRect;
94
95 friend class QQuickShapeSoftwareRenderer;
96};
97
98QT_END_NAMESPACE
99
100#endif // QQUICKSHAPESOFTWARERENDERER_P_H
101

source code of qtdeclarative/src/quickshapes/qquickshapesoftwarerenderer_p.h