Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: experimental/svg/model/SkSVGLinearGradient.cpp

Issue 2337203002: [SVGDom] Linear gradient 'spreadMethod' support (Closed)
Patch Set: review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/model/SkSVGLinearGradient.h ('k') | experimental/svg/model/SkSVGTypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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::setSpreadMethod(const SkSVGSpreadMethod& spread) {
21 fSpreadMethod = spread;
22 }
23
20 void SkSVGLinearGradient::setX1(const SkSVGLength& x1) { 24 void SkSVGLinearGradient::setX1(const SkSVGLength& x1) {
21 fX1 = x1; 25 fX1 = x1;
22 } 26 }
23 27
24 void SkSVGLinearGradient::setY1(const SkSVGLength& y1) { 28 void SkSVGLinearGradient::setY1(const SkSVGLength& y1) {
25 fY1 = y1; 29 fY1 = y1;
26 } 30 }
27 31
28 void SkSVGLinearGradient::setX2(const SkSVGLength& x2) { 32 void SkSVGLinearGradient::setX2(const SkSVGLength& x2) {
29 fX2 = x2; 33 fX2 = x2;
30 } 34 }
31 35
32 void SkSVGLinearGradient::setY2(const SkSVGLength& y2) { 36 void SkSVGLinearGradient::setY2(const SkSVGLength& y2) {
33 fY2 = y2; 37 fY2 = y2;
34 } 38 }
35 39
36 void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 40 void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
37 switch (attr) { 41 switch (attr) {
38 case SkSVGAttribute::kHref: 42 case SkSVGAttribute::kHref:
39 if (const auto* href = v.as<SkSVGStringValue>()) { 43 if (const auto* href = v.as<SkSVGStringValue>()) {
40 this->setHref(*href); 44 this->setHref(*href);
41 } 45 }
42 break; 46 break;
47 case SkSVGAttribute::kSpreadMethod:
48 if (const auto* spread = v.as<SkSVGSpreadMethodValue>()) {
49 this->setSpreadMethod(*spread);
50 }
51 break;
43 case SkSVGAttribute::kX1: 52 case SkSVGAttribute::kX1:
44 if (const auto* x1 = v.as<SkSVGLengthValue>()) { 53 if (const auto* x1 = v.as<SkSVGLengthValue>()) {
45 this->setX1(*x1); 54 this->setX1(*x1);
46 } 55 }
47 break; 56 break;
48 case SkSVGAttribute::kY1: 57 case SkSVGAttribute::kY1:
49 if (const auto* y1 = v.as<SkSVGLengthValue>()) { 58 if (const auto* y1 = v.as<SkSVGLengthValue>()) {
50 this->setY1(*y1); 59 this->setY1(*y1);
51 } 60 }
52 break; 61 break;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 112
104 const SkPoint pts[2] = { {x1, y1}, {x2, y2}}; 113 const SkPoint pts[2] = { {x1, y1}, {x2, y2}};
105 SkSTArray<2, SkColor , true> colors; 114 SkSTArray<2, SkColor , true> colors;
106 SkSTArray<2, SkScalar, true> pos; 115 SkSTArray<2, SkScalar, true> pos;
107 116
108 this->collectColorStops(ctx, &pos, &colors); 117 this->collectColorStops(ctx, &pos, &colors);
109 // TODO: 118 // TODO:
110 // * stop (lazy?) sorting 119 // * stop (lazy?) sorting
111 // * href loop detection 120 // * href loop detection
112 // * href attribute inheritance (not just color stops) 121 // * href attribute inheritance (not just color stops)
113 // * spreadMethods support
114 // * objectBoundingBox units support 122 // * objectBoundingBox units support
115 123
124 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kPad) ==
125 SkShader::kClamp_TileMode, "SkSVGSpreadMethod::Type is out of sync");
126 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRepe at) ==
127 SkShader::kRepeat_TileMode, "SkSVGSpreadMethod::Type is out of sync");
128 static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRefl ect) ==
129 SkShader::kMirror_TileMode, "SkSVGSpreadMethod::Type is out of sync");
130 const auto tileMode = static_cast<SkShader::TileMode>(fSpreadMethod.type());
131
116 paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin (), colors.count(), 132 paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin (), colors.count(),
117 SkShader::kClamp_TileMode)); 133 tileMode));
118 return true; 134 return true;
119 } 135 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGLinearGradient.h ('k') | experimental/svg/model/SkSVGTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698