Flutter Engine
 
Loading...
Searching...
No Matches
command_buffer.cc File Reference

Go to the source code of this file.

Namespaces

namespace  flutter
 
namespace  flutter::gpu
 

Functions

 flutter::gpu::IMPLEMENT_WRAPPERTYPEINFO (flutter_gpu, CommandBuffer)
 
bool InternalFlutterGpu_CommandBuffer_Initialize (Dart_Handle wrapper, flutter::gpu::Context *contextWrapper)
 
Dart_Handle InternalFlutterGpu_CommandBuffer_Submit (flutter::gpu::CommandBuffer *wrapper, Dart_Handle completion_callback)
 

Function Documentation

◆ InternalFlutterGpu_CommandBuffer_Initialize()

bool InternalFlutterGpu_CommandBuffer_Initialize ( Dart_Handle  wrapper,
flutter::gpu::Context contextWrapper 
)

Exports

Definition at line 80 of file command_buffer.cc.

82 {
83 auto res = fml::MakeRefCounted<flutter::gpu::CommandBuffer>(
84 contextWrapper->GetContextShared(),
85 contextWrapper->GetContext().CreateCommandBuffer());
86 res->AssociateWithDartWrapper(wrapper);
87
88 return true;
89}
std::shared_ptr< impeller::Context > & GetContextShared()
Definition context.cc:81
impeller::Context & GetContext()
Definition context.cc:77
virtual std::shared_ptr< CommandBuffer > CreateCommandBuffer() const =0
Create a new command buffer. Command buffers can be used to encode graphics, blit,...

References impeller::Context::CreateCommandBuffer(), flutter::gpu::Context::GetContext(), and flutter::gpu::Context::GetContextShared().

◆ InternalFlutterGpu_CommandBuffer_Submit()

Dart_Handle InternalFlutterGpu_CommandBuffer_Submit ( flutter::gpu::CommandBuffer wrapper,
Dart_Handle  completion_callback 
)

Definition at line 91 of file command_buffer.cc.

93 {
94 if (Dart_IsNull(completion_callback)) {
95 bool success = wrapper->Submit();
96 if (!success) {
97 return tonic::ToDart("Failed to submit CommandBuffer");
98 }
99 return Dart_Null();
100 }
101
102 if (!Dart_IsClosure(completion_callback)) {
103 return tonic::ToDart("Completion callback must be a function");
104 }
105
106 auto dart_state = flutter::UIDartState::Current();
107 auto& task_runners = dart_state->GetTaskRunners();
108
109 auto persistent_completion_callback =
110 std::make_unique<tonic::DartPersistentValue>(dart_state,
111 completion_callback);
112
113 auto ui_task_completion_callback = fml::MakeCopyable(
114 [callback = std::move(persistent_completion_callback),
115 task_runners](impeller::CommandBuffer::Status status) mutable {
116 bool success = status != impeller::CommandBuffer::Status::kError;
117
118 auto ui_completion_task = fml::MakeCopyable(
119 [callback = std::move(callback), success]() mutable {
120 auto dart_state = callback->dart_state().lock();
121 if (!dart_state) {
122 // The root isolate could have died in the meantime.
123 return;
124 }
125 tonic::DartState::Scope scope(dart_state);
126
127 tonic::DartInvoke(callback->Get(), {tonic::ToDart(success)});
128
129 // callback is associated with the Dart isolate and must be
130 // deleted on the UI thread.
131 callback.reset();
132 });
133 task_runners.GetUITaskRunner()->PostTask(ui_completion_task);
134 });
135 bool success = wrapper->Submit(ui_task_completion_callback);
136 if (!success) {
137 return tonic::ToDart("Failed to submit CommandBuffer");
138 }
139 return Dart_Null();
140}
static UIDartState * Current()
FlutterDesktopBinaryReply callback
internal::CopyableLambda< T > MakeCopyable(T lambda)
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)

References callback, flutter::UIDartState::Current(), tonic::DartInvoke(), impeller::CommandBuffer::kError, fml::MakeCopyable(), flutter::gpu::CommandBuffer::Submit(), and tonic::ToDart().