Flutter Impeller
surface_context_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 "flutter/fml/trace_event.h"
13 
14 namespace impeller {
15 
16 SurfaceContextVK::SurfaceContextVK(const std::shared_ptr<ContextVK>& parent)
17  : parent_(parent) {}
18 
20 
22  return parent_->GetBackendType();
23 }
24 
26  return parent_->DescribeGpuModel();
27 }
28 
30  return parent_->IsValid();
31 }
32 
33 std::shared_ptr<Allocator> SurfaceContextVK::GetResourceAllocator() const {
34  return parent_->GetResourceAllocator();
35 }
36 
37 std::shared_ptr<ShaderLibrary> SurfaceContextVK::GetShaderLibrary() const {
38  return parent_->GetShaderLibrary();
39 }
40 
41 std::shared_ptr<SamplerLibrary> SurfaceContextVK::GetSamplerLibrary() const {
42  return parent_->GetSamplerLibrary();
43 }
44 
45 std::shared_ptr<PipelineLibrary> SurfaceContextVK::GetPipelineLibrary() const {
46  return parent_->GetPipelineLibrary();
47 }
48 
49 std::shared_ptr<CommandBuffer> SurfaceContextVK::CreateCommandBuffer() const {
50  return parent_->CreateCommandBuffer();
51 }
52 
53 std::shared_ptr<CommandQueue> SurfaceContextVK::GetCommandQueue() const {
54  return parent_->GetCommandQueue();
55 }
56 
57 const std::shared_ptr<const Capabilities>& SurfaceContextVK::GetCapabilities()
58  const {
59  return parent_->GetCapabilities();
60 }
61 
62 std::shared_ptr<const IdleWaiter> SurfaceContextVK::GetIdleWaiter() const {
63  return parent_->GetIdleWaiter();
64 }
65 
67  parent_->Shutdown();
68 }
69 
70 bool SurfaceContextVK::SetWindowSurface(vk::UniqueSurfaceKHR surface,
71  const ISize& size) {
72  return SetSwapchain(SwapchainVK::Create(parent_, std::move(surface), size));
73 }
74 
75 bool SurfaceContextVK::SetSwapchain(std::shared_ptr<SwapchainVK> swapchain) {
76  if (!swapchain || !swapchain->IsValid()) {
77  VALIDATION_LOG << "Invalid swapchain.";
78  return false;
79  }
80  swapchain_ = std::move(swapchain);
81  return true;
82 }
83 
84 std::unique_ptr<Surface> SurfaceContextVK::AcquireNextSurface() {
85  TRACE_EVENT0("impeller", __FUNCTION__);
86  auto surface = swapchain_ ? swapchain_->AcquireNextDrawable() : nullptr;
87  if (!surface) {
88  return nullptr;
89  }
90  MarkFrameEnd();
91  return surface;
92 }
93 
95  if (auto pipeline_library = parent_->GetPipelineLibrary()) {
96  impeller::PipelineLibraryVK::Cast(*pipeline_library)
98  }
99  parent_->DisposeThreadLocalCachedResources();
100  parent_->GetResourceAllocator()->DebugTraceMemoryStatistics();
101 }
102 
104  swapchain_->UpdateSurfaceSize(size);
105 }
106 
107 const vk::Device& SurfaceContextVK::GetDevice() const {
108  return parent_->GetDevice();
109 }
110 
112  parent_->InitializeCommonlyUsedShadersIfNeeded();
113 }
114 
116  parent_->DisposeThreadLocalCachedResources();
117 }
118 
119 const std::shared_ptr<ContextVK>& SurfaceContextVK::GetParent() const {
120  return parent_;
121 }
122 
124  std::shared_ptr<CommandBuffer> command_buffer) {
125  return parent_->EnqueueCommandBuffer(std::move(command_buffer));
126 }
127 
129  return parent_->FlushCommandBuffers();
130 }
131 
133  std::shared_ptr<CommandBuffer> cmd_buffer) {
134  swapchain_->AddFinalCommandBuffer(std::move(cmd_buffer));
135  return true;
136 }
137 
139  return parent_->GetRuntimeStageBackend();
140 }
141 
142 } // namespace impeller
static PipelineLibraryVK & Cast(PipelineLibrary &base)
Definition: backend_cast.h:13
bool SetWindowSurface(vk::UniqueSurfaceKHR surface, const ISize &size)
SurfaceContextVK(const std::shared_ptr< ContextVK > &parent)
RuntimeStageBackend GetRuntimeStageBackend() const override
Retrieve the runtime stage for this context type.
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
void MarkFrameEnd()
Performs frame incrementing processes like AcquireNextSurface but without the surface.
bool EnqueueCommandBuffer(std::shared_ptr< CommandBuffer > command_buffer) override
Enqueue command_buffer for submission by the end of the frame.
bool SubmitOnscreen(std::shared_ptr< CommandBuffer > cmd_buffer) override
Submit the command buffer that renders to the onscreen surface.
const std::shared_ptr< ContextVK > & GetParent() const
bool SetSwapchain(std::shared_ptr< SwapchainVK > swapchain)
bool FlushCommandBuffers() override
Flush all pending command buffers.
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
std::string DescribeGpuModel() const override
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
void UpdateSurfaceSize(const ISize &size) const
Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.
std::unique_ptr< Surface > AcquireNextSurface()
std::shared_ptr< const IdleWaiter > GetIdleWaiter() const override
const vk::Device & GetDevice() const
void DisposeThreadLocalCachedResources() override
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
void InitializeCommonlyUsedShadersIfNeeded() const override
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
static std::shared_ptr< SwapchainVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true)
Definition: swapchain_vk.cc:18
#define VALIDATION_LOG
Definition: validation.h:91