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

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

Issue 993893004: Add back overdraw visualization for Skia BenchmarkingCanvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove todo Created 5 years, 9 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
« no previous file with comments | « skia/ext/benchmarking_canvas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "skia/ext/benchmarking_canvas.h" 8 #include "skia/ext/benchmarking_canvas.h"
9 #include "skia/ext/refptr.h"
9 #include "third_party/skia/include/core/SkColorFilter.h" 10 #include "third_party/skia/include/core/SkColorFilter.h"
11 #include "third_party/skia/include/core/SkDrawFilter.h"
10 #include "third_party/skia/include/core/SkImageFilter.h" 12 #include "third_party/skia/include/core/SkImageFilter.h"
11 #include "third_party/skia/include/core/SkPicture.h" 13 #include "third_party/skia/include/core/SkPicture.h"
12 #include "third_party/skia/include/core/SkRegion.h" 14 #include "third_party/skia/include/core/SkRegion.h"
15 #include "third_party/skia/include/core/SkString.h"
13 #include "third_party/skia/include/core/SkTextBlob.h" 16 #include "third_party/skia/include/core/SkTextBlob.h"
14 #include "third_party/skia/include/core/SkXfermode.h" 17 #include "third_party/skia/include/core/SkXfermode.h"
15 18
16 namespace { 19 namespace {
17 20
18 class FlagsBuilder { 21 class FlagsBuilder {
19 public: 22 public:
20 FlagsBuilder(char separator) 23 FlagsBuilder(char separator)
21 : separator_(separator) {} 24 : separator_(separator) {}
22 25
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 WARN_UNUSED_RESULT 402 WARN_UNUSED_RESULT
400 scoped_ptr<base::Value> AsListValue(const T array[], size_t count) { 403 scoped_ptr<base::Value> AsListValue(const T array[], size_t count) {
401 scoped_ptr<base::ListValue> val(new base::ListValue()); 404 scoped_ptr<base::ListValue> val(new base::ListValue());
402 405
403 for (size_t i = 0; i < count; ++i) 406 for (size_t i = 0; i < count; ++i)
404 val->Append(AsValue(array[i]).release()); 407 val->Append(AsValue(array[i]).release());
405 408
406 return val.Pass(); 409 return val.Pass();
407 } 410 }
408 411
412 class OverdrawXfermode : public SkXfermode {
413 public:
414 SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override {
415 // This table encodes the color progression of the overdraw visualization
416 static const SkPMColor gTable[] = {
417 SkPackARGB32(0x00, 0x00, 0x00, 0x00),
418 SkPackARGB32(0xFF, 128, 158, 255),
419 SkPackARGB32(0xFF, 170, 185, 212),
420 SkPackARGB32(0xFF, 213, 195, 170),
421 SkPackARGB32(0xFF, 255, 192, 127),
422 SkPackARGB32(0xFF, 255, 185, 85),
423 SkPackARGB32(0xFF, 255, 165, 42),
424 SkPackARGB32(0xFF, 255, 135, 0),
425 SkPackARGB32(0xFF, 255, 95, 0),
426 SkPackARGB32(0xFF, 255, 50, 0),
427 SkPackARGB32(0xFF, 255, 0, 0)
428 };
429
robertphillips 2015/03/10 17:23:41 // TODO: seems like there should be a far faster w
f(malita) 2015/03/10 22:28:32 Refactored to use interpolation instead of table l
430 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable) - 1; ++i) {
431 if (gTable[i] == dst) {
432 return gTable[i + 1];
433 }
434 }
435
436 return gTable[SK_ARRAY_COUNT(gTable) - 1];
437 }
438
439 Factory getFactory() const override { return NULL; }
440 #ifndef SK_IGNORE_TO_STRING
441 void toString(SkString* str) const override { str->set("OverdrawXfermode"); }
442 #endif
robertphillips 2015/03/10 17:23:41 private: typedef SkXfermode INHERITED; ?
f(malita) 2015/03/10 22:28:32 Done.
443 };
444
445 class OverdrawFilter : public SkDrawFilter {
446 public:
447 OverdrawFilter() { fXferMode = skia::AdoptRef(new OverdrawXfermode); }
448
449 bool filter(SkPaint* p, Type) override {
450 p->setXfermode(fXferMode.get());
451 return true;
452 }
453
454 private:
455 typedef SkDrawFilter INHERITED;
456
457 skia::RefPtr<SkXfermode> fXferMode;
458 };
459
409 } // namespace 460 } // namespace
410 461
411 namespace skia { 462 namespace skia {
412 463
413 class BenchmarkingCanvas::AutoOp { 464 class BenchmarkingCanvas::AutoOp {
414 public: 465 public:
415 AutoOp(BenchmarkingCanvas* canvas, const char op_name[], 466 AutoOp(BenchmarkingCanvas* canvas, const char op_name[],
416 const SkPaint* paint = nullptr) 467 const SkPaint* paint = nullptr)
417 : canvas_(canvas) 468 : canvas_(canvas)
418 , op_record_(new base::DictionaryValue()) 469 , op_record_(new base::DictionaryValue())
(...skipping 30 matching lines...) Expand all
449 base::DictionaryValue* op_record_; 500 base::DictionaryValue* op_record_;
450 base::ListValue* op_params_; 501 base::ListValue* op_params_;
451 base::TimeTicks start_ticks_; 502 base::TimeTicks start_ticks_;
452 }; 503 };
453 504
454 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags) 505 BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags)
455 : INHERITED(canvas->imageInfo().width(), 506 : INHERITED(canvas->imageInfo().width(),
456 canvas->imageInfo().height()) 507 canvas->imageInfo().height())
457 , flags_(flags) { 508 , flags_(flags) {
458 addCanvas(canvas); 509 addCanvas(canvas);
510
511 if (flags & kOverdrawVisualization_Flag) {
512 skia::RefPtr<SkDrawFilter> draw_filter = skia::AdoptRef(new OverdrawFilter);
513 this->setDrawFilter(draw_filter.get());
514 }
459 } 515 }
460 516
461 BenchmarkingCanvas::~BenchmarkingCanvas() { 517 BenchmarkingCanvas::~BenchmarkingCanvas() {
462 } 518 }
463 519
464 size_t BenchmarkingCanvas::CommandCount() const { 520 size_t BenchmarkingCanvas::CommandCount() const {
465 return op_records_.GetSize(); 521 return op_records_.GetSize();
466 } 522 }
467 523
468 const base::ListValue& BenchmarkingCanvas::Commands() const { 524 const base::ListValue& BenchmarkingCanvas::Commands() const {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 DCHECK(blob); 808 DCHECK(blob);
753 AutoOp op(this, "DrawTextBlob", &paint); 809 AutoOp op(this, "DrawTextBlob", &paint);
754 op.addParam("blob", AsValue(*blob)); 810 op.addParam("blob", AsValue(*blob));
755 op.addParam("x", AsValue(x)); 811 op.addParam("x", AsValue(x));
756 op.addParam("y", AsValue(y)); 812 op.addParam("y", AsValue(y));
757 813
758 INHERITED::onDrawTextBlob(blob, x, y, paint); 814 INHERITED::onDrawTextBlob(blob, x, y, paint);
759 } 815 }
760 816
761 } // namespace skia 817 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/benchmarking_canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698