OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGradientShader.h" | 8 #include "SkGradientShader.h" |
9 #include "SkSVGLinearGradient.h" | 9 #include "SkSVGLinearGradient.h" |
10 #include "SkSVGRenderContext.h" | 10 #include "SkSVGRenderContext.h" |
11 #include "SkSVGStop.h" | 11 #include "SkSVGStop.h" |
12 #include "SkSVGValue.h" | 12 #include "SkSVGValue.h" |
13 | 13 |
14 SkSVGLinearGradient::SkSVGLinearGradient() : INHERITED(SkSVGTag::kLinearGradient
) {} | 14 SkSVGLinearGradient::SkSVGLinearGradient() : INHERITED(SkSVGTag::kLinearGradient
) {} |
15 | 15 |
16 void SkSVGLinearGradient::setHref(const SkSVGStringType& href) { | 16 void SkSVGLinearGradient::setHref(const SkSVGStringType& href) { |
17 fHref = std::move(href); | 17 fHref = std::move(href); |
18 } | 18 } |
19 | 19 |
| 20 void SkSVGLinearGradient::setGradientTransform(const SkSVGTransformType& t) { |
| 21 fGradientTransform = t; |
| 22 } |
| 23 |
20 void SkSVGLinearGradient::setSpreadMethod(const SkSVGSpreadMethod& spread) { | 24 void SkSVGLinearGradient::setSpreadMethod(const SkSVGSpreadMethod& spread) { |
21 fSpreadMethod = spread; | 25 fSpreadMethod = spread; |
22 } | 26 } |
23 | 27 |
24 void SkSVGLinearGradient::setX1(const SkSVGLength& x1) { | 28 void SkSVGLinearGradient::setX1(const SkSVGLength& x1) { |
25 fX1 = x1; | 29 fX1 = x1; |
26 } | 30 } |
27 | 31 |
28 void SkSVGLinearGradient::setY1(const SkSVGLength& y1) { | 32 void SkSVGLinearGradient::setY1(const SkSVGLength& y1) { |
29 fY1 = y1; | 33 fY1 = y1; |
30 } | 34 } |
31 | 35 |
32 void SkSVGLinearGradient::setX2(const SkSVGLength& x2) { | 36 void SkSVGLinearGradient::setX2(const SkSVGLength& x2) { |
33 fX2 = x2; | 37 fX2 = x2; |
34 } | 38 } |
35 | 39 |
36 void SkSVGLinearGradient::setY2(const SkSVGLength& y2) { | 40 void SkSVGLinearGradient::setY2(const SkSVGLength& y2) { |
37 fY2 = y2; | 41 fY2 = y2; |
38 } | 42 } |
39 | 43 |
40 void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue&
v) { | 44 void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue&
v) { |
41 switch (attr) { | 45 switch (attr) { |
| 46 case SkSVGAttribute::kGradientTransform: |
| 47 if (const auto* t = v.as<SkSVGTransformValue>()) { |
| 48 this->setGradientTransform(*t); |
| 49 } |
| 50 break; |
42 case SkSVGAttribute::kHref: | 51 case SkSVGAttribute::kHref: |
43 if (const auto* href = v.as<SkSVGStringValue>()) { | 52 if (const auto* href = v.as<SkSVGStringValue>()) { |
44 this->setHref(*href); | 53 this->setHref(*href); |
45 } | 54 } |
46 break; | 55 break; |
47 case SkSVGAttribute::kSpreadMethod: | 56 case SkSVGAttribute::kSpreadMethod: |
48 if (const auto* spread = v.as<SkSVGSpreadMethodValue>()) { | 57 if (const auto* spread = v.as<SkSVGSpreadMethodValue>()) { |
49 this->setSpreadMethod(*spread); | 58 this->setSpreadMethod(*spread); |
50 } | 59 } |
51 break; | 60 break; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 132 |
124 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kPad)
== | 133 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kPad)
== |
125 SkShader::kClamp_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); | 134 SkShader::kClamp_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); |
126 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRepe
at) == | 135 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRepe
at) == |
127 SkShader::kRepeat_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); | 136 SkShader::kRepeat_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); |
128 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRefl
ect) == | 137 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRefl
ect) == |
129 SkShader::kMirror_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); | 138 SkShader::kMirror_TileMode, "SkSVGSpreadMethod::Type is out of
sync"); |
130 const auto tileMode = static_cast<SkShader::TileMode>(fSpreadMethod.type()); | 139 const auto tileMode = static_cast<SkShader::TileMode>(fSpreadMethod.type()); |
131 | 140 |
132 paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin
(), colors.count(), | 141 paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin
(), colors.count(), |
133 tileMode)); | 142 tileMode, 0, &fGradientTransfo
rm.value())); |
134 return true; | 143 return true; |
135 } | 144 } |
OLD | NEW |