Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions
command_buffer.h File Reference
#include "flutter/lib/gpu/context.h"
#include "flutter/lib/gpu/export.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "impeller/renderer/command_buffer.h"

Go to the source code of this file.

Classes

class  flutter::gpu::CommandBuffer
 

Namespaces

namespace  flutter
 
namespace  flutter::gpu
 

Functions

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

Function Documentation

◆ InternalFlutterGpu_CommandBuffer_Initialize()

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

Exports

Definition at line 61 of file command_buffer.cc.

63 {
64 auto res = fml::MakeRefCounted<flutter::gpu::CommandBuffer>(
65 contextWrapper->GetContext(),
66 contextWrapper->GetContext()->CreateCommandBuffer());
67 res->AssociateWithDartWrapper(wrapper);
68
69 return true;
70}
std::shared_ptr< impeller::Context > GetContext()
Definition: context.cc:65

◆ InternalFlutterGpu_CommandBuffer_Submit()

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

Definition at line 72 of file command_buffer.cc.

74 {
75 if (Dart_IsNull(completion_callback)) {
76 bool success = wrapper->Submit();
77 if (!success) {
78 return tonic::ToDart("Failed to submit CommandBuffer");
79 }
80 return Dart_Null();
81 }
82
83 if (!Dart_IsClosure(completion_callback)) {
84 return tonic::ToDart("Completion callback must be a function");
85 }
86
87 auto dart_state = flutter::UIDartState::Current();
88 auto& task_runners = dart_state->GetTaskRunners();
89
90 auto persistent_completion_callback =
91 std::make_unique<tonic::DartPersistentValue>(dart_state,
92 completion_callback);
93
94 bool success = wrapper->Submit(fml::MakeCopyable(
95 [callback = std::move(persistent_completion_callback),
96 task_runners](impeller::CommandBuffer::Status status) mutable {
97 bool success = status != impeller::CommandBuffer::Status::kError;
98
99 auto ui_completion_task = fml::MakeCopyable(
100 [callback = std::move(callback), success]() mutable {
101 auto dart_state = callback->dart_state().lock();
102 if (!dart_state) {
103 // The root isolate could have died in the meantime.
104 return;
105 }
106 tonic::DartState::Scope scope(dart_state);
107
108 tonic::DartInvoke(callback->Get(), {tonic::ToDart(success)});
109
110 // callback is associated with the Dart isolate and must be
111 // deleted on the UI thread.
112 callback.reset();
113 });
114 task_runners.GetUITaskRunner()->PostTask(ui_completion_task);
115 }));
116 if (!success) {
117 return tonic::ToDart("Failed to submit CommandBuffer");
118 }
119 return Dart_Null();
120}
static UIDartState * Current()
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20