aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/DrawBitmapAABench.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-07-06 05:25:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-06 05:25:17 -0700
commitf0ebdd7463275f8183df94f1f8a8ec3761652e7c (patch)
tree02af3a546716080a286b65f60d75dbf9e6080a6e /bench/DrawBitmapAABench.cpp
parent20c07e11b02bb41f805a7697a1e95e894788735c (diff)
Add a bench for measuring drawBitmap anti-aliasing overhead
R=reed@google.com,mtklein@google.com Review URL: https://codereview.chromium.org/1207403007
Diffstat (limited to 'bench/DrawBitmapAABench.cpp')
-rw-r--r--bench/DrawBitmapAABench.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/bench/DrawBitmapAABench.cpp b/bench/DrawBitmapAABench.cpp
new file mode 100644
index 0000000000..1738ce71d5
--- /dev/null
+++ b/bench/DrawBitmapAABench.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2015 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 "SkMatrix.h"
+#include "SkPaint.h"
+#include "SkString.h"
+
+/**
+ * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
+ * matrix combinations.
+ */
+
+class DrawBitmapAABench : public Benchmark {
+public:
+ DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
+ : fMatrix(matrix)
+ , fName("draw_bitmap_") {
+
+ fPaint.setAntiAlias(doAA);
+ fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
+ }
+
+protected:
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ void onPreDraw() override {
+ fBitmap.allocN32Pixels(200, 200);
+ fBitmap.eraseARGB(255, 0, 255, 0);
+ }
+
+ void onDraw(const int loops, SkCanvas* canvas) override {
+ canvas->concat(fMatrix);
+ for (int i = 0; i < loops; i++) {
+ canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
+ }
+ }
+
+private:
+ SkPaint fPaint;
+ SkMatrix fMatrix;
+ SkString fName;
+ SkBitmap fBitmap;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
+
+DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
+
+DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
+
+DEF_BENCH(
+ SkMatrix m;
+ m.reset();
+ m.preRotate(15);
+ return new DrawBitmapAABench(false, m, "rotate");
+)
+
+DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
+
+DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
+
+DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
+
+DEF_BENCH(
+ SkMatrix m;
+ m.reset();
+ m.preRotate(15);
+ return new DrawBitmapAABench(true, m, "rotate");
+)