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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/LoggingCanvas.cpp

Issue 2807923002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/graphics (Closed)
Patch Set: fix typo Created 3 years, 8 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 String PointModeName(SkCanvas::PointMode mode) { 80 String PointModeName(SkCanvas::PointMode mode) {
81 switch (mode) { 81 switch (mode) {
82 case SkCanvas::kPoints_PointMode: 82 case SkCanvas::kPoints_PointMode:
83 return "Points"; 83 return "Points";
84 case SkCanvas::kLines_PointMode: 84 case SkCanvas::kLines_PointMode:
85 return "Lines"; 85 return "Lines";
86 case SkCanvas::kPolygon_PointMode: 86 case SkCanvas::kPolygon_PointMode:
87 return "Polygon"; 87 return "Polygon";
88 default: 88 default:
89 ASSERT_NOT_REACHED(); 89 NOTREACHED();
90 return "?"; 90 return "?";
91 }; 91 };
92 } 92 }
93 93
94 std::unique_ptr<JSONObject> ObjectForSkPoint(const SkPoint& point) { 94 std::unique_ptr<JSONObject> ObjectForSkPoint(const SkPoint& point) {
95 std::unique_ptr<JSONObject> point_item = JSONObject::Create(); 95 std::unique_ptr<JSONObject> point_item = JSONObject::Create();
96 point_item->SetDouble("x", point.x()); 96 point_item->SetDouble("x", point.x());
97 point_item->SetDouble("y", point.y()); 97 point_item->SetDouble("y", point.y());
98 return point_item; 98 return point_item;
99 } 99 }
(...skipping 23 matching lines...) Expand all
123 return "Rect"; 123 return "Rect";
124 case SkRRect::kOval_Type: 124 case SkRRect::kOval_Type:
125 return "Oval"; 125 return "Oval";
126 case SkRRect::kSimple_Type: 126 case SkRRect::kSimple_Type:
127 return "Simple"; 127 return "Simple";
128 case SkRRect::kNinePatch_Type: 128 case SkRRect::kNinePatch_Type:
129 return "Nine-patch"; 129 return "Nine-patch";
130 case SkRRect::kComplex_Type: 130 case SkRRect::kComplex_Type:
131 return "Complex"; 131 return "Complex";
132 default: 132 default:
133 ASSERT_NOT_REACHED(); 133 NOTREACHED();
134 return "?"; 134 return "?";
135 }; 135 };
136 } 136 }
137 137
138 String RadiusName(SkRRect::Corner corner) { 138 String RadiusName(SkRRect::Corner corner) {
139 switch (corner) { 139 switch (corner) {
140 case SkRRect::kUpperLeft_Corner: 140 case SkRRect::kUpperLeft_Corner:
141 return "upperLeftRadius"; 141 return "upperLeftRadius";
142 case SkRRect::kUpperRight_Corner: 142 case SkRRect::kUpperRight_Corner:
143 return "upperRightRadius"; 143 return "upperRightRadius";
144 case SkRRect::kLowerRight_Corner: 144 case SkRRect::kLowerRight_Corner:
145 return "lowerRightRadius"; 145 return "lowerRightRadius";
146 case SkRRect::kLowerLeft_Corner: 146 case SkRRect::kLowerLeft_Corner:
147 return "lowerLeftRadius"; 147 return "lowerLeftRadius";
148 default: 148 default:
149 ASSERT_NOT_REACHED(); 149 NOTREACHED();
150 return "?"; 150 return "?";
151 } 151 }
152 } 152 }
153 153
154 std::unique_ptr<JSONObject> ObjectForSkRRect(const SkRRect& rrect) { 154 std::unique_ptr<JSONObject> ObjectForSkRRect(const SkRRect& rrect) {
155 std::unique_ptr<JSONObject> rrect_item = JSONObject::Create(); 155 std::unique_ptr<JSONObject> rrect_item = JSONObject::Create();
156 rrect_item->SetString("type", RrectTypeName(rrect.type())); 156 rrect_item->SetString("type", RrectTypeName(rrect.type()));
157 rrect_item->SetDouble("left", rrect.rect().left()); 157 rrect_item->SetDouble("left", rrect.rect().left());
158 rrect_item->SetDouble("top", rrect.rect().top()); 158 rrect_item->SetDouble("top", rrect.rect().top());
159 rrect_item->SetDouble("right", rrect.rect().right()); 159 rrect_item->SetDouble("right", rrect.rect().right());
160 rrect_item->SetDouble("bottom", rrect.rect().bottom()); 160 rrect_item->SetDouble("bottom", rrect.rect().bottom());
161 for (int i = 0; i < 4; ++i) 161 for (int i = 0; i < 4; ++i)
162 rrect_item->SetObject(RadiusName((SkRRect::Corner)i), 162 rrect_item->SetObject(RadiusName((SkRRect::Corner)i),
163 ObjectForRadius(rrect, (SkRRect::Corner)i)); 163 ObjectForRadius(rrect, (SkRRect::Corner)i));
164 return rrect_item; 164 return rrect_item;
165 } 165 }
166 166
167 String FillTypeName(SkPath::FillType type) { 167 String FillTypeName(SkPath::FillType type) {
168 switch (type) { 168 switch (type) {
169 case SkPath::kWinding_FillType: 169 case SkPath::kWinding_FillType:
170 return "Winding"; 170 return "Winding";
171 case SkPath::kEvenOdd_FillType: 171 case SkPath::kEvenOdd_FillType:
172 return "EvenOdd"; 172 return "EvenOdd";
173 case SkPath::kInverseWinding_FillType: 173 case SkPath::kInverseWinding_FillType:
174 return "InverseWinding"; 174 return "InverseWinding";
175 case SkPath::kInverseEvenOdd_FillType: 175 case SkPath::kInverseEvenOdd_FillType:
176 return "InverseEvenOdd"; 176 return "InverseEvenOdd";
177 default: 177 default:
178 ASSERT_NOT_REACHED(); 178 NOTREACHED();
179 return "?"; 179 return "?";
180 }; 180 };
181 } 181 }
182 182
183 String ConvexityName(SkPath::Convexity convexity) { 183 String ConvexityName(SkPath::Convexity convexity) {
184 switch (convexity) { 184 switch (convexity) {
185 case SkPath::kUnknown_Convexity: 185 case SkPath::kUnknown_Convexity:
186 return "Unknown"; 186 return "Unknown";
187 case SkPath::kConvex_Convexity: 187 case SkPath::kConvex_Convexity:
188 return "Convex"; 188 return "Convex";
189 case SkPath::kConcave_Convexity: 189 case SkPath::kConcave_Convexity:
190 return "Concave"; 190 return "Concave";
191 default: 191 default:
192 ASSERT_NOT_REACHED(); 192 NOTREACHED();
193 return "?"; 193 return "?";
194 }; 194 };
195 } 195 }
196 196
197 VerbParams SegmentParams(SkPath::Verb verb) { 197 VerbParams SegmentParams(SkPath::Verb verb) {
198 switch (verb) { 198 switch (verb) {
199 case SkPath::kMove_Verb: 199 case SkPath::kMove_Verb:
200 return VerbParams("Move", 1, 0); 200 return VerbParams("Move", 1, 0);
201 case SkPath::kLine_Verb: 201 case SkPath::kLine_Verb:
202 return VerbParams("Line", 1, 1); 202 return VerbParams("Line", 1, 1);
203 case SkPath::kQuad_Verb: 203 case SkPath::kQuad_Verb:
204 return VerbParams("Quad", 2, 1); 204 return VerbParams("Quad", 2, 1);
205 case SkPath::kConic_Verb: 205 case SkPath::kConic_Verb:
206 return VerbParams("Conic", 2, 1); 206 return VerbParams("Conic", 2, 1);
207 case SkPath::kCubic_Verb: 207 case SkPath::kCubic_Verb:
208 return VerbParams("Cubic", 3, 1); 208 return VerbParams("Cubic", 3, 1);
209 case SkPath::kClose_Verb: 209 case SkPath::kClose_Verb:
210 return VerbParams("Close", 0, 0); 210 return VerbParams("Close", 0, 0);
211 case SkPath::kDone_Verb: 211 case SkPath::kDone_Verb:
212 return VerbParams("Done", 0, 0); 212 return VerbParams("Done", 0, 0);
213 default: 213 default:
214 ASSERT_NOT_REACHED(); 214 NOTREACHED();
215 return VerbParams("?", 0, 0); 215 return VerbParams("?", 0, 0);
216 }; 216 };
217 } 217 }
218 218
219 std::unique_ptr<JSONObject> ObjectForSkPath(const SkPath& path) { 219 std::unique_ptr<JSONObject> ObjectForSkPath(const SkPath& path) {
220 std::unique_ptr<JSONObject> path_item = JSONObject::Create(); 220 std::unique_ptr<JSONObject> path_item = JSONObject::Create();
221 path_item->SetString("fillType", FillTypeName(path.getFillType())); 221 path_item->SetString("fillType", FillTypeName(path.getFillType()));
222 path_item->SetString("convexity", ConvexityName(path.getConvexity())); 222 path_item->SetString("convexity", ConvexityName(path.getConvexity()));
223 path_item->SetBoolean("isRect", path.isRect(0)); 223 path_item->SetBoolean("isRect", path.isRect(0));
224 SkPath::Iter iter(path, false); 224 SkPath::Iter iter(path, false);
225 SkPoint points[4]; 225 SkPoint points[4];
226 std::unique_ptr<JSONArray> path_points_array = JSONArray::Create(); 226 std::unique_ptr<JSONArray> path_points_array = JSONArray::Create();
227 for (SkPath::Verb verb = iter.next(points, false); verb != SkPath::kDone_Verb; 227 for (SkPath::Verb verb = iter.next(points, false); verb != SkPath::kDone_Verb;
228 verb = iter.next(points, false)) { 228 verb = iter.next(points, false)) {
229 VerbParams verb_params = SegmentParams(verb); 229 VerbParams verb_params = SegmentParams(verb);
230 std::unique_ptr<JSONObject> path_point_item = JSONObject::Create(); 230 std::unique_ptr<JSONObject> path_point_item = JSONObject::Create();
231 path_point_item->SetString("verb", verb_params.name); 231 path_point_item->SetString("verb", verb_params.name);
232 ASSERT(verb_params.point_count + verb_params.point_offset <= 232 DCHECK_LE(verb_params.point_count + verb_params.point_offset,
233 WTF_ARRAY_LENGTH(points)); 233 WTF_ARRAY_LENGTH(points));
234 path_point_item->SetArray( 234 path_point_item->SetArray(
235 "points", ArrayForSkPoints(verb_params.point_count, 235 "points", ArrayForSkPoints(verb_params.point_count,
236 points + verb_params.point_offset)); 236 points + verb_params.point_offset));
237 if (SkPath::kConic_Verb == verb) 237 if (SkPath::kConic_Verb == verb)
238 path_point_item->SetDouble("conicWeight", iter.conicWeight()); 238 path_point_item->SetDouble("conicWeight", iter.conicWeight());
239 path_points_array->PushObject(std::move(path_point_item)); 239 path_points_array->PushObject(std::move(path_point_item));
240 } 240 }
241 path_item->SetArray("pathPoints", std::move(path_points_array)); 241 path_item->SetArray("pathPoints", std::move(path_points_array));
242 path_item->SetObject("bounds", ObjectForSkRect(path.getBounds())); 242 path_item->SetObject("bounds", ObjectForSkRect(path.getBounds()));
243 return path_item; 243 return path_item;
244 } 244 }
245 245
246 String ColorTypeName(SkColorType color_type) { 246 String ColorTypeName(SkColorType color_type) {
247 switch (color_type) { 247 switch (color_type) {
248 case kUnknown_SkColorType: 248 case kUnknown_SkColorType:
249 return "None"; 249 return "None";
250 case kAlpha_8_SkColorType: 250 case kAlpha_8_SkColorType:
251 return "A8"; 251 return "A8";
252 case kIndex_8_SkColorType: 252 case kIndex_8_SkColorType:
253 return "Index8"; 253 return "Index8";
254 case kRGB_565_SkColorType: 254 case kRGB_565_SkColorType:
255 return "RGB565"; 255 return "RGB565";
256 case kARGB_4444_SkColorType: 256 case kARGB_4444_SkColorType:
257 return "ARGB4444"; 257 return "ARGB4444";
258 case kN32_SkColorType: 258 case kN32_SkColorType:
259 return "ARGB8888"; 259 return "ARGB8888";
260 default: 260 default:
261 ASSERT_NOT_REACHED(); 261 NOTREACHED();
262 return "?"; 262 return "?";
263 }; 263 };
264 } 264 }
265 265
266 std::unique_ptr<JSONObject> ObjectForBitmapData(const SkBitmap& bitmap) { 266 std::unique_ptr<JSONObject> ObjectForBitmapData(const SkBitmap& bitmap) {
267 Vector<unsigned char> output; 267 Vector<unsigned char> output;
268 268
269 if (sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap)) { 269 if (sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap)) {
270 ImagePixelLocker pixel_locker(image, kUnpremul_SkAlphaType, 270 ImagePixelLocker pixel_locker(image, kUnpremul_SkAlphaType,
271 kRGBA_8888_SkColorType); 271 kRGBA_8888_SkColorType);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 switch (filter_quality) { 359 switch (filter_quality) {
360 case kNone_SkFilterQuality: 360 case kNone_SkFilterQuality:
361 return "None"; 361 return "None";
362 case kLow_SkFilterQuality: 362 case kLow_SkFilterQuality:
363 return "Low"; 363 return "Low";
364 case kMedium_SkFilterQuality: 364 case kMedium_SkFilterQuality:
365 return "Medium"; 365 return "Medium";
366 case kHigh_SkFilterQuality: 366 case kHigh_SkFilterQuality:
367 return "High"; 367 return "High";
368 default: 368 default:
369 ASSERT_NOT_REACHED(); 369 NOTREACHED();
370 return "?"; 370 return "?";
371 }; 371 };
372 } 372 }
373 373
374 String TextAlignName(SkPaint::Align align) { 374 String TextAlignName(SkPaint::Align align) {
375 switch (align) { 375 switch (align) {
376 case SkPaint::kLeft_Align: 376 case SkPaint::kLeft_Align:
377 return "Left"; 377 return "Left";
378 case SkPaint::kCenter_Align: 378 case SkPaint::kCenter_Align:
379 return "Center"; 379 return "Center";
380 case SkPaint::kRight_Align: 380 case SkPaint::kRight_Align:
381 return "Right"; 381 return "Right";
382 default: 382 default:
383 ASSERT_NOT_REACHED(); 383 NOTREACHED();
384 return "?"; 384 return "?";
385 }; 385 };
386 } 386 }
387 387
388 String StrokeCapName(SkPaint::Cap cap) { 388 String StrokeCapName(SkPaint::Cap cap) {
389 switch (cap) { 389 switch (cap) {
390 case SkPaint::kButt_Cap: 390 case SkPaint::kButt_Cap:
391 return "Butt"; 391 return "Butt";
392 case SkPaint::kRound_Cap: 392 case SkPaint::kRound_Cap:
393 return "Round"; 393 return "Round";
394 case SkPaint::kSquare_Cap: 394 case SkPaint::kSquare_Cap:
395 return "Square"; 395 return "Square";
396 default: 396 default:
397 ASSERT_NOT_REACHED(); 397 NOTREACHED();
398 return "?"; 398 return "?";
399 }; 399 };
400 } 400 }
401 401
402 String StrokeJoinName(SkPaint::Join join) { 402 String StrokeJoinName(SkPaint::Join join) {
403 switch (join) { 403 switch (join) {
404 case SkPaint::kMiter_Join: 404 case SkPaint::kMiter_Join:
405 return "Miter"; 405 return "Miter";
406 case SkPaint::kRound_Join: 406 case SkPaint::kRound_Join:
407 return "Round"; 407 return "Round";
408 case SkPaint::kBevel_Join: 408 case SkPaint::kBevel_Join:
409 return "Bevel"; 409 return "Bevel";
410 default: 410 default:
411 ASSERT_NOT_REACHED(); 411 NOTREACHED();
412 return "?"; 412 return "?";
413 }; 413 };
414 } 414 }
415 415
416 String StyleName(SkPaint::Style style) { 416 String StyleName(SkPaint::Style style) {
417 switch (style) { 417 switch (style) {
418 case SkPaint::kFill_Style: 418 case SkPaint::kFill_Style:
419 return "Fill"; 419 return "Fill";
420 case SkPaint::kStroke_Style: 420 case SkPaint::kStroke_Style:
421 return "Stroke"; 421 return "Stroke";
422 case SkPaint::kStrokeAndFill_Style: 422 case SkPaint::kStrokeAndFill_Style:
423 return "StrokeAndFill"; 423 return "StrokeAndFill";
424 default: 424 default:
425 ASSERT_NOT_REACHED(); 425 NOTREACHED();
426 return "?"; 426 return "?";
427 }; 427 };
428 } 428 }
429 429
430 String TextEncodingName(SkPaint::TextEncoding encoding) { 430 String TextEncodingName(SkPaint::TextEncoding encoding) {
431 switch (encoding) { 431 switch (encoding) {
432 case SkPaint::kUTF8_TextEncoding: 432 case SkPaint::kUTF8_TextEncoding:
433 return "UTF-8"; 433 return "UTF-8";
434 case SkPaint::kUTF16_TextEncoding: 434 case SkPaint::kUTF16_TextEncoding:
435 return "UTF-16"; 435 return "UTF-16";
436 case SkPaint::kUTF32_TextEncoding: 436 case SkPaint::kUTF32_TextEncoding:
437 return "UTF-32"; 437 return "UTF-32";
438 case SkPaint::kGlyphID_TextEncoding: 438 case SkPaint::kGlyphID_TextEncoding:
439 return "GlyphID"; 439 return "GlyphID";
440 default: 440 default:
441 ASSERT_NOT_REACHED(); 441 NOTREACHED();
442 return "?"; 442 return "?";
443 }; 443 };
444 } 444 }
445 445
446 String HintingName(SkPaint::Hinting hinting) { 446 String HintingName(SkPaint::Hinting hinting) {
447 switch (hinting) { 447 switch (hinting) {
448 case SkPaint::kNo_Hinting: 448 case SkPaint::kNo_Hinting:
449 return "None"; 449 return "None";
450 case SkPaint::kSlight_Hinting: 450 case SkPaint::kSlight_Hinting:
451 return "Slight"; 451 return "Slight";
452 case SkPaint::kNormal_Hinting: 452 case SkPaint::kNormal_Hinting:
453 return "Normal"; 453 return "Normal";
454 case SkPaint::kFull_Hinting: 454 case SkPaint::kFull_Hinting:
455 return "Full"; 455 return "Full";
456 default: 456 default:
457 ASSERT_NOT_REACHED(); 457 NOTREACHED();
458 return "?"; 458 return "?";
459 }; 459 };
460 } 460 }
461 461
462 std::unique_ptr<JSONObject> ObjectForSkPaint(const SkPaint& paint) { 462 std::unique_ptr<JSONObject> ObjectForSkPaint(const SkPaint& paint) {
463 std::unique_ptr<JSONObject> paint_item = JSONObject::Create(); 463 std::unique_ptr<JSONObject> paint_item = JSONObject::Create();
464 paint_item->SetDouble("textSize", paint.getTextSize()); 464 paint_item->SetDouble("textSize", paint.getTextSize());
465 paint_item->SetDouble("textScaleX", paint.getTextScaleX()); 465 paint_item->SetDouble("textScaleX", paint.getTextScaleX());
466 paint_item->SetDouble("textSkewX", paint.getTextSkewX()); 466 paint_item->SetDouble("textSkewX", paint.getTextSkewX());
467 if (SkShader* shader = paint.getShader()) 467 if (SkShader* shader = paint.getShader())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return StringForUTFText(text, byte_length, encoding); 536 return StringForUTFText(text, byte_length, encoding);
537 case SkPaint::kGlyphID_TextEncoding: { 537 case SkPaint::kGlyphID_TextEncoding: {
538 WTF::Vector<SkUnichar> data_vector(byte_length / 2); 538 WTF::Vector<SkUnichar> data_vector(byte_length / 2);
539 SkUnichar* text_data = data_vector.Data(); 539 SkUnichar* text_data = data_vector.Data();
540 paint.glyphsToUnichars(static_cast<const uint16_t*>(text), 540 paint.glyphsToUnichars(static_cast<const uint16_t*>(text),
541 byte_length / 2, text_data); 541 byte_length / 2, text_data);
542 return WTF::UTF32LittleEndianEncoding().Decode( 542 return WTF::UTF32LittleEndianEncoding().Decode(
543 reinterpret_cast<const char*>(text_data), byte_length * 2); 543 reinterpret_cast<const char*>(text_data), byte_length * 2);
544 } 544 }
545 default: 545 default:
546 ASSERT_NOT_REACHED(); 546 NOTREACHED();
547 return "?"; 547 return "?";
548 } 548 }
549 } 549 }
550 550
551 } // namespace 551 } // namespace
552 552
553 class AutoLogger 553 class AutoLogger
554 : InterceptingCanvasBase::CanvasInterceptorBase<LoggingCanvas> { 554 : InterceptingCanvasBase::CanvasInterceptorBase<LoggingCanvas> {
555 public: 555 public:
556 explicit AutoLogger(LoggingCanvas* canvas) 556 explicit AutoLogger(LoggingCanvas* canvas)
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 record_as_json->SetArray("operations", canvas.Log()); 914 record_as_json->SetArray("operations", canvas.Log());
915 return record_as_json->ToPrettyJSONString(); 915 return record_as_json->ToPrettyJSONString();
916 } 916 }
917 917
918 void ShowPaintRecord(const PaintRecord* record) { 918 void ShowPaintRecord(const PaintRecord* record) {
919 WTFLogAlways("%s\n", RecordAsDebugString(record).Utf8().Data()); 919 WTFLogAlways("%s\n", RecordAsDebugString(record).Utf8().Data());
920 } 920 }
921 #endif 921 #endif
922 922
923 } // namespace blink 923 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698