| 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::EncodeAndSubmit(
40 const std::shared_ptr<RenderPass>& render_pass) {
41 TRACE_EVENT0("impeller", "CommandBuffer::EncodeAndSubmit");
42 if (!render_pass->IsValid() || !IsValid()) {
43 return false;
44 }
45 if (!render_pass->EncodeCommands()) {
46 return false;
47 }
48
49 return SubmitCommands(nullptr);
50 }
51
52 bool CommandBuffer::EncodeAndSubmit(
53 const std::shared_ptr<BlitPass>& blit_pass,
54 const std::shared_ptr<Allocator>& allocator) {
55 TRACE_EVENT0("impeller", "CommandBuffer::EncodeAndSubmit");
56 if (!blit_pass->IsValid() || !IsValid()) {
57 return false;
58 }
59 if (!blit_pass->EncodeCommands(allocator)) {
60 return false;
61 }
62
63 return SubmitCommands(nullptr);
64 }
65
66 std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
67 const RenderTarget& render_target) {
68 auto pass = OnCreateRenderPass(render_target);
69 if (pass && pass->IsValid()) {
70 pass->SetLabel("RenderPass");
71 return pass;
72 }
73 return nullptr;
74 }
75
76 std::shared_ptr<BlitPass> CommandBuffer::CreateBlitPass() {
77 auto pass = OnCreateBlitPass();
78 if (pass && pass->IsValid()) {
79 pass->SetLabel("BlitPass");
80 return pass;
81 }
82 return nullptr;
83 }
84
85 std::shared_ptr<ComputePass> CommandBuffer::CreateComputePass() {
86 if (!IsValid()) {
87 return nullptr;
88 }
89 auto pass = OnCreateComputePass();
90 if (pass && pass->IsValid()) {
91 pass->SetLabel("ComputePass");
92 return pass;
93 }
94 return nullptr;
95 }
96
97 } // 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:66
impeller::CommandBuffer::OnCreateRenderPass
virtual std::shared_ptr< RenderPass > OnCreateRenderPass(RenderTarget render_target)=0
impeller::CommandBuffer::OnCreateComputePass
virtual std::shared_ptr< ComputePass > OnCreateComputePass()=0
impeller::CommandBuffer::CompletionCallback
std::function< void(Status)> CompletionCallback
Definition: command_buffer.h:55
impeller::CommandBuffer::CreateComputePass
std::shared_ptr< ComputePass > CreateComputePass()
Create a compute pass to record compute commands into.
Definition: command_buffer.cc:85
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:49
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:76
std
Definition: comparable.h:95
impeller::CommandBuffer::EncodeAndSubmit
virtual bool EncodeAndSubmit(const 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::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()