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

Side by Side Diff: ui/gfx/paint_vector_icon.cc

Issue 2680943002: ui: Clean up naming of paint-related identifiers (Closed)
Patch Set: Created 3 years, 10 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 | « ui/gfx/paint_throbber.cc ('k') | ui/gfx/render_text.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 // 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 void PaintPath(Canvas* canvas, 84 void PaintPath(Canvas* canvas,
85 const PathElement* path_elements, 85 const PathElement* path_elements,
86 int dip_size, 86 int dip_size,
87 SkColor color) { 87 SkColor color) {
88 SkPath path; 88 SkPath path;
89 path.setFillType(SkPath::kEvenOdd_FillType); 89 path.setFillType(SkPath::kEvenOdd_FillType);
90 90
91 int canvas_size = kReferenceSizeDip; 91 int canvas_size = kReferenceSizeDip;
92 std::vector<SkPath> paths; 92 std::vector<SkPath> paths;
93 std::vector<cc::PaintFlags> paints; 93 std::vector<cc::PaintFlags> flags_array;
94 SkRect clip_rect = SkRect::MakeEmpty(); 94 SkRect clip_rect = SkRect::MakeEmpty();
95 bool flips_in_rtl = false; 95 bool flips_in_rtl = false;
96 CommandType previous_command_type = NEW_PATH; 96 CommandType previous_command_type = NEW_PATH;
97 97
98 for (size_t i = 0; path_elements[i].type != END; i++) { 98 for (size_t i = 0; path_elements[i].type != END; i++) {
99 if (paths.empty() || path_elements[i].type == NEW_PATH) { 99 if (paths.empty() || path_elements[i].type == NEW_PATH) {
100 paths.push_back(SkPath()); 100 paths.push_back(SkPath());
101 paths.back().setFillType(SkPath::kEvenOdd_FillType); 101 paths.back().setFillType(SkPath::kEvenOdd_FillType);
102 102
103 paints.push_back(cc::PaintFlags()); 103 flags_array.push_back(cc::PaintFlags());
104 paints.back().setColor(color); 104 flags_array.back().setColor(color);
105 paints.back().setAntiAlias(true); 105 flags_array.back().setAntiAlias(true);
106 paints.back().setStrokeCap(cc::PaintFlags::kRound_Cap); 106 flags_array.back().setStrokeCap(cc::PaintFlags::kRound_Cap);
107 } 107 }
108 108
109 SkPath& path = paths.back(); 109 SkPath& path = paths.back();
110 cc::PaintFlags& paint = paints.back(); 110 cc::PaintFlags& flags = flags_array.back();
111 CommandType command_type = path_elements[i].type; 111 CommandType command_type = path_elements[i].type;
112 switch (command_type) { 112 switch (command_type) {
113 // Handled above. 113 // Handled above.
114 case NEW_PATH: 114 case NEW_PATH:
115 continue; 115 continue;
116 116
117 case PATH_COLOR_ARGB: { 117 case PATH_COLOR_ARGB: {
118 int a = SkScalarFloorToInt(path_elements[++i].arg); 118 int a = SkScalarFloorToInt(path_elements[++i].arg);
119 int r = SkScalarFloorToInt(path_elements[++i].arg); 119 int r = SkScalarFloorToInt(path_elements[++i].arg);
120 int g = SkScalarFloorToInt(path_elements[++i].arg); 120 int g = SkScalarFloorToInt(path_elements[++i].arg);
121 int b = SkScalarFloorToInt(path_elements[++i].arg); 121 int b = SkScalarFloorToInt(path_elements[++i].arg);
122 paint.setColor(SkColorSetARGB(a, r, g, b)); 122 flags.setColor(SkColorSetARGB(a, r, g, b));
123 break; 123 break;
124 } 124 }
125 125
126 case PATH_MODE_CLEAR: { 126 case PATH_MODE_CLEAR: {
127 paint.setBlendMode(SkBlendMode::kClear); 127 flags.setBlendMode(SkBlendMode::kClear);
128 break; 128 break;
129 }; 129 };
130 130
131 case STROKE: { 131 case STROKE: {
132 paint.setStyle(cc::PaintFlags::kStroke_Style); 132 flags.setStyle(cc::PaintFlags::kStroke_Style);
133 SkScalar width = path_elements[++i].arg; 133 SkScalar width = path_elements[++i].arg;
134 paint.setStrokeWidth(width); 134 flags.setStrokeWidth(width);
135 break; 135 break;
136 } 136 }
137 137
138 case CAP_SQUARE: { 138 case CAP_SQUARE: {
139 paint.setStrokeCap(cc::PaintFlags::kSquare_Cap); 139 flags.setStrokeCap(cc::PaintFlags::kSquare_Cap);
140 break; 140 break;
141 } 141 }
142 142
143 case MOVE_TO: { 143 case MOVE_TO: {
144 SkScalar x = path_elements[++i].arg; 144 SkScalar x = path_elements[++i].arg;
145 SkScalar y = path_elements[++i].arg; 145 SkScalar y = path_elements[++i].arg;
146 path.moveTo(x, y); 146 path.moveTo(x, y);
147 break; 147 break;
148 } 148 }
149 149
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 case CLIP: { 303 case CLIP: {
304 SkScalar x = path_elements[++i].arg; 304 SkScalar x = path_elements[++i].arg;
305 SkScalar y = path_elements[++i].arg; 305 SkScalar y = path_elements[++i].arg;
306 SkScalar w = path_elements[++i].arg; 306 SkScalar w = path_elements[++i].arg;
307 SkScalar h = path_elements[++i].arg; 307 SkScalar h = path_elements[++i].arg;
308 clip_rect = SkRect::MakeXYWH(x, y, w, h); 308 clip_rect = SkRect::MakeXYWH(x, y, w, h);
309 break; 309 break;
310 } 310 }
311 311
312 case DISABLE_AA: { 312 case DISABLE_AA: {
313 paint.setAntiAlias(false); 313 flags.setAntiAlias(false);
314 break; 314 break;
315 } 315 }
316 316
317 case FLIPS_IN_RTL: { 317 case FLIPS_IN_RTL: {
318 flips_in_rtl = true; 318 flips_in_rtl = true;
319 break; 319 break;
320 } 320 }
321 321
322 case END: 322 case END:
323 NOTREACHED(); 323 NOTREACHED();
324 break; 324 break;
325 } 325 }
326 326
327 previous_command_type = command_type; 327 previous_command_type = command_type;
328 } 328 }
329 329
330 gfx::ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size, 330 gfx::ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size,
331 flips_in_rtl); 331 flips_in_rtl);
332 332
333 if (dip_size != canvas_size) { 333 if (dip_size != canvas_size) {
334 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size); 334 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size);
335 canvas->sk_canvas()->scale(scale, scale); 335 canvas->sk_canvas()->scale(scale, scale);
336 } 336 }
337 337
338 if (!clip_rect.isEmpty()) 338 if (!clip_rect.isEmpty())
339 canvas->sk_canvas()->clipRect(clip_rect); 339 canvas->sk_canvas()->clipRect(clip_rect);
340 340
341 DCHECK_EQ(paints.size(), paths.size()); 341 DCHECK_EQ(flags_array.size(), paths.size());
342 for (size_t i = 0; i < paths.size(); ++i) 342 for (size_t i = 0; i < paths.size(); ++i)
343 canvas->DrawPath(paths[i], paints[i]); 343 canvas->DrawPath(paths[i], flags_array[i]);
344 } 344 }
345 345
346 class VectorIconSource : public CanvasImageSource { 346 class VectorIconSource : public CanvasImageSource {
347 public: 347 public:
348 VectorIconSource(const VectorIcon& icon, 348 VectorIconSource(const VectorIcon& icon,
349 int dip_size, 349 int dip_size,
350 SkColor color, 350 SkColor color,
351 const VectorIcon& badge_icon) 351 const VectorIcon& badge_icon)
352 : CanvasImageSource(gfx::Size(dip_size, dip_size), false), 352 : CanvasImageSource(gfx::Size(dip_size, dip_size), false),
353 color_(color), 353 color_(color),
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 595 }
596 596
597 ImageSkia CreateVectorIconFromSource(const std::string& source, 597 ImageSkia CreateVectorIconFromSource(const std::string& source,
598 int dip_size, 598 int dip_size,
599 SkColor color) { 599 SkColor color) {
600 return CanvasImageSource::MakeImageSkia<VectorIconSourceLegacy>( 600 return CanvasImageSource::MakeImageSkia<VectorIconSourceLegacy>(
601 source, dip_size, color); 601 source, dip_size, color);
602 } 602 }
603 603
604 } // namespace gfx 604 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/paint_throbber.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698