Mike Reed | f8a6b5b | 2020-07-10 08:36:42 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | class FilteringBench : public Benchmark { |
| 16 | public: |
| 17 | FilteringBench(SkFilterOptions options) : fOptions(options) { |
| 18 | fName.printf("filteroptions_sampling_%d_mipmap_%d", |
| 19 | (int)options.fSampling, (int)options.fMipmap); |
| 20 | } |
| 21 | |
| 22 | protected: |
| 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 | |
| 49 | private: |
| 50 | SkString fName; |
| 51 | SkRect fRect; |
| 52 | sk_sp<SkShader> fShader; |
| 53 | SkFilterOptions fOptions; |
| 54 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 55 | using INHERITED = Benchmark; |
Mike Reed | f8a6b5b | 2020-07-10 08:36:42 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kLinear}); ) |
| 59 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kNearest}); ) |
| 60 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kLinear, SkMipmapMode::kNone}); ) |
| 61 | |
| 62 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kLinear}); ) |
| 63 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kNearest}); ) |
| 64 | DEF_BENCH( return new FilteringBench({SkSamplingMode::kNearest, SkMipmapMode::kNone}); ) |