Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Typedefs | Functions | Variables
SkRuntimeEffect.cpp File Reference
#include "include/effects/SkRuntimeEffect.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBlender.h"
#include "include/core/SkCapabilities.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkData.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMutex.h"
#include "include/private/base/SkOnce.h"
#include "include/private/base/SkTArray.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkEnumBitMask.h"
#include "src/base/SkNoDestructor.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkChecksum.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkEffectPriv.h"
#include "src/core/SkLRUCache.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkRuntimeBlender.h"
#include "src/core/SkRuntimeEffectPriv.h"
#include "src/core/SkStreamPriv.h"
#include "src/core/SkWriteBuffer.h"
#include "src/effects/colorfilters/SkColorFilterBase.h"
#include "src/effects/colorfilters/SkRuntimeColorFilter.h"
#include "src/shaders/SkLocalMatrixShader.h"
#include "src/shaders/SkRuntimeShader.h"
#include "src/shaders/SkShaderBase.h"
#include "src/sksl/SkSLAnalysis.h"
#include "src/sksl/SkSLBuiltinTypes.h"
#include "src/sksl/SkSLCompiler.h"
#include "src/sksl/SkSLContext.h"
#include "src/sksl/SkSLDefines.h"
#include "src/sksl/SkSLProgramKind.h"
#include "src/sksl/SkSLProgramSettings.h"
#include "src/sksl/analysis/SkSLProgramUsage.h"
#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include "src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h"
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLLayout.h"
#include "src/sksl/ir/SkSLModifierFlags.h"
#include "src/sksl/ir/SkSLProgram.h"
#include "src/sksl/ir/SkSLProgramElement.h"
#include "src/sksl/ir/SkSLStatement.h"
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLVarDeclarations.h"
#include "src/sksl/ir/SkSLVariable.h"
#include "src/sksl/tracing/SkSLDebugTracePriv.h"
#include <algorithm>

Go to the source code of this file.

Macros

#define RETURN_FAILURE(...)   return Result{nullptr, SkStringPrintf(__VA_ARGS__)}
 

Typedefs

using ChildType = SkRuntimeEffect::ChildType
 

Functions

static bool init_uniform_type (const SkSL::Context &ctx, const SkSL::Type *type, SkRuntimeEffect::Uniform *v)
 
static ChildType child_type (const SkSL::Type &type)
 
static bool flattenable_is_valid_as_child (const SkFlattenable *f)
 
static bool verify_child_effects (const std::vector< SkRuntimeEffect::Child > &reflected, SkSpan< const SkRuntimeEffect::ChildPtr > effectPtrs)
 
sk_sp< SkRuntimeEffectSkMakeCachedRuntimeEffect (SkRuntimeEffect::Result(*make)(SkString sksl, const SkRuntimeEffect::Options &), SkString sksl)
 
static size_t uniform_element_size (SkRuntimeEffect::Uniform::Type type)
 

Variables

constexpr bool kRPEnableLiveTrace = false
 

Macro Definition Documentation

◆ RETURN_FAILURE

#define RETURN_FAILURE (   ...)    return Result{nullptr, SkStringPrintf(__VA_ARGS__)}

Definition at line 465 of file SkRuntimeEffect.cpp.

Typedef Documentation

◆ ChildType

Definition at line 72 of file SkRuntimeEffect.cpp.

Function Documentation

◆ child_type()

static ChildType child_type ( const SkSL::Type type)
static

Definition at line 133 of file SkRuntimeEffect.cpp.

133 {
134 switch (type.typeKind()) {
135 case SkSL::Type::TypeKind::kBlender: return ChildType::kBlender;
136 case SkSL::Type::TypeKind::kColorFilter: return ChildType::kColorFilter;
137 case SkSL::Type::TypeKind::kShader: return ChildType::kShader;
138 default: SkUNREACHABLE;
139 }
140}
#define SkUNREACHABLE
Definition SkAssert.h:135

◆ flattenable_is_valid_as_child()

static bool flattenable_is_valid_as_child ( const SkFlattenable f)
static

Definition at line 365 of file SkRuntimeEffect.cpp.

365 {
366 if (!f) { return true; }
367 switch (f->getFlattenableType()) {
371 return true;
372 default:
373 return false;
374 }
375}

◆ init_uniform_type()

static bool init_uniform_type ( const SkSL::Context ctx,
const SkSL::Type type,
SkRuntimeEffect::Uniform v 
)
static

Definition at line 74 of file SkRuntimeEffect.cpp.

76 {
78 if (type->matches(*ctx.fTypes.fFloat)) { v->type = Type::kFloat; return true; }
79 if (type->matches(*ctx.fTypes.fHalf)) { v->type = Type::kFloat; return true; }
80 if (type->matches(*ctx.fTypes.fFloat2)) { v->type = Type::kFloat2; return true; }
81 if (type->matches(*ctx.fTypes.fHalf2)) { v->type = Type::kFloat2; return true; }
82 if (type->matches(*ctx.fTypes.fFloat3)) { v->type = Type::kFloat3; return true; }
83 if (type->matches(*ctx.fTypes.fHalf3)) { v->type = Type::kFloat3; return true; }
84 if (type->matches(*ctx.fTypes.fFloat4)) { v->type = Type::kFloat4; return true; }
85 if (type->matches(*ctx.fTypes.fHalf4)) { v->type = Type::kFloat4; return true; }
86 if (type->matches(*ctx.fTypes.fFloat2x2)) { v->type = Type::kFloat2x2; return true; }
87 if (type->matches(*ctx.fTypes.fHalf2x2)) { v->type = Type::kFloat2x2; return true; }
88 if (type->matches(*ctx.fTypes.fFloat3x3)) { v->type = Type::kFloat3x3; return true; }
89 if (type->matches(*ctx.fTypes.fHalf3x3)) { v->type = Type::kFloat3x3; return true; }
90 if (type->matches(*ctx.fTypes.fFloat4x4)) { v->type = Type::kFloat4x4; return true; }
91 if (type->matches(*ctx.fTypes.fHalf4x4)) { v->type = Type::kFloat4x4; return true; }
92
93 if (type->matches(*ctx.fTypes.fInt)) { v->type = Type::kInt; return true; }
94 if (type->matches(*ctx.fTypes.fInt2)) { v->type = Type::kInt2; return true; }
95 if (type->matches(*ctx.fTypes.fInt3)) { v->type = Type::kInt3; return true; }
96 if (type->matches(*ctx.fTypes.fInt4)) { v->type = Type::kInt4; return true; }
97
98 return false;
99}
const std::unique_ptr< Type > fFloat2
const std::unique_ptr< Type > fHalf4
const std::unique_ptr< Type > fInt4
const std::unique_ptr< Type > fHalf2x2
const std::unique_ptr< Type > fInt2
const std::unique_ptr< Type > fInt
const std::unique_ptr< Type > fFloat2x2
const std::unique_ptr< Type > fFloat4x4
const std::unique_ptr< Type > fInt3
const std::unique_ptr< Type > fFloat4
const std::unique_ptr< Type > fHalf2
const std::unique_ptr< Type > fHalf3x3
const std::unique_ptr< Type > fFloat3x3
const std::unique_ptr< Type > fHalf3
const std::unique_ptr< Type > fFloat
const std::unique_ptr< Type > fFloat3
const std::unique_ptr< Type > fHalf
const std::unique_ptr< Type > fHalf4x4
const BuiltinTypes & fTypes
Definition SkSLContext.h:30

◆ SkMakeCachedRuntimeEffect()

sk_sp< SkRuntimeEffect > SkMakeCachedRuntimeEffect ( SkRuntimeEffect::Result(*)(SkString sksl, const SkRuntimeEffect::Options &)  make,
SkString  sksl 
)

Definition at line 680 of file SkRuntimeEffect.cpp.

682 {
683 static SkNoDestructor<SkMutex> mutex;
685
686 uint64_t key = SkChecksum::Hash64(sksl.c_str(), sksl.size());
687 {
688 SkAutoMutexExclusive _(*mutex);
689 if (sk_sp<SkRuntimeEffect>* found = cache->find(key)) {
690 return *found;
691 }
692 }
693
696
697 auto [effect, err] = make(std::move(sksl), options);
698 if (!effect) {
699 SkDEBUGFAILF("%s", err.c_str());
700 return nullptr;
701 }
702 SkASSERT(err.isEmpty());
703
704 {
705 SkAutoMutexExclusive _(*mutex);
706 cache->insert_or_update(key, effect);
707 }
708 return effect;
709}
const char * options
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119
#define SkASSERT(cond)
Definition SkAssert.h:116
static void AllowPrivateAccess(SkRuntimeEffect::Options *options)
size_t size() const
Definition SkString.h:131
const char * c_str() const
Definition SkString.h:133
static sk_sp< SkImage > make(sk_sp< SkColorSpace > cs)
Definition mipmap.cpp:65
uint64_t Hash64(const void *data, size_t bytes, uint64_t seed)
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191

◆ uniform_element_size()

static size_t uniform_element_size ( SkRuntimeEffect::Uniform::Type  type)
static

Definition at line 711 of file SkRuntimeEffect.cpp.

711 {
712 switch (type) {
714 case SkRuntimeEffect::Uniform::Type::kFloat2: return sizeof(float) * 2;
715 case SkRuntimeEffect::Uniform::Type::kFloat3: return sizeof(float) * 3;
716 case SkRuntimeEffect::Uniform::Type::kFloat4: return sizeof(float) * 4;
717
718 case SkRuntimeEffect::Uniform::Type::kFloat2x2: return sizeof(float) * 4;
719 case SkRuntimeEffect::Uniform::Type::kFloat3x3: return sizeof(float) * 9;
720 case SkRuntimeEffect::Uniform::Type::kFloat4x4: return sizeof(float) * 16;
721
722 case SkRuntimeEffect::Uniform::Type::kInt: return sizeof(int);
723 case SkRuntimeEffect::Uniform::Type::kInt2: return sizeof(int) * 2;
724 case SkRuntimeEffect::Uniform::Type::kInt3: return sizeof(int) * 3;
725 case SkRuntimeEffect::Uniform::Type::kInt4: return sizeof(int) * 4;
726 default: SkUNREACHABLE;
727 }
728}
Type::kYUV Type::kRGBA() int(0.7 *637)

◆ verify_child_effects()

static bool verify_child_effects ( const std::vector< SkRuntimeEffect::Child > &  reflected,
SkSpan< const SkRuntimeEffect::ChildPtr effectPtrs 
)
static

Definition at line 381 of file SkRuntimeEffect.cpp.

382 {
383 // Verify that the number of passed-in child-effect pointers matches the SkSL code.
384 if (reflected.size() != effectPtrs.size()) {
385 return false;
386 }
387
388 // Verify that each child object's type matches its declared type in the SkSL.
389 for (size_t i = 0; i < effectPtrs.size(); ++i) {
390 std::optional<ChildType> effectType = effectPtrs[i].type();
391 if (effectType && effectType != reflected[i].type) {
392 return false;
393 }
394 }
395 return true;
396}
constexpr size_t size() const
Definition SkSpan_impl.h:95

Variable Documentation

◆ kRPEnableLiveTrace

constexpr bool kRPEnableLiveTrace = false
constexpr

Definition at line 70 of file SkRuntimeEffect.cpp.