1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBenchmark.h"
9#include "SkCanvas.h"
10#include "SkRandom.h"
11#include "SkShader.h"
12#include "SkString.h"
13#include "SkBicubicImageFilter.h"
14
15// This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to
16// 100x100, 400x100, 100x400, and 400x400.
17
18class BicubicBench : public SkBenchmark {
19    SkSize         fScale;
20    SkString       fName;
21
22public:
23    BicubicBench(void* param, float x, float y)
24        :  INHERITED(param), fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToScalar(y))) {
25        fName.printf("bicubic_%gx%g",
26            SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight));
27    }
28
29protected:
30    virtual const char* onGetName() {
31        return fName.c_str();
32    }
33
34    virtual void onDraw(SkCanvas* canvas) {
35        SkPaint paint;
36        this->setupPaint(&paint);
37
38        paint.setAntiAlias(true);
39
40        SkRandom rand;
41        SkRect r = SkRect::MakeWH(40, 40);
42        SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(fScale));
43        paint.setImageFilter(bicubic);
44        canvas->save();
45        canvas->clipRect(r);
46        canvas->drawOval(r, paint);
47        canvas->restore();
48    }
49
50private:
51    typedef SkBenchmark INHERITED;
52};
53
54static SkBenchmark* Fact00(void* p) { return new BicubicBench(p, 10.0f, 10.0f); }
55static SkBenchmark* Fact01(void* p) { return new BicubicBench(p, 2.5f, 10.0f); }
56static SkBenchmark* Fact02(void* p) { return new BicubicBench(p, 10.0f, 2.5f); }
57static SkBenchmark* Fact03(void* p) { return new BicubicBench(p, 2.5f, 2.5f); }
58
59static BenchRegistry gReg00(Fact00);
60static BenchRegistry gReg01(Fact01);
61static BenchRegistry gReg02(Fact02);
62static BenchRegistry gReg03(Fact03);
63