blob: 75ffba932d056fc1f12c79ae7cee159617297502 [file] [log] [blame]
Florin Malitadf007e12017-10-09 15:14:13 -04001/*
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
15class SkMatrix;
16class SkSVGRenderContext;
17
18class SkSVGGradient : public SkSVGHiddenContainer {
19public:
20 ~SkSVGGradient() override = default;
21
22 void setHref(const SkSVGStringType&);
23 void setGradientTransform(const SkSVGTransformType&);
24 void setSpreadMethod(const SkSVGSpreadMethod&);
25
26protected:
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
37private:
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