• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
FilteringBench(SkFilterMode fm,SkMipmapMode mm)17     FilteringBench(SkFilterMode fm, SkMipmapMode mm) : fSampling(fm, mm) {
18         fName.printf("samplingoptions_filter_%d_mipmap_%d", (int)fm, (int)mm);
19     }
20 
21 protected:
onGetName()22     const char* onGetName() override {
23         return fName.c_str();
24     }
25 
onDelayedSetup()26     void onDelayedSetup() override {
27         auto img = GetResourceAsImage("images/ship.png");
28         // need to force raster since lazy doesn't support filteroptions yet
29         img = img->makeRasterImage();
30 
31         fRect = SkRect::MakeIWH(img->width(), img->height());
32         fShader = img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, fSampling);
33     }
34 
onDraw(int loops,SkCanvas * canvas)35     void onDraw(int loops, SkCanvas* canvas) override {
36         // scale so we will trigger lerping between levels if we mipmapping
37         canvas->scale(0.75f, 0.75f);
38 
39         SkPaint paint;
40         paint.setShader(fShader);
41         for (int i = 0; i < loops; ++i) {
42             for (int j = 0; j < 10; ++j) {
43                 canvas->drawRect(fRect, paint);
44             }
45         }
46     }
47 
48 private:
49     SkString        fName;
50     SkRect          fRect;
51     sk_sp<SkShader> fShader;
52     SkSamplingOptions fSampling;
53 
54     using INHERITED = Benchmark;
55 };
56 
57 DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear,  SkMipmapMode::kLinear); )
58 DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear,  SkMipmapMode::kNearest); )
59 DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear,  SkMipmapMode::kNone); )
60 
61 DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kLinear); )
62 DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kNearest); )
63 DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kNone); )
64