Flutter Engine
The Flutter Engine
ShaderMaskFilterBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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"
18
20 SkPaint p;
21 p.setColor(SK_ColorBLACK);
22 p.setAntiAlias(true);
23
25 surface->getCanvas()->drawCircle(50, 50, 50, p);
26
27 return surface->makeImageSnapshot()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
29}
30
32 SkPaint p;
33 p.setColor(SK_ColorBLACK);
34 p.setAntiAlias(true);
35
36 SkPictureRecorder recorder;
37 recorder.beginRecording(100, 100)->drawCircle(50, 50, 50, p);
38
41}
42
43class ShaderMFBench final : public Benchmark {
44
45public:
47
48 ShaderMFBench(const char* nm, bool opaque, const ShaderMaker maker)
49 : fMaker{maker}
50 , fColor{opaque ? 0xff00ff00 : 0x8000ff00} {
51 fName = SkStringPrintf("shadermaskfilter_%s_%x", nm, SkColorGetA(fColor));
52 }
53
54protected:
55 const char* onGetName() override {
56 return fName.c_str();
57 }
58
59 void onDelayedSetup() override {
60 fMaskFilter = SkShaderMaskFilter::Make(fMaker());
61 }
62
63 void onDraw(int loops, SkCanvas* canvas) override {
64 SkPaint maskPaint;
65 maskPaint.setMaskFilter(fMaskFilter);
66
67 for (int i = 0; i < loops; ++i) {
68 SkAutoCanvasRestore arc(canvas, false);
69 canvas->saveLayer(nullptr, &maskPaint);
70 canvas->drawColor(fColor);
71 }
72 }
73
74private:
75 const ShaderMaker fMaker;
76 const SkColor fColor;
77 SkString fName;
78 sk_sp<SkMaskFilter> fMaskFilter;
79
80 using INHERITED = Benchmark;
81};
82
83DEF_BENCH( return new ShaderMFBench("bitmap" , true , make_bitmap_shader ); )
84DEF_BENCH( return new ShaderMFBench("bitmap" , false, make_bitmap_shader ); )
85DEF_BENCH( return new ShaderMFBench("picture", true , make_picture_shader); )
86DEF_BENCH( return new ShaderMFBench("picture", false, make_picture_shader); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
static sk_sp< SkShader > make_picture_shader()
static sk_sp< SkShader > make_bitmap_shader()
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SkColorGetA(color)
Definition: SkColor.h:61
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
ShaderMFBench(const char *nm, bool opaque, const ShaderMaker maker)
void onDelayedSetup() override
sk_sp< SkShader >(*)() ShaderMaker
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
static sk_sp< SkMaskFilter > Make(sk_sp< SkShader > shader)
const char * c_str() const
Definition: SkString.h:133
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)