• 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 "experimental/svg/model/SkSVGHiddenContainer.h"
12 #include "experimental/svg/model/SkSVGTypes.h"
13 #include "include/core/SkShader.h"
14 
15 class SkMatrix;
16 class SkSVGRenderContext;
17 
18 #ifdef USE_SYSTEM_SKIA
19 enum class SkTileMode {
20     kClamp = SkShader::kClamp_TileMode,
21     kRepeat = SkShader::kRepeat_TileMode,
22     kMirror = SkShader::kMirror_TileMode,
23     kDecal = SkShader::kDecal_TileMode,
24     kLastTileMode = kDecal,
25 };
26 #endif
27 
28 class SkSVGGradient : public SkSVGHiddenContainer {
29 public:
30     ~SkSVGGradient() override = default;
31 
32     void setHref(const SkSVGStringType&);
33     void setGradientTransform(const SkSVGTransformType&);
34     void setSpreadMethod(const SkSVGSpreadMethod&);
35 
36 protected:
SkSVGGradient(SkSVGTag t)37     explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {}
38 
39     void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
40 
41     bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final;
42 
43     virtual sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&,
44                                          const SkColor*, const SkScalar*, int count,
45                                          SkTileMode, const SkMatrix& localMatrix) const = 0;
46 
47 private:
48     using StopPositionArray = SkSTArray<2, SkScalar, true>;
49     using    StopColorArray = SkSTArray<2,  SkColor, true>;
50     void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const;
51 
52     SkSVGStringType    fHref;
53     SkSVGTransformType fGradientTransform = SkSVGTransformType(SkMatrix::I());
54     SkSVGSpreadMethod  fSpreadMethod = SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad);
55 
56     typedef SkSVGHiddenContainer INHERITED;
57 };
58 
59 #endif // SkSVGGradient_DEFINED
60