blob: ece7cbe503f484a58f01bf48ce9823bea1725869 [file] [log] [blame]
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +00001/*
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"
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000010#include "SkShader.h"
11#include "SkString.h"
12#include "SkBicubicImageFilter.h"
13
14// This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to
15// 100x100, 400x100, 100x400, and 400x400.
16
17class BicubicBench : public SkBenchmark {
18 SkSize fScale;
19 SkString fName;
20
21public:
22 BicubicBench(void* param, float x, float y)
23 : INHERITED(param), fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToScalar(y))) {
24 fName.printf("bicubic_%gx%g",
25 SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight));
26 }
27
28protected:
29 virtual const char* onGetName() {
30 return fName.c_str();
31 }
32
33 virtual void onDraw(SkCanvas* canvas) {
34 SkPaint paint;
35 this->setupPaint(&paint);
36
37 paint.setAntiAlias(true);
38
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000039 SkRect r = SkRect::MakeWH(40, 40);
40 SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(fScale));
41 paint.setImageFilter(bicubic);
mtklein@google.comc2897432013-09-10 19:23:38 +000042
43 for (int i = 0; i < this->getLoops(); i++) {
44 canvas->save();
45 canvas->clipRect(r);
46 canvas->drawOval(r, paint);
47 canvas->restore();
48 }
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000049 }
50
51private:
52 typedef SkBenchmark INHERITED;
53};
54
55static SkBenchmark* Fact00(void* p) { return new BicubicBench(p, 10.0f, 10.0f); }
56static SkBenchmark* Fact01(void* p) { return new BicubicBench(p, 2.5f, 10.0f); }
57static SkBenchmark* Fact02(void* p) { return new BicubicBench(p, 10.0f, 2.5f); }
58static SkBenchmark* Fact03(void* p) { return new BicubicBench(p, 2.5f, 2.5f); }
59
60static BenchRegistry gReg00(Fact00);
61static BenchRegistry gReg01(Fact01);
62static BenchRegistry gReg02(Fact02);
63static BenchRegistry gReg03(Fact03);