blob: b1061a1cde7df39afd5f44743d20ae6e2ace5a39 [file] [log] [blame]
robertphillips@google.com6806bda2012-09-04 13:39:01 +00001/*
2 * Copyright 2012 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
robertphillips@google.com6806bda2012-09-04 13:39:01 +00009#include "SkCanvas.h"
10
11
12/**
13 * This bench mark tests the use case where the user writes the a canvas
14 * and then reads small chunks from it repeatedly. This can cause trouble
15 * for the GPU as readbacks are very expensive.
16 */
tfarinaf168b862014-06-19 12:32:29 -070017class ReadPixBench : public Benchmark {
robertphillips@google.com6806bda2012-09-04 13:39:01 +000018public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000019 ReadPixBench() {}
robertphillips@google.com6806bda2012-09-04 13:39:01 +000020
21protected:
mtklein36352bf2015-03-25 18:17:31 -070022 const char* onGetName() override {
robertphillips@google.com6806bda2012-09-04 13:39:01 +000023 return "readpix";
24 }
25
mtkleina1ebeb22015-10-01 09:43:39 -070026 void onDraw(int loops, SkCanvas* canvas) override {
robertphillips@google.com6806bda2012-09-04 13:39:01 +000027 canvas->clear(SK_ColorBLACK);
28
29 SkISize size = canvas->getDeviceSize();
30
31 int offX = (size.width() - kWindowSize) / kNumStepsX;
32 int offY = (size.height() - kWindowSize) / kNumStepsY;
33
34 SkPaint paint;
35
36 paint.setColor(SK_ColorBLUE);
37
skia.committer@gmail.com73bb3be2012-09-05 02:01:29 +000038 canvas->drawCircle(SkIntToScalar(size.width()/2),
39 SkIntToScalar(size.height()/2),
robertphillips@google.com6806bda2012-09-04 13:39:01 +000040 SkIntToScalar(size.width()/2),
41 paint);
42
43 SkBitmap bitmap;
44
reed6c225732014-06-09 19:52:07 -070045 bitmap.setInfo(SkImageInfo::MakeN32Premul(kWindowSize, kWindowSize));
robertphillips@google.com6806bda2012-09-04 13:39:01 +000046
commit-bot@chromium.org33614712013-12-03 18:17:16 +000047 for (int i = 0; i < loops; i++) {
mtklein@google.comc2897432013-09-10 19:23:38 +000048 for (int x = 0; x < kNumStepsX; ++x) {
49 for (int y = 0; y < kNumStepsY; ++y) {
50 canvas->readPixels(&bitmap, x * offX, y * offY);
51 }
robertphillips@google.com6806bda2012-09-04 13:39:01 +000052 }
53 }
54 }
55
56private:
57 static const int kNumStepsX = 30;
58 static const int kNumStepsY = 30;
59 static const int kWindowSize = 5;
60
tfarinaf168b862014-06-19 12:32:29 -070061 typedef Benchmark INHERITED;
robertphillips@google.com6806bda2012-09-04 13:39:01 +000062};
63
64////////////////////////////////////////////////////////////////////////////////
65
mtklein@google.com410e6e82013-09-13 19:52:27 +000066DEF_BENCH( return new ReadPixBench(); )