Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkRuntimeShader Class Reference

#include <SkRuntimeShader.h>

Inheritance diagram for SkRuntimeShader:
SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 SkRuntimeShader (sk_sp< SkRuntimeEffect > effect, sk_sp< SkSL::DebugTracePriv > debugTrace, sk_sp< const SkData > uniforms, SkSpan< const SkRuntimeEffect::ChildPtr > children)
 
 SkRuntimeShader (sk_sp< SkRuntimeEffect > effect, sk_sp< SkSL::DebugTracePriv > debugTrace, UniformsCallback uniformsCallback, SkSpan< const SkRuntimeEffect::ChildPtr > children)
 
SkRuntimeEffect::TracedShader makeTracedClone (const SkIPoint &coord)
 
bool isOpaque () const override
 
ShaderType type () const override
 
bool appendStages (const SkStageRec &rec, const SkShaders::MatrixRec &mRec) const override
 
void flatten (SkWriteBuffer &buffer) const override
 
SkRuntimeEffectasRuntimeEffect () const override
 
sk_sp< SkRuntimeEffecteffect () const
 
SkSpan< const SkRuntimeEffect::ChildPtrchildren () const
 
sk_sp< const SkDatauniformData (const SkColorSpace *dstCS) const
 
- Public Member Functions inherited from SkShaderBase
 ~SkShaderBase () override
 
sk_sp< SkShadermakeInvertAlpha () const
 
sk_sp< SkShadermakeWithCTM (const SkMatrix &) const
 
virtual bool isConstant () const
 
virtual ShaderType type () const =0
 
virtual GradientType asGradient (GradientInfo *info=nullptr, SkMatrix *localMatrix=nullptr) const
 
ContextmakeContext (const ContextRec &, SkArenaAlloc *) const
 
bool asLuminanceColor (SkColor4f *) const
 
bool appendRootStages (const SkStageRec &rec, const SkMatrix &ctm) const
 
virtual bool appendStages (const SkStageRec &, const SkShaders::MatrixRec &) const =0
 
virtual SkImageonIsAImage (SkMatrix *, SkTileMode[2]) const
 
virtual SkRuntimeEffectasRuntimeEffect () const
 
Type getFlattenableType () const override
 
virtual sk_sp< SkShadermakeAsALocalMatrixShader (SkMatrix *localMatrix) const
 
- Public Member Functions inherited from SkShader
virtual bool isOpaque () const
 
SkImageisAImage (SkMatrix *localMatrix, SkTileMode xy[2]) const
 
bool isAImage () const
 
sk_sp< SkShadermakeWithLocalMatrix (const SkMatrix &) const
 
sk_sp< SkShadermakeWithColorFilter (sk_sp< SkColorFilter >) const
 
sk_sp< SkShadermakeWithWorkingColorSpace (sk_sp< SkColorSpace >) const
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
virtual void flatten (SkWriteBuffer &) const
 
virtual Type getFlattenableType () 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
 

Additional Inherited Members

- Public Types inherited from SkShaderBase
enum class  ShaderType { M }
 
enum class  GradientType { kNone , M }
 
enum  Flags { kOpaqueAlpha_Flag = 1 << 0 }
 
- 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 SkShaderBase
static Type GetFlattenableType ()
 
static sk_sp< SkShaderBaseDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
static void RegisterFlattenables ()
 
static SkMatrix ConcatLocalMatrices (const SkMatrix &parentLM, const SkMatrix &childLM)
 
- 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)
 
- Protected Member Functions inherited from SkShaderBase
 SkShaderBase ()
 
void flatten (SkWriteBuffer &) const override
 
virtual bool onAsLuminanceColor (SkColor4f *) const
 

Detailed Description

Definition at line 30 of file SkRuntimeShader.h.

Constructor & Destructor Documentation

◆ SkRuntimeShader() [1/2]

SkRuntimeShader::SkRuntimeShader ( sk_sp< SkRuntimeEffect effect,
sk_sp< SkSL::DebugTracePriv debugTrace,
sk_sp< const SkData uniforms,
SkSpan< const SkRuntimeEffect::ChildPtr children 
)

Definition at line 44 of file SkRuntimeShader.cpp.

48 : fEffect(std::move(effect))
49 , fDebugTrace(std::move(debugTrace))
50 , fUniformData(std::move(uniforms))
51 , fChildren(children.begin(), children.end()) {}
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
sk_sp< SkRuntimeEffect > effect() const
constexpr T * begin() const
Definition: SkSpan_impl.h:90
constexpr T * end() const
Definition: SkSpan_impl.h:91

◆ SkRuntimeShader() [2/2]

SkRuntimeShader::SkRuntimeShader ( sk_sp< SkRuntimeEffect effect,
sk_sp< SkSL::DebugTracePriv debugTrace,
UniformsCallback  uniformsCallback,
SkSpan< const SkRuntimeEffect::ChildPtr children 
)

Definition at line 53 of file SkRuntimeShader.cpp.

57 : fEffect(std::move(effect))
58 , fDebugTrace(std::move(debugTrace))
59 , fUniformsCallback(std::move(uniformsCallback))
60 , fChildren(children.begin(), children.end()) {}

Member Function Documentation

◆ appendStages()

bool SkRuntimeShader::appendStages ( const SkStageRec ,
const SkShaders::MatrixRec  
) const
overridevirtual

