aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ReadPixBench.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-09-04 13:39:01 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-09-04 13:39:01 +0000
commit6806bdaca8b22927ba7ef537fd5336311c7258e1 (patch)
treecd89593c5bd7cc0d5e8a59885e794ad7ad9d6796 /bench/ReadPixBench.cpp
parent6fc9518a55d57f362b4e13f4a48fa6d9c85d0cd2 (diff)
Added bench to test multiple readPixels case
Diffstat (limited to 'bench/ReadPixBench.cpp')
-rw-r--r--bench/ReadPixBench.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/bench/ReadPixBench.cpp b/bench/ReadPixBench.cpp
new file mode 100644
index 0000000000..abcfbeabd1
--- /dev/null
+++ b/bench/ReadPixBench.cpp
@@ -0,0 +1,66 @@
+
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBenchmark.h"
+#include "SkCanvas.h"
+
+
+/**
+ * This bench mark tests the use case where the user writes the a canvas
+ * and then reads small chunks from it repeatedly. This can cause trouble
+ * for the GPU as readbacks are very expensive.
+ */
+class ReadPixBench : public SkBenchmark {
+public:
+ ReadPixBench(void* param) : INHERITED(param) {}
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return "readpix";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->clear(SK_ColorBLACK);
+
+ SkISize size = canvas->getDeviceSize();
+
+ int offX = (size.width() - kWindowSize) / kNumStepsX;
+ int offY = (size.height() - kWindowSize) / kNumStepsY;
+
+ SkPaint paint;
+
+ paint.setColor(SK_ColorBLUE);
+
+ canvas->drawCircle(SkIntToScalar(size.width()/2),
+ SkIntToScalar(size.height()/2),
+ SkIntToScalar(size.width()/2),
+ paint);
+
+ SkBitmap bitmap;
+
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWindowSize, kWindowSize);
+
+ for (int x = 0; x < kNumStepsX; ++x) {
+ for (int y = 0; y < kNumStepsY; ++y) {
+ canvas->readPixels(&bitmap, x * offX, y * offY);
+ }
+ }
+ }
+
+private:
+ static const int kNumStepsX = 30;
+ static const int kNumStepsY = 30;
+ static const int kWindowSize = 5;
+
+ typedef SkBenchmark INHERITED;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+static SkBenchmark* fact(void* p) { return new ReadPixBench(p); }
+static BenchRegistry gReg(fact);