Flutter Engine
The Flutter Engine
Classes | Public Types | Static Public Member Functions | List of all members
SkRuntimeEffectPriv Class Reference

#include <SkRuntimeEffectPriv.h>

Classes

struct  UniformsCallbackContext
 

Public Types

using UniformsCallback = std::function< sk_sp< const SkData >(const UniformsCallbackContext &)>
 

Static Public Member Functions

static sk_sp< SkShaderMakeDeferredShader (const SkRuntimeEffect *effect, UniformsCallback uniformsCallback, SkSpan< const SkRuntimeEffect::ChildPtr > children, const SkMatrix *localMatrix=nullptr)
 
static bool SupportsConstantOutputForConstantInput (const SkRuntimeEffect *effect)
 
static uint32_t Hash (const SkRuntimeEffect &effect)
 
static uint32_t StableKey (const SkRuntimeEffect &effect)
 
static const SkSL::ProgramProgram (const SkRuntimeEffect &effect)
 
static SkRuntimeEffect::Options ES3Options ()
 
static void AllowPrivateAccess (SkRuntimeEffect::Options *options)
 
static void SetStableKey (SkRuntimeEffect::Options *options, uint32_t stableKey)
 
static SkRuntimeEffect::Uniform VarAsUniform (const SkSL::Variable &, const SkSL::Context &, size_t *offset)
 
static SkRuntimeEffect::Child VarAsChild (const SkSL::Variable &var, int index)
 
static const char * ChildTypeToStr (SkRuntimeEffect::ChildType type)
 
static sk_sp< const SkDataTransformUniforms (SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, const SkColorSpaceXformSteps &)
 
static sk_sp< const SkDataTransformUniforms (SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, const SkColorSpace *dstCS)
 
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 *)
 
static bool CanDraw (const SkCapabilities *, const SkRuntimeEffect *)
 
static bool ReadChildEffects (SkReadBuffer &buffer, const SkRuntimeEffect *effect, skia_private::TArray< SkRuntimeEffect::ChildPtr > *children)
 
static void WriteChildEffects (SkWriteBuffer &buffer, SkSpan< const SkRuntimeEffect::ChildPtr > children)
 
static bool UsesColorTransform (const SkRuntimeEffect *effect)
 

Detailed Description

Definition at line 50 of file SkRuntimeEffectPriv.h.

Member Typedef Documentation

◆ UniformsCallback

Definition at line 62 of file SkRuntimeEffectPriv.h.

Member Function Documentation

◆ AllowPrivateAccess()

static void SkRuntimeEffectPriv::AllowPrivateAccess ( SkRuntimeEffect::Options options)
inlinestatic

Definition at line 96 of file SkRuntimeEffectPriv.h.

96 {
97 options->allowPrivateAccess = true;
98 }
const char * options

◆ CanDraw() [1/2]

bool SkRuntimeEffectPriv::CanDraw ( const SkCapabilities caps,
const SkRuntimeEffect effect 
)
static

Definition at line 358 of file SkRuntimeEffect.cpp.

358 {
359 SkASSERT(effect);
360 return CanDraw(caps, effect->fBaseProgram.get());
361}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool CanDraw(const SkCapabilities *, const SkSL::Program *)

◆ CanDraw() [2/2]

bool SkRuntimeEffectPriv::CanDraw ( const SkCapabilities caps,
const SkSL::Program program 
)
static

Definition at line 352 of file SkRuntimeEffect.cpp.

352 {
353 SkASSERT(caps && program);
354 SkASSERT(program->fConfig->enforcesSkSLVersion());
355 return program->fConfig->fRequiredSkSLVersion <= caps->skslVersion();
356}
SkSL::Version skslVersion() const
std::unique_ptr< ProgramConfig > fConfig
Definition: SkSLProgram.h:153

◆ ChildTypeToStr()

const char * SkRuntimeEffectPriv::ChildTypeToStr ( SkRuntimeEffect::ChildType  type)
static

