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 "ui/gfx/paint_vector_icon.h" | 5 #include "ui/gfx/paint_vector_icon.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 case MOVE_TO: { | 142 case MOVE_TO: { |
143 SkScalar x = path_elements[++i].arg; | 143 SkScalar x = path_elements[++i].arg; |
144 SkScalar y = path_elements[++i].arg; | 144 SkScalar y = path_elements[++i].arg; |
145 path.moveTo(x, y); | 145 path.moveTo(x, y); |
146 break; | 146 break; |
147 } | 147 } |
148 | 148 |
149 case R_MOVE_TO: { | 149 case R_MOVE_TO: { |
150 if (previous_command_type == CLOSE) { | 150 if (previous_command_type == CLOSE) { |
151 // This triggers injectMoveToIfNeeded() so that the next subpath will | 151 // This triggers injectMoveToIfNeeded() so that the next subpath |
152 // start at the correct place. See | 152 // will start at the correct place. See [ |
153 // [ https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand ]. | 153 // https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand ]. |
154 path.rLineTo(0, 0); | 154 path.rLineTo(0, 0); |
155 } | 155 } |
156 | 156 |
157 SkScalar x = path_elements[++i].arg; | 157 SkScalar x = path_elements[++i].arg; |
158 SkScalar y = path_elements[++i].arg; | 158 SkScalar y = path_elements[++i].arg; |
159 path.rMoveTo(x, y); | 159 path.rMoveTo(x, y); |
160 break; | 160 break; |
161 } | 161 } |
162 | 162 |
163 case ARC_TO: | 163 case ARC_TO: |
164 case R_ARC_TO: { | 164 case R_ARC_TO: { |
165 SkScalar rx = path_elements[++i].arg; | 165 SkScalar rx = path_elements[++i].arg; |
166 SkScalar ry = path_elements[++i].arg; | 166 SkScalar ry = path_elements[++i].arg; |
167 SkScalar angle = path_elements[++i].arg; | 167 SkScalar angle = path_elements[++i].arg; |
168 SkScalar large_arc_flag = path_elements[++i].arg; | 168 SkScalar large_arc_flag = path_elements[++i].arg; |
169 SkScalar arc_sweep_flag = path_elements[++i].arg; | 169 SkScalar arc_sweep_flag = path_elements[++i].arg; |
170 SkScalar x = path_elements[++i].arg; | 170 SkScalar x = path_elements[++i].arg; |
171 SkScalar y = path_elements[++i].arg; | 171 SkScalar y = path_elements[++i].arg; |
172 | 172 |
173 auto path_fn = | 173 auto path_fn = |
174 command_type == ARC_TO | 174 command_type == ARC_TO |
175 ? static_cast<void (SkPath::*)( | 175 ? static_cast<void (SkPath::*)( |
176 SkScalar, SkScalar, SkScalar, SkPath::ArcSize, | 176 SkScalar, SkScalar, SkScalar, SkPath::ArcSize, |
177 SkPath::Direction, SkScalar, SkScalar)>(&SkPath::arcTo) | 177 SkPath::Direction, SkScalar, SkScalar)>(&SkPath::arcTo) |
178 : &SkPath::rArcTo; | 178 : &SkPath::rArcTo; |
179 (path.*path_fn)( | 179 (path.*path_fn)( |
180 rx, ry, angle, | 180 rx, ry, angle, |
181 large_arc_flag ? SkPath::kLarge_ArcSize : SkPath::kSmall_ArcSize, | 181 large_arc_flag ? SkPath::kLarge_ArcSize : SkPath::kSmall_ArcSize, |
182 arc_sweep_flag ? SkPath::kCW_Direction : SkPath::kCCW_Direction, | 182 arc_sweep_flag ? SkPath::kCW_Direction : SkPath::kCCW_Direction, x, |
183 x, y); | 183 y); |
184 break; | 184 break; |
185 } | 185 } |
186 | 186 |
187 case LINE_TO: { | 187 case LINE_TO: { |
188 SkScalar x = path_elements[++i].arg; | 188 SkScalar x = path_elements[++i].arg; |
189 SkScalar y = path_elements[++i].arg; | 189 SkScalar y = path_elements[++i].arg; |
190 path.lineTo(x, y); | 190 path.lineTo(x, y); |
191 break; | 191 break; |
192 } | 192 } |
193 | 193 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 DISALLOW_COPY_AND_ASSIGN(VectorIconCache); | 445 DISALLOW_COPY_AND_ASSIGN(VectorIconCache); |
446 }; | 446 }; |
447 | 447 |
448 static base::LazyInstance<VectorIconCache>::DestructorAtExit g_icon_cache = | 448 static base::LazyInstance<VectorIconCache>::DestructorAtExit g_icon_cache = |
449 LAZY_INSTANCE_INITIALIZER; | 449 LAZY_INSTANCE_INITIALIZER; |
450 | 450 |
451 } // namespace | 451 } // namespace |
452 | 452 |
453 const VectorIcon kNoneIcon = {}; | 453 const VectorIcon kNoneIcon = {}; |
454 | 454 |
| 455 void PaintVectorIcon(Canvas* canvas, const VectorIcon& icon, SkColor color) { |
| 456 PaintVectorIcon(canvas, icon, GetDefaultSizeOfVectorIcon(icon), color); |
| 457 } |
| 458 |
455 void PaintVectorIcon(Canvas* canvas, | 459 void PaintVectorIcon(Canvas* canvas, |
456 const VectorIcon& icon, | 460 const VectorIcon& icon, |
457 int dip_size, | 461 int dip_size, |
458 SkColor color) { | 462 SkColor color) { |
459 DCHECK(!icon.is_empty()); | 463 DCHECK(!icon.is_empty()); |
460 const PathElement* path = (canvas->image_scale() == 1.f && icon.path_1x_) | 464 const PathElement* path = (canvas->image_scale() == 1.f && icon.path_1x_) |
461 ? icon.path_1x_ | 465 ? icon.path_1x_ |
462 : icon.path_; | 466 : icon.path_; |
463 PaintPath(canvas, path, dip_size, color); | 467 PaintPath(canvas, path, dip_size, color); |
464 } | 468 } |
465 | 469 |
466 ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) { | 470 ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) { |
467 const PathElement* one_x_path = icon.path_1x_ ? icon.path_1x_ : icon.path_; | 471 return CreateVectorIcon(icon, GetDefaultSizeOfVectorIcon(icon), color); |
468 int size = one_x_path[0].type == CANVAS_DIMENSIONS ? one_x_path[1].arg | |
469 : kReferenceSizeDip; | |
470 return CreateVectorIcon(icon, size, color); | |
471 } | 472 } |
472 | 473 |
473 ImageSkia CreateVectorIcon(const VectorIcon& icon, | 474 ImageSkia CreateVectorIcon(const VectorIcon& icon, |
474 int dip_size, | 475 int dip_size, |
475 SkColor color) { | 476 SkColor color) { |
476 return CreateVectorIconWithBadge(icon, dip_size, color, kNoneIcon); | 477 return CreateVectorIconWithBadge(icon, dip_size, color, kNoneIcon); |
477 } | 478 } |
478 | 479 |
479 ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon, | 480 ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon, |
480 int dip_size, | 481 int dip_size, |
481 SkColor color, | 482 SkColor color, |
482 const VectorIcon& badge_icon) { | 483 const VectorIcon& badge_icon) { |
483 return icon.is_empty() ? gfx::ImageSkia() | 484 return icon.is_empty() ? gfx::ImageSkia() |
484 : g_icon_cache.Get().GetOrCreateIcon( | 485 : g_icon_cache.Get().GetOrCreateIcon( |
485 icon, dip_size, color, badge_icon); | 486 icon, dip_size, color, badge_icon); |
486 } | 487 } |
487 | 488 |
488 ImageSkia CreateVectorIconFromSource(const std::string& source, | 489 ImageSkia CreateVectorIconFromSource(const std::string& source, |
489 int dip_size, | 490 int dip_size, |
490 SkColor color) { | 491 SkColor color) { |
491 return CanvasImageSource::MakeImageSkia<VectorIconSource>(source, dip_size, | 492 return CanvasImageSource::MakeImageSkia<VectorIconSource>(source, dip_size, |
492 color); | 493 color); |
493 } | 494 } |
494 | 495 |
| 496 int GetDefaultSizeOfVectorIcon(const gfx::VectorIcon& icon) { |
| 497 const PathElement* one_x_path = icon.path_1x_ ? icon.path_1x_ : icon.path_; |
| 498 return one_x_path[0].type == CANVAS_DIMENSIONS ? one_x_path[1].arg |
| 499 : kReferenceSizeDip; |
| 500 } |
| 501 |
495 } // namespace gfx | 502 } // namespace gfx |
OLD | NEW |