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

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

Issue 1250323003: Vectorize profile badges in avatar menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: aa Created 5 years, 4 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
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 "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/image/canvas_image_source.h" 8 #include "ui/gfx/image/canvas_image_source.h"
9 #include "ui/gfx/vector_icon_types.h" 9 #include "ui/gfx/vector_icon_types.h"
10 #include "ui/gfx/vector_icons2.h" 10 #include "ui/gfx/vector_icons2.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 SkColor color) { 44 SkColor color) {
45 DCHECK(VectorIconId::VECTOR_ICON_NONE != id); 45 DCHECK(VectorIconId::VECTOR_ICON_NONE != id);
46 const PathElement* path_elements = GetPathForVectorIcon(id); 46 const PathElement* path_elements = GetPathForVectorIcon(id);
47 SkPath path; 47 SkPath path;
48 path.setFillType(SkPath::kEvenOdd_FillType); 48 path.setFillType(SkPath::kEvenOdd_FillType);
49 if (dip_size != kReferenceSizeDip) { 49 if (dip_size != kReferenceSizeDip) {
50 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(kReferenceSizeDip); 50 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(kReferenceSizeDip);
51 canvas->sk_canvas()->scale(scale, scale); 51 canvas->sk_canvas()->scale(scale, scale);
52 } 52 }
53 53
54 for (size_t i = 0; path_elements[i].type != END;) { 54 for (size_t i = 0; path_elements[i].type != END; i++) {
55 switch (path_elements[i++].type) { 55 switch (path_elements[i].type) {
56 case MOVE_TO: { 56 case MOVE_TO: {
57 SkScalar x = path_elements[i++].arg; 57 SkScalar x = path_elements[++i].arg;
58 SkScalar y = path_elements[i++].arg; 58 SkScalar y = path_elements[++i].arg;
59 path.moveTo(x, y); 59 path.moveTo(x, y);
60 break; 60 break;
61 } 61 }
62 62
63 case R_MOVE_TO: { 63 case R_MOVE_TO: {
64 SkScalar x = path_elements[i++].arg; 64 SkScalar x = path_elements[++i].arg;
65 SkScalar y = path_elements[i++].arg; 65 SkScalar y = path_elements[++i].arg;
66 path.rMoveTo(x, y); 66 path.rMoveTo(x, y);
67 break; 67 break;
68 } 68 }
69 69
70 case LINE_TO: { 70 case LINE_TO: {
71 SkScalar x = path_elements[i++].arg; 71 SkScalar x = path_elements[++i].arg;
72 SkScalar y = path_elements[i++].arg; 72 SkScalar y = path_elements[++i].arg;
73 path.lineTo(x, y); 73 path.lineTo(x, y);
74 break; 74 break;
75 } 75 }
76 76
77 case R_LINE_TO: { 77 case R_LINE_TO: {
78 SkScalar x = path_elements[i++].arg; 78 SkScalar x = path_elements[++i].arg;
79 SkScalar y = path_elements[i++].arg; 79 SkScalar y = path_elements[++i].arg;
80 path.rLineTo(x, y); 80 path.rLineTo(x, y);
81 break; 81 break;
82 } 82 }
83 83
84 case H_LINE_TO: { 84 case H_LINE_TO: {
85 SkPoint last_point; 85 SkPoint last_point;
86 path.getLastPt(&last_point); 86 path.getLastPt(&last_point);
87 SkScalar x = path_elements[i++].arg; 87 SkScalar x = path_elements[++i].arg;
88 path.lineTo(x, last_point.fY); 88 path.lineTo(x, last_point.fY);
89 break; 89 break;
90 } 90 }
91 91
92 case R_H_LINE_TO: { 92 case R_H_LINE_TO: {
93 SkScalar x = path_elements[i++].arg; 93 SkScalar x = path_elements[++i].arg;
94 path.rLineTo(x, 0); 94 path.rLineTo(x, 0);
95 break; 95 break;
96 } 96 }
97 97
98 case V_LINE_TO: { 98 case V_LINE_TO: {
99 SkPoint last_point; 99 SkPoint last_point;
100 path.getLastPt(&last_point); 100 path.getLastPt(&last_point);
101 SkScalar y = path_elements[i++].arg; 101 SkScalar y = path_elements[++i].arg;
102 path.lineTo(last_point.fX, y); 102 path.lineTo(last_point.fX, y);
103 break; 103 break;
104 } 104 }
105 105
106 case R_V_LINE_TO: { 106 case R_V_LINE_TO: {
107 SkScalar y = path_elements[i++].arg; 107 SkScalar y = path_elements[++i].arg;
108 path.rLineTo(0, y); 108 path.rLineTo(0, y);
109 break; 109 break;
110 } 110 }
111 111
112 case CUBIC_TO: { 112 case CUBIC_TO: {
113 SkScalar x1 = path_elements[i++].arg; 113 SkScalar x1 = path_elements[++i].arg;
114 SkScalar y1 = path_elements[i++].arg; 114 SkScalar y1 = path_elements[++i].arg;
115 SkScalar x2 = path_elements[i++].arg; 115 SkScalar x2 = path_elements[++i].arg;
116 SkScalar y2 = path_elements[i++].arg; 116 SkScalar y2 = path_elements[++i].arg;
117 SkScalar x3 = path_elements[i++].arg; 117 SkScalar x3 = path_elements[++i].arg;
118 SkScalar y3 = path_elements[i++].arg; 118 SkScalar y3 = path_elements[++i].arg;
119 path.cubicTo(x1, y1, x2, y2, x3, y3); 119 path.cubicTo(x1, y1, x2, y2, x3, y3);
120 break; 120 break;
121 } 121 }
122 122
123 case R_CUBIC_TO: { 123 case R_CUBIC_TO: {
124 SkScalar x1 = path_elements[i++].arg; 124 SkScalar x1 = path_elements[++i].arg;
125 SkScalar y1 = path_elements[i++].arg; 125 SkScalar y1 = path_elements[++i].arg;
126 SkScalar x2 = path_elements[i++].arg; 126 SkScalar x2 = path_elements[++i].arg;
127 SkScalar y2 = path_elements[i++].arg; 127 SkScalar y2 = path_elements[++i].arg;
128 SkScalar x3 = path_elements[i++].arg; 128 SkScalar x3 = path_elements[++i].arg;
129 SkScalar y3 = path_elements[i++].arg; 129 SkScalar y3 = path_elements[++i].arg;
130 path.rCubicTo(x1, y1, x2, y2, x3, y3); 130 path.rCubicTo(x1, y1, x2, y2, x3, y3);
131 break; 131 break;
132 } 132 }
133 133
134 case CLOSE: { 134 case CLOSE: {
135 path.close(); 135 path.close();
136 break; 136 break;
137 } 137 }
138 138
139 case CIRCLE: { 139 case CIRCLE: {
140 SkScalar x = path_elements[i++].arg; 140 SkScalar x = path_elements[++i].arg;
141 SkScalar y = path_elements[i++].arg; 141 SkScalar y = path_elements[++i].arg;
142 SkScalar r = path_elements[i++].arg; 142 SkScalar r = path_elements[++i].arg;
143 path.addCircle(x, y, r); 143 path.addCircle(x, y, r);
144 break; 144 break;
145 } 145 }
146 146
147 case END: 147 case END:
148 NOTREACHED(); 148 NOTREACHED();
149 break; 149 break;
150 } 150 }
151 } 151 }
152 152
153 SkPaint paint; 153 SkPaint paint;
154 paint.setStyle(SkPaint::kFill_Style); 154 paint.setStyle(SkPaint::kFill_Style);
155 paint.setAntiAlias(true); 155 paint.setAntiAlias(true);
156 paint.setColor(color); 156 paint.setColor(color);
157 canvas->DrawPath(path, paint); 157 canvas->DrawPath(path, paint);
158 } 158 }
159 159
160 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { 160 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) {
161 return ImageSkia( 161 return ImageSkia(
162 new VectorIconSource(id, dip_size, color), 162 new VectorIconSource(id, dip_size, color),
163 gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); 163 gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)));
164 } 164 }
165 165
166 } // namespace gfx 166 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698