5#include "flutter/lib/ui/painting/scene/scene_node.h"
10#include "flutter/assets/asset_manager.h"
11#include "flutter/fml/make_copyable.h"
12#include "flutter/fml/trace_event.h"
13#include "flutter/lib/ui/dart_wrapper.h"
14#include "flutter/lib/ui/painting/scene/scene_shader.h"
15#include "flutter/lib/ui/ui_dart_state.h"
16#include "flutter/lib/ui/window/platform_configuration.h"
31 auto res = fml::MakeRefCounted<SceneNode>();
32 res->AssociateWithDartWrapper(wrapper);
37 FML_TRACE_EVENT(
"flutter",
"SceneNode::initFromAsset",
"asset", asset_name);
40 return "Completion callback must be a function.";
44 if (!dart_state->IsImpellerEnabled()) {
45 return "3D scenes require the Impeller rendering backend to be enabled.";
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.");
55 auto& task_runners = dart_state->GetTaskRunners();
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()
66 auto persistent_completion_callback =
67 std::make_unique<tonic::DartPersistentValue>(dart_state,
68 completion_callback_handle);
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();
80 node_ = std::move(
node);
88 task_runners.GetRasterTaskRunner()->PostTask(
90 impeller_context = impeller_context_promise.get(),
92 auto node = impeller::scene::Node::MakeFromFlatbuffer(
93 *data, *impeller_context->GetResourceAllocator());
95 task_runners.GetUITaskRunner()->PostTask(
96 [ui_task, node = std::move(node)]() { ui_task(node); });
121void SceneNode::initFromTransform(
const tonic::Float64List& matrix4) {
122 node_ = std::make_shared<impeller::scene::Node>();
123 node_->SetLocalTransform(
ToMatrix(matrix4));
135 node_->AddChild(scene_node->node_);
136 children_.push_back(
fml::Ref(scene_node));
139void SceneNode::SetTransform(
const tonic::Float64List& matrix4) {
142 node_->AddMutation(entry);
145void SceneNode::SetAnimationState(
const std::string& animation_name,
154 .weight =
static_cast<float>(weight),
155 .time_scale =
static_cast<float>(time_scale),
157 node_->AddMutation(entry);
160void SceneNode::SeekAnimation(
const std::string& animation_name,
double time) {
163 .time =
static_cast<float>(
time),
165 node_->AddMutation(entry);
168SceneNode::SceneNode() =
default;
170SceneNode::~SceneNode() =
default;
A scene node, which may be a deserialized ipscene asset. This node can be safely added as a child to ...
static void Create(Dart_Handle wrapper)
fml::RefPtr< SceneNode > node(Dart_Handle shader)
std::string initFromAsset(const std::string &asset_name, Dart_Handle completion_callback_handle)
static UIDartState * Current()
struct _Dart_Handle * Dart_Handle
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
static impeller::Matrix ToMatrix(const tonic::Float64List &matrix4)
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)
SK_API sk_sp< PrecompileColorFilter > Matrix()
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
static double time(int loops, Benchmark *bench, Target *target)
A 4x4 matrix using column-major storage.
std::string animation_name
std::string animation_name
#define FML_TRACE_EVENT(category_group, name,...)