Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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)
 
Dart_Handle InternalFlutterGpu_CommandBuffer_CopyBufferToTexture (flutter::gpu::CommandBuffer *command_buffer, flutter::gpu::DeviceBuffer *source, int source_offset_in_bytes, int source_length_in_bytes, flutter::gpu::Texture *destination, int destination_x, int destination_y, int destination_width, int destination_height, int mip_level, int slice)
 
Dart_Handle InternalFlutterGpu_CommandBuffer_CopyTextureToBuffer (flutter::gpu::CommandBuffer *command_buffer, flutter::gpu::Texture *source, int source_x, int source_y, int source_width, int source_height, flutter::gpu::DeviceBuffer *destination, int destination_offset_in_bytes)
 
Dart_Handle InternalFlutterGpu_CommandBuffer_CopyTextureToTexture (flutter::gpu::CommandBuffer *command_buffer, flutter::gpu::Texture *source, flutter::gpu::Texture *destination, int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y)
 

Function Documentation

◆ InternalFlutterGpu_CommandBuffer_CopyBufferToTexture()

Dart_Handle InternalFlutterGpu_CommandBuffer_CopyBufferToTexture ( flutter::gpu::CommandBuffer command_buffer,
flutter::gpu::DeviceBuffer source,
int  source_offset_in_bytes,
int  source_length_in_bytes,
flutter::gpu::Texture destination,
int  destination_x,
int  destination_y,
int  destination_width,
int  destination_height,
int  mip_level,
int  slice 
)

Definition at line 259 of file command_buffer.cc.

270 {
271 if (!command_buffer->CopyBufferToTexture(
272 *source, static_cast<size_t>(source_offset_in_bytes),
273 static_cast<size_t>(source_length_in_bytes), *destination,
274 impeller::IRect::MakeXYWH(destination_x, destination_y,
275 destination_width, destination_height),
276 static_cast<uint32_t>(mip_level), static_cast<uint32_t>(slice))) {
277 return tonic::ToDart("Failed to append copyBufferToTexture");
278 }
279 return Dart_Null();
280}
Dart_Handle ToDart(const T &object)
std::shared_ptr< CommandBuffer > command_buffer
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136

References command_buffer, impeller::TRect< T >::MakeXYWH(), and tonic::ToDart().

◆ InternalFlutterGpu_CommandBuffer_CopyTextureToBuffer()

Dart_Handle InternalFlutterGpu_CommandBuffer_CopyTextureToBuffer ( flutter::gpu::CommandBuffer command_buffer,
flutter::gpu::Texture source,
int  source_x,
int  source_y,
int  source_width,
int  source_height,
flutter::gpu::DeviceBuffer destination,
int  destination_offset_in_bytes 
)

Definition at line 282 of file command_buffer.cc.

290 {
291 if (!command_buffer->CopyTextureToBuffer(
292 *source,
293 impeller::IRect::MakeXYWH(source_x, source_y, source_width,
294 source_height),
295 *destination, static_cast<size_t>(destination_offset_in_bytes))) {
296 return tonic::ToDart("Failed to append copyTextureToBuffer");
297 }
298 return Dart_Null();
299}

References command_buffer, impeller::TRect< T >::MakeXYWH(), and tonic::ToDart().

◆ InternalFlutterGpu_CommandBuffer_CopyTextureToTexture()

Dart_Handle InternalFlutterGpu_CommandBuffer_CopyTextureToTexture ( flutter::gpu::CommandBuffer command_buffer,
flutter::gpu::Texture source,
flutter::gpu::Texture destination,
int  source_x,
int  source_y,
int  source_width,
int  source_height,
int  destination_x,
int  destination_y 
)

Definition at line 301 of file command_buffer.cc.

310 {
311 if (!command_buffer->CopyTextureToTexture(
312 *source, *destination,
313 impeller::IRect::MakeXYWH(source_x, source_y, source_width,
314 source_height),
315 impeller::IPoint(destination_x, destination_y))) {
316 return tonic::ToDart("Failed to append copyTextureToTexture");
317 }
318 return Dart_Null();
319}

References command_buffer, impeller::TRect< T >::MakeXYWH(), and tonic::ToDart().

◆ InternalFlutterGpu_CommandBuffer_Initialize()

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

Exports

Definition at line 197 of file command_buffer.cc.

199 {
200 auto res = fml::MakeRefCounted<flutter::gpu::CommandBuffer>(
201 contextWrapper->GetContextShared(),
202 contextWrapper->GetContext().CreateCommandBuffer());
203 res->AssociateWithDartWrapper(wrapper);
204
205 return true;
206}
std::shared_ptr< impeller::Context > & GetContextShared()
Definition context.cc:91
impeller::Context & GetContext()
Definition context.cc:87
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 208 of file command_buffer.cc.

210 {
211 if (Dart_IsNull(completion_callback)) {
212 bool success = wrapper->Submit();
213 if (!success) {
214 return tonic::ToDart("Failed to submit CommandBuffer");
215 }
216 return Dart_Null();
217 }
218
219 if (!Dart_IsClosure(completion_callback)) {
220 return tonic::ToDart("Completion callback must be a function");
221 }
222
223 auto dart_state = flutter::UIDartState::Current();
224 auto& task_runners = dart_state->GetTaskRunners();
225
226 auto persistent_completion_callback =
227 std::make_unique<tonic::DartPersistentValue>(dart_state,
228 completion_callback);
229
230 auto ui_task_completion_callback = fml::MakeCopyable(
231 [callback = std::move(persistent_completion_callback),
232 task_runners](impeller::CommandBuffer::Status status) mutable {
233 bool success = status != impeller::CommandBuffer::Status::kError;
234
235 auto ui_completion_task = fml::MakeCopyable(
236 [callback = std::move(callback), success]() mutable {
237 auto dart_state = callback->dart_state().lock();
238 if (!dart_state) {
239 // The root isolate could have died in the meantime.
240 return;
241 }
242 tonic::DartState::Scope scope(dart_state);
243
244 tonic::DartInvoke(callback->Get(), {tonic::ToDart(success)});
245
246 // callback is associated with the Dart isolate and must be
247 // deleted on the UI thread.
248 callback.reset();
249 });
250 task_runners.GetUITaskRunner()->PostTask(ui_completion_task);
251 });
252 bool success = wrapper->Submit(ui_task_completion_callback);
253 if (!success) {
254 return tonic::ToDart("Failed to submit CommandBuffer");
255 }
256 return Dart_Null();
257}
static UIDartState * Current()
FlutterDesktopBinaryReply callback
internal::CopyableLambda< T > MakeCopyable(T lambda)
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().