Chromium Code Reviews| 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/optional.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" |
| 21 #include "third_party/skia/include/core/SkTLazy.h" | |
| 22 #include "third_party/skia/include/core/SkTextBlob.h" | 22 #include "third_party/skia/include/core/SkTextBlob.h" |
| 23 #include "third_party/skia/include/core/SkXfermode.h" | 23 #include "third_party/skia/include/core/SkXfermode.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class FlagsBuilder { | 27 class FlagsBuilder { |
| 28 public: | 28 public: |
| 29 FlagsBuilder(char separator) | 29 FlagsBuilder(char separator) |
| 30 : separator_(separator) {} | 30 : separator_(separator) {} |
| 31 | 31 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 | 467 |
| 468 op_record_->SetString("cmd_string", op_name); | 468 op_record_->SetString("cmd_string", op_name); |
| 469 op_record_->Set("info", op_params_); | 469 op_record_->Set("info", op_params_); |
| 470 | 470 |
| 471 if (paint) | 471 if (paint) |
| 472 this->addParam("paint", AsValue(*paint)); | 472 this->addParam("paint", AsValue(*paint)); |
| 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 if (paint) { |
| 478 filtered_paint_.get()->setXfermode(canvas->overdraw_xfermode_); | 478 filtered_paint_ = *paint; |
| 479 filtered_paint_.get()->setAntiAlias(false); | 479 } else { |
| 480 filtered_paint_.emplace(); | |
| 481 } | |
| 482 paint_ = &(*filtered_paint_); | |
|
danakj
2016/04/27 18:27:52
nit: no ()
not seeing the point of the paint_ mem
| |
| 483 filtered_paint_->setXfermode(canvas->overdraw_xfermode_); | |
| 484 filtered_paint_->setAntiAlias(false); | |
| 480 } | 485 } |
| 481 | 486 |
| 482 start_ticks_ = base::TimeTicks::Now(); | 487 start_ticks_ = base::TimeTicks::Now(); |
| 483 } | 488 } |
| 484 | 489 |
| 485 ~AutoOp() { | 490 ~AutoOp() { |
| 486 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; | 491 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; |
| 487 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); | 492 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); |
| 488 | 493 |
| 489 canvas_->op_records_.Append(op_record_); | 494 canvas_->op_records_.Append(op_record_); |
| 490 } | 495 } |
| 491 | 496 |
| 492 void addParam(const char name[], std::unique_ptr<base::Value> value) { | 497 void addParam(const char name[], std::unique_ptr<base::Value> value) { |
| 493 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); | 498 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); |
| 494 param->Set(name, std::move(value)); | 499 param->Set(name, std::move(value)); |
| 495 | 500 |
| 496 op_params_->Append(param.release()); | 501 op_params_->Append(param.release()); |
| 497 } | 502 } |
| 498 | 503 |
| 499 const SkPaint* paint() const { return paint_; } | 504 const SkPaint* paint() const { return paint_; } |
| 500 | 505 |
| 501 private: | 506 private: |
| 502 BenchmarkingCanvas* canvas_; | 507 BenchmarkingCanvas* canvas_; |
| 503 base::DictionaryValue* op_record_; | 508 base::DictionaryValue* op_record_; |
| 504 base::ListValue* op_params_; | 509 base::ListValue* op_params_; |
| 505 base::TimeTicks start_ticks_; | 510 base::TimeTicks start_ticks_; |
| 506 | 511 |
| 507 const SkPaint* paint_; | 512 const SkPaint* paint_; |
| 508 SkTLazy<SkPaint> filtered_paint_; | 513 base::Optional<SkPaint> filtered_paint_; |
| 509 }; | 514 }; |
| 510 | 515 |
| 511 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) | 516 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) |
| 512 : INHERITED(canvas->imageInfo().width(), | 517 : INHERITED(canvas->imageInfo().width(), |
| 513 canvas->imageInfo().height()) | 518 canvas->imageInfo().height()) |
| 514 , flags_(flags) { | 519 , flags_(flags) { |
| 515 addCanvas(canvas); | 520 addCanvas(canvas); |
| 516 | 521 |
| 517 if (flags & kOverdrawVisualization_Flag) | 522 if (flags & kOverdrawVisualization_Flag) |
| 518 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>(); | 523 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>(); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 DCHECK(blob); | 805 DCHECK(blob); |
| 801 AutoOp op(this, "DrawTextBlob", &paint); | 806 AutoOp op(this, "DrawTextBlob", &paint); |
| 802 op.addParam("blob", AsValue(*blob)); | 807 op.addParam("blob", AsValue(*blob)); |
| 803 op.addParam("x", AsValue(x)); | 808 op.addParam("x", AsValue(x)); |
| 804 op.addParam("y", AsValue(y)); | 809 op.addParam("y", AsValue(y)); |
| 805 | 810 |
| 806 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); | 811 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); |
| 807 } | 812 } |
| 808 | 813 |
| 809 } // namespace skia | 814 } // namespace skia |
| OLD | NEW |