2020-07-10 12:36:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
|
|
|
|
class FilteringBench : public Benchmark {
|
|
|
|
public:
|
2020-11-20 23:45:36 +00:00
|
|
|
FilteringBench(SkFilterMode fm, SkMipmapMode mm) : fSampling(fm, mm) {
|
|
|
|
fName.printf("samplingoptions_filter_%d_mipmap_%d", (int)fm, (int)mm);
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDelayedSetup() override {
|
|
|
|
auto img = GetResourceAsImage("images/ship.png");
|
|
|
|
// need to force raster since lazy doesn't support filteroptions yet
|
|
|
|
img = img->makeRasterImage();
|
|
|
|
|
|
|
|
fRect = SkRect::MakeIWH(img->width(), img->height());
|
2020-11-20 23:45:36 +00:00
|
|
|
fShader = img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, fSampling);
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
|
|
// scale so we will trigger lerping between levels if we mipmapping
|
|
|
|
canvas->scale(0.75f, 0.75f);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(fShader);
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
canvas->drawRect(fRect, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
SkRect fRect;
|
|
|
|
sk_sp<SkShader> fShader;
|
2020-11-20 23:45:36 +00:00
|
|
|
SkSamplingOptions fSampling;
|
2020-07-10 12:36:42 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2020-07-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
|
2020-11-20 23:45:36 +00:00
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear, SkMipmapMode::kLinear); )
|
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear, SkMipmapMode::kNearest); )
|
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kLinear, SkMipmapMode::kNone); )
|
2020-07-10 12:36:42 +00:00
|
|
|
|
2020-11-20 23:45:36 +00:00
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kLinear); )
|
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kNearest); )
|
|
|
|
DEF_BENCH( return new FilteringBench(SkFilterMode::kNearest, SkMipmapMode::kNone); )
|