blob: 162ec61370c37ff33fc32a6e874809aa5ac86b5d [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:
mtklein@google.com410e6e82013-09-13 19:52:27 +000022 BicubicBench(float x, float y)
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000023 : fScale(SkSize::Make(x, y)) {
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000024 fName.printf("bicubic_%gx%g",
mtklein@google.com410e6e82013-09-13 19:52:27 +000025 SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight));
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000026 }
27
28protected:
29 virtual const char* onGetName() {
30 return fName.c_str();
31 }
32
commit-bot@chromium.org33614712013-12-03 18:17:16 +000033 virtual void onDraw(const int loops, SkCanvas* canvas) {
senorblanco@chromium.orgc3799ad2013-02-08 16:40:14 +000034 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
commit-bot@chromium.org33614712013-12-03 18:17:16 +000043 for (int i = 0; i < loops; i++) {
mtklein@google.comc2897432013-09-10 19:23:38 +000044 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
mtklein@google.com410e6e82013-09-13 19:52:27 +000055DEF_BENCH( return new BicubicBench(10.0f, 10.0f); )
56DEF_BENCH( return new BicubicBench(2.5f, 10.0f); )
57DEF_BENCH( return new BicubicBench(10.0f, 2.5f); )
58DEF_BENCH( return new BicubicBench(2.5f, 2.5f); )