OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "modules/canvas2d/CanvasRenderingContext2DState.h" | 7 #include "modules/canvas2d/CanvasRenderingContext2DState.h" |
8 | 8 |
9 #include "core/css/CSSFontSelector.h" | 9 #include "core/css/CSSFontSelector.h" |
10 #include "core/css/resolver/FilterOperationResolver.h" | 10 #include "core/css/resolver/FilterOperationResolver.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 { | 192 { |
193 m_lineDash = dash; | 193 m_lineDash = dash; |
194 // Spec requires the concatenation of two copies the dash list when the | 194 // Spec requires the concatenation of two copies the dash list when the |
195 // number of elements is odd | 195 // number of elements is odd |
196 if (dash.size() % 2) | 196 if (dash.size() % 2) |
197 m_lineDash.appendVector(dash); | 197 m_lineDash.appendVector(dash); |
198 | 198 |
199 m_lineDashDirty = true; | 199 m_lineDashDirty = true; |
200 } | 200 } |
201 | 201 |
| 202 static bool hasANonZeroElement(const Vector<float>& lineDash) |
| 203 { |
| 204 for (size_t i = 0; i < lineDash.size(); i++) { |
| 205 if (lineDash[i] != 0.0f) |
| 206 return true; |
| 207 } |
| 208 return false; |
| 209 } |
| 210 |
202 void CanvasRenderingContext2DState::updateLineDash() const | 211 void CanvasRenderingContext2DState::updateLineDash() const |
203 { | 212 { |
204 if (!m_lineDashDirty) | 213 if (!m_lineDashDirty) |
205 return; | 214 return; |
206 | 215 |
207 if (m_lineDash.size() == 0) { | 216 if (!hasANonZeroElement(m_lineDash)) { |
208 m_strokePaint.setPathEffect(0); | 217 m_strokePaint.setPathEffect(0); |
209 } else { | 218 } else { |
210 RefPtr<SkPathEffect> dashPathEffect = adoptRef(SkDashPathEffect::Create(
m_lineDash.data(), m_lineDash.size(), m_lineDashOffset)); | 219 RefPtr<SkPathEffect> dashPathEffect = adoptRef(SkDashPathEffect::Create(
m_lineDash.data(), m_lineDash.size(), m_lineDashOffset)); |
211 m_strokePaint.setPathEffect(dashPathEffect.get()); | 220 m_strokePaint.setPathEffect(dashPathEffect.get()); |
212 } | 221 } |
213 | 222 |
214 m_lineDashDirty = false; | 223 m_lineDashDirty = false; |
215 } | 224 } |
216 | 225 |
217 void CanvasRenderingContext2DState::setStrokeStyle(CanvasStyle* style) | 226 void CanvasRenderingContext2DState::setStrokeStyle(CanvasStyle* style) |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 paint->setLooper(0); | 533 paint->setLooper(0); |
525 paint->setImageFilter(shadowAndForegroundImageFilter()); | 534 paint->setImageFilter(shadowAndForegroundImageFilter()); |
526 return paint; | 535 return paint; |
527 } | 536 } |
528 paint->setLooper(shadowAndForegroundDrawLooper()); | 537 paint->setLooper(shadowAndForegroundDrawLooper()); |
529 paint->setImageFilter(0); | 538 paint->setImageFilter(0); |
530 return paint; | 539 return paint; |
531 } | 540 } |
532 | 541 |
533 } // blink | 542 } // blink |
OLD | NEW |