/src/skia/modules/svg/include/SkSVGGradient.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2017 Google Inc. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #ifndef SkSVGGradient_DEFINED |
9 | | #define SkSVGGradient_DEFINED |
10 | | |
11 | | #include "include/core/SkColor.h" |
12 | | #include "include/core/SkMatrix.h" |
13 | | #include "include/core/SkRefCnt.h" |
14 | | #include "include/core/SkScalar.h" |
15 | | #include "include/private/base/SkAPI.h" |
16 | | #include "include/private/base/SkTArray.h" |
17 | | #include "modules/svg/include/SkSVGHiddenContainer.h" |
18 | | #include "modules/svg/include/SkSVGNode.h" |
19 | | #include "modules/svg/include/SkSVGTypes.h" |
20 | | |
21 | | class SkPaint; |
22 | | class SkSVGRenderContext; |
23 | | class SkSVGStop; |
24 | | class SkShader; |
25 | | enum class SkTileMode; |
26 | | |
27 | | class SK_API SkSVGGradient : public SkSVGHiddenContainer { |
28 | | public: |
29 | | SVG_ATTR(Href, SkSVGIRI, SkSVGIRI()) |
30 | | SVG_ATTR(GradientTransform, SkSVGTransformType, SkSVGTransformType(SkMatrix::I())) |
31 | | SVG_ATTR(SpreadMethod, SkSVGSpreadMethod, SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad)) |
32 | | SVG_ATTR(GradientUnits, |
33 | | SkSVGObjectBoundingBoxUnits, |
34 | | SkSVGObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox)) |
35 | | |
36 | | protected: |
37 | 74 | explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {} |
38 | | |
39 | | bool parseAndSetAttribute(const char*, const char*) override; |
40 | | |
41 | | bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final; |
42 | | |
43 | | virtual sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&, |
44 | | const SkColor4f*, const SkScalar*, int count, |
45 | | SkTileMode, const SkMatrix& localMatrix) const = 0; |
46 | | |
47 | | private: |
48 | | using StopPositionArray = skia_private::STArray<2, SkScalar , true>; |
49 | | using StopColorArray = skia_private::STArray<2, SkColor4f, true>; |
50 | | void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const; |
51 | | SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const; |
52 | | |
53 | | using INHERITED = SkSVGHiddenContainer; |
54 | | }; |
55 | | |
56 | | #endif // SkSVGGradient_DEFINED |