Definition at line 142 of file SkRuntimeEffect.cpp.

142 {
143 switch (type) {
144 case ChildType::kBlender: return "blender";
145 case ChildType::kColorFilter: return "color filter";
146 case ChildType::kShader: return "shader";
147 default: SkUNREACHABLE;
148 }
149}
#define SkUNREACHABLE
Definition: SkAssert.h:135
GLenum type

◆ ES3Options()

static SkRuntimeEffect::Options SkRuntimeEffectPriv::ES3Options ( )
inlinestatic

Definition at line 90 of file SkRuntimeEffectPriv.h.

◆ Hash()

static uint32_t SkRuntimeEffectPriv::Hash ( const SkRuntimeEffect effect)
inlinestatic

Definition at line 78 of file SkRuntimeEffectPriv.h.

78 {
79 return effect.hash();
80 }

◆ MakeDeferredShader()

sk_sp< SkShader > SkRuntimeEffectPriv::MakeDeferredShader ( const SkRuntimeEffect effect,
UniformsCallback  uniformsCallback,
SkSpan< const SkRuntimeEffect::ChildPtr children,
const SkMatrix localMatrix = nullptr 
)
static

Definition at line 800 of file SkRuntimeEffect.cpp.

804 {
805 if (!effect->allowShader()) {
806 return nullptr;
807 }
808 if (!verify_child_effects(effect->fChildren, children)) {
809 return nullptr;
810 }
811 if (!uniformsCallback) {
812 return nullptr;
813 }
814 return SkLocalMatrixShader::MakeWrapped<SkRuntimeShader>(localMatrix,
815 sk_ref_sp(effect),
816 /*debugTrace=*/nullptr,
817 std::move(uniformsCallback),
818 children);
819}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static bool verify_child_effects(const std::vector< SkRuntimeEffect::Child > &reflected, SkSpan< const SkRuntimeEffect::ChildPtr > effectPtrs)
bool allowShader() const

◆ Program()

static const SkSL::Program & SkRuntimeEffectPriv::Program ( const SkRuntimeEffect effect)
inlinestatic

Definition at line 86 of file SkRuntimeEffectPriv.h.

86 {
87 return *effect.fBaseProgram;
88 }

◆ ReadChildEffects()

bool SkRuntimeEffectPriv::ReadChildEffects ( SkReadBuffer buffer,
const SkRuntimeEffect effect,
skia_private::TArray< SkRuntimeEffect::ChildPtr > *  children 
)
static

If effect is specified, then the number and type of child objects are validated against the children() of effect. If it's nullptr, this is skipped, allowing deserialization of children, even when the effect could not be constructed (ie, due to malformed SkSL).

Definition at line 403 of file SkRuntimeEffect.cpp.

405 {
406 size_t childCount = buffer.read32();
407 if (effect && !buffer.validate(childCount == effect->children().size())) {
408 return false;
409 }
410
411 children->clear();
412 children->reserve_exact(childCount);
413
414 for (size_t i = 0; i < childCount; i++) {
415 sk_sp<SkFlattenable> obj(buffer.readRawFlattenable());
416 if (!flattenable_is_valid_as_child(obj.get())) {
417 buffer.validate(false);
418 return false;
419 }
420 children->push_back(std::move(obj));
421 }
422
423 // If we are validating against an effect, make sure any (non-null) children are the right type
424 if (effect) {
425 auto childInfo = effect->children();
426 SkASSERT(childInfo.size() == SkToSizeT(children->size()));
427 for (size_t i = 0; i < childCount; i++) {
428 std::optional<ChildType> ct = (*children)[i].type();
429 if (ct.has_value() && (*ct) != childInfo[i].type) {
430 buffer.validate(false);
431 }
432 }
433 }
434
435 return buffer.isValid();
436}
static bool flattenable_is_valid_as_child(const SkFlattenable *f)
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
SkSpan< const Child > children() const
int size() const
Definition: SkTArray.h:421
void reserve_exact(int n)
Definition: SkTArray.h:181
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

