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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkSVGAttribute.h" | 9 #include "SkSVGAttribute.h" |
10 #include "SkSVGRenderContext.h" | 10 #include "SkSVGRenderContext.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 case SkSVGPaint::Type::kCurrentColor: | 106 case SkSVGPaint::Type::kCurrentColor: |
107 SkDebugf("unimplemented 'currentColor' paint type"); | 107 SkDebugf("unimplemented 'currentColor' paint type"); |
108 // Fall through. | 108 // Fall through. |
109 case SkSVGPaint::Type::kNone: | 109 case SkSVGPaint::Type::kNone: |
110 // Fall through. | 110 // Fall through. |
111 case SkSVGPaint::Type::kInherit: | 111 case SkSVGPaint::Type::kInherit: |
112 break; | 112 break; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
| 116 inline uint8_t opacity_to_alpha(SkScalar o) { |
| 117 return SkTo<uint8_t>(SkScalarRoundToInt(o * 255)); |
| 118 } |
| 119 |
116 // Commit the selected attribute to the paint cache. | 120 // Commit the selected attribute to the paint cache. |
117 template <SkSVGAttribute> | 121 template <SkSVGAttribute> |
118 void commitToPaint(const SkSVGPresentationAttributes&, | 122 void commitToPaint(const SkSVGPresentationAttributes&, |
119 const SkSVGLengthContext&, | 123 const SkSVGLengthContext&, |
120 SkSVGPresentationContext*); | 124 SkSVGPresentationContext*); |
121 | 125 |
122 template <> | 126 template <> |
123 void commitToPaint<SkSVGAttribute::kFill>(const SkSVGPresentationAttributes& att
rs, | 127 void commitToPaint<SkSVGAttribute::kFill>(const SkSVGPresentationAttributes& att
rs, |
124 const SkSVGLengthContext&, | 128 const SkSVGLengthContext&, |
125 SkSVGPresentationContext* pctx) { | 129 SkSVGPresentationContext* pctx) { |
126 applySvgPaint(*attrs.fFill.get(), &pctx->fFillPaint); | 130 applySvgPaint(*attrs.fFill.get(), &pctx->fFillPaint); |
127 } | 131 } |
128 | 132 |
129 template <> | 133 template <> |
130 void commitToPaint<SkSVGAttribute::kStroke>(const SkSVGPresentationAttributes& a
ttrs, | 134 void commitToPaint<SkSVGAttribute::kStroke>(const SkSVGPresentationAttributes& a
ttrs, |
131 const SkSVGLengthContext&, | 135 const SkSVGLengthContext&, |
132 SkSVGPresentationContext* pctx) { | 136 SkSVGPresentationContext* pctx) { |
133 applySvgPaint(*attrs.fStroke.get(), &pctx->fStrokePaint); | 137 applySvgPaint(*attrs.fStroke.get(), &pctx->fStrokePaint); |
134 } | 138 } |
135 | 139 |
136 template <> | 140 template <> |
137 void commitToPaint<SkSVGAttribute::kFillOpacity>(const SkSVGPresentationAttribut
es& attrs, | 141 void commitToPaint<SkSVGAttribute::kFillOpacity>(const SkSVGPresentationAttribut
es& attrs, |
138 const SkSVGLengthContext&, | 142 const SkSVGLengthContext&, |
139 SkSVGPresentationContext* pctx)
{ | 143 SkSVGPresentationContext* pctx)
{ |
140 pctx->fFillPaint.setAlpha(static_cast<uint8_t>(*attrs.fFillOpacity.get() * 2
55)); | 144 pctx->fFillPaint.setAlpha(opacity_to_alpha(*attrs.fFillOpacity.get())); |
141 } | 145 } |
142 | 146 |
143 template <> | 147 template <> |
144 void commitToPaint<SkSVGAttribute::kStrokeLineCap>(const SkSVGPresentationAttrib
utes& attrs, | 148 void commitToPaint<SkSVGAttribute::kStrokeLineCap>(const SkSVGPresentationAttrib
utes& attrs, |
145 const SkSVGLengthContext&, | 149 const SkSVGLengthContext&, |
146 SkSVGPresentationContext* pct
x) { | 150 SkSVGPresentationContext* pct
x) { |
147 const auto& cap = *attrs.fStrokeLineCap.get(); | 151 const auto& cap = *attrs.fStrokeLineCap.get(); |
148 if (cap.type() != SkSVGLineCap::Type::kInherit) { | 152 if (cap.type() != SkSVGLineCap::Type::kInherit) { |
149 pctx->fStrokePaint.setStrokeCap(toSkCap(cap)); | 153 pctx->fStrokePaint.setStrokeCap(toSkCap(cap)); |
150 } | 154 } |
151 } | 155 } |
152 | 156 |
153 template <> | 157 template <> |
154 void commitToPaint<SkSVGAttribute::kStrokeLineJoin>(const SkSVGPresentationAttri
butes& attrs, | 158 void commitToPaint<SkSVGAttribute::kStrokeLineJoin>(const SkSVGPresentationAttri
butes& attrs, |
155 const SkSVGLengthContext&, | 159 const SkSVGLengthContext&, |
156 SkSVGPresentationContext* pc
tx) { | 160 SkSVGPresentationContext* pc
tx) { |
157 const auto& join = *attrs.fStrokeLineJoin.get(); | 161 const auto& join = *attrs.fStrokeLineJoin.get(); |
158 if (join.type() != SkSVGLineJoin::Type::kInherit) { | 162 if (join.type() != SkSVGLineJoin::Type::kInherit) { |
159 pctx->fStrokePaint.setStrokeJoin(toSkJoin(join)); | 163 pctx->fStrokePaint.setStrokeJoin(toSkJoin(join)); |
160 } | 164 } |
161 } | 165 } |
162 | 166 |
163 template <> | 167 template <> |
164 void commitToPaint<SkSVGAttribute::kStrokeOpacity>(const SkSVGPresentationAttrib
utes& attrs, | 168 void commitToPaint<SkSVGAttribute::kStrokeOpacity>(const SkSVGPresentationAttrib
utes& attrs, |
165 const SkSVGLengthContext&, | 169 const SkSVGLengthContext&, |
166 SkSVGPresentationContext* pct
x) { | 170 SkSVGPresentationContext* pct
x) { |
167 pctx->fStrokePaint.setAlpha(static_cast<uint8_t>(*attrs.fStrokeOpacity.get()
* 255)); | 171 pctx->fStrokePaint.setAlpha(opacity_to_alpha(*attrs.fStrokeOpacity.get())); |
168 } | 172 } |
169 | 173 |
170 template <> | 174 template <> |
171 void commitToPaint<SkSVGAttribute::kStrokeWidth>(const SkSVGPresentationAttribut
es& attrs, | 175 void commitToPaint<SkSVGAttribute::kStrokeWidth>(const SkSVGPresentationAttribut
es& attrs, |
172 const SkSVGLengthContext& lctx, | 176 const SkSVGLengthContext& lctx, |
173 SkSVGPresentationContext* pctx)
{ | 177 SkSVGPresentationContext* pctx)
{ |
174 auto strokeWidth = lctx.resolve(*attrs.fStrokeWidth.get(), | 178 auto strokeWidth = lctx.resolve(*attrs.fStrokeWidth.get(), |
175 SkSVGLengthContext::LengthType::kOther); | 179 SkSVGLengthContext::LengthType::kOther); |
176 pctx->fStrokePaint.setStrokeWidth(strokeWidth); | 180 pctx->fStrokePaint.setStrokeWidth(strokeWidth); |
177 } | 181 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 ApplyLazyInheritedAttribute(StrokeLineJoin); | 243 ApplyLazyInheritedAttribute(StrokeLineJoin); |
240 ApplyLazyInheritedAttribute(StrokeOpacity); | 244 ApplyLazyInheritedAttribute(StrokeOpacity); |
241 ApplyLazyInheritedAttribute(StrokeWidth); | 245 ApplyLazyInheritedAttribute(StrokeWidth); |
242 | 246 |
243 #undef ApplyLazyInheritedAttribute | 247 #undef ApplyLazyInheritedAttribute |
244 | 248 |
245 // Uninherited attributes. Only apply to the current context. | 249 // Uninherited attributes. Only apply to the current context. |
246 | 250 |
247 if (auto* opacity = attrs.fOpacity.getMaybeNull()) { | 251 if (auto* opacity = attrs.fOpacity.getMaybeNull()) { |
248 SkPaint opacityPaint; | 252 SkPaint opacityPaint; |
249 opacityPaint.setAlpha(static_cast<uint8_t>(opacity->value() * 255)); | 253 opacityPaint.setAlpha(opacity_to_alpha(opacity->value())); |
250 // Balanced in the destructor, via restoreToCount(). | 254 // Balanced in the destructor, via restoreToCount(). |
251 fCanvas->saveLayer(nullptr, &opacityPaint); | 255 fCanvas->saveLayer(nullptr, &opacityPaint); |
252 } | 256 } |
253 } | 257 } |
254 | 258 |
255 const SkPaint* SkSVGRenderContext::fillPaint() const { | 259 const SkPaint* SkSVGRenderContext::fillPaint() const { |
256 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge
t()->type(); | 260 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge
t()->type(); |
257 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa
int : nullptr; | 261 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa
int : nullptr; |
258 } | 262 } |
259 | 263 |
260 const SkPaint* SkSVGRenderContext::strokePaint() const { | 264 const SkPaint* SkSVGRenderContext::strokePaint() const { |
261 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke.
get()->type(); | 265 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke.
get()->type(); |
262 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke
Paint : nullptr; | 266 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke
Paint : nullptr; |
263 } | 267 } |
OLD | NEW |