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