36 {
37 FML_TRACE_EVENT(
"flutter",
"SceneNode::initFromAsset",
"asset", asset_name);
38
40 return "Completion callback must be a function.";
41 }
42
44 if (!dart_state->IsImpellerEnabled()) {
45 return "3D scenes require the Impeller rendering backend to be enabled.";
46 }
47
48 std::shared_ptr<AssetManager> asset_manager =
49 dart_state->platform_configuration()->client()->GetAssetManager();
50 std::unique_ptr<fml::Mapping>
data = asset_manager->GetAsMapping(asset_name);
51 if (
data ==
nullptr) {
52 return std::string("Asset '") + asset_name + std::string("' not found.");
53 }
54
55 auto& task_runners = dart_state->GetTaskRunners();
56
57 std::promise<std::shared_ptr<impeller::Context>> context_promise;
58 auto impeller_context_promise = context_promise.get_future();
59 task_runners.GetIOTaskRunner()->PostTask(
61 io_manager = dart_state->GetIOManager()]() mutable {
62 promise.set_value(io_manager ? io_manager->GetImpellerContext()
63 : nullptr);
64 }));
65
66 auto persistent_completion_callback =
67 std::make_unique<tonic::DartPersistentValue>(dart_state,
68 completion_callback_handle);
69
71 [
this,
callback = std::move(persistent_completion_callback)](
72 std::shared_ptr<impeller::scene::Node>
node)
mutable {
73 auto dart_state =
callback->dart_state().lock();
74 if (!dart_state) {
75
76 return;
77 }
79
80 node_ = std::move(
node);
82
83
84
86 });
87
88 task_runners.GetRasterTaskRunner()->PostTask(
90 impeller_context = impeller_context_promise.get(),
92 auto node = impeller::scene::Node::MakeFromFlatbuffer(
93 *data, *impeller_context->GetResourceAllocator());
94
95 task_runners.GetUITaskRunner()->PostTask(
96 [ui_task, node = std::move(node)]() { ui_task(node); });
97 }));
98
99 return "";
100}
fml::RefPtr< SceneNode > node(Dart_Handle shader)
static UIDartState * Current()
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
internal::CopyableLambda< T > MakeCopyable(T lambda)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
#define FML_TRACE_EVENT(category_group, name,...)