add bench for colorfilter-mixer
Change-Id: Iab8a25b086a492838931b0fab2d6239ae975b435 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/204640 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com> Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
0d33eac1aa
commit
cc8c7bee79
@ -279,3 +279,67 @@ DEF_BENCH( return new ColorFilterBrightBlueBench(false); )
|
||||
DEF_BENCH( return new ColorFilterBrightBench(false); )
|
||||
DEF_BENCH( return new ColorFilterBlueBench(false); )
|
||||
DEF_BENCH( return new ColorFilterGrayBench(false); )
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Resources.h"
|
||||
#include "SkMixer.h"
|
||||
|
||||
class CFMixerBench : public Benchmark {
|
||||
SkString fName;
|
||||
enum Flags {
|
||||
kUseCF0 = 1 << 0,
|
||||
kUseCF1 = 1 << 1,
|
||||
};
|
||||
|
||||
sk_sp<SkShader> fShader;
|
||||
sk_sp<SkColorFilter> fFilter;
|
||||
const unsigned fFlags;
|
||||
|
||||
public:
|
||||
CFMixerBench(unsigned flags) : fFlags(flags) {
|
||||
fName.printf("colorfilter_mixer_%d", flags);
|
||||
}
|
||||
~CFMixerBench() override {}
|
||||
|
||||
protected:
|
||||
const char* onGetName() override { return fName.c_str(); }
|
||||
void onDelayedSetup() override {
|
||||
auto img = GetResourceAsImage("images/mandrill_256.png");
|
||||
if (img) {
|
||||
img = img->makeRasterImage();
|
||||
}
|
||||
fShader = img->makeShader();
|
||||
auto cf0 = SkColorFilter::MakeModeFilter(0x88FF3366, SkBlendMode::kDstIn);
|
||||
auto cf1 = SkColorFilter::MakeModeFilter(0x88FF3366, SkBlendMode::kDstATop);
|
||||
auto mx = SkMixer::MakeLerp(0.5f);
|
||||
if (!(fFlags & kUseCF0)) {
|
||||
cf0 = nullptr;
|
||||
}
|
||||
if (!(fFlags & kUseCF1)) {
|
||||
cf1 = nullptr;
|
||||
}
|
||||
fFilter = SkColorFilter::MakeMixer(cf0, cf1, mx);
|
||||
}
|
||||
void onDraw(int loops, SkCanvas* canvas) override {
|
||||
SkRect r = SkRect::MakeWH(256, 256);
|
||||
SkPaint paint;
|
||||
paint.setShader(fShader);
|
||||
paint.setColorFilter(fFilter);
|
||||
paint.setBlendMode(SkBlendMode::kSrc); // no need to measure this step
|
||||
|
||||
for (int j = 0; j < 100; ++j) {
|
||||
for (int i = 0; i < loops; i++) {
|
||||
canvas->drawRect(r, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef Benchmark INHERITED;
|
||||
};
|
||||
DEF_BENCH(return new CFMixerBench(0);)
|
||||
DEF_BENCH(return new CFMixerBench(1);)
|
||||
DEF_BENCH(return new CFMixerBench(2);)
|
||||
DEF_BENCH(return new CFMixerBench(3);)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user