| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "skia/ext/benchmarking_canvas.h" | 5 #include "skia/ext/benchmarking_canvas.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "third_party/skia/include/core/SkColorFilter.h" | 14 #include "third_party/skia/include/core/SkColorFilter.h" |
| 14 #include "third_party/skia/include/core/SkImageFilter.h" | 15 #include "third_party/skia/include/core/SkImageFilter.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "third_party/skia/include/core/SkPicture.h" | 18 #include "third_party/skia/include/core/SkPicture.h" |
| 18 #include "third_party/skia/include/core/SkRRect.h" | 19 #include "third_party/skia/include/core/SkRRect.h" |
| 19 #include "third_party/skia/include/core/SkRegion.h" | 20 #include "third_party/skia/include/core/SkRegion.h" |
| 20 #include "third_party/skia/include/core/SkString.h" | 21 #include "third_party/skia/include/core/SkString.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 std::string str() const { | 41 std::string str() const { |
| 41 return oss_.str(); | 42 return oss_.str(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 char separator_; | 46 char separator_; |
| 46 std::ostringstream oss_; | 47 std::ostringstream oss_; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 WARN_UNUSED_RESULT | |
| 50 std::unique_ptr<base::Value> AsValue(bool b) { | 50 std::unique_ptr<base::Value> AsValue(bool b) { |
| 51 std::unique_ptr<base::FundamentalValue> val(new base::FundamentalValue(b)); | 51 std::unique_ptr<base::FundamentalValue> val(new base::FundamentalValue(b)); |
| 52 | 52 |
| 53 return std::move(val); | 53 return std::move(val); |
| 54 } | 54 } |
| 55 | 55 |
| 56 WARN_UNUSED_RESULT | |
| 57 std::unique_ptr<base::Value> AsValue(SkScalar scalar) { | 56 std::unique_ptr<base::Value> AsValue(SkScalar scalar) { |
| 58 std::unique_ptr<base::FundamentalValue> val( | 57 std::unique_ptr<base::FundamentalValue> val( |
| 59 new base::FundamentalValue(scalar)); | 58 new base::FundamentalValue(scalar)); |
| 60 | 59 |
| 61 return std::move(val); | 60 return std::move(val); |
| 62 } | 61 } |
| 63 | 62 |
| 64 WARN_UNUSED_RESULT | |
| 65 std::unique_ptr<base::Value> AsValue(const SkSize& size) { | 63 std::unique_ptr<base::Value> AsValue(const SkSize& size) { |
| 66 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 64 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 67 val->Set("width", AsValue(size.width())); | 65 val->Set("width", AsValue(size.width())); |
| 68 val->Set("height", AsValue(size.height())); | 66 val->Set("height", AsValue(size.height())); |
| 69 | 67 |
| 70 return std::move(val); | 68 return std::move(val); |
| 71 } | 69 } |
| 72 | 70 |
| 73 WARN_UNUSED_RESULT | |
| 74 std::unique_ptr<base::Value> AsValue(const SkPoint& point) { | 71 std::unique_ptr<base::Value> AsValue(const SkPoint& point) { |
| 75 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 72 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 76 val->Set("x", AsValue(point.x())); | 73 val->Set("x", AsValue(point.x())); |
| 77 val->Set("y", AsValue(point.y())); | 74 val->Set("y", AsValue(point.y())); |
| 78 | 75 |
| 79 return std::move(val); | 76 return std::move(val); |
| 80 } | 77 } |
| 81 | 78 |
| 82 WARN_UNUSED_RESULT | |
| 83 std::unique_ptr<base::Value> AsValue(const SkRect& rect) { | 79 std::unique_ptr<base::Value> AsValue(const SkRect& rect) { |
| 84 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 80 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 85 val->Set("left", AsValue(rect.fLeft)); | 81 val->Set("left", AsValue(rect.fLeft)); |
| 86 val->Set("top", AsValue(rect.fTop)); | 82 val->Set("top", AsValue(rect.fTop)); |
| 87 val->Set("right", AsValue(rect.fRight)); | 83 val->Set("right", AsValue(rect.fRight)); |
| 88 val->Set("bottom", AsValue(rect.fBottom)); | 84 val->Set("bottom", AsValue(rect.fBottom)); |
| 89 | 85 |
| 90 return std::move(val); | 86 return std::move(val); |
| 91 } | 87 } |
| 92 | 88 |
| 93 WARN_UNUSED_RESULT | |
| 94 std::unique_ptr<base::Value> AsValue(const SkRRect& rrect) { | 89 std::unique_ptr<base::Value> AsValue(const SkRRect& rrect) { |
| 95 std::unique_ptr<base::DictionaryValue> radii_val(new base::DictionaryValue()); | 90 std::unique_ptr<base::DictionaryValue> radii_val(new base::DictionaryValue()); |
| 96 radii_val->Set("upper-left", AsValue(rrect.radii(SkRRect::kUpperLeft_Corner)))
; | 91 radii_val->Set("upper-left", AsValue(rrect.radii(SkRRect::kUpperLeft_Corner)))
; |
| 97 radii_val->Set("upper-right", AsValue(rrect.radii(SkRRect::kUpperRight_Corner)
)); | 92 radii_val->Set("upper-right", AsValue(rrect.radii(SkRRect::kUpperRight_Corner)
)); |
| 98 radii_val->Set("lower-right", AsValue(rrect.radii(SkRRect::kLowerRight_Corner)
)); | 93 radii_val->Set("lower-right", AsValue(rrect.radii(SkRRect::kLowerRight_Corner)
)); |
| 99 radii_val->Set("lower-left", AsValue(rrect.radii(SkRRect::kLowerLeft_Corner)))
; | 94 radii_val->Set("lower-left", AsValue(rrect.radii(SkRRect::kLowerLeft_Corner)))
; |
| 100 | 95 |
| 101 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 96 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 102 val->Set("rect", AsValue(rrect.rect())); | 97 val->Set("rect", AsValue(rrect.rect())); |
| 103 val->Set("radii", std::move(radii_val)); | 98 val->Set("radii", std::move(radii_val)); |
| 104 | 99 |
| 105 return std::move(val); | 100 return std::move(val); |
| 106 } | 101 } |
| 107 | 102 |
| 108 WARN_UNUSED_RESULT | |
| 109 std::unique_ptr<base::Value> AsValue(const SkMatrix& matrix) { | 103 std::unique_ptr<base::Value> AsValue(const SkMatrix& matrix) { |
| 110 std::unique_ptr<base::ListValue> val(new base::ListValue()); | 104 std::unique_ptr<base::ListValue> val(new base::ListValue()); |
| 111 for (int i = 0; i < 9; ++i) | 105 for (int i = 0; i < 9; ++i) |
| 112 val->Append(AsValue(matrix[i])); // no scoped_ptr-aware Append() variant | 106 val->Append(AsValue(matrix[i])); |
| 113 | 107 |
| 114 return std::move(val); | 108 return std::move(val); |
| 115 } | 109 } |
| 116 | 110 |
| 117 WARN_UNUSED_RESULT | |
| 118 std::unique_ptr<base::Value> AsValue(SkColor color) { | 111 std::unique_ptr<base::Value> AsValue(SkColor color) { |
| 119 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 112 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 120 val->SetInteger("a", SkColorGetA(color)); | 113 val->SetInteger("a", SkColorGetA(color)); |
| 121 val->SetInteger("r", SkColorGetR(color)); | 114 val->SetInteger("r", SkColorGetR(color)); |
| 122 val->SetInteger("g", SkColorGetG(color)); | 115 val->SetInteger("g", SkColorGetG(color)); |
| 123 val->SetInteger("b", SkColorGetB(color)); | 116 val->SetInteger("b", SkColorGetB(color)); |
| 124 | 117 |
| 125 return std::move(val); | 118 return std::move(val); |
| 126 } | 119 } |
| 127 | 120 |
| 128 WARN_UNUSED_RESULT | |
| 129 std::unique_ptr<base::Value> AsValue(SkXfermode::Mode mode) { | 121 std::unique_ptr<base::Value> AsValue(SkXfermode::Mode mode) { |
| 130 std::unique_ptr<base::StringValue> val( | 122 std::unique_ptr<base::StringValue> val( |
| 131 new base::StringValue(SkXfermode::ModeName(mode))); | 123 new base::StringValue(SkXfermode::ModeName(mode))); |
| 132 | 124 |
| 133 return std::move(val); | 125 return std::move(val); |
| 134 } | 126 } |
| 135 | 127 |
| 136 WARN_UNUSED_RESULT | |
| 137 std::unique_ptr<base::Value> AsValue(SkCanvas::PointMode mode) { | 128 std::unique_ptr<base::Value> AsValue(SkCanvas::PointMode mode) { |
| 138 static const char* gModeStrings[] = { "Points", "Lines", "Polygon" }; | 129 static const char* gModeStrings[] = { "Points", "Lines", "Polygon" }; |
| 139 DCHECK_LT(static_cast<size_t>(mode), SK_ARRAY_COUNT(gModeStrings)); | 130 DCHECK_LT(static_cast<size_t>(mode), SK_ARRAY_COUNT(gModeStrings)); |
| 140 | 131 |
| 141 std::unique_ptr<base::StringValue> val( | 132 std::unique_ptr<base::StringValue> val( |
| 142 new base::StringValue(gModeStrings[mode])); | 133 new base::StringValue(gModeStrings[mode])); |
| 143 | 134 |
| 144 return std::move(val); | 135 return std::move(val); |
| 145 } | 136 } |
| 146 | 137 |
| 147 WARN_UNUSED_RESULT | |
| 148 std::unique_ptr<base::Value> AsValue(const SkXfermode& xfermode) { | 138 std::unique_ptr<base::Value> AsValue(const SkXfermode& xfermode) { |
| 149 SkXfermode::Mode mode; | 139 SkXfermode::Mode mode; |
| 150 if (xfermode.asMode(&mode)) | 140 if (xfermode.asMode(&mode)) |
| 151 return AsValue(mode); | 141 return AsValue(mode); |
| 152 | 142 |
| 153 std::unique_ptr<base::StringValue> val(new base::StringValue("unknown")); | 143 std::unique_ptr<base::StringValue> val(new base::StringValue("unknown")); |
| 154 return std::move(val); | 144 return std::move(val); |
| 155 } | 145 } |
| 156 | 146 |
| 157 WARN_UNUSED_RESULT | |
| 158 std::unique_ptr<base::Value> AsValue(const SkColorFilter& filter) { | 147 std::unique_ptr<base::Value> AsValue(const SkColorFilter& filter) { |
| 159 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 148 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 160 | 149 |
| 161 if (unsigned flags = filter.getFlags()) { | 150 if (unsigned flags = filter.getFlags()) { |
| 162 FlagsBuilder builder('|'); | 151 FlagsBuilder builder('|'); |
| 163 builder.addFlag(flags & SkColorFilter::kAlphaUnchanged_Flag, | 152 builder.addFlag(flags & SkColorFilter::kAlphaUnchanged_Flag, |
| 164 "kAlphaUnchanged_Flag"); | 153 "kAlphaUnchanged_Flag"); |
| 165 | 154 |
| 166 val->SetString("flags", builder.str()); | 155 val->SetString("flags", builder.str()); |
| 167 } | 156 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 if (filter.asComponentTable(nullptr)) { | 178 if (filter.asComponentTable(nullptr)) { |
| 190 std::unique_ptr<base::DictionaryValue> component_table_val( | 179 std::unique_ptr<base::DictionaryValue> component_table_val( |
| 191 new base::DictionaryValue()); | 180 new base::DictionaryValue()); |
| 192 // use this as a marker for now | 181 // use this as a marker for now |
| 193 val->Set("component_table", std::move(component_table_val)); | 182 val->Set("component_table", std::move(component_table_val)); |
| 194 } | 183 } |
| 195 | 184 |
| 196 return std::move(val); | 185 return std::move(val); |
| 197 } | 186 } |
| 198 | 187 |
| 199 WARN_UNUSED_RESULT | |
| 200 std::unique_ptr<base::Value> AsValue(const SkImageFilter& filter) { | 188 std::unique_ptr<base::Value> AsValue(const SkImageFilter& filter) { |
| 201 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 189 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 202 val->SetInteger("inputs", filter.countInputs()); | 190 val->SetInteger("inputs", filter.countInputs()); |
| 203 | 191 |
| 204 SkColorFilter* color_filter; | 192 SkColorFilter* color_filter; |
| 205 if (filter.asColorFilter(&color_filter)) { | 193 if (filter.asColorFilter(&color_filter)) { |
| 206 val->Set("color_filter", AsValue(*color_filter)); | 194 val->Set("color_filter", AsValue(*color_filter)); |
| 207 SkSafeUnref(color_filter); // ref'd in asColorFilter | 195 SkSafeUnref(color_filter); // ref'd in asColorFilter |
| 208 } | 196 } |
| 209 | 197 |
| 210 return std::move(val); | 198 return std::move(val); |
| 211 } | 199 } |
| 212 | 200 |
| 213 WARN_UNUSED_RESULT | |
| 214 std::unique_ptr<base::Value> AsValue(const SkPaint& paint) { | 201 std::unique_ptr<base::Value> AsValue(const SkPaint& paint) { |
| 215 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 202 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 216 SkPaint default_paint; | 203 SkPaint default_paint; |
| 217 | 204 |
| 218 if (paint.getColor() != default_paint.getColor()) | 205 if (paint.getColor() != default_paint.getColor()) |
| 219 val->Set("Color", AsValue(paint.getColor())); | 206 val->Set("Color", AsValue(paint.getColor())); |
| 220 | 207 |
| 221 if (paint.getStyle() != default_paint.getStyle()) { | 208 if (paint.getStyle() != default_paint.getStyle()) { |
| 222 static const char* gStyleStrings[] = { "Fill", "Stroke", "StrokeFill" }; | 209 static const char* gStyleStrings[] = { "Fill", "Stroke", "StrokeFill" }; |
| 223 DCHECK_LT(static_cast<size_t>(paint.getStyle()), | 210 DCHECK_LT(static_cast<size_t>(paint.getStyle()), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 255 |
| 269 if (paint.getColorFilter()) | 256 if (paint.getColorFilter()) |
| 270 val->Set("ColorFilter", AsValue(*paint.getColorFilter())); | 257 val->Set("ColorFilter", AsValue(*paint.getColorFilter())); |
| 271 | 258 |
| 272 if (paint.getImageFilter()) | 259 if (paint.getImageFilter()) |
| 273 val->Set("ImageFilter", AsValue(*paint.getImageFilter())); | 260 val->Set("ImageFilter", AsValue(*paint.getImageFilter())); |
| 274 | 261 |
| 275 return std::move(val); | 262 return std::move(val); |
| 276 } | 263 } |
| 277 | 264 |
| 278 WARN_UNUSED_RESULT | |
| 279 std::unique_ptr<base::Value> SaveLayerFlagsAsValue( | 265 std::unique_ptr<base::Value> SaveLayerFlagsAsValue( |
| 280 SkCanvas::SaveLayerFlags flags) { | 266 SkCanvas::SaveLayerFlags flags) { |
| 281 FlagsBuilder builder('|'); | 267 FlagsBuilder builder('|'); |
| 282 builder.addFlag(flags & SkCanvas::kIsOpaque_SaveLayerFlag, | 268 builder.addFlag(flags & SkCanvas::kIsOpaque_SaveLayerFlag, |
| 283 "kIsOpaque"); | 269 "kIsOpaque"); |
| 284 builder.addFlag(flags & SkCanvas::kPreserveLCDText_SaveLayerFlag, | 270 builder.addFlag(flags & SkCanvas::kPreserveLCDText_SaveLayerFlag, |
| 285 "kPreserveLCDText"); | 271 "kPreserveLCDText"); |
| 286 | 272 |
| 287 std::unique_ptr<base::StringValue> val(new base::StringValue(builder.str())); | 273 std::unique_ptr<base::StringValue> val(new base::StringValue(builder.str())); |
| 288 | 274 |
| 289 return std::move(val); | 275 return std::move(val); |
| 290 } | 276 } |
| 291 | 277 |
| 292 WARN_UNUSED_RESULT | |
| 293 std::unique_ptr<base::Value> AsValue(SkRegion::Op op) { | 278 std::unique_ptr<base::Value> AsValue(SkRegion::Op op) { |
| 294 static const char* gOpStrings[] = { "Difference", | 279 static const char* gOpStrings[] = { "Difference", |
| 295 "Intersect", | 280 "Intersect", |
| 296 "Union", | 281 "Union", |
| 297 "XOR", | 282 "XOR", |
| 298 "ReverseDifference", | 283 "ReverseDifference", |
| 299 "Replace" | 284 "Replace" |
| 300 }; | 285 }; |
| 301 DCHECK_LT(static_cast<size_t>(op), SK_ARRAY_COUNT(gOpStrings)); | 286 DCHECK_LT(static_cast<size_t>(op), SK_ARRAY_COUNT(gOpStrings)); |
| 302 std::unique_ptr<base::StringValue> val(new base::StringValue(gOpStrings[op])); | 287 std::unique_ptr<base::StringValue> val(new base::StringValue(gOpStrings[op])); |
| 303 return std::move(val); | 288 return std::move(val); |
| 304 } | 289 } |
| 305 | 290 |
| 306 WARN_UNUSED_RESULT | |
| 307 std::unique_ptr<base::Value> AsValue(const SkRegion& region) { | 291 std::unique_ptr<base::Value> AsValue(const SkRegion& region) { |
| 308 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 292 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 309 val->Set("bounds", AsValue(SkRect::Make(region.getBounds()))); | 293 val->Set("bounds", AsValue(SkRect::Make(region.getBounds()))); |
| 310 | 294 |
| 311 return std::move(val); | 295 return std::move(val); |
| 312 } | 296 } |
| 313 | 297 |
| 314 WARN_UNUSED_RESULT | |
| 315 std::unique_ptr<base::Value> AsValue(const SkBitmap& bitmap) { | 298 std::unique_ptr<base::Value> AsValue(const SkBitmap& bitmap) { |
| 316 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 299 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 317 val->Set("size", AsValue(SkSize::Make(bitmap.width(), bitmap.height()))); | 300 val->Set("size", AsValue(SkSize::Make(bitmap.width(), bitmap.height()))); |
| 318 | 301 |
| 319 return std::move(val); | 302 return std::move(val); |
| 320 } | 303 } |
| 321 | 304 |
| 322 WARN_UNUSED_RESULT | |
| 323 std::unique_ptr<base::Value> AsValue(const SkImage& image) { | 305 std::unique_ptr<base::Value> AsValue(const SkImage& image) { |
| 324 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 306 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 325 val->Set("size", AsValue(SkSize::Make(image.width(), image.height()))); | 307 val->Set("size", AsValue(SkSize::Make(image.width(), image.height()))); |
| 326 | 308 |
| 327 return std::move(val); | 309 return std::move(val); |
| 328 } | 310 } |
| 329 | 311 |
| 330 WARN_UNUSED_RESULT | |
| 331 std::unique_ptr<base::Value> AsValue(const SkTextBlob& blob) { | 312 std::unique_ptr<base::Value> AsValue(const SkTextBlob& blob) { |
| 332 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 313 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 333 val->Set("bounds", AsValue(blob.bounds())); | 314 val->Set("bounds", AsValue(blob.bounds())); |
| 334 | 315 |
| 335 return std::move(val); | 316 return std::move(val); |
| 336 } | 317 } |
| 337 | 318 |
| 338 WARN_UNUSED_RESULT | |
| 339 std::unique_ptr<base::Value> AsValue(const SkPath& path) { | 319 std::unique_ptr<base::Value> AsValue(const SkPath& path) { |
| 340 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 320 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
| 341 | 321 |
| 342 static const char* gFillStrings[] = | 322 static const char* gFillStrings[] = |
| 343 { "winding", "even-odd", "inverse-winding", "inverse-even-odd" }; | 323 { "winding", "even-odd", "inverse-winding", "inverse-even-odd" }; |
| 344 DCHECK_LT(static_cast<size_t>(path.getFillType()), | 324 DCHECK_LT(static_cast<size_t>(path.getFillType()), |
| 345 SK_ARRAY_COUNT(gFillStrings)); | 325 SK_ARRAY_COUNT(gFillStrings)); |
| 346 val->SetString("fill-type", gFillStrings[path.getFillType()]); | 326 val->SetString("fill-type", gFillStrings[path.getFillType()]); |
| 347 | 327 |
| 348 static const char* gConvexityStrings[] = { "Unknown", "Convex", "Concave" }; | 328 static const char* gConvexityStrings[] = { "Unknown", "Convex", "Concave" }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 verb_val->Set("weight", AsValue(iter.conicWeight())); | 368 verb_val->Set("weight", AsValue(iter.conicWeight())); |
| 389 | 369 |
| 390 verbs_val->Append(std::move(verb_val)); | 370 verbs_val->Append(std::move(verb_val)); |
| 391 } | 371 } |
| 392 val->Set("verbs", std::move(verbs_val)); | 372 val->Set("verbs", std::move(verbs_val)); |
| 393 | 373 |
| 394 return std::move(val); | 374 return std::move(val); |
| 395 } | 375 } |
| 396 | 376 |
| 397 template <typename T> | 377 template <typename T> |
| 398 WARN_UNUSED_RESULT std::unique_ptr<base::Value> AsListValue(const T array[], | 378 std::unique_ptr<base::Value> AsListValue(const T array[], size_t count) { |
| 399 size_t count) { | |
| 400 std::unique_ptr<base::ListValue> val(new base::ListValue()); | 379 std::unique_ptr<base::ListValue> val(new base::ListValue()); |
| 401 | 380 |
| 402 for (size_t i = 0; i < count; ++i) | 381 for (size_t i = 0; i < count; ++i) |
| 403 val->Append(AsValue(array[i])); | 382 val->Append(AsValue(array[i])); |
| 404 | 383 |
| 405 return std::move(val); | 384 return std::move(val); |
| 406 } | 385 } |
| 407 | 386 |
| 408 class OverdrawXfermode : public SkXfermode { | 387 class OverdrawXfermode : public SkXfermode { |
| 409 public: | 388 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 filtered_paint_.setAntiAlias(false); | 457 filtered_paint_.setAntiAlias(false); |
| 479 } | 458 } |
| 480 | 459 |
| 481 start_ticks_ = base::TimeTicks::Now(); | 460 start_ticks_ = base::TimeTicks::Now(); |
| 482 } | 461 } |
| 483 | 462 |
| 484 ~AutoOp() { | 463 ~AutoOp() { |
| 485 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; | 464 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; |
| 486 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); | 465 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); |
| 487 | 466 |
| 488 canvas_->op_records_.Append(op_record_); | 467 canvas_->op_records_.Append(std::move(op_record_)); |
| 489 } | 468 } |
| 490 | 469 |
| 491 void addParam(const char name[], std::unique_ptr<base::Value> value) { | 470 void addParam(const char name[], std::unique_ptr<base::Value> value) { |
| 492 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); | 471 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); |
| 493 param->Set(name, std::move(value)); | 472 param->Set(name, std::move(value)); |
| 494 | 473 |
| 495 op_params_->Append(std::move(param)); | 474 op_params_->Append(std::move(param)); |
| 496 } | 475 } |
| 497 | 476 |
| 498 const SkPaint* paint() const { return &filtered_paint_; } | 477 const SkPaint* paint() const { return &filtered_paint_; } |
| 499 | 478 |
| 500 private: | 479 private: |
| 501 BenchmarkingCanvas* canvas_; | 480 BenchmarkingCanvas* canvas_; |
| 502 base::DictionaryValue* op_record_; | 481 std::unique_ptr<base::DictionaryValue> op_record_; |
| 503 base::ListValue* op_params_; | 482 base::ListValue* op_params_; |
| 504 base::TimeTicks start_ticks_; | 483 base::TimeTicks start_ticks_; |
| 505 | 484 |
| 506 SkPaint filtered_paint_; | 485 SkPaint filtered_paint_; |
| 507 }; | 486 }; |
| 508 | 487 |
| 509 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) | 488 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) |
| 510 : INHERITED(canvas->imageInfo().width(), | 489 : INHERITED(canvas->imageInfo().width(), |
| 511 canvas->imageInfo().height()) | 490 canvas->imageInfo().height()) |
| 512 , flags_(flags) { | 491 , flags_(flags) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 DCHECK(blob); | 777 DCHECK(blob); |
| 799 AutoOp op(this, "DrawTextBlob", &paint); | 778 AutoOp op(this, "DrawTextBlob", &paint); |
| 800 op.addParam("blob", AsValue(*blob)); | 779 op.addParam("blob", AsValue(*blob)); |
| 801 op.addParam("x", AsValue(x)); | 780 op.addParam("x", AsValue(x)); |
| 802 op.addParam("y", AsValue(y)); | 781 op.addParam("y", AsValue(y)); |
| 803 | 782 |
| 804 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); | 783 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); |
| 805 } | 784 } |
| 806 | 785 |
| 807 } // namespace skia | 786 } // namespace skia |
| OLD | NEW |