Flutter Impeller
command_buffer_vk.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 
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "flutter/fml/logging.h"
20 
21 namespace impeller {
22 
23 CommandBufferVK::CommandBufferVK(
24  std::weak_ptr<const Context> context,
25  std::shared_ptr<CommandEncoderFactoryVK> encoder_factory)
26  : CommandBuffer(std::move(context)),
27  encoder_factory_(std::move(encoder_factory)) {}
28 
30 
31 void CommandBufferVK::SetLabel(const std::string& label) const {
32  if (!encoder_) {
33  encoder_factory_->SetLabel(label);
34  } else {
35  auto context = context_.lock();
36  if (!context || !encoder_) {
37  return;
38  }
39  ContextVK::Cast(*context).SetDebugName(encoder_->GetCommandBuffer(), label);
40  }
41 }
42 
43 bool CommandBufferVK::IsValid() const {
44  return true;
45 }
46 
47 const std::shared_ptr<CommandEncoderVK>& CommandBufferVK::GetEncoder() {
48  if (!encoder_) {
49  encoder_ = encoder_factory_->Create();
50  }
51  return encoder_;
52 }
53 
54 bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) {
55  if (!callback) {
56  return encoder_->Submit();
57  }
58  return encoder_->Submit([callback](bool submitted) {
59  callback(submitted ? CommandBuffer::Status::kCompleted
61  });
62 }
63 
64 void CommandBufferVK::OnWaitUntilScheduled() {}
65 
66 std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
67  RenderTarget target) {
68  auto context = context_.lock();
69  if (!context) {
70  return nullptr;
71  }
72  auto pass =
73  std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
74  target, //
75  weak_from_this() //
76  ));
77  if (!pass->IsValid()) {
78  return nullptr;
79  }
80  return pass;
81 }
82 
83 std::shared_ptr<BlitPass> CommandBufferVK::OnCreateBlitPass() {
84  if (!IsValid()) {
85  return nullptr;
86  }
87  auto pass = std::shared_ptr<BlitPassVK>(new BlitPassVK(weak_from_this()));
88  if (!pass->IsValid()) {
89  return nullptr;
90  }
91  return pass;
92 }
93 
94 std::shared_ptr<ComputePass> CommandBufferVK::OnCreateComputePass() {
95  if (!IsValid()) {
96  return nullptr;
97  }
98  auto context = context_.lock();
99  if (!context) {
100  return nullptr;
101  }
102  auto pass =
103  std::shared_ptr<ComputePassVK>(new ComputePassVK(context, //
104  weak_from_this() //
105  ));
106  if (!pass->IsValid()) {
107  return nullptr;
108  }
109  return pass;
110 }
111 
112 } // namespace impeller
impeller::CommandBuffer::Status::kError
@ kError
impeller::CommandBufferVK::GetEncoder
const std::shared_ptr< CommandEncoderVK > & GetEncoder()
Definition: command_buffer_vk.cc:47
compute_pass_vk.h
command_encoder_vk.h
formats_vk.h
render_pass_vk.h
validation.h
command_buffer_vk.h
impeller::CommandBuffer::context_
std::weak_ptr< const Context > context_
Definition: command_buffer.h:117
impeller::CommandBufferVK::~CommandBufferVK
~CommandBufferVK() override
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:96
blit_pass_vk.h
command_buffer.h
std
Definition: comparable.h:98
impeller::CommandBuffer::Status::kCompleted
@ kCompleted
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:14
render_target.h
context_vk.h
impeller
Definition: aiks_context.cc:10