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

Unified Diff: bench/GrMipMapBench.cpp

Issue 2030673002: New benchmark to measure GPU mip-mapping performance (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/GrMipMapBench.cpp
diff --git a/bench/GrMipMapBench.cpp b/bench/GrMipMapBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3b4db2459612a2dd4f783067738ec628e4d81bcf
--- /dev/null
+++ b/bench/GrMipMapBench.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "SkCanvas.h"
+#include "SkImage.h"
+#include "SkPaint.h"
+#include "SkSurface.h"
+
+#if SK_SUPPORT_GPU
+
+class GrMipMapBench: public Benchmark {
+ sk_sp<SkSurface> fSurface;
+ SkString fName;
+ const int fW, fH;
+
+public:
+ GrMipMapBench(int w, int h) : fW(w), fH(h) {
+ fName.printf("gr_mipmap_build_%dx%d", w, h);
+ }
+
+protected:
+ bool isSuitableFor(Backend backend) override {
+ return kGPU_Backend == backend;
+ }
+
+ const char* onGetName() override { return fName.c_str(); }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ if (!fSurface) {
+ GrContext* context = canvas->getGrContext();
+ if (nullptr == context) {
bsalomon 2016/06/01 19:37:29 you can just say !context if you prefer, but it do
+ return;
+ }
+ SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPremul_SkAlphaType,
+ kSRGB_SkColorProfileType);
+ fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
+ }
+
+ // Clear surface once:
+ fSurface->getCanvas()->clear(SK_ColorBLACK);
+
+ SkPaint paint;
+ paint.setFilterQuality(kMedium_SkFilterQuality);
+
+ for (int i = 0; i < loops; i++) {
+ // Touch surface so mips are dirtied
+ fSurface->getCanvas()->drawPoint(0, 0, SK_ColorWHITE);
+
+ // Draw reduced version of surface to original canvas, to trigger mip generation
+ canvas->save();
+ canvas->scale(0.1f, 0.1f);
+ canvas->drawImage(fSurface->makeImageSnapshot(SkBudgeted::kNo), 0, 0, &paint);
+ canvas->restore();
+ }
+ }
+
+private:
+ typedef Benchmark INHERITED;
+};
+
+// Build variants that exercise the width and heights being even or odd at each level, as the
+// impl specializes on each of these.
+//
+DEF_BENCH( return new GrMipMapBench(511, 1023); )
+DEF_BENCH( return new GrMipMapBench(512, 511); )
+DEF_BENCH( return new GrMipMapBench(511, 512); )
+DEF_BENCH( return new GrMipMapBench(512, 512); )
+
+#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698