2018-04-18 15:14:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/effects/SkShaderMaskFilter.h"
|
|
|
|
#include "src/shaders/SkPictureShader.h"
|
2018-04-18 15:14:50 +00:00
|
|
|
|
|
|
|
static sk_sp<SkShader> make_bitmap_shader() {
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
|
|
|
|
auto surface = SkSurface::MakeRasterN32Premul(100, 100);
|
|
|
|
surface->getCanvas()->drawCircle(50, 50, 50, p);
|
|
|
|
|
2020-12-08 18:16:56 +00:00
|
|
|
return surface->makeImageSnapshot()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
|
|
|
SkSamplingOptions());
|
2018-04-18 15:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkShader> make_picture_shader() {
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
recorder.beginRecording(100, 100)->drawCircle(50, 50, 50, p);
|
|
|
|
|
2021-03-18 21:18:58 +00:00
|
|
|
return recorder.finishRecordingAsPicture()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
|
|
|
SkFilterMode::kNearest);
|
2018-04-18 15:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ShaderMFBench final : public Benchmark {
|
|
|
|
|
|
|
|
public:
|
|
|
|
using ShaderMaker = sk_sp<SkShader>(*)();
|
|
|
|
|
2021-09-23 18:35:56 +00:00
|
|
|
ShaderMFBench(const char* nm, bool opaque, const ShaderMaker maker)
|
|
|
|
: fMaker{maker}
|
|
|
|
, fColor{opaque ? 0xff00ff00 : 0x8000ff00} {
|
2018-04-18 15:14:50 +00:00
|
|
|
fName = SkStringPrintf("shadermaskfilter_%s_%x", nm, SkColorGetA(fColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:35:56 +00:00
|
|
|
void onDelayedSetup() override {
|
|
|
|
fMaskFilter = SkShaderMaskFilter::Make(fMaker());
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:14:50 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
|
|
SkPaint maskPaint;
|
|
|
|
maskPaint.setMaskFilter(fMaskFilter);
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
SkAutoCanvasRestore arc(canvas, false);
|
|
|
|
canvas->saveLayer(nullptr, &maskPaint);
|
|
|
|
canvas->drawColor(fColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-09-23 18:35:56 +00:00
|
|
|
const ShaderMaker fMaker;
|
|
|
|
const SkColor fColor;
|
|
|
|
SkString fName;
|
2018-04-18 15:14:50 +00:00
|
|
|
sk_sp<SkMaskFilter> fMaskFilter;
|
|
|
|
|
|
|
|
using INHERITED = Benchmark;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new ShaderMFBench("bitmap" , true , make_bitmap_shader ); )
|
|
|
|
DEF_BENCH( return new ShaderMFBench("bitmap" , false, make_bitmap_shader ); )
|
|
|
|
DEF_BENCH( return new ShaderMFBench("picture", true , make_picture_shader); )
|
|
|
|
DEF_BENCH( return new ShaderMFBench("picture", false, make_picture_shader); )
|