| 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 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 SkColor color) { | 94 SkColor color) { |
| 95 DCHECK(VectorIconId::VECTOR_ICON_NONE != id); | 95 DCHECK(VectorIconId::VECTOR_ICON_NONE != id); |
| 96 const PathElement* path_elements = GetPathForVectorIcon(id); | 96 const PathElement* path_elements = GetPathForVectorIcon(id); |
| 97 SkPath path; | 97 SkPath path; |
| 98 path.setFillType(SkPath::kEvenOdd_FillType); | 98 path.setFillType(SkPath::kEvenOdd_FillType); |
| 99 if (dip_size != kReferenceSizeDip) { | 99 if (dip_size != kReferenceSizeDip) { |
| 100 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(kReferenceSizeDip); | 100 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(kReferenceSizeDip); |
| 101 canvas->sk_canvas()->scale(scale, scale); | 101 canvas->sk_canvas()->scale(scale, scale); |
| 102 } | 102 } |
| 103 | 103 |
| 104 for (size_t i = 0; path_elements[i].type != END;) { | 104 for (size_t i = 0; path_elements[i].type != END; i++) { |
| 105 switch (path_elements[i++].type) { | 105 switch (path_elements[i].type) { |
| 106 case MOVE_TO: { | 106 case MOVE_TO: { |
| 107 SkScalar x = path_elements[i++].arg; | 107 SkScalar x = path_elements[++i].arg; |
| 108 SkScalar y = path_elements[i++].arg; | 108 SkScalar y = path_elements[++i].arg; |
| 109 path.moveTo(x, y); | 109 path.moveTo(x, y); |
| 110 break; | 110 break; |
| 111 } | 111 } |
| 112 | 112 |
| 113 case R_MOVE_TO: { | 113 case R_MOVE_TO: { |
| 114 SkScalar x = path_elements[i++].arg; | 114 SkScalar x = path_elements[++i].arg; |
| 115 SkScalar y = path_elements[i++].arg; | 115 SkScalar y = path_elements[++i].arg; |
| 116 path.rMoveTo(x, y); | 116 path.rMoveTo(x, y); |
| 117 break; | 117 break; |
| 118 } | 118 } |
| 119 | 119 |
| 120 case LINE_TO: { | 120 case LINE_TO: { |
| 121 SkScalar x = path_elements[i++].arg; | 121 SkScalar x = path_elements[++i].arg; |
| 122 SkScalar y = path_elements[i++].arg; | 122 SkScalar y = path_elements[++i].arg; |
| 123 path.lineTo(x, y); | 123 path.lineTo(x, y); |
| 124 break; | 124 break; |
| 125 } | 125 } |
| 126 | 126 |
| 127 case R_LINE_TO: { | 127 case R_LINE_TO: { |
| 128 SkScalar x = path_elements[i++].arg; | 128 SkScalar x = path_elements[++i].arg; |
| 129 SkScalar y = path_elements[i++].arg; | 129 SkScalar y = path_elements[++i].arg; |
| 130 path.rLineTo(x, y); | 130 path.rLineTo(x, y); |
| 131 break; | 131 break; |
| 132 } | 132 } |
| 133 | 133 |
| 134 case H_LINE_TO: { | 134 case H_LINE_TO: { |
| 135 SkPoint last_point; | 135 SkPoint last_point; |
| 136 path.getLastPt(&last_point); | 136 path.getLastPt(&last_point); |
| 137 SkScalar x = path_elements[i++].arg; | 137 SkScalar x = path_elements[++i].arg; |
| 138 path.lineTo(x, last_point.fY); | 138 path.lineTo(x, last_point.fY); |
| 139 break; | 139 break; |
| 140 } | 140 } |
| 141 | 141 |
| 142 case R_H_LINE_TO: { | 142 case R_H_LINE_TO: { |
| 143 SkScalar x = path_elements[i++].arg; | 143 SkScalar x = path_elements[++i].arg; |
| 144 path.rLineTo(x, 0); | 144 path.rLineTo(x, 0); |
| 145 break; | 145 break; |
| 146 } | 146 } |
| 147 | 147 |
| 148 case V_LINE_TO: { | 148 case V_LINE_TO: { |
| 149 SkPoint last_point; | 149 SkPoint last_point; |
| 150 path.getLastPt(&last_point); | 150 path.getLastPt(&last_point); |
| 151 SkScalar y = path_elements[i++].arg; | 151 SkScalar y = path_elements[++i].arg; |
| 152 path.lineTo(last_point.fX, y); | 152 path.lineTo(last_point.fX, y); |
| 153 break; | 153 break; |
| 154 } | 154 } |
| 155 | 155 |
| 156 case R_V_LINE_TO: { | 156 case R_V_LINE_TO: { |
| 157 SkScalar y = path_elements[i++].arg; | 157 SkScalar y = path_elements[++i].arg; |
| 158 path.rLineTo(0, y); | 158 path.rLineTo(0, y); |
| 159 break; | 159 break; |
| 160 } | 160 } |
| 161 | 161 |
| 162 case CUBIC_TO: { | 162 case CUBIC_TO: { |
| 163 SkScalar x1 = path_elements[i++].arg; | 163 SkScalar x1 = path_elements[++i].arg; |
| 164 SkScalar y1 = path_elements[i++].arg; | 164 SkScalar y1 = path_elements[++i].arg; |
| 165 SkScalar x2 = path_elements[i++].arg; | 165 SkScalar x2 = path_elements[++i].arg; |
| 166 SkScalar y2 = path_elements[i++].arg; | 166 SkScalar y2 = path_elements[++i].arg; |
| 167 SkScalar x3 = path_elements[i++].arg; | 167 SkScalar x3 = path_elements[++i].arg; |
| 168 SkScalar y3 = path_elements[i++].arg; | 168 SkScalar y3 = path_elements[++i].arg; |
| 169 path.cubicTo(x1, y1, x2, y2, x3, y3); | 169 path.cubicTo(x1, y1, x2, y2, x3, y3); |
| 170 break; | 170 break; |
| 171 } | 171 } |
| 172 | 172 |
| 173 case R_CUBIC_TO: { | 173 case R_CUBIC_TO: { |
| 174 SkScalar x1 = path_elements[i++].arg; | 174 SkScalar x1 = path_elements[++i].arg; |
| 175 SkScalar y1 = path_elements[i++].arg; | 175 SkScalar y1 = path_elements[++i].arg; |
| 176 SkScalar x2 = path_elements[i++].arg; | 176 SkScalar x2 = path_elements[++i].arg; |
| 177 SkScalar y2 = path_elements[i++].arg; | 177 SkScalar y2 = path_elements[++i].arg; |
| 178 SkScalar x3 = path_elements[i++].arg; | 178 SkScalar x3 = path_elements[++i].arg; |
| 179 SkScalar y3 = path_elements[i++].arg; | 179 SkScalar y3 = path_elements[++i].arg; |
| 180 path.rCubicTo(x1, y1, x2, y2, x3, y3); | 180 path.rCubicTo(x1, y1, x2, y2, x3, y3); |
| 181 break; | 181 break; |
| 182 } | 182 } |
| 183 | 183 |
| 184 case CIRCLE: { |
| 185 SkScalar x = path_elements[++i].arg; |
| 186 SkScalar y = path_elements[++i].arg; |
| 187 SkScalar r = path_elements[++i].arg; |
| 188 path.addCircle(x, y, r); |
| 189 break; |
| 190 } |
| 191 |
| 184 case CLOSE: { | 192 case CLOSE: { |
| 185 path.close(); | 193 path.close(); |
| 186 break; | 194 break; |
| 187 } | 195 } |
| 188 | 196 |
| 189 case CIRCLE: { | |
| 190 SkScalar x = path_elements[i++].arg; | |
| 191 SkScalar y = path_elements[i++].arg; | |
| 192 SkScalar r = path_elements[i++].arg; | |
| 193 path.addCircle(x, y, r); | |
| 194 break; | |
| 195 } | |
| 196 | |
| 197 case END: | 197 case END: |
| 198 NOTREACHED(); | 198 NOTREACHED(); |
| 199 break; | 199 break; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 SkPaint paint; | 203 SkPaint paint; |
| 204 paint.setStyle(SkPaint::kFill_Style); | 204 paint.setStyle(SkPaint::kFill_Style); |
| 205 paint.setAntiAlias(true); | 205 paint.setAntiAlias(true); |
| 206 paint.setColor(color); | 206 paint.setColor(color); |
| 207 canvas->DrawPath(path, paint); | 207 canvas->DrawPath(path, paint); |
| 208 } | 208 } |
| 209 | 209 |
| 210 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { | 210 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { |
| 211 return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color); | 211 return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color); |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace gfx | 214 } // namespace gfx |
| OLD | NEW |