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

Side by Side Diff: skia/ext/benchmarking_canvas.cc

Issue 1925433002: Replace SkTLazy with base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No Optional Created 4 years, 7 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 // 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
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 } else {
473 filtered_paint_ = SkPaint();
bungeman-chromium 2016/04/27 19:59:34 I don't think we need this else clause, the filter
474 }
475
473 476
474 if (canvas->flags_ & kOverdrawVisualization_Flag) { 477 if (canvas->flags_ & kOverdrawVisualization_Flag) {
475 DCHECK(canvas->overdraw_xfermode_); 478 DCHECK(canvas->overdraw_xfermode_);
476 479
477 paint_ = paint ? filtered_paint_.set(*paint) : filtered_paint_.init(); 480 filtered_paint_.setXfermode(canvas->overdraw_xfermode_);
478 filtered_paint_.get()->setXfermode(canvas->overdraw_xfermode_); 481 filtered_paint_.setAntiAlias(false);
479 filtered_paint_.get()->setAntiAlias(false);
480 } 482 }
481 483
482 start_ticks_ = base::TimeTicks::Now(); 484 start_ticks_ = base::TimeTicks::Now();
483 } 485 }
484 486
485 ~AutoOp() { 487 ~AutoOp() {
486 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_; 488 base::TimeDelta ticks = base::TimeTicks::Now() - start_ticks_;
487 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF()); 489 op_record_->SetDouble("cmd_time", ticks.InMillisecondsF());
488 490
489 canvas_->op_records_.Append(op_record_); 491 canvas_->op_records_.Append(op_record_);
490 } 492 }
491 493
492 void addParam(const char name[], std::unique_ptr<base::Value> value) { 494 void addParam(const char name[], std::unique_ptr<base::Value> value) {
493 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue()); 495 std::unique_ptr<base::DictionaryValue> param(new base::DictionaryValue());
494 param->Set(name, std::move(value)); 496 param->Set(name, std::move(value));
495 497
496 op_params_->Append(param.release()); 498 op_params_->Append(param.release());
497 } 499 }
498 500
499 const SkPaint* paint() const { return paint_; } 501 const SkPaint* paint() const { return &filtered_paint_; }
500 502
501 private: 503 private:
502 BenchmarkingCanvas* canvas_; 504 BenchmarkingCanvas* canvas_;
503 base::DictionaryValue* op_record_; 505 base::DictionaryValue* op_record_;
504 base::ListValue* op_params_; 506 base::ListValue* op_params_;
505 base::TimeTicks start_ticks_; 507 base::TimeTicks start_ticks_;
506 508
507 const SkPaint* paint_; 509 SkPaint filtered_paint_;
508 SkTLazy<SkPaint> filtered_paint_;
509 }; 510 };
510 511
511 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) 512 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags)
512 : INHERITED(canvas->imageInfo().width(), 513 : INHERITED(canvas->imageInfo().width(),
513 canvas->imageInfo().height()) 514 canvas->imageInfo().height())
514 , flags_(flags) { 515 , flags_(flags) {
515 addCanvas(canvas); 516 addCanvas(canvas);
516 517
517 if (flags & kOverdrawVisualization_Flag) 518 if (flags & kOverdrawVisualization_Flag)
518 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>(); 519 overdraw_xfermode_ = sk_make_sp<OverdrawXfermode>();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 DCHECK(blob); 801 DCHECK(blob);
801 AutoOp op(this, "DrawTextBlob", &paint); 802 AutoOp op(this, "DrawTextBlob", &paint);
802 op.addParam("blob", AsValue(*blob)); 803 op.addParam("blob", AsValue(*blob));
803 op.addParam("x", AsValue(x)); 804 op.addParam("x", AsValue(x));
804 op.addParam("y", AsValue(y)); 805 op.addParam("y", AsValue(y));
805 806
806 INHERITED::onDrawTextBlob(blob, x, y, *op.paint()); 807 INHERITED::onDrawTextBlob(blob, x, y, *op.paint());
807 } 808 }
808 809
809 } // namespace skia 810 } // namespace skia
OLDNEW
« cc/playback/image_hijack_canvas.cc ('K') | « cc/playback/raster_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698