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"
12 
13 namespace impeller {
14 
15 SurfaceContextVK::SurfaceContextVK(const std::shared_ptr<ContextVK>& parent)
16  : parent_(parent) {}
17 
19 
21  return parent_->GetBackendType();
22 }
23 
25  return parent_->DescribeGpuModel();
26 }
27 
29  return parent_->IsValid();
30 }
31 
32 std::shared_ptr<Allocator> SurfaceContextVK::GetResourceAllocator() const {
33  return parent_->GetResourceAllocator();
34 }
35 
36 std::shared_ptr<ShaderLibrary> SurfaceContextVK::GetShaderLibrary() const {
37  return parent_->GetShaderLibrary();
38 }
39 
40 std::shared_ptr<SamplerLibrary> SurfaceContextVK::GetSamplerLibrary() const {
41  return parent_->GetSamplerLibrary();
42 }
43 
44 std::shared_ptr<PipelineLibrary> SurfaceContextVK::GetPipelineLibrary() const {
45  return parent_->GetPipelineLibrary();
46 }
47 
48 std::shared_ptr<CommandBuffer> SurfaceContextVK::CreateCommandBuffer() const {
49  return parent_->CreateCommandBuffer();
50 }
51 
52 std::shared_ptr<CommandQueue> SurfaceContextVK::GetCommandQueue() const {
53  return parent_->GetCommandQueue();
54 }
55 
56 const std::shared_ptr<const Capabilities>& SurfaceContextVK::GetCapabilities()
57  const {
58  return parent_->GetCapabilities();
59 }
60 
62  parent_->Shutdown();
63 }
64 
65 bool SurfaceContextVK::SetWindowSurface(vk::UniqueSurfaceKHR surface,
66  const ISize& size) {
67  return SetSwapchain(SwapchainVK::Create(parent_, std::move(surface), size));
68 }
69 
70 bool SurfaceContextVK::SetSwapchain(std::shared_ptr<SwapchainVK> swapchain) {
71  if (!swapchain || !swapchain->IsValid()) {
72  VALIDATION_LOG << "Invalid swapchain.";
73  return false;
74  }
75  swapchain_ = std::move(swapchain);
76  return true;
77 }
78 
79 std::unique_ptr<Surface> SurfaceContextVK::AcquireNextSurface() {
80  TRACE_EVENT0("impeller", __FUNCTION__);
81  auto surface = swapchain_ ? swapchain_->AcquireNextDrawable() : nullptr;
82  if (!surface) {
83  return nullptr;
84  }
85  if (auto pipeline_library = parent_->GetPipelineLibrary()) {
86  impeller::PipelineLibraryVK::Cast(*pipeline_library)
88  }
89  parent_->GetCommandPoolRecycler()->Dispose();
90  parent_->GetResourceAllocator()->DebugTraceMemoryStatistics();
91  return surface;
92 }
93 
94 void SurfaceContextVK::UpdateSurfaceSize(const ISize& size) const {
95  swapchain_->UpdateSurfaceSize(size);
96 }
97 
98 const vk::Device& SurfaceContextVK::GetDevice() const {
99  return parent_->GetDevice();
100 }
101 
103  parent_->InitializeCommonlyUsedShadersIfNeeded();
104 }
105 
107  parent_->DisposeThreadLocalCachedResources();
108 }
109 
110 const std::shared_ptr<ContextVK>& SurfaceContextVK::GetParent() const {
111  return parent_;
112 }
113 
114 } // namespace impeller
khr_swapchain_vk.h
impeller::Context::BackendType
BackendType
Definition: context.h:48
impeller::SurfaceContextVK::AcquireNextSurface
std::unique_ptr< Surface > AcquireNextSurface()
Definition: surface_context_vk.cc:79
impeller::SurfaceContextVK::GetParent
const std::shared_ptr< ContextVK > & GetParent() const
Definition: surface_context_vk.cc:110
impeller::SurfaceContextVK::SetWindowSurface
bool SetWindowSurface(vk::UniqueSurfaceKHR surface, const ISize &size)
Definition: surface_context_vk.cc:65
impeller::SurfaceContextVK::GetSamplerLibrary
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
Definition: surface_context_vk.cc:40
impeller::SurfaceContextVK::~SurfaceContextVK
~SurfaceContextVK() override
surface_context_vk.h
impeller::SurfaceContextVK::GetBackendType
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
Definition: surface_context_vk.cc:20
impeller::SurfaceContextVK::SetSwapchain
bool SetSwapchain(std::shared_ptr< SwapchainVK > swapchain)
Definition: surface_context_vk.cc:70
impeller::SurfaceContextVK::InitializeCommonlyUsedShadersIfNeeded
void InitializeCommonlyUsedShadersIfNeeded() const override
Definition: surface_context_vk.cc:102
impeller::SurfaceContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: surface_context_vk.cc:98
impeller::PipelineLibraryVK::DidAcquireSurfaceFrame
void DidAcquireSurfaceFrame()
Definition: pipeline_library_vk.cc:279
impeller::SurfaceContextVK::CreateCommandBuffer
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
Definition: surface_context_vk.cc:48
impeller::SurfaceContextVK::GetShaderLibrary
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
Definition: surface_context_vk.cc:36
command_pool_vk.h
surface.h
impeller::TSize
Definition: size.h:19
impeller::SurfaceContextVK::UpdateSurfaceSize
void UpdateSurfaceSize(const ISize &size) const
Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.
Definition: surface_context_vk.cc:94
impeller::SurfaceContextVK::GetCapabilities
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
Definition: surface_context_vk.cc:56
impeller::SurfaceContextVK::SurfaceContextVK
SurfaceContextVK(const std::shared_ptr< ContextVK > &parent)
Definition: surface_context_vk.cc:15
impeller::SwapchainVK::Create
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:19
impeller::SurfaceContextVK::DisposeThreadLocalCachedResources
void DisposeThreadLocalCachedResources() override
Definition: surface_context_vk.cc:106
impeller::SurfaceContextVK::DescribeGpuModel
std::string DescribeGpuModel() const override
Definition: surface_context_vk.cc:24
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::BackendCast< PipelineLibraryVK, PipelineLibrary >::Cast
static PipelineLibraryVK & Cast(PipelineLibrary &base)
Definition: backend_cast.h:13
impeller::SurfaceContextVK::GetCommandQueue
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
Definition: surface_context_vk.cc:52
impeller::SurfaceContextVK::GetResourceAllocator
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
Definition: surface_context_vk.cc:32
impeller::SurfaceContextVK::GetPipelineLibrary
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
Definition: surface_context_vk.cc:44
context_vk.h
impeller::SurfaceContextVK::IsValid
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
Definition: surface_context_vk.cc:28
impeller
Definition: allocation.cc:12
impeller::SurfaceContextVK::Shutdown
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
Definition: surface_context_vk.cc:61