Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: bench/BitmapFractionalBench.cpp

Issue 491793003: Benchmark designed to exercise fractional image scale/translation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/BitmapFractionalBench.cpp
diff --git a/bench/BitmapScaleBench.cpp b/bench/BitmapFractionalBench.cpp
similarity index 50%
copy from bench/BitmapScaleBench.cpp
copy to bench/BitmapFractionalBench.cpp
index fad741aebc72d3cf6bda55088e8227a903b066ab..7b47514d2e6d33ab944c9397d9e17de4e101e580 100644
--- a/bench/BitmapScaleBench.cpp
+++ b/bench/BitmapFractionalBench.cpp
@@ -13,18 +13,14 @@
#include "SkShader.h"
#include "SkString.h"
-class BitmapScaleBench: public Benchmark {
- int fLoopCount;
+class BitmapFractionalBench: public Benchmark {
int fInputSize;
int fOutputSize;
- SkString fName;
public:
- BitmapScaleBench( int is, int os) {
+ BitmapFractionalBench( int is ) {
fInputSize = is;
- fOutputSize = os;
-
- fLoopCount = 20;
+ fOutputSize = 2*is;
}
protected:
@@ -33,7 +29,7 @@ protected:
SkMatrix fMatrix;
virtual const char* onGetName() {
- return fName.c_str();
+ return "bitmap_fractional_bench";
}
int inputSize() const {
@@ -44,25 +40,15 @@ protected:
return fOutputSize;
}
- float scale() const {
- return float(outputSize())/inputSize();
- }
-
SkIPoint onGetSize() SK_OVERRIDE {
return SkIPoint::Make( fOutputSize, fOutputSize );
}
- void setName(const char * name) {
- fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize );
- }
-
virtual void onPreDraw() {
fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true);
fInputBitmap.eraseColor(SK_ColorWHITE);
fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true);
-
- fMatrix.setScale( scale(), scale() );
}
virtual void onDraw(const int loops, SkCanvas*) {
@@ -71,41 +57,36 @@ protected:
preBenchSetup();
+ SkCanvas canvas( fOutputBitmap );
+ paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
+ fInputBitmap.notifyPixelsChanged();
+
for (int i = 0; i < loops; i++) {
- doScaleImage();
+ // re-scale the image by a variety of close, fractional scales
+ for (int j = 0 ; j < 10 ; j++) {
+ fMatrix = SkMatrix::I();
+ fMatrix.setScale( 1 + j/3.f, 1 + j/3.f );
+ canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
+ }
+ // Now try some fractional translates
+ for (int j = 0 ; j < 10 ; j++) {
+ fMatrix = SkMatrix::I();
+ fMatrix.setTranslate( j/3.f, j/3.f );
+ canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
+ }
+ // Finally, some fractional translates with non-identity scale.
+ for (int j = 0 ; j < 10 ; j++) {
+ fMatrix = SkMatrix::I();
+ fMatrix.setTranslate( j/3.f, j/3.f );
+ fMatrix.preScale( 1.5, 1.5 );
reed1 2014/08/25 17:10:15 may get some warnings of double->float here.
+ canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
+ }
}
}
- virtual void doScaleImage() = 0;
virtual void preBenchSetup() {}
private:
typedef Benchmark INHERITED;
};
-class BitmapFilterScaleBench: public BitmapScaleBench {
- public:
- BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) {
- setName( "filter" );
- }
-protected:
- virtual void doScaleImage() SK_OVERRIDE {
- SkCanvas canvas( fOutputBitmap );
- SkPaint paint;
-
- paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
- fInputBitmap.notifyPixelsChanged();
- canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
- }
-private:
- typedef BitmapScaleBench INHERITED;
-};
-
-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);)
+DEF_BENCH(return new BitmapFractionalBench(256);)
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698