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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkBlurMask.h"
|
|
|
|
|
|
|
|
class BitmapScaleBench: public SkBenchmark {
|
|
|
|
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() {
|
|
|
|
fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fInputSize, fInputSize);
|
|
|
|
fInputBitmap.allocPixels();
|
|
|
|
fInputBitmap.eraseColor(SK_ColorWHITE);
|
|
|
|
fInputBitmap.setIsOpaque(true);
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fOutputSize, fOutputSize);
|
|
|
|
fOutputBitmap.allocPixels();
|
|
|
|
fOutputBitmap.setIsOpaque(true);
|
2013-07-10 07:00:58 +00:00
|
|
|
|
2013-07-09 21:37:14 +00:00
|
|
|
fMatrix.setScale( scale(), scale() );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
preBenchSetup();
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); i++) {
|
2013-07-09 21:37:14 +00:00
|
|
|
doScaleImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void doScaleImage() = 0;
|
|
|
|
virtual void preBenchSetup() {}
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void doScaleImage() SK_OVERRIDE {
|
|
|
|
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);
|
2013-07-09 21:37:14 +00:00
|
|
|
canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
|
|
|
|
}
|
|
|
|
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);)
|