| 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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "third_party/skia/include/core/SkColorFilter.h" | 13 #include "third_party/skia/include/core/SkColorFilter.h" |
| 14 #include "third_party/skia/include/core/SkImageFilter.h" | 14 #include "third_party/skia/include/core/SkImageFilter.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "third_party/skia/include/core/SkPicture.h" | 17 #include "third_party/skia/include/core/SkPicture.h" |
| 18 #include "third_party/skia/include/core/SkRRect.h" | 18 #include "third_party/skia/include/core/SkRRect.h" |
| 19 #include "third_party/skia/include/core/SkRegion.h" | 19 #include "third_party/skia/include/core/SkRegion.h" |
| 20 #include "third_party/skia/include/core/SkString.h" | 20 #include "third_party/skia/include/core/SkString.h" |
| 21 #include "third_party/skia/include/core/SkTLazy.h" | |
| 22 #include "third_party/skia/include/core/SkTextBlob.h" | 21 #include "third_party/skia/include/core/SkTextBlob.h" |
| 23 #include "third_party/skia/include/core/SkXfermode.h" | 22 #include "third_party/skia/include/core/SkXfermode.h" |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 class FlagsBuilder { | 26 class FlagsBuilder { |
| 28 public: | 27 public: |
| 29 FlagsBuilder(char separator) | 28 FlagsBuilder(char separator) |
| 30 : separator_(separator) {} | 29 : separator_(separator) {} |
| 31 | 30 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 void toString(SkString* str) const override { str->set("OverdrawXfermode"); } | 445 void toString(SkString* str) const override { str->set("OverdrawXfermode"); } |
| 447 #endif | 446 #endif |
| 448 }; | 447 }; |
| 449 | 448 |
| 450 } // namespace | 449 } // namespace |
| 451 | 450 |
| 452 namespace skia { | 451 namespace skia { |
| 453 | 452 |
| 454 class BenchmarkingCanvas::AutoOp { | 453 class BenchmarkingCanvas::AutoOp { |
| 455 public: | 454 public: |
| 455 // AutoOp objects are always scoped within draw call frames, |
| 456 // so the paint is guaranteed to be valid for their lifetime. |
| 456 AutoOp(BenchmarkingCanvas* canvas, const char op_name[], | 457 AutoOp(BenchmarkingCanvas* canvas, const char op_name[], |
| 457 const SkPaint* paint = nullptr) | 458 const SkPaint* paint = nullptr) |
| 458 : canvas_(canvas) | 459 : canvas_(canvas) |
| 459 , op_record_(new base::DictionaryValue()) | 460 , op_record_(new base::DictionaryValue()) |
| 460 , op_params_(new base::ListValue()) | 461 , op_params_(new base::ListValue()) { |
| 461 // AutoOp objects are always scoped within draw call frames, | |
| 462 // so the paint is guaranteed to be valid for their lifetime. | |
| 463 , paint_(paint) { | |
| 464 | 462 |
| 465 DCHECK(canvas); | 463 DCHECK(canvas); |
| 466 DCHECK(op_name); | 464 DCHECK(op_name); |
| 467 | 465 |
| 468 op_record_->SetString("cmd_string", op_name); | 466 op_record_->SetString("cmd_string", op_name); |
| 469 op_record_->Set("info", op_params_); | 467 op_record_->Set("info", op_params_); |
| 470 | 468 |
| 471 if (paint) | 469 if (paint) { |
| 472 this->addParam("paint", AsValue(*paint)); | 470 this->addParam("paint", AsValue(*paint)); |
| 471 filtered_paint_ = *paint; |
| 472 } |
| 473 | 473 |
| 474 if (canvas->flags_ & kOverdrawVisualization_Flag) { | 474 if (canvas->flags_ & kOverdrawVisualization_Flag) { |
| 475 DCHECK(canvas->overdraw_xfermode_); | 475 DCHECK(canvas->overdraw_xfermode_); |
| 476 | 476 |
| 477 paint_ = paint ? filtered_paint_.set(*paint) : filtered_paint_.init(); | 477 filtered_paint_.setXfermode(canvas->overdraw_xfermode_); |
| 478 filtered_paint_.get()->setXfermode(canvas->overdraw_xfermode_); | 478 filtered_paint_.setAntiAlias(false); |
| 479 filtered_paint_.get()->setAntiAlias(false); | |
| 480 } | 479 } |
| 481 | 480 |
| 482 start_ticks_ = base::TimeTicks::Now(); | 481 start_ticks_ = base::TimeTicks::Now(); |
| 483 } | 482 } |
| 484 | 483 |
| 485 ~AutoOp() { | 484 ~AutoOp() { |
| 486 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; | 485 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; |
| 487 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); | 486 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); |
| 488 | 487 |
| 489 canvas_->op_records_.Append(op_record_); | 488 canvas_->op_records_.Append(op_record_); |
| 490 } | 489 } |
| 491 | 490 |
| 492 void addParam(const char name[], std::unique_ptr<base::Value> value) { | 491 void addParam(const char name[], std::unique_ptr<base::Value> value) { |
| 493 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); | 492 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); |
| 494 param->Set(name, std::move(value)); | 493 param->Set(name, std::move(value)); |
| 495 | 494 |
| 496 op_params_->Append(param.release()); | 495 op_params_->Append(param.release()); |
| 497 } | 496 } |
| 498 | 497 |
| 499 const SkPaint* paint() const { return paint_; } | 498 const SkPaint* paint() const { return &filtered_paint_; } |
| 500 | 499 |
| 501 private: | 500 private: |
| 502 BenchmarkingCanvas* canvas_; | 501 BenchmarkingCanvas* canvas_; |
| 503 base::DictionaryValue* op_record_; | 502 base::DictionaryValue* op_record_; |
| 504 base::ListValue* op_params_; | 503 base::ListValue* op_params_; |
| 505 base::TimeTicks start_ticks_; | 504 base::TimeTicks start_ticks_; |
| 506 | 505 |
| 507 const SkPaint* paint_; | 506 SkPaint filtered_paint_; |
| 508 SkTLazy<SkPaint> filtered_paint_; | |
| 509 }; | 507 }; |
| 510 | 508 |
| 511 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) | 509 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) |
| 512 : INHERITED(canvas->imageInfo().width(), | 510 : INHERITED(canvas->imageInfo().width(), |
| 513 canvas->imageInfo().height()) | 511 canvas->imageInfo().height()) |
| 514 , flags_(flags) { | 512 , flags_(flags) { |
| 515 addCanvas(canvas); | 513 addCanvas(canvas); |
| 516 | 514 |
| 517 if (flags & kOverdrawVisualization_Flag) | 515 if (flags & kOverdrawVisualization_Flag) |
| 518 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>(); | 516 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>(); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 DCHECK(blob); | 798 DCHECK(blob); |
| 801 AutoOp op(this, "DrawTextBlob", &paint); | 799 AutoOp op(this, "DrawTextBlob", &paint); |
| 802 op.addParam("blob", AsValue(*blob)); | 800 op.addParam("blob", AsValue(*blob)); |
| 803 op.addParam("x", AsValue(x)); | 801 op.addParam("x", AsValue(x)); |
| 804 op.addParam("y", AsValue(y)); | 802 op.addParam("y", AsValue(y)); |
| 805 | 803 |
| 806 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); | 804 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); |
| 807 } | 805 } |
| 808 | 806 |
| 809 } // namespace skia | 807 } // namespace skia |
| OLD | NEW |