Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::FragmentProgram Class Reference

#include <fragment_program.h>

Inheritance diagram for flutter::FragmentProgram:
flutter::RefCountedDartWrappable< FragmentProgram > fml::RefCountedThreadSafe< FragmentProgram > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~FragmentProgram () override
 
std::string initFromAsset (const std::string &asset_name)
 
fml::RefPtr< FragmentShader > shader (Dart_Handle shader, Dart_Handle uniforms_handle, Dart_Handle samplers)
 
std::shared_ptr< DlColorSourceMakeDlColorSource (std::shared_ptr< std::vector< uint8_t > > float_uniforms, const std::vector< std::shared_ptr< DlColorSource > > &children)
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< FragmentProgram >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< FragmentProgram >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void Create (Dart_Handle wrapper)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< FragmentProgram >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 23 of file fragment_program.h.

Constructor & Destructor Documentation

◆ ~FragmentProgram()

flutter::FragmentProgram::~FragmentProgram ( )
overridedefault

Member Function Documentation

◆ Create()

void flutter::FragmentProgram::Create ( Dart_Handle  wrapper)
static

Definition at line 147 of file fragment_program.cc.

147 {
148 auto res = fml::MakeRefCounted<FragmentProgram>();
149 res->AssociateWithDartWrapper(wrapper);
150}

◆ initFromAsset()

std::string flutter::FragmentProgram::initFromAsset ( const std::string &  asset_name)

Definition at line 39 of file fragment_program.cc.

39 {
40 FML_TRACE_EVENT("flutter", "FragmentProgram::initFromAsset", "asset",
41 asset_name);
42 UIDartState* ui_dart_state = UIDartState::Current();
43 std::shared_ptr<AssetManager> asset_manager =
44 ui_dart_state->platform_configuration()->client()->GetAssetManager();
45
46 std::unique_ptr<fml::Mapping> data = asset_manager->GetAsMapping(asset_name);
47 if (data == nullptr) {
48 return std::string("Asset '") + asset_name + std::string("' not found");
49 }
50
51 auto runtime_stages =
53
54 if (runtime_stages.empty()) {
55 return std::string("Asset '") + asset_name +
56 std::string("' does not contain any shader data.");
57 }
58
60 ui_dart_state->GetRuntimeStageBackend();
61 std::shared_ptr<impeller::RuntimeStage> runtime_stage =
62 runtime_stages[backend];
63 if (!runtime_stage) {
64 std::ostringstream stream;
65 stream << "Asset '" << asset_name
66 << "' does not contain appropriate runtime stage data for current "
67 "backend ("
68 << RuntimeStageBackendToString(backend) << ")." << std::endl
69 << "Found stages: ";
70 for (const auto& kvp : runtime_stages) {
71 if (kvp.second) {
72 stream << RuntimeStageBackendToString(kvp.first) << " ";
73 }
74 }
75 return stream.str();
76 }
77
78 int sampled_image_count = 0;
79 size_t other_uniforms_bytes = 0;
80 for (const auto& uniform_description : runtime_stage->GetUniforms()) {
81 if (uniform_description.type ==
83 sampled_image_count++;
84 } else {
85 other_uniforms_bytes += uniform_description.GetSize();
86 }
87 }
88
89 if (UIDartState::Current()->IsImpellerEnabled()) {
90 // Spawn (but do not block on) a task that will load the runtime stage and
91 // populate an initial shader variant.
92 auto snapshot_controller = UIDartState::Current()->GetSnapshotDelegate();
93 ui_dart_state->GetTaskRunners().GetRasterTaskRunner()->PostTask(
94 [runtime_stage, snapshot_controller]() {
95 if (!snapshot_controller) {
96 return;
97 }
98 snapshot_controller->CacheRuntimeStage(runtime_stage);
99 });
100 runtime_effect_ = DlRuntimeEffect::MakeImpeller(std::move(runtime_stage));
101 } else {
102 const auto& code_mapping = runtime_stage->GetCodeMapping();
103 auto code_size = code_mapping->GetSize();
104 const char* sksl =
105 reinterpret_cast<const char*>(code_mapping->GetMapping());
106 // SkString makes a copy.
109 if (result.effect == nullptr) {
110 return std::string("Invalid SkSL:\n") + sksl +
111 std::string("\nSkSL Error:\n") + result.errorText.c_str();
112 }
113 runtime_effect_ = DlRuntimeEffect::MakeSkia(result.effect);
114 }
115
117 if (Dart_IsError(ths)) {
119 }
120
121 Dart_Handle result = Dart_SetField(ths, tonic::ToDart("_samplerCount"),
122 Dart_NewInteger(sampled_image_count));
123 if (Dart_IsError(result)) {
124 return "Failed to set sampler count for fragment program.";
125 }
126
127 size_t rounded_uniform_bytes =
128 (other_uniforms_bytes + sizeof(float) - 1) & ~(sizeof(float) - 1);
129 size_t float_count = rounded_uniform_bytes / sizeof(float);
130
131 result = Dart_SetField(ths, tonic::ToDart("_uniformFloatCount"),
132 Dart_NewInteger(float_count));
133 if (Dart_IsError(result)) {
134 return "Failed to set uniform float count for fragment program.";
135 }
136
137 return "";
138}
const char * backend
static Result MakeForShader(SkString sksl, const Options &)
static sk_sp< DlRuntimeEffect > MakeSkia(const sk_sp< SkRuntimeEffect > &runtime_effect)
static sk_sp< DlRuntimeEffect > MakeImpeller(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > GetSnapshotDelegate() const
static UIDartState * Current()
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Dart_WeakPersistentHandle dart_wrapper() const
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object)
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
static std::string RuntimeStageBackendToString(impeller::RuntimeStageBackend backend)
Dart_Handle ToDart(const T &object)
#define FML_TRACE_EVENT(category_group, name,...)
Definition: trace_event.h:121

◆ MakeDlColorSource()

std::shared_ptr< DlColorSource > flutter::FragmentProgram::MakeDlColorSource ( std::shared_ptr< std::vector< uint8_t > >  float_uniforms,
const std::vector< std::shared_ptr< DlColorSource > > &  children 
)

Definition at line 140 of file fragment_program.cc.

142 {
143 return DlColorSource::MakeRuntimeEffect(runtime_effect_, children,
144 std::move(float_uniforms));
145}
static std::shared_ptr< DlRuntimeEffectColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)

◆ shader()

fml::RefPtr< FragmentShader > flutter::FragmentProgram::shader ( Dart_Handle  shader,
Dart_Handle  uniforms_handle,
Dart_Handle  samplers 
)

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