Adds stages to implement this shader. To ensure that the correct input coords are present in r,g MatrixRec::apply() must be called (unless the shader doesn't require it's input coords). The default impl creates shadercontext and calls that (not very efficient).

Implements SkShaderBase.

Definition at line 79 of file SkRuntimeShader.cpp.

79 {
81 // SkRP has support for many parts of #version 300 already, but for now, we restrict its
82 // usage in runtime effects to just #version 100.
83 return false;
84 }
85 if (const SkSL::RP::Program* program = fEffect->getRPProgram(fDebugTrace.get())) {
86 std::optional<SkShaders::MatrixRec> newMRec = mRec.apply(rec);
87 if (!newMRec.has_value()) {
88 return false;
89 }
90 SkSpan<const float> uniforms =
92 this->uniformData(rec.fDstCS),
93 /*alwaysCopyIntoAlloc=*/fUniformData == nullptr,
94 rec.fDstCS,
95 rec.fAlloc);
96 RuntimeEffectRPCallbacks callbacks(rec, *newMRec, fChildren, fEffect->fSampleUsages);
97 bool success = program->appendStages(rec.fPipeline, rec.fAlloc, &callbacks, uniforms);
98 return success;
99 }
100 return false;
101}
static sk_sp< const SkCapabilities > RasterBackend()
static SkSpan< const float > UniformsAsSpan(SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, bool alwaysCopyIntoAlloc, const SkColorSpace *destColorSpace, SkArenaAlloc *alloc)
static bool CanDraw(const SkCapabilities *, const SkSL::Program *)
SkSpan< const Uniform > uniforms() const
T * get() const
Definition: SkRefCnt.h:303
const myers::Point & get(const myers::Segment &)

◆ asRuntimeEffect()

SkRuntimeEffect * SkRuntimeShader::asRuntimeEffect ( ) const
inlineoverridevirtual

Reimplemented from SkShaderBase.

Definition at line 52 of file SkRuntimeShader.h.

52{ return fEffect.get(); }

◆ children()

SkSpan< const SkRuntimeEffect::ChildPtr > SkRuntimeShader::children ( ) const
inline

Definition at line 55 of file SkRuntimeShader.h.

55{ return fChildren; }

◆ effect()

sk_sp< SkRuntimeEffect > SkRuntimeShader::effect ( ) const
inline

Definition at line 54 of file SkRuntimeShader.h.

54{ return fEffect; }

◆ flatten()

void SkRuntimeShader::flatten ( SkWriteBuffer ) const
overridevirtual

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 SkFlattenable.

Definition at line 103 of file SkRuntimeShader.cpp.

103 {
104 buffer.writeString(fEffect->source().c_str());
105 buffer.writeDataAsByteArray(this->uniformData(nullptr).get());
107}
static void WriteChildEffects(SkWriteBuffer &buffer, SkSpan< const SkRuntimeEffect::ChildPtr > children)
const std::string & source() const
sk_sp< const SkData > uniformData(const SkColorSpace *dstCS) const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ isOpaque()

bool SkRuntimeShader::isOpaque ( ) const
inlineoverridevirtual

Returns true if the shader is guaranteed to produce only opaque colors, subject to the SkPaint using the shader to apply an opaque alpha value. Subclasses should override this to allow some optimizations.

Reimplemented from SkShader.

Definition at line 44 of file SkRuntimeShader.h.

44{ return fEffect->alwaysOpaque(); }

◆ makeTracedClone()

SkRuntimeEffect::TracedShader SkRuntimeShader::makeTracedClone ( const SkIPoint coord)

Definition at line 70 of file SkRuntimeShader.cpp.

70 {
71 sk_sp<SkRuntimeEffect> unoptimized = fEffect->makeUnoptimizedClone();
72 sk_sp<SkSL::DebugTracePriv> debugTrace = make_debug_trace(unoptimized.get(), coord);
73 auto debugShader = sk_make_sp<SkRuntimeShader>(
74 unoptimized, debugTrace, this->uniformData(nullptr), SkSpan(fChildren));
75
76 return SkRuntimeEffect::TracedShader{std::move(debugShader), std::move(debugTrace)};
77}
static sk_sp< SkSL::DebugTracePriv > make_debug_trace(SkRuntimeEffect *effect, const SkIPoint &coord)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >

◆ type()

ShaderType SkRuntimeShader::type ( ) const
inlineoverridevirtual

Implements SkShaderBase.

Definition at line 46 of file SkRuntimeShader.h.

46{ return ShaderType::kRuntime; }

◆ uniformData()

sk_sp< const SkData > SkRuntimeShader::uniformData ( const SkColorSpace dstCS) const

Definition at line 109 of file SkRuntimeShader.cpp.

109 {
110 if (fUniformData) {
111 return fUniformData;
112 }
113
114 // We want to invoke the uniforms-callback each time a paint occurs.
115 SkASSERT(fUniformsCallback);
116 sk_sp<const SkData> uniforms = fUniformsCallback({dstCS});
117 SkASSERT(uniforms && uniforms->size() == fEffect->uniformSize());
118 return uniforms;
119}
#define SkASSERT(cond)
Definition: SkAssert.h:116
size_t size() const
Definition: SkData.h:30
size_t uniformSize() const

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