robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkBenchmark.h" |
| 10 | #include "SkCanvas.h" |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * This bench mark tests the use case where the user writes the a canvas |
| 15 | * and then reads small chunks from it repeatedly. This can cause trouble |
| 16 | * for the GPU as readbacks are very expensive. |
| 17 | */ |
| 18 | class ReadPixBench : public SkBenchmark { |
| 19 | public: |
| 20 | ReadPixBench(void* param) : INHERITED(param) {} |
| 21 | |
| 22 | protected: |
| 23 | virtual const char* onGetName() SK_OVERRIDE { |
| 24 | return "readpix"; |
| 25 | } |
| 26 | |
| 27 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 28 | canvas->clear(SK_ColorBLACK); |
| 29 | |
| 30 | SkISize size = canvas->getDeviceSize(); |
| 31 | |
| 32 | int offX = (size.width() - kWindowSize) / kNumStepsX; |
| 33 | int offY = (size.height() - kWindowSize) / kNumStepsY; |
| 34 | |
| 35 | SkPaint paint; |
| 36 | |
| 37 | paint.setColor(SK_ColorBLUE); |
| 38 | |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 39 | canvas->drawCircle(SkIntToScalar(size.width()/2), |
| 40 | SkIntToScalar(size.height()/2), |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 41 | SkIntToScalar(size.width()/2), |
| 42 | paint); |
| 43 | |
| 44 | SkBitmap bitmap; |
| 45 | |
| 46 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWindowSize, kWindowSize); |
| 47 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame^] | 48 | for (int i = 0; i < this->getLoops(); i++) { |
| 49 | for (int x = 0; x < kNumStepsX; ++x) { |
| 50 | for (int y = 0; y < kNumStepsY; ++y) { |
| 51 | canvas->readPixels(&bitmap, x * offX, y * offY); |
| 52 | } |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | static const int kNumStepsX = 30; |
| 59 | static const int kNumStepsY = 30; |
| 60 | static const int kWindowSize = 5; |
| 61 | |
| 62 | typedef SkBenchmark INHERITED; |
| 63 | }; |
| 64 | |
| 65 | //////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | static SkBenchmark* fact(void* p) { return new ReadPixBench(p); } |
| 68 | static BenchRegistry gReg(fact); |