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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "cc/paint/paint_canvas.h" |
| 17 #include "cc/paint/paint_flags.h" |
17 #include "third_party/skia/include/core/SkPath.h" | 18 #include "third_party/skia/include/core/SkPath.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/image/canvas_image_source.h" | 20 #include "ui/gfx/image/canvas_image_source.h" |
20 #include "ui/gfx/scoped_canvas.h" | 21 #include "ui/gfx/scoped_canvas.h" |
21 #include "ui/gfx/vector_icon_types.h" | 22 #include "ui/gfx/vector_icon_types.h" |
22 #include "ui/gfx/vector_icons_public.h" | 23 #include "ui/gfx/vector_icons_public.h" |
23 | 24 |
24 namespace gfx { | 25 namespace gfx { |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 void PaintPath(Canvas* canvas, | 84 void PaintPath(Canvas* canvas, |
84 const PathElement* path_elements, | 85 const PathElement* path_elements, |
85 int dip_size, | 86 int dip_size, |
86 SkColor color) { | 87 SkColor color) { |
87 SkPath path; | 88 SkPath path; |
88 path.setFillType(SkPath::kEvenOdd_FillType); | 89 path.setFillType(SkPath::kEvenOdd_FillType); |
89 | 90 |
90 int canvas_size = kReferenceSizeDip; | 91 int canvas_size = kReferenceSizeDip; |
91 std::vector<SkPath> paths; | 92 std::vector<SkPath> paths; |
92 std::vector<SkPaint> paints; | 93 std::vector<cc::PaintFlags> paints; |
93 SkRect clip_rect = SkRect::MakeEmpty(); | 94 SkRect clip_rect = SkRect::MakeEmpty(); |
94 bool flips_in_rtl = false; | 95 bool flips_in_rtl = false; |
95 CommandType previous_command_type = NEW_PATH; | 96 CommandType previous_command_type = NEW_PATH; |
96 | 97 |
97 for (size_t i = 0; path_elements[i].type != END; i++) { | 98 for (size_t i = 0; path_elements[i].type != END; i++) { |
98 if (paths.empty() || path_elements[i].type == NEW_PATH) { | 99 if (paths.empty() || path_elements[i].type == NEW_PATH) { |
99 paths.push_back(SkPath()); | 100 paths.push_back(SkPath()); |
100 paths.back().setFillType(SkPath::kEvenOdd_FillType); | 101 paths.back().setFillType(SkPath::kEvenOdd_FillType); |
101 | 102 |
102 paints.push_back(SkPaint()); | 103 paints.push_back(cc::PaintFlags()); |
103 paints.back().setColor(color); | 104 paints.back().setColor(color); |
104 paints.back().setAntiAlias(true); | 105 paints.back().setAntiAlias(true); |
105 paints.back().setStrokeCap(SkPaint::kRound_Cap); | 106 paints.back().setStrokeCap(cc::PaintFlags::kRound_Cap); |
106 } | 107 } |
107 | 108 |
108 SkPath& path = paths.back(); | 109 SkPath& path = paths.back(); |
109 SkPaint& paint = paints.back(); | 110 cc::PaintFlags& paint = paints.back(); |
110 CommandType command_type = path_elements[i].type; | 111 CommandType command_type = path_elements[i].type; |
111 switch (command_type) { | 112 switch (command_type) { |
112 // Handled above. | 113 // Handled above. |
113 case NEW_PATH: | 114 case NEW_PATH: |
114 continue; | 115 continue; |
115 | 116 |
116 case PATH_COLOR_ARGB: { | 117 case PATH_COLOR_ARGB: { |
117 int a = SkScalarFloorToInt(path_elements[++i].arg); | 118 int a = SkScalarFloorToInt(path_elements[++i].arg); |
118 int r = SkScalarFloorToInt(path_elements[++i].arg); | 119 int r = SkScalarFloorToInt(path_elements[++i].arg); |
119 int g = SkScalarFloorToInt(path_elements[++i].arg); | 120 int g = SkScalarFloorToInt(path_elements[++i].arg); |
120 int b = SkScalarFloorToInt(path_elements[++i].arg); | 121 int b = SkScalarFloorToInt(path_elements[++i].arg); |
121 paint.setColor(SkColorSetARGB(a, r, g, b)); | 122 paint.setColor(SkColorSetARGB(a, r, g, b)); |
122 break; | 123 break; |
123 } | 124 } |
124 | 125 |
125 case PATH_MODE_CLEAR: { | 126 case PATH_MODE_CLEAR: { |
126 paint.setBlendMode(SkBlendMode::kClear); | 127 paint.setBlendMode(SkBlendMode::kClear); |
127 break; | 128 break; |
128 }; | 129 }; |
129 | 130 |
130 case STROKE: { | 131 case STROKE: { |
131 paint.setStyle(SkPaint::kStroke_Style); | 132 paint.setStyle(cc::PaintFlags::kStroke_Style); |
132 SkScalar width = path_elements[++i].arg; | 133 SkScalar width = path_elements[++i].arg; |
133 paint.setStrokeWidth(width); | 134 paint.setStrokeWidth(width); |
134 break; | 135 break; |
135 } | 136 } |
136 | 137 |
137 case CAP_SQUARE: { | 138 case CAP_SQUARE: { |
138 paint.setStrokeCap(SkPaint::kSquare_Cap); | 139 paint.setStrokeCap(cc::PaintFlags::kSquare_Cap); |
139 break; | 140 break; |
140 } | 141 } |
141 | 142 |
142 case MOVE_TO: { | 143 case MOVE_TO: { |
143 SkScalar x = path_elements[++i].arg; | 144 SkScalar x = path_elements[++i].arg; |
144 SkScalar y = path_elements[++i].arg; | 145 SkScalar y = path_elements[++i].arg; |
145 path.moveTo(x, y); | 146 path.moveTo(x, y); |
146 break; | 147 break; |
147 } | 148 } |
148 | 149 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 595 } |
595 | 596 |
596 ImageSkia CreateVectorIconFromSource(const std::string& source, | 597 ImageSkia CreateVectorIconFromSource(const std::string& source, |
597 int dip_size, | 598 int dip_size, |
598 SkColor color) { | 599 SkColor color) { |
599 return CanvasImageSource::MakeImageSkia<VectorIconSourceLegacy>( | 600 return CanvasImageSource::MakeImageSkia<VectorIconSourceLegacy>( |
600 source, dip_size, color); | 601 source, dip_size, color); |
601 } | 602 } |
602 | 603 |
603 } // namespace gfx | 604 } // namespace gfx |
OLD | NEW |