Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
ThresholdRT Class Reference
Inheritance diagram for ThresholdRT:
RuntimeShaderGM skiagm::GM

Public Member Functions

 ThresholdRT ()
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
- Public Member Functions inherited from RuntimeShaderGM
 RuntimeShaderGM (const char *name, SkISize size, const char *sksl, uint32_t flags=0)
 
void onOnceBeforeDraw () override
 
bool runAsBench () const override
 
SkString getName () const override
 
SkISize getISize () override
 
bool onAnimate (double nanos) override
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Public Attributes

sk_sp< SkShaderfBefore
 
sk_sp< SkShaderfAfter
 
sk_sp< SkShaderfThreshold
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 
- Protected Attributes inherited from RuntimeShaderGM
SkString fName
 
SkISize fSize
 
uint32_t fFlags
 
float fSecs = 0.0f
 
SkString fSkSL
 
sk_sp< SkRuntimeEffectfEffect
 

Detailed Description

Definition at line 130 of file runtimeshader.cpp.

Constructor & Destructor Documentation

◆ ThresholdRT()

ThresholdRT::ThresholdRT ( )
inline

Definition at line 132 of file runtimeshader.cpp.

132 : RuntimeShaderGM("threshold_rt", {256, 256}, R"(
133 uniform shader before_map;
134 uniform shader after_map;
135 uniform shader threshold_map;
136
137 uniform float cutoff;
138 uniform float slope;
139
140 float smooth_cutoff(float x) {
141 x = x * slope + (0.5 - slope * cutoff);
142 return clamp(x, 0, 1);
143 }
144
145 half4 main(float2 xy) {
146 half4 before = before_map.eval(xy);
147 half4 after = after_map.eval(xy);
148
149 float m = smooth_cutoff(threshold_map.eval(xy).a);
150 return mix(before, after, m);
151 }
RuntimeShaderGM(const char *name, SkISize size, const char *sksl, uint32_t flags=0)
@ kAnimate_RTFlag
@ kBench_RTFlag

Member Function Documentation

◆ onDraw()

void ThresholdRT::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 165 of file runtimeshader.cpp.

165 {
167
168 builder.uniform("cutoff") = sinf(fSecs) * 0.55f + 0.5f;
169 builder.uniform("slope") = 10.0f;
170
171 builder.child("before_map") = fBefore;
172 builder.child("after_map") = fAfter;
173 builder.child("threshold_map") = fThreshold;
174
176 paint.setShader(builder.makeShader());
177 canvas->drawRect({0, 0, 256, 256}, paint);
178
179 auto draw = [&](SkScalar x, SkScalar y, sk_sp<SkShader> shader) {
180 paint.setShader(shader);
181 canvas->save();
182 canvas->translate(x, y);
183 canvas->drawRect({0, 0, 256, 256}, paint);
184 canvas->restore();
185 };
186 draw(256, 0, fThreshold);
187 draw( 0, 256, fBefore);
188 draw(256, 256, fAfter);
189 }
sk_sp< SkRuntimeEffect > fEffect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
sk_sp< SkShader > fAfter
sk_sp< SkShader > fBefore
sk_sp< SkShader > fThreshold
DrawResult draw(SkCanvas *canvas)
Definition: gm.h:140
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x

◆ onOnceBeforeDraw()

void ThresholdRT::onOnceBeforeDraw ( )
inlineoverridevirtual

Reimplemented from RuntimeShaderGM.

Definition at line 156 of file runtimeshader.cpp.

156 {
157 const SkISize size = {256, 256};
159 fBefore = make_shader(ToolUtils::GetResourceAsImage("images/mandrill_256.png"), size);
161
163 }
void onOnceBeforeDraw() override
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static sk_sp< SkShader > make_shader(sk_sp< SkImage > img, SkISize size)
static sk_sp< SkShader > make_threshold(SkISize size)
Definition: SkSize.h:16

Member Data Documentation

◆ fAfter

sk_sp<SkShader> ThresholdRT::fAfter

Definition at line 154 of file runtimeshader.cpp.

◆ fBefore

sk_sp<SkShader> ThresholdRT::fBefore

Definition at line 154 of file runtimeshader.cpp.

◆ fThreshold

sk_sp<SkShader> ThresholdRT::fThreshold

Definition at line 154 of file runtimeshader.cpp.


The documentation for this class was generated from the following file: