21 std::shared_ptr<impeller::Context>
context,
28bool CommandBuffer::Encodable::EncodeCommands()
const {
33 return blit_pass->EncodeCommands();
39 return command_buffer_;
43 std::shared_ptr<impeller::RenderPass>
render_pass) {
46 encodables_.push_back(std::move(encodable));
49std::shared_ptr<impeller::BlitPass> CommandBuffer::GetOrCreateBlitPass() {
50 if (!encodables_.empty() && encodables_.back().blit_pass) {
51 return encodables_.back().blit_pass;
53 auto blit_pass = command_buffer_->CreateBlitPass();
58 encodable.blit_pass = blit_pass;
59 encodables_.push_back(std::move(encodable));
70 auto blit_pass = GetOrCreateBlitPass();
76 return blit_pass->AddCopy(
77 std::move(source_view), destination.
GetTexture(), destination_region,
78 "CommandBuffer.copyBufferToTexture", mip_level, slice);
84 size_t destination_offset) {
85 auto blit_pass = GetOrCreateBlitPass();
90 source_region, destination_offset,
91 "CommandBuffer.copyTextureToBuffer");
98 auto blit_pass = GetOrCreateBlitPass();
103 source_region, destination_origin,
104 "CommandBuffer.copyTextureToTexture");
112 if (completion_callback) {
113 completion_callbacks_.push_back(std::move(completion_callback));
129 std::vector<impeller::CommandBuffer::CompletionCallback> callbacks =
130 std::move(completion_callbacks_);
131 if (completion_callback) {
132 callbacks.push_back(completion_callback);
135 if (!callbacks.empty()) {
136 combined_completion_callback =
137 [callbacks = std::move(callbacks)](
149 auto& task_runners = dart_state->GetTaskRunners();
151 task_runners.GetRasterTaskRunner()->PostTask(
153 completion_callback = combined_completion_callback,
154 encodables = encodables_]()
mutable {
155 for (
auto& encodable : encodables) {
156 if (!encodable.EncodeCommands()) {
157 if (completion_callback) {
160 context->DisposeThreadLocalCachedResources();
166 completion_callback);
167 if (!status.ok() && completion_callback) {
170 context->DisposeThreadLocalCachedResources();
175 for (
auto& encodable : encodables_) {
176 if (!encodable.EncodeCommands()) {
181 auto status = context_->GetCommandQueue()->Submit(
182 {command_buffer_}, combined_completion_callback);
183 context_->DisposeThreadLocalCachedResources();
184 if (!status.ok() && combined_completion_callback) {
200 auto res = fml::MakeRefCounted<flutter::gpu::CommandBuffer>(
203 res->AssociateWithDartWrapper(wrapper);
210 Dart_Handle completion_callback) {
211 if (Dart_IsNull(completion_callback)) {
212 bool success = wrapper->
Submit();
219 if (!Dart_IsClosure(completion_callback)) {
220 return tonic::ToDart(
"Completion callback must be a function");
224 auto& task_runners = dart_state->GetTaskRunners();
226 auto persistent_completion_callback =
227 std::make_unique<tonic::DartPersistentValue>(dart_state,
228 completion_callback);
231 [
callback = std::move(persistent_completion_callback),
237 auto dart_state =
callback->dart_state().lock();
250 task_runners.GetUITaskRunner()->PostTask(ui_completion_task);
252 bool success = wrapper->
Submit(ui_task_completion_callback);
262 int source_offset_in_bytes,
263 int source_length_in_bytes,
267 int destination_width,
268 int destination_height,
272 *source,
static_cast<size_t>(source_offset_in_bytes),
273 static_cast<size_t>(source_length_in_bytes), *destination,
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");
290 int destination_offset_in_bytes) {
295 *destination,
static_cast<size_t>(destination_offset_in_bytes))) {
296 return tonic::ToDart(
"Failed to append copyTextureToBuffer");
312 *source, *destination,
316 return tonic::ToDart(
"Failed to append copyTextureToTexture");
static UIDartState * Current()
CommandBuffer(std::shared_ptr< impeller::Context > context, std::shared_ptr< impeller::CommandBuffer > command_buffer)
bool CopyBufferToTexture(DeviceBuffer &source, size_t source_offset, size_t source_length, Texture &destination, impeller::IRect destination_region, uint32_t mip_level, uint32_t slice)
~CommandBuffer() override
std::shared_ptr< impeller::CommandBuffer > GetCommandBuffer()
bool CopyTextureToTexture(Texture &source, Texture &destination, impeller::IRect source_region, impeller::IPoint destination_origin)
void AddRenderPass(std::shared_ptr< impeller::RenderPass > render_pass)
bool AddCompletionCallback(impeller::CommandBuffer::CompletionCallback completion_callback)
bool CopyTextureToBuffer(Texture &source, impeller::IRect source_region, DeviceBuffer &destination, size_t destination_offset)
std::shared_ptr< impeller::Context > & GetContextShared()
impeller::Context & GetContext()
std::shared_ptr< impeller::DeviceBuffer > GetBuffer()
std::shared_ptr< impeller::Texture > GetTexture()
std::function< void(Status)> CompletionCallback
virtual std::shared_ptr< CommandBuffer > CreateCommandBuffer() const =0
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
FlutterDesktopBinaryReply 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_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)
Dart_Handle InternalFlutterGpu_CommandBuffer_Submit(flutter::gpu::CommandBuffer *wrapper, Dart_Handle completion_callback)
bool InternalFlutterGpu_CommandBuffer_Initialize(Dart_Handle wrapper, flutter::gpu::Context *contextWrapper)
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)
internal::CopyableLambda< T > MakeCopyable(T lambda)
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
std::shared_ptr< ContextGLES > context
std::shared_ptr< RenderPass > render_pass
std::shared_ptr< CommandBuffer > command_buffer
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)