2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurMask.h"
16 class BitmapScaleBench: public Benchmark {
23 BitmapScaleBench( int is, int os) {
32 SkBitmap fInputBitmap, fOutputBitmap;
35 virtual const char* onGetName() {
39 int inputSize() const {
43 int outputSize() const {
48 return float(outputSize())/inputSize();
51 SkIPoint onGetSize() SK_OVERRIDE {
52 return SkIPoint::Make( fOutputSize, fOutputSize );
55 void setName(const char * name) {
56 fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize );
59 virtual void onPreDraw() {
60 fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true);
61 fInputBitmap.eraseColor(SK_ColorWHITE);
63 fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true);
65 fMatrix.setScale( scale(), scale() );
68 virtual void onDraw(const int loops, SkCanvas*) {
70 this->setupPaint(&paint);
74 for (int i = 0; i < loops; i++) {
79 virtual void doScaleImage() = 0;
80 virtual void preBenchSetup() {}
82 typedef Benchmark INHERITED;
85 class BitmapFilterScaleBench: public BitmapScaleBench {
87 BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) {
91 void doScaleImage() SK_OVERRIDE {
92 SkCanvas canvas( fOutputBitmap );
95 paint.setFilterQuality(kHigh_SkFilterQuality);
96 fInputBitmap.notifyPixelsChanged();
97 canvas.concat(fMatrix);
98 canvas.drawBitmap(fInputBitmap, 0, 0, &paint );
101 typedef BitmapScaleBench INHERITED;
104 DEF_BENCH(return new BitmapFilterScaleBench(10, 90);)
105 DEF_BENCH(return new BitmapFilterScaleBench(30, 90);)
106 DEF_BENCH(return new BitmapFilterScaleBench(80, 90);)
107 DEF_BENCH(return new BitmapFilterScaleBench(90, 90);)
108 DEF_BENCH(return new BitmapFilterScaleBench(90, 80);)
109 DEF_BENCH(return new BitmapFilterScaleBench(90, 30);)
110 DEF_BENCH(return new BitmapFilterScaleBench(90, 10);)
111 DEF_BENCH(return new BitmapFilterScaleBench(256, 64);)
112 DEF_BENCH(return new BitmapFilterScaleBench(64, 256);)