◆ SetStableKey()

static void SkRuntimeEffectPriv::SetStableKey ( SkRuntimeEffect::Options options,
uint32_t  stableKey 
)
inlinestatic

Definition at line 100 of file SkRuntimeEffectPriv.h.

100 {
101 options->fStableKey = stableKey;
102 }

◆ StableKey()

static uint32_t SkRuntimeEffectPriv::StableKey ( const SkRuntimeEffect effect)
inlinestatic

Definition at line 82 of file SkRuntimeEffectPriv.h.

82 {
83 return effect.fStableKey;
84 }

◆ SupportsConstantOutputForConstantInput()

static bool SkRuntimeEffectPriv::SupportsConstantOutputForConstantInput ( const SkRuntimeEffect effect)
inlinestatic

Definition at line 70 of file SkRuntimeEffectPriv.h.

70 {
71 // This optimization is only implemented for color filters without any children.
72 if (!effect->allowColorFilter() || !effect->children().empty()) {
73 return false;
74 }
75 return true;
76 }
bool allowColorFilter() const

◆ TransformUniforms() [1/2]

sk_sp< const SkData > SkRuntimeEffectPriv::TransformUniforms ( SkSpan< const SkRuntimeEffect::Uniform uniforms,
sk_sp< const SkData originalData,
const SkColorSpace dstCS 
)
static

Definition at line 159 of file SkRuntimeEffect.cpp.

162 {
163 if (!dstCS) {
164 // There's no destination color-space; we can early-out immediately.
165 return originalData;
166 }
168 dstCS, kUnpremul_SkAlphaType);
169 return TransformUniforms(uniforms, std::move(originalData), steps);
170}
kUnpremul_SkAlphaType
SkColorSpace * sk_srgb_singleton()
static sk_sp< const SkData > TransformUniforms(SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, const SkColorSpaceXformSteps &)

◆ TransformUniforms() [2/2]

sk_sp< const SkData > SkRuntimeEffectPriv::TransformUniforms ( SkSpan< const SkRuntimeEffect::Uniform uniforms,
sk_sp< const SkData originalData,
const SkColorSpaceXformSteps steps 
)
static

Definition at line 172 of file SkRuntimeEffect.cpp.

175 {
178
179 sk_sp<SkData> data = nullptr;
180 auto writableData = [&]() {
181 if (!data) {
182 data = SkData::MakeWithCopy(originalData->data(), originalData->size());
183 }
184 return data->writable_data();
185 };
186
187 for (const auto& u : uniforms) {
188 if (u.flags & Flags::kColor_Flag) {
189 SkASSERT(u.type == Type::kFloat3 || u.type == Type::kFloat4);
190 if (steps.flags.mask()) {
191 float* color = SkTAddOffset<float>(writableData(), u.offset);
192 if (u.type == Type::kFloat4) {
193 // RGBA, easy case
194 for (int i = 0; i < u.count; ++i) {
195 steps.apply(color);
196 color += 4;
197 }
198 } else {
199 // RGB, need to pad out to include alpha. Technically, this isn't necessary,
200 // because steps shouldn't include unpremul or premul, and thus shouldn't
201 // read or write the fourth element. But let's be safe.
202 float rgba[4];
203 for (int i = 0; i < u.count; ++i) {
204 memcpy(rgba, color, 3 * sizeof(float));
205 rgba[3] = 1.0f;
206 steps.apply(rgba);
207 memcpy(color, rgba, 3 * sizeof(float));
208 color += 3;
209 }
210 }
211 }
212 }
213 }
214 return data ? data : originalData;
215}
static const uint32_t rgba[kNumPixels]
const void * data() const
Definition: SkData.h:37
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
size_t size() const
Definition: SkData.h:30
DlColor color
constexpr uint32_t mask() const
void apply(float rgba[4]) const
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ UniformsAsSpan()

SkSpan< const float > SkRuntimeEffectPriv::UniformsAsSpan ( SkSpan< const SkRuntimeEffect::Uniform uniforms,
sk_sp< const SkData originalData,
bool  alwaysCopyIntoAlloc,
const SkColorSpace destColorSpace,
SkArenaAlloc alloc 
)
static

Definition at line 260 of file SkRuntimeEffect.cpp.

265 {
266 // Transform the uniforms into the destination colorspace.
268 originalData,
269 destColorSpace);
270 if (alwaysCopyIntoAlloc || originalData != transformedData) {
271 // The transformed uniform data's lifetime is not long enough to reuse; instead, we copy the
272 // uniform data directly into the alloc.
273 int numBytes = transformedData->size();
274 int numFloats = numBytes / sizeof(float);
275 float* uniformsInAlloc = alloc->makeArrayDefault<float>(numFloats);
276 memcpy(uniformsInAlloc, transformedData->data(), numBytes);
277 return SkSpan{uniformsInAlloc, numFloats};
278 }
279 // It's safe to return a pointer into existing data.
280 return SkSpan{static_cast<const float*>(originalData->data()),
281 originalData->size() / sizeof(float)};
282}
T * makeArrayDefault(size_t count)
Definition: SkArenaAlloc.h:171

◆ UsesColorTransform()

static bool SkRuntimeEffectPriv::UsesColorTransform ( const SkRuntimeEffect effect)
inlinestatic

Definition at line 137 of file SkRuntimeEffectPriv.h.

137 {
138 return effect->usesColorTransform();
139 }

◆ VarAsChild()

SkRuntimeEffect::Child SkRuntimeEffectPriv::VarAsChild ( const SkSL::Variable var,
int  index 
)
static

Definition at line 151 of file SkRuntimeEffect.cpp.

151 {
153 c.name = var.name();
154 c.type = child_type(var.type());
155 c.index = index;
156 return c;
157}
static ChildType child_type(const SkSL::Type &type)
std::string_view name() const
Definition: SkSLSymbol.h:51
const Type & type() const
Definition: SkSLSymbol.h:42
std::string_view name

◆ VarAsUniform()

SkRuntimeEffect::Uniform SkRuntimeEffectPriv::VarAsUniform ( const SkSL::Variable var,
const SkSL::Context context,
size_t *  offset 
)
static

Definition at line 101 of file SkRuntimeEffect.cpp.

103 {
106 Uniform uni;
107 uni.name = var.name();
108 uni.flags = 0;
109 uni.count = 1;
110
111 const SkSL::Type* type = &var.type();
112 if (type->isArray()) {
114 uni.count = type->columns();
115 type = &type->componentType();
116 }
117
118 if (type->hasPrecision() && !type->highPrecision()) {
120 }
121
122 SkAssertResult(init_uniform_type(context, type, &uni));
125 }
126
127 uni.offset = *offset;
128 *offset += uni.sizeInBytes();
130 return uni;
131}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static constexpr bool SkIsAlign4(T x)
Definition: SkAlign.h:20
SkMeshSpecification::Uniform Uniform
Definition: SkMesh.cpp:66
static bool init_uniform_type(const SkSL::Context &ctx, const SkSL::Type *type, SkRuntimeEffect::Uniform *v)
ModifierFlags modifierFlags() const
Definition: SkSLVariable.h:89
virtual const Layout & layout() const
SeparatedVector2 offset
LayoutFlags fFlags
Definition: SkSLLayout.h:112

◆ WriteChildEffects()

void SkRuntimeEffectPriv::WriteChildEffects ( SkWriteBuffer buffer,
SkSpan< const SkRuntimeEffect::ChildPtr children 
)
static

Definition at line 438 of file SkRuntimeEffect.cpp.

439 {
440 buffer.write32(children.size());
441 for (const auto& child : children) {
442 buffer.writeFlattenable(child.flattenable());
443 }
444}
constexpr size_t size() const
Definition: SkSpan_impl.h:95

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