9#include "flutter/lib/ui/painting/fragment_program.h"
11#include "flutter/assets/asset_manager.h"
12#include "flutter/fml/trace_event.h"
13#include "flutter/impeller/runtime_stage/runtime_stage.h"
14#include "flutter/lib/ui/ui_dart_state.h"
15#include "flutter/lib/ui/window/platform_configuration.h"
43 std::shared_ptr<AssetManager> asset_manager =
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");
54 if (runtime_stages.empty()) {
55 return std::string(
"Asset '") + asset_name +
56 std::string(
"' does not contain any shader data.");
61 std::shared_ptr<impeller::RuntimeStage> runtime_stage =
65 stream <<
"Asset '" << asset_name
66 <<
"' does not contain appropriate runtime stage data for current "
70 for (
const auto& kvp : runtime_stages) {
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++;
85 other_uniforms_bytes += uniform_description.GetSize();
94 [runtime_stage, snapshot_controller]() {
95 if (!snapshot_controller) {
98 snapshot_controller->CacheRuntimeStage(runtime_stage);
102 const auto& code_mapping = runtime_stage->GetCodeMapping();
103 auto code_size = code_mapping->GetSize();
105 reinterpret_cast<const char*
>(code_mapping->GetMapping());
109 if (
result.effect ==
nullptr) {
110 return std::string(
"Invalid SkSL:\n") + sksl +
111 std::string(
"\nSkSL Error:\n") +
result.errorText.c_str();
124 return "Failed to set sampler count for fragment program.";
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);
134 return "Failed to set uniform float count for fragment program.";
141 std::shared_ptr<std::vector<uint8_t>> float_uniforms,
142 const std::vector<std::shared_ptr<DlColorSource>>& children) {
144 std::move(float_uniforms));
148 auto res = fml::MakeRefCounted<FragmentProgram>();
149 res->AssociateWithDartWrapper(wrapper);
152FragmentProgram::FragmentProgram() =
default;
static Result MakeForShader(SkString sksl, const Options &)
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)
static sk_sp< DlRuntimeEffect > MakeSkia(const sk_sp< SkRuntimeEffect > &runtime_effect)
static sk_sp< DlRuntimeEffect > MakeImpeller(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
std::shared_ptr< DlColorSource > MakeDlColorSource(std::shared_ptr< std::vector< uint8_t > > float_uniforms, const std::vector< std::shared_ptr< DlColorSource > > &children)
~FragmentProgram() override
std::string initFromAsset(const std::string &asset_name)
static void Create(Dart_Handle wrapper)
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
PlatformConfiguration * platform_configuration() const
const TaskRunners & GetTaskRunners() const
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > GetSnapshotDelegate() const
impeller::RuntimeStageBackend GetRuntimeStageBackend() const
The expected type for runtime stage shaders.
static UIDartState * Current()
virtual void PostTask(const fml::closure &task) override
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Dart_WeakPersistentHandle dart_wrapper() const
struct _Dart_Handle * Dart_Handle
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)
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static std::string RuntimeStageBackendToString(impeller::RuntimeStageBackend backend)
Dart_Handle ToDart(const T &object)
#define FML_TRACE_EVENT(category_group, name,...)