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