blob: 52ba266271d76d47611ef650db41887ac762bce1 [file] [log] [blame]
Mike Reedf8a6b5b2020-07-10 08:36:42 -04001/*
2 * Copyright 2012 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 "bench/Benchmark.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkShader.h"
12#include "include/core/SkString.h"
13#include "tools/Resources.h"
14
15class FilteringBench : public Benchmark {
16public:
17 FilteringBench(SkFilterOptions options) : fOptions(options) {
18 fName.printf("filteroptions_sampling_%d_mipmap_%d",
19 (int)options.fSampling, (int)options.fMipmap);
20 }
21
22protected:
23 const char* onGetName() override {
24 return fName.c_str();
25 }
26
27 void onDelayedSetup() override {
28 auto img = GetResourceAsImage("images/ship.png");
29 // need to force raster since lazy doesn't support filteroptions yet
30 img = img->makeRasterImage();
31
32 fRect = SkRect::MakeIWH(img->width(), img->height());
33 fShader = img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, fOptions);
34 }
35
36 void onDraw(int loops, SkCanvas* canvas) override {
37 // scale so we will trigger lerping between levels if we mipmapping
38 canvas->scale(0.75f, 0.75f);
39
40 SkPaint paint;
41 paint.setShader(fShader);
42 for (int i = 0; i < loops; ++i) {
43 for (int j = 0; j < 10; ++j) {
44 canvas->drawRect(fRect, paint);
45 }
46 }
47 }
48
49private:
50 SkString fName;
51 SkRect fRect;
52 sk_sp<SkShader> fShader;
53 SkFilterOptions fOptions;
54
John Stiles7571f9e2020-09-02 22:42:33 -040055 using INHERITED = Benchmark;
Mike Reedf8a6b5b2020-07-10 08:36:42 -040056};
57
58DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kLinear}); )
59DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kNearest}); )
60DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kNone}); )
61
62DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kLinear}); )
63DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kNearest}); )
64DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kNone}); )