2012-09-04 13:39:01 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2017-05-03 19:16:58 +00:00
|
|
|
#include "SkBitmap.h"
|
2012-09-04 13:39:01 +00:00
|
|
|
#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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
class ReadPixBench : public Benchmark {
|
2012-09-04 13:39:01 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ReadPixBench() {}
|
2012-09-04 13:39:01 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-09-04 13:39:01 +00:00
|
|
|
return "readpix";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-09-04 13:39:01 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
|
2017-02-22 18:21:42 +00:00
|
|
|
SkISize size = canvas->getBaseLayerSize();
|
2012-09-04 13:39:01 +00:00
|
|
|
|
|
|
|
int offX = (size.width() - kWindowSize) / kNumStepsX;
|
|
|
|
int offY = (size.height() - kWindowSize) / kNumStepsY;
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
|
2012-09-05 02:01:29 +00:00
|
|
|
canvas->drawCircle(SkIntToScalar(size.width()/2),
|
|
|
|
SkIntToScalar(size.height()/2),
|
2012-09-04 13:39:01 +00:00
|
|
|
SkIntToScalar(size.width()/2),
|
|
|
|
paint);
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
|
2017-04-17 14:53:29 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(kWindowSize, kWindowSize));
|
2012-09-04 13:39:01 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int x = 0; x < kNumStepsX; ++x) {
|
|
|
|
for (int y = 0; y < kNumStepsY; ++y) {
|
2017-04-17 14:53:29 +00:00
|
|
|
canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
|
|
|
|
x * offX, y * offY);
|
2013-09-10 19:23:38 +00:00
|
|
|
}
|
2012-09-04 13:39:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kNumStepsX = 30;
|
|
|
|
static const int kNumStepsY = 30;
|
|
|
|
static const int kWindowSize = 5;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-09-04 13:39:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ReadPixBench(); )
|