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
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
virtual const char* onGetName() {
|
|
|
|
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
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
SkIPoint onGetSize() SK_OVERRIDE {
|
|
|
|
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
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
virtual void onPreDraw() {
|
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() );
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
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-01-09 18:06:39 +00:00
|
|
|
void doScaleImage() SK_OVERRIDE {
|
2013-07-09 21:37:14 +00:00
|
|
|
SkCanvas canvas( fOutputBitmap );
|
|
|
|
SkPaint paint;
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-22 17:18:18 +00:00
|
|
|
paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
|
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);)
|