• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkShader.h"
12 #include "modules/svg/include/SkSVGHiddenContainer.h"
13 #include "modules/svg/include/SkSVGTypes.h"
14 
15 class SkMatrix;
16 class SkSVGRenderContext;
17 class SkSVGStop;
18 
19 class SkSVGGradient : public SkSVGHiddenContainer {
20 public:
SVG_ATTR(Href,SkSVGIRI,SkSVGIRI ())21     SVG_ATTR(Href, SkSVGIRI, SkSVGIRI())
22     SVG_ATTR(GradientTransform, SkSVGTransformType, SkSVGTransformType(SkMatrix::I()))
23     SVG_ATTR(SpreadMethod, SkSVGSpreadMethod, SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad))
24     SVG_ATTR(GradientUnits,
25              SkSVGObjectBoundingBoxUnits,
26              SkSVGObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox))
27 
28 protected:
29     explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {}
30 
31     bool parseAndSetAttribute(const char*, const char*) override;
32 
33     bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final;
34 
35     virtual sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&,
36                                          const SkColor4f*, const SkScalar*, int count,
37                                          SkTileMode, const SkMatrix& localMatrix) const = 0;
38 
39 private:
40     using StopPositionArray = SkSTArray<2, SkScalar , true>;
41     using    StopColorArray = SkSTArray<2, SkColor4f, true>;
42     void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const;
43     SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const;
44 
45     using INHERITED = SkSVGHiddenContainer;
46 };
47 
48 #endif // SkSVGGradient_DEFINED
49