Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
SkRuntimeImageFilter Class Referencefinal
Inheritance diagram for SkRuntimeImageFilter:
SkImageFilter_Base SkImageFilter SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 SkRuntimeImageFilter (const SkRuntimeShaderBuilder &builder, float maxSampleRadius, std::string_view childShaderNames[], const sk_sp< SkImageFilter > inputs[], int inputCount)
 
SkRect computeFastBounds (const SkRect &src) const override
 
- Public Member Functions inherited from SkImageFilter_Base
skif::FilterResult filterImage (const skif::Context &context) const
 
sk_sp< SkImagemakeImageWithFilter (sk_sp< skif::Backend > backend, sk_sp< SkImage > src, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset) const
 
skif::LayerSpace< SkIRectgetInputBounds (const skif::Mapping &mapping, const skif::DeviceSpace< SkIRect > &desiredOutput, std::optional< skif::ParameterSpace< SkRect > > knownContentBounds) const
 
std::optional< skif::DeviceSpace< SkIRect > > getOutputBounds (const skif::Mapping &mapping, const skif::ParameterSpace< SkRect > &contentBounds) const
 
bool affectsTransparentBlack () const
 
bool usesSource () const
 
MatrixCapability getCTMCapability () const
 
uint32_t uniqueID () const
 
SkFlattenable::Type getFlattenableType () const override
 
- Public Member Functions inherited from SkImageFilter
SkIRect filterBounds (const SkIRect &src, const SkMatrix &ctm, MapDirection, const SkIRect *inputRect=nullptr) const
 
bool isColorFilterNode (SkColorFilter **filterPtr) const
 
bool asColorFilter (SkColorFilter **filterPtr) const
 
bool asAColorFilter (SkColorFilter **filterPtr) const
 
int countInputs () const
 
const SkImageFiltergetInput (int i) const
 
bool canComputeFastBounds () const
 
sk_sp< SkImageFiltermakeWithLocalMatrix (const SkMatrix &matrix) const
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

void flatten (SkWriteBuffer &) const override
 
- Protected Member Functions inherited from SkImageFilter_Base
 SkImageFilter_Base (sk_sp< SkImageFilter > const *inputs, int inputCount, std::optional< bool > usesSrc={})
 
 ~SkImageFilter_Base () override
 
skif::LayerSpace< SkIRectgetChildInputLayerBounds (int index, const skif::Mapping &mapping, const skif::LayerSpace< SkIRect > &desiredOutput, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const
 
std::optional< skif::LayerSpace< SkIRect > > getChildOutputLayerBounds (int index, const skif::Mapping &mapping, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const
 
skif::FilterResult getChildOutput (int index, const skif::Context &ctx) const
 
- Protected Member Functions inherited from SkImageFilter
sk_sp< SkImageFilterrefMe () const
 

Private Member Functions

bool onAffectsTransparentBlack () const override
 
MatrixCapability onGetCTMCapability () const override
 
skif::FilterResult onFilterImage (const skif::Context &) const override
 
skif::LayerSpace< SkIRectonGetInputLayerBounds (const skif::Mapping &mapping, const skif::LayerSpace< SkIRect > &desiredOutput, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const override
 
std::optional< skif::LayerSpace< SkIRect > > onGetOutputLayerBounds (const skif::Mapping &mapping, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const override
 

Additional Inherited Members

- Public Types inherited from SkImageFilter_Base
using MatrixCapability = skif::MatrixCapability
 
- Public Types inherited from SkImageFilter
enum  MapDirection { kForward_MapDirection , kReverse_MapDirection }
 
- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 
- Static Public Member Functions inherited from SkImageFilter_Base
static SkFlattenable::Type GetFlattenableType ()
 
static std::pair< sk_sp< SkImageFilter >, std::optional< SkRect > > Unflatten (SkReadBuffer &buffer)
 
- Static Public Member Functions inherited from SkImageFilter
static sk_sp< SkImageFilterDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 

Detailed Description

Definition at line 41 of file SkRuntimeImageFilter.cpp.

Constructor & Destructor Documentation

◆ SkRuntimeImageFilter()

SkRuntimeImageFilter::SkRuntimeImageFilter ( const SkRuntimeShaderBuilder builder,
float  maxSampleRadius,
std::string_view  childShaderNames[],
const sk_sp< SkImageFilter inputs[],
int  inputCount 
)
inline

Definition at line 43 of file SkRuntimeImageFilter.cpp.

48 : SkImageFilter_Base(inputs, inputCount)
49 , fRuntimeEffectBuilder(builder)
50 , fMaxSampleRadius(maxSampleRadius) {
51 SkASSERT(maxSampleRadius >= 0.f);
52 fChildShaderNames.reserve_exact(inputCount);
53 for (int i = 0; i < inputCount; i++) {
54 fChildShaderNames.push_back(SkString(childShaderNames[i]));
55 }
56 }
#define SkASSERT(cond)
Definition SkAssert.h:116
friend class SkImageFilter_Base
void reserve_exact(int n)
Definition SkTArray.h:176

Member Function Documentation

◆ computeFastBounds()

SkRect SkRuntimeImageFilter::computeFastBounds ( const SkRect src) const
overridevirtual

Reimplemented from SkImageFilter.

Definition at line 300 of file SkRuntimeImageFilter.cpp.

300 {
301 // Can't predict what the RT Shader will generate (see onGetOutputLayerBounds)
303}
static SkRect MakeLargeS32()
Definition SkRectPriv.h:33

◆ flatten()

void SkRuntimeImageFilter::flatten ( SkWriteBuffer ) const
overrideprotectedvirtual

Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()).

DEPRECATED public : will move to protected ... use serialize() instead

Reimplemented from SkImageFilter_Base.

Definition at line 217 of file SkRuntimeImageFilter.cpp.

217 {
219 fRuntimeEffectLock.acquire();
220 buffer.writeString(fRuntimeEffectBuilder.effect()->source().c_str());
221 buffer.writeDataAsByteArray(fRuntimeEffectBuilder.uniforms().get());
222 for (const SkString& name : fChildShaderNames) {
223 buffer.writeString(name.c_str());
224 }
225 for (size_t x = 0; x < fRuntimeEffectBuilder.children().size(); x++) {
226 buffer.writeFlattenable(fRuntimeEffectBuilder.children()[x].flattenable());
227 }
228 fRuntimeEffectLock.release();
229
230 buffer.writeScalar(fMaxSampleRadius);
231}
void flatten(SkWriteBuffer &) const override
sk_sp< const SkData > uniforms() const
const SkRuntimeEffect * effect() const
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
const std::string & source() const
T * get() const
Definition SkRefCnt.h:303
static const uint8_t buffer[]
const char * name
Definition fuchsia.cc:50
double x
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

◆ onAffectsTransparentBlack()

bool SkRuntimeImageFilter::onAffectsTransparentBlack ( ) const
inlineoverrideprivatevirtual

Return true if this filter would transform transparent black pixels to a color other than transparent black. When false, optimizations can be taken to discard regions known to be transparent black and thus process fewer pixels.

Reimplemented from SkImageFilter_Base.

Definition at line 67 of file SkRuntimeImageFilter.cpp.

67{ return true; }

◆ onFilterImage()

skif::FilterResult SkRuntimeImageFilter::onFilterImage ( const skif::Context context) const
overrideprivatevirtual

This is the virtual which should be overridden by the derived class to perform image filtering. Subclasses are responsible for recursing to their input filters, although the filterInput() function is provided to handle all necessary details of this.

If the image cannot be created (either because of an error or if the result would be empty because it was clipped out), this should return a filtered Image with a null SkSpecialImage. In these situations, callers that do not affect transparent black can end early, since the "transparent" implicit image would be unchanged. Callers that affect transparent black need to safely handle these null and empty images and return an image filling the context's clip bounds as if its input filtered image were transparent black.

Implements SkImageFilter_Base.

Definition at line 235 of file SkRuntimeImageFilter.cpp.

235 {
236 using ShaderFlags = skif::FilterResult::ShaderFlags;
237
238 const int inputCount = this->countInputs();
239 SkASSERT(inputCount == fChildShaderNames.size());
240
241 skif::Context inputCtx = ctx.withNewDesiredOutput(
242 this->applyMaxSampleRadius(ctx.mapping(), ctx.desiredOutput()));
244 for (int i = 0; i < inputCount; ++i) {
245 // Record the input context's desired output as the sample bounds for the child shaders
246 // since the runtime shader can go up to max sample radius away from its desired output
247 // (which is the default sample bounds if we didn't override it here).
248 builder.add(this->getChildOutput(i, inputCtx),
249 inputCtx.desiredOutput(),
250 ShaderFlags::kNonTrivialSampling);
251 }
252 return builder.eval([&](SkSpan<sk_sp<SkShader>> inputs) {
253 // lock the mutation of the builder and creation of the shader so that the builder's state
254 // is const and is safe for multi-threaded access.
255 fRuntimeEffectLock.acquire();
256 for (int i = 0; i < inputCount; i++) {
257 fRuntimeEffectBuilder.child(fChildShaderNames[i].c_str()) = inputs[i];
258 }
259 sk_sp<SkShader> shader = fRuntimeEffectBuilder.makeShader();
260
261 // Remove the inputs from the builder to avoid unnecessarily prolonging the input shaders'
262 // lifetimes.
263 for (int i = 0; i < inputCount; i++) {
264 fRuntimeEffectBuilder.child(fChildShaderNames[i].c_str()) = nullptr;
265 }
266 fRuntimeEffectLock.release();
267
268 return shader;
269 }, {}, /*evaluateInParameterSpace=*/true);
270}
skif::FilterResult getChildOutput(int index, const skif::Context &ctx) const
int countInputs() const
BuilderChild child(std::string_view name)
sk_sp< SkShader > makeShader(const SkMatrix *localMatrix=nullptr) const
int size() const
Definition SkTArray.h:416
const LayerSpace< SkIRect > & desiredOutput() const
Context withNewDesiredOutput(const LayerSpace< SkIRect > &desiredOutput) const

◆ onGetCTMCapability()

MatrixCapability SkRuntimeImageFilter::onGetCTMCapability ( ) const
inlineoverrideprivatevirtual

Return the most complex matrix type this filter can support (mapping from its parameter space to a layer space). If this returns anything less than kComplex, the filter only needs to worry about mapping from parameter to layer using a matrix that is constrained in that way (eg, scale+translate).

Reimplemented from SkImageFilter_Base.

Definition at line 71 of file SkRuntimeImageFilter.cpp.

71{ return MatrixCapability::kTranslate; }

◆ onGetInputLayerBounds()

skif::LayerSpace< SkIRect > SkRuntimeImageFilter::onGetInputLayerBounds ( const skif::Mapping mapping,
const skif::LayerSpace< SkIRect > &  desiredOutput,
std::optional< skif::LayerSpace< SkIRect > >  contentBounds 
) const
overrideprivatevirtual

Calculates the necessary input layer size in order for the final output of the filter to cover the desired output bounds. The provided 'desiredOutput' represents the requested input bounds for this node's parent filter node, i.e. this function answers "what does this node require for input in order to satisfy (as its own output), the input needs of its parent?".

'contentBounds' represents the bounds of the non-transparent content that will form the source image when the filter graph is invoked. If it's not instantiated, implementations should treat the content as extending infinitely. However, since the output is known and bounded, implementations should still be able to determine a finite input bounds under these circumstances.

Unlike the public getInputBounds(), all internal bounds calculations are done in the shared layer space defined by 'mapping'.

Implements SkImageFilter_Base.

Definition at line 272 of file SkRuntimeImageFilter.cpp.

275 {
276 const int inputCount = this->countInputs();
277 if (inputCount <= 0) {
279 } else {
280 // Provide 'maxSampleRadius' pixels (in layer space) to the child shaders.
281 skif::LayerSpace<SkIRect> requiredInput =
282 this->applyMaxSampleRadius(mapping, desiredOutput);
283
284 // Union of all child input bounds so that one source image can provide for all of them.
286 inputCount,
287 [&](int i) {
288 return this->getChildInputLayerBounds(i, mapping, requiredInput, contentBounds);
289 });
290 }
291}
skif::LayerSpace< SkIRect > getChildInputLayerBounds(int index, const skif::Mapping &mapping, const skif::LayerSpace< SkIRect > &desiredOutput, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const

◆ onGetOutputLayerBounds()

std::optional< skif::LayerSpace< SkIRect > > SkRuntimeImageFilter::onGetOutputLayerBounds ( const skif::Mapping mapping,
std::optional< skif::LayerSpace< SkIRect > >  contentBounds 
) const
overrideprivatevirtual

Calculates the output bounds that this filter node would touch when processing an input sized to 'contentBounds'. This function is responsible for recursing to its child image filters and accounting for what they output. It is up to the filter to determine how to aggregate the outputs of its children.

'contentBounds' represents the bounds of the non-transparent content that will form the source image when the filter graph is invoked. If it's not instantiated, implementations should treat the content as extending infinitely. However, since the output is known and bounded, implementations should still be able to determine a finite input bounds under these circumstances.

If the non-transparent output extends infinitely, subclasses should return an uninstantiated optional. Implementations must also be able to handle when their children return such unbounded "outputs" and react accordingly.

Unlike the public getOutputBounds(), all internal bounds calculations are done in the shared layer space defined by 'mapping'.

Implements SkImageFilter_Base.

Definition at line 293 of file SkRuntimeImageFilter.cpp.

295 {
296 // Pessimistically assume it can cover anything
298}

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