3 * Copyright 2012 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
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.
18 class ReadPixBench : public Benchmark {
23 const char* onGetName() SK_OVERRIDE {
27 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
28 canvas->clear(SK_ColorBLACK);
30 SkISize size = canvas->getDeviceSize();
32 int offX = (size.width() - kWindowSize) / kNumStepsX;
33 int offY = (size.height() - kWindowSize) / kNumStepsY;
37 paint.setColor(SK_ColorBLUE);
39 canvas->drawCircle(SkIntToScalar(size.width()/2),
40 SkIntToScalar(size.height()/2),
41 SkIntToScalar(size.width()/2),
46 bitmap.setInfo(SkImageInfo::MakeN32Premul(kWindowSize, kWindowSize));
48 for (int i = 0; i < loops; 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);
58 static const int kNumStepsX = 30;
59 static const int kNumStepsY = 30;
60 static const int kWindowSize = 5;
62 typedef Benchmark INHERITED;
65 ////////////////////////////////////////////////////////////////////////////////
67 DEF_BENCH( return new ReadPixBench(); )