| Flutter Impeller |

command_buffer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/command_buffer.h"
6
7 #include "flutter/fml/trace_event.h"
8 #include "impeller/renderer/compute_pass.h"
9 #include "impeller/renderer/render_pass.h"
10 #include "impeller/renderer/render_target.h"
11
12 namespace impeller {
13
14 CommandBuffer::CommandBuffer(std::weak_ptr<const Context> context)
15 : context_(std::move(context)) {}
16
17 CommandBuffer::~CommandBuffer() = default;
18
19 bool CommandBuffer::SubmitCommands(const CompletionCallback& callback) {
20 TRACE_EVENT0("impeller", "CommandBuffer::SubmitCommands");
21 if (!IsValid()) {
22 // Already committed or was never valid. Either way, this is caller error.
23 if (callback) {
24 callback(Status::kError);
25 }
26 return false;
27 }
28 return OnSubmitCommands(callback);
29 }
30
31 bool CommandBuffer::SubmitCommands() {
32 return SubmitCommands(nullptr);
33 }
34
35 void CommandBuffer::WaitUntilScheduled() {
36 return OnWaitUntilScheduled();
37 }
38
39 bool CommandBuffer::SubmitCommandsAsync(
40 std::shared_ptr<RenderPass>
41 render_pass // NOLINT(performance-unnecessary-value-param)
42 ) {
43 TRACE_EVENT0("impeller", "CommandBuffer::SubmitCommandsAsync");
44 if (!render_pass->IsValid() || !IsValid()) {
45 return false;
46 }
47 if (!render_pass->EncodeCommands()) {
48 return false;
49 }
50
51 return SubmitCommands(nullptr);
52 }
53
54 std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
55 const RenderTarget& render_target) {
56 auto pass = OnCreateRenderPass(render_target);
57 if (pass && pass->IsValid()) {
58 pass->SetLabel("RenderPass");
59 return pass;
60 }
61 return nullptr;
62 }
63
64 std::shared_ptr<BlitPass> CommandBuffer::CreateBlitPass() {
65 auto pass = OnCreateBlitPass();
66 if (pass && pass->IsValid()) {
67 pass->SetLabel("BlitPass");
68 return pass;
69 }
70 return nullptr;
71 }
72
73 std::shared_ptr<ComputePass> CommandBuffer::CreateComputePass() {
74 if (!IsValid()) {
75 return nullptr;
76 }
77 auto pass = OnCreateComputePass();
78 if (pass && pass->IsValid()) {
79 pass->SetLabel("ComputePass");
80 return pass;
81 }
82 return nullptr;
83 }
84
85 } // namespace impeller
impeller::CommandBuffer::Status::kError
@ kError
impeller::CommandBuffer::SubmitCommands
bool SubmitCommands()
Definition: command_buffer.cc:31
impeller::CommandBuffer::OnSubmitCommands
virtual bool OnSubmitCommands(CompletionCallback callback)=0
impeller::CommandBuffer::CreateRenderPass
std::shared_ptr< RenderPass > CreateRenderPass(const RenderTarget &render_target)
Create a render pass to record render commands into.
Definition: command_buffer.cc:54
impeller::CommandBuffer::OnCreateRenderPass
virtual std::shared_ptr< RenderPass > OnCreateRenderPass(RenderTarget render_target)=0
impeller::CommandBuffer::SubmitCommandsAsync
virtual bool SubmitCommandsAsync(std::shared_ptr< RenderPass > render_pass)
Schedule the command encoded by render passes within this command buffer on the GPU....
Definition: command_buffer.cc:39
impeller::CommandBuffer::OnCreateComputePass
virtual std::shared_ptr< ComputePass > OnCreateComputePass()=0
impeller::CommandBuffer::CompletionCallback
std::function< void(Status)> CompletionCallback
Definition: command_buffer.h:54
impeller::CommandBuffer::CreateComputePass
std::shared_ptr< ComputePass > CreateComputePass()
Create a compute pass to record compute commands into.
Definition: command_buffer.cc:73
render_pass.h
impeller::CommandBuffer::WaitUntilScheduled
void WaitUntilScheduled()
Force execution of pending GPU commands.
Definition: command_buffer.cc:35
impeller::CommandBuffer::IsValid
virtual bool IsValid() const =0
impeller::RenderTarget
Definition: render_target.h:48
impeller::CommandBuffer::OnCreateBlitPass
virtual std::shared_ptr< BlitPass > OnCreateBlitPass()=0
command_buffer.h
impeller::CommandBuffer::OnWaitUntilScheduled
virtual void OnWaitUntilScheduled()=0
impeller::CommandBuffer::CreateBlitPass
std::shared_ptr< BlitPass > CreateBlitPass()
Create a blit pass to record blit commands into.
Definition: command_buffer.cc:64
std
Definition: comparable.h:98
impeller::CommandBuffer::CommandBuffer
CommandBuffer(std::weak_ptr< const Context > context)
Definition: command_buffer.cc:14
render_target.h
compute_pass.h
impeller
Definition: aiks_context.cc:10
impeller::CommandBuffer::~CommandBuffer
virtual ~CommandBuffer()