2013-07-09 21:37:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "SkBlurMask.h"
|
2013-07-09 21:37:14 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BitmapScaleBench: public Benchmark {
|
2013-07-09 21:37:14 +00:00
|
|
|
int fLoopCount;
|
|
|
|
int fInputSize;
|
|
|
|
int fOutputSize;
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BitmapScaleBench( int is, int os) {
|
2013-07-09 21:37:14 +00:00
|
|
|
fInputSize = is;
|
|
|
|
fOutputSize = os;
|
|
|
|
|
2013-07-11 20:28:30 +00:00
|
|
|
fLoopCount = 20;
|
2013-07-09 21:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
SkBitmap fInputBitmap, fOutputBitmap;
|
|
|
|
SkMatrix fMatrix;
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-07-09 21:37:14 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int inputSize() const {
|
|
|
|
return fInputSize;
|
|
|
|
}
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
int outputSize() const {
|
|
|
|
return fOutputSize;
|
|
|
|
}
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
float scale() const {
|
|
|
|
return float(outputSize())/inputSize();
|
|
|
|
}
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkIPoint onGetSize() override {
|
2013-07-09 21:37:14 +00:00
|
|
|
return SkIPoint::Make( fOutputSize, fOutputSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setName(const char * name) {
|
|
|
|
fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize );
|
|
|
|
}
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2014-06-10 02:52:07 +00:00
|
|
|
fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true);
|
2013-07-09 21:37:14 +00:00
|
|
|
fInputBitmap.eraseColor(SK_ColorWHITE);
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2014-06-10 02:52:07 +00:00
|
|
|
fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true);
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
fMatrix.setScale( scale(), scale() );
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-07-09 21:37:14 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
preBenchSetup();
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-07-09 21:37:14 +00:00
|
|
|
doScaleImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void doScaleImage() = 0;
|
|
|
|
virtual void preBenchSetup() {}
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-07-09 21:37:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BitmapFilterScaleBench: public BitmapScaleBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) {
|
2013-07-09 21:37:14 +00:00
|
|
|
setName( "filter" );
|
|
|
|
}
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void doScaleImage() override {
|
2013-07-09 21:37:14 +00:00
|
|
|
SkCanvas canvas( fOutputBitmap );
|
|
|
|
SkPaint paint;
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
2014-03-06 17:16:37 +00:00
|
|
|
fInputBitmap.notifyPixelsChanged();
|
2014-12-10 17:02:16 +00:00
|
|
|
canvas.concat(fMatrix);
|
|
|
|
canvas.drawBitmap(fInputBitmap, 0, 0, &paint );
|
2013-07-09 21:37:14 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef BitmapScaleBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(10, 90);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(30, 90);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(80, 90);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(90, 90);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(90, 80);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(90, 30);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(90, 10);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(256, 64);)
|
|
|
|
DEF_BENCH(return new BitmapFilterScaleBench(64, 256);)
|