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

A scene node, which may be a deserialized ipscene asset. This node can be safely added as a child to multiple scene nodes, whether they're in the same scene or a different scene. The deserialized node itself is treated as immutable on the IO thread. More...

#include <scene_node.h>

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

Public Member Functions

 SceneNode ()
 
 ~SceneNode () override
 
std::string initFromAsset (const std::string &asset_name, Dart_Handle completion_callback_handle)
 
void initFromTransform (const tonic::Float64List &matrix4)
 
void AddChild (Dart_Handle scene_node_handle)
 
void SetTransform (const tonic::Float64List &matrix4)
 
void SetAnimationState (const std::string &animation_name, bool playing, bool loop, double weight, double time_scale)
 
void SeekAnimation (const std::string &animation_name, double time)
 
fml::RefPtr< SceneNodenode (Dart_Handle shader)
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< SceneNode >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< SceneNode >
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< SceneNode >
 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

A scene node, which may be a deserialized ipscene asset. This node can be safely added as a child to multiple scene nodes, whether they're in the same scene or a different scene. The deserialized node itself is treated as immutable on the IO thread.

Internally, nodes may have an animation player, which is controlled via the mutation log in the DlSceneColorSource, which is built by SceneShader.

Definition at line 30 of file scene_node.h.

Constructor & Destructor Documentation

◆ SceneNode()

flutter::SceneNode::SceneNode ( )
default

◆ ~SceneNode()

flutter::SceneNode::~SceneNode ( )
overridedefault

Member Function Documentation

◆ AddChild()

void flutter::SceneNode::AddChild ( Dart_Handle  scene_node_handle)

Definition at line 126 of file scene_node.cc.

126 {
127 if (!node_) {
128 return;
129 }
130 auto* scene_node =
132 if (!scene_node) {
133 return;
134 }
135 node_->AddChild(scene_node->node_);
136 children_.push_back(fml::Ref(scene_node));
137}
RefPtr< T > Ref(T *ptr)
Definition: ref_ptr.h:237

◆ Create()

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

Definition at line 30 of file scene_node.cc.

30 {
31 auto res = fml::MakeRefCounted<SceneNode>();
32 res->AssociateWithDartWrapper(wrapper);
33}

◆ initFromAsset()

std::string flutter::SceneNode::initFromAsset ( const std::string &  asset_name,
Dart_Handle  completion_callback_handle 
)

Definition at line 35 of file scene_node.cc.

36 {
37 FML_TRACE_EVENT("flutter", "SceneNode::initFromAsset", "asset", asset_name);
38
39 if (!Dart_IsClosure(completion_callback_handle)) {
40 return "Completion callback must be a function.";
41 }
42
43 auto dart_state = UIDartState::Current();
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(
60 fml::MakeCopyable([promise = std::move(context_promise),
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
70 auto ui_task = fml::MakeCopyable(
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 // The root isolate could have died in the meantime.
76 return;
77 }
78 tonic::DartState::Scope scope(dart_state);
79
80 node_ = std::move(node);
81 tonic::DartInvoke(callback->Get(), {Dart_TypeVoid()});
82
83 // callback is associated with the Dart isolate and must be
84 // deleted on the UI thread.
85 callback.reset();
86 });
87
88 task_runners.GetRasterTaskRunner()->PostTask(
89 fml::MakeCopyable([ui_task = std::move(ui_task), task_runners,
90 impeller_context = impeller_context_promise.get(),
91 data = std::move(data)]() {
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
Definition: switches.h:41
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
#define FML_TRACE_EVENT(category_group, name,...)
Definition: trace_event.h:121

◆ initFromTransform()

void flutter::SceneNode::initFromTransform ( const tonic::Float64List &  matrix4)

Definition at line 121 of file scene_node.cc.

121 {
122 node_ = std::make_shared<impeller::scene::Node>();
123 node_->SetLocalTransform(ToMatrix(matrix4));
124}
static impeller::Matrix ToMatrix(const tonic::Float64List &matrix4)
Definition: scene_node.cc:102

◆ node()

fml::RefPtr< SceneNode > flutter::SceneNode::node ( Dart_Handle  shader)

◆ SeekAnimation()

void flutter::SceneNode::SeekAnimation ( const std::string &  animation_name,
double  time 
)

Definition at line 160 of file scene_node.cc.

160 {
162 .animation_name = animation_name,
163 .time = static_cast<float>(time),
164 };
165 node_->AddMutation(entry);
166}
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394

◆ SetAnimationState()

void flutter::SceneNode::SetAnimationState ( const std::string &  animation_name,
bool  playing,
bool  loop,
double  weight,
double  time_scale 
)

Definition at line 145 of file scene_node.cc.

149 {
151 .animation_name = animation_name,
152 .playing = playing,
153 .loop = loop,
154 .weight = static_cast<float>(weight),
155 .time_scale = static_cast<float>(time_scale),
156 };
157 node_->AddMutation(entry);
158}

◆ SetTransform()

void flutter::SceneNode::SetTransform ( const tonic::Float64List &  matrix4)

Definition at line 139 of file scene_node.cc.

139 {
141 ToMatrix(matrix4)};
142 node_->AddMutation(entry);
143}

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