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" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 val->Set("rect", AsValue(rrect.rect())); | 102 val->Set("rect", AsValue(rrect.rect())); |
103 val->Set("radii", std::move(radii_val)); | 103 val->Set("radii", std::move(radii_val)); |
104 | 104 |
105 return std::move(val); | 105 return std::move(val); |
106 } | 106 } |
107 | 107 |
108 WARN_UNUSED_RESULT | 108 WARN_UNUSED_RESULT |
109 std::unique_ptr<base::Value> AsValue(const SkMatrix& matrix) { | 109 std::unique_ptr<base::Value> AsValue(const SkMatrix& matrix) { |
110 std::unique_ptr<base::ListValue> val(new base::ListValue()); | 110 std::unique_ptr<base::ListValue> val(new base::ListValue()); |
111 for (int i = 0; i < 9; ++i) | 111 for (int i = 0; i < 9; ++i) |
112 val->Append(AsValue(matrix[i]).release()); // no scoped_ptr-aware Append() v
ariant | 112 val->Append(AsValue(matrix[i])); // no scoped_ptr-aware Append() variant |
113 | 113 |
114 return std::move(val); | 114 return std::move(val); |
115 } | 115 } |
116 | 116 |
117 WARN_UNUSED_RESULT | 117 WARN_UNUSED_RESULT |
118 std::unique_ptr<base::Value> AsValue(SkColor color) { | 118 std::unique_ptr<base::Value> AsValue(SkColor color) { |
119 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 119 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); |
120 val->SetInteger("a", SkColorGetA(color)); | 120 val->SetInteger("a", SkColorGetA(color)); |
121 val->SetInteger("r", SkColorGetR(color)); | 121 val->SetInteger("r", SkColorGetR(color)); |
122 val->SetInteger("g", SkColorGetG(color)); | 122 val->SetInteger("g", SkColorGetG(color)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 builder.addFlag(flags & SkColorFilter::kAlphaUnchanged_Flag, | 163 builder.addFlag(flags & SkColorFilter::kAlphaUnchanged_Flag, |
164 "kAlphaUnchanged_Flag"); | 164 "kAlphaUnchanged_Flag"); |
165 | 165 |
166 val->SetString("flags", builder.str()); | 166 val->SetString("flags", builder.str()); |
167 } | 167 } |
168 | 168 |
169 SkScalar color_matrix[20]; | 169 SkScalar color_matrix[20]; |
170 if (filter.asColorMatrix(color_matrix)) { | 170 if (filter.asColorMatrix(color_matrix)) { |
171 std::unique_ptr<base::ListValue> color_matrix_val(new base::ListValue()); | 171 std::unique_ptr<base::ListValue> color_matrix_val(new base::ListValue()); |
172 for (unsigned i = 0; i < 20; ++i) | 172 for (unsigned i = 0; i < 20; ++i) |
173 color_matrix_val->Append(AsValue(color_matrix[i]).release()); | 173 color_matrix_val->Append(AsValue(color_matrix[i])); |
174 | 174 |
175 val->Set("color_matrix", std::move(color_matrix_val)); | 175 val->Set("color_matrix", std::move(color_matrix_val)); |
176 } | 176 } |
177 | 177 |
178 SkColor color; | 178 SkColor color; |
179 SkXfermode::Mode mode; | 179 SkXfermode::Mode mode; |
180 if (filter.asColorMode(&color, &mode)) { | 180 if (filter.asColorMode(&color, &mode)) { |
181 std::unique_ptr<base::DictionaryValue> color_mode_val( | 181 std::unique_ptr<base::DictionaryValue> color_mode_val( |
182 new base::DictionaryValue()); | 182 new base::DictionaryValue()); |
183 color_mode_val->Set("color", AsValue(color)); | 183 color_mode_val->Set("color", AsValue(color)); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 373 |
374 for(SkPath::Verb verb = iter.next(points, false); | 374 for(SkPath::Verb verb = iter.next(points, false); |
375 verb != SkPath::kDone_Verb; verb = iter.next(points, false)) { | 375 verb != SkPath::kDone_Verb; verb = iter.next(points, false)) { |
376 DCHECK_LT(static_cast<size_t>(verb), SK_ARRAY_COUNT(gVerbStrings)); | 376 DCHECK_LT(static_cast<size_t>(verb), SK_ARRAY_COUNT(gVerbStrings)); |
377 | 377 |
378 std::unique_ptr<base::DictionaryValue> verb_val( | 378 std::unique_ptr<base::DictionaryValue> verb_val( |
379 new base::DictionaryValue()); | 379 new base::DictionaryValue()); |
380 std::unique_ptr<base::ListValue> pts_val(new base::ListValue()); | 380 std::unique_ptr<base::ListValue> pts_val(new base::ListValue()); |
381 | 381 |
382 for (int i = 0; i < gPtsPerVerb[verb]; ++i) | 382 for (int i = 0; i < gPtsPerVerb[verb]; ++i) |
383 pts_val->Append(AsValue(points[i + gPtOffsetPerVerb[verb]]).release()); | 383 pts_val->Append(AsValue(points[i + gPtOffsetPerVerb[verb]])); |
384 | 384 |
385 verb_val->Set(gVerbStrings[verb], std::move(pts_val)); | 385 verb_val->Set(gVerbStrings[verb], std::move(pts_val)); |
386 | 386 |
387 if (SkPath::kConic_Verb == verb) | 387 if (SkPath::kConic_Verb == verb) |
388 verb_val->Set("weight", AsValue(iter.conicWeight())); | 388 verb_val->Set("weight", AsValue(iter.conicWeight())); |
389 | 389 |
390 verbs_val->Append(verb_val.release()); | 390 verbs_val->Append(std::move(verb_val)); |
391 } | 391 } |
392 val->Set("verbs", std::move(verbs_val)); | 392 val->Set("verbs", std::move(verbs_val)); |
393 | 393 |
394 return std::move(val); | 394 return std::move(val); |
395 } | 395 } |
396 | 396 |
397 template <typename T> | 397 template <typename T> |
398 WARN_UNUSED_RESULT std::unique_ptr<base::Value> AsListValue(const T array[], | 398 WARN_UNUSED_RESULT std::unique_ptr<base::Value> AsListValue(const T array[], |
399 size_t count) { | 399 size_t count) { |
400 std::unique_ptr<base::ListValue> val(new base::ListValue()); | 400 std::unique_ptr<base::ListValue> val(new base::ListValue()); |
401 | 401 |
402 for (size_t i = 0; i < count; ++i) | 402 for (size_t i = 0; i < count; ++i) |
403 val->Append(AsValue(array[i]).release()); | 403 val->Append(AsValue(array[i])); |
404 | 404 |
405 return std::move(val); | 405 return std::move(val); |
406 } | 406 } |
407 | 407 |
408 class OverdrawXfermode : public SkXfermode { | 408 class OverdrawXfermode : public SkXfermode { |
409 public: | 409 public: |
410 SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override { | 410 SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override { |
411 // This table encodes the color progression of the overdraw visualization | 411 // This table encodes the color progression of the overdraw visualization |
412 static const SkPMColor gTable[] = { | 412 static const SkPMColor gTable[] = { |
413 SkPackARGB32(0x00, 0x00, 0x00, 0x00), | 413 SkPackARGB32(0x00, 0x00, 0x00, 0x00), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; | 485 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; |
486 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); | 486 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); |
487 | 487 |
488 canvas_->op_records_.Append(op_record_); | 488 canvas_->op_records_.Append(op_record_); |
489 } | 489 } |
490 | 490 |
491 void addParam(const char name[], std::unique_ptr<base::Value> value) { | 491 void addParam(const char name[], std::unique_ptr<base::Value> value) { |
492 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); | 492 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); |
493 param->Set(name, std::move(value)); | 493 param->Set(name, std::move(value)); |
494 | 494 |
495 op_params_->Append(param.release()); | 495 op_params_->Append(std::move(param)); |
496 } | 496 } |
497 | 497 |
498 const SkPaint* paint() const { return &filtered_paint_; } | 498 const SkPaint* paint() const { return &filtered_paint_; } |
499 | 499 |
500 private: | 500 private: |
501 BenchmarkingCanvas* canvas_; | 501 BenchmarkingCanvas* canvas_; |
502 base::DictionaryValue* op_record_; | 502 base::DictionaryValue* op_record_; |
503 base::ListValue* op_params_; | 503 base::ListValue* op_params_; |
504 base::TimeTicks start_ticks_; | 504 base::TimeTicks start_ticks_; |
505 | 505 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 DCHECK(blob); | 798 DCHECK(blob); |
799 AutoOp op(this, "DrawTextBlob", &paint); | 799 AutoOp op(this, "DrawTextBlob", &paint); |
800 op.addParam("blob", AsValue(*blob)); | 800 op.addParam("blob", AsValue(*blob)); |
801 op.addParam("x", AsValue(x)); | 801 op.addParam("x", AsValue(x)); |
802 op.addParam("y", AsValue(y)); | 802 op.addParam("y", AsValue(y)); |
803 | 803 |
804 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); | 804 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); |
805 } | 805 } |
806 | 806 |
807 } // namespace skia | 807 } // namespace skia |
OLD | NEW |