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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/benchmarking_canvas.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/benchmarking_canvas.cc
diff --git a/skia/ext/benchmarking_canvas.cc b/skia/ext/benchmarking_canvas.cc
index 2af0d1a956ae58292ffe33461c97c39cdde30afd..b2c17288282de130441dd1b17b21e326d08aa681 100644
--- a/skia/ext/benchmarking_canvas.cc
+++ b/skia/ext/benchmarking_canvas.cc
@@ -6,10 +6,13 @@
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "skia/ext/benchmarking_canvas.h"
+#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkColorFilter.h"
+#include "third_party/skia/include/core/SkDrawFilter.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkRegion.h"
+#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTextBlob.h"
#include "third_party/skia/include/core/SkXfermode.h"
@@ -406,6 +409,54 @@ scoped_ptr<base::Value> AsListValue(const T array[], size_t count) {
return val.Pass();
}
+class OverdrawXfermode : public SkXfermode {
+public:
+ SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override {
+ // This table encodes the color progression of the overdraw visualization
+ static const SkPMColor gTable[] = {
+ SkPackARGB32(0x00, 0x00, 0x00, 0x00),
+ SkPackARGB32(0xFF, 128, 158, 255),
+ SkPackARGB32(0xFF, 170, 185, 212),
+ SkPackARGB32(0xFF, 213, 195, 170),
+ SkPackARGB32(0xFF, 255, 192, 127),
+ SkPackARGB32(0xFF, 255, 185, 85),
+ SkPackARGB32(0xFF, 255, 165, 42),
+ SkPackARGB32(0xFF, 255, 135, 0),
+ SkPackARGB32(0xFF, 255, 95, 0),
+ SkPackARGB32(0xFF, 255, 50, 0),
+ SkPackARGB32(0xFF, 255, 0, 0)
+ };
+
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
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gTable) - 1; ++i) {
+ if (gTable[i] == dst) {
+ return gTable[i + 1];
+ }
+ }
+
+ return gTable[SK_ARRAY_COUNT(gTable) - 1];
+ }
+
+ Factory getFactory() const override { return NULL; }
+#ifndef SK_IGNORE_TO_STRING
+ void toString(SkString* str) const override { str->set("OverdrawXfermode"); }
+#endif
robertphillips 2015/03/10 17:23:41 private: typedef SkXfermode INHERITED; ?
f(malita) 2015/03/10 22:28:32 Done.
+};
+
+class OverdrawFilter : public SkDrawFilter {
+public:
+ OverdrawFilter() { fXferMode = skia::AdoptRef(new OverdrawXfermode); }
+
+ bool filter(SkPaint* p, Type) override {
+ p->setXfermode(fXferMode.get());
+ return true;
+ }
+
+private:
+ typedef SkDrawFilter INHERITED;
+
+ skia::RefPtr<SkXfermode> fXferMode;
+};
+
} // namespace
namespace skia {
@@ -456,6 +507,11 @@ BenchmarkingCanvas::BenchmarkingCanvas(SkCanvas* canvas, unsigned flags)
canvas->imageInfo().height())
, flags_(flags) {
addCanvas(canvas);
+
+ if (flags & kOverdrawVisualization_Flag) {
+ skia::RefPtr<SkDrawFilter> draw_filter = skia::AdoptRef(new OverdrawFilter);
+ this->setDrawFilter(draw_filter.get());
+ }
}
BenchmarkingCanvas::~BenchmarkingCanvas() {
« 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