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

Unified Diff: tools/VisualBench/WrappedBenchmark.h

Issue 1409603004: Add NVPR to VisualBench (Closed) Base URL: https://skia.googlesource.com/skia.git@vb5
Patch Set: tweaks Created 5 years, 2 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 | « tools/VisualBench/VisualFlags.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/VisualBench/WrappedBenchmark.h
diff --git a/tools/VisualBench/WrappedBenchmark.h b/tools/VisualBench/WrappedBenchmark.h
new file mode 100644
index 0000000000000000000000000000000000000000..6fac145d3aae70b20bb87c2c3a9c0e692a5cd05b
--- /dev/null
+++ b/tools/VisualBench/WrappedBenchmark.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef WrappedBenchmark_DEFINED
+#define WrappedBenchmark_DEFINED
+
+#include "Benchmark.h"
+#include "SkSurface.h"
+
+// Wrap some other benchmark to allow specialization to either
+// cpu or gpu backends. The derived class will override 'setupOffScreen'
+// to create an offscreen surface in which the actual rendering will occur.
+class WrappedBenchmark : public Benchmark {
+public:
+ // Takes ownership of caller's ref on `bench`.
+ explicit WrappedBenchmark(Benchmark* bench) : fBench(bench) {}
+
+ const char* onGetName() override { return fBench->getName(); }
+ const char* onGetUniqueName() override { return fBench->getUniqueName(); }
+
+ void onDelayedSetup() override { fBench->delayedSetup(); }
+ void onPerCanvasPreDraw(SkCanvas* canvas) override {
+ fOffScreen.reset(this->setupOffScreen(canvas));
+ fBench->perCanvasPreDraw(fOffScreen->getCanvas());
+ }
+ void onPreDraw(SkCanvas* canvas) override {
+ SkASSERT(fOffScreen.get());
+ fBench->preDraw(fOffScreen->getCanvas());
+ }
+ void onPostDraw(SkCanvas* canvas) override {
+ SkASSERT(fOffScreen.get());
+ fBench->postDraw(fOffScreen->getCanvas());
+ }
+ void onPerCanvasPostDraw(SkCanvas* canvas) override {
+ SkASSERT(fOffScreen.get());
+ fBench->perCanvasPostDraw(fOffScreen->getCanvas());
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ SkASSERT(fOffScreen.get());
+ fBench->draw(loops, fOffScreen->getCanvas());
+ SkAutoTUnref<SkImage> image(fOffScreen->newImageSnapshot());
+ canvas->drawImage(image, 0,0);
+ }
+
+ virtual SkIPoint onGetSize() override { return fBench->getSize(); }
+
+private:
+ virtual SkSurface* setupOffScreen(SkCanvas*)=0;
+
+ SkAutoTUnref<SkSurface> fOffScreen;
+ SkAutoTUnref<Benchmark> fBench;
+};
+
+// Create a raster surface for off screen rendering
+class CpuWrappedBenchmark : public WrappedBenchmark {
+public:
+ explicit CpuWrappedBenchmark(Benchmark* bench) : INHERITED(bench) {}
+
+private:
+ SkSurface* setupOffScreen(SkCanvas* canvas) override {
+ return SkSurface::NewRaster(canvas->imageInfo());
+ }
+
+ typedef WrappedBenchmark INHERITED;
+};
+
+// Create an MSAA & NVPR-enabled GPU backend
+class NvprWrappedBenchmark : public WrappedBenchmark {
+public:
+ explicit NvprWrappedBenchmark(Benchmark* bench, int numSamples)
+ : INHERITED(bench)
+ , fNumSamples(numSamples) {}
+
+private:
+ SkSurface* setupOffScreen(SkCanvas* canvas) override {
+ return SkSurface::NewRenderTarget(canvas->getGrContext(),
+ SkSurface::kNo_Budgeted,
+ canvas->imageInfo(),
+ fNumSamples);
+ }
+
+ int fNumSamples;
+ typedef WrappedBenchmark INHERITED;
+};
+
+#endif //WrappedBenchmark_DEFINED
« no previous file with comments | « tools/VisualBench/VisualFlags.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698