| Flutter Impeller |

surface_context_vk.h
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 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_CONTEXT_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_CONTEXT_VK_H_
7
8 #include <memory>
9
10 #include "impeller/base/backend_cast.h"
11 #include "impeller/renderer/backend/vulkan/vk.h"
12 #include "impeller/renderer/command_queue.h"
13 #include "impeller/renderer/context.h"
14
15 namespace impeller {
16
17 class ContextVK;
18 class Surface;
19 class SwapchainVK;
20
21 /// For Vulkan, there is both a ContextVK that implements Context and a
22 /// SurfaceContextVK that also implements Context and takes a ContextVK as its
23 /// parent. There is a one to many relationship between ContextVK and
24 /// SurfaceContextVK.
25 ///
26 /// Most operations in this class are delegated to the parent ContextVK.
27 /// This class specifically manages swapchains and creation of VkSurfaces on
28 /// Android. By maintaining the swapchain this way, it is possible to have
29 /// multiple surfaces sharing the same ContextVK without stepping on each
30 /// other's swapchains.
31 class SurfaceContextVK : public Context,
32 public BackendCast<SurfaceContextVK, Context> {
33 public:
34 explicit SurfaceContextVK(const std::shared_ptr<ContextVK>& parent);
35
36 // |Context|
37 ~SurfaceContextVK() override;
38
39 // |Context|
40 BackendType GetBackendType() const override;
41
42 // |Context|
43 std::string DescribeGpuModel() const override;
44
45 // |Context|
46 bool IsValid() const override;
47
48 // |Context|
49 std::shared_ptr<Allocator> GetResourceAllocator() const override;
50
51 // |Context|
52 std::shared_ptr<ShaderLibrary> GetShaderLibrary() const override;
53
54 // |Context|
55 std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const override;
56
57 // |Context|
58 std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const override;
59
60 // |Context|
61 std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override;
62
63 // |Context|
64 const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
65
66 // |Context|
67 std::shared_ptr<CommandQueue> GetCommandQueue() const override;
68
69 // |Context|
70 void Shutdown() override;
71
72 [[nodiscard]] bool SetWindowSurface(vk::UniqueSurfaceKHR surface,
73 const ISize& size);
74
75 [[nodiscard]] bool SetSwapchain(std::shared_ptr<SwapchainVK> swapchain);
76
77 std::unique_ptr<Surface> AcquireNextSurface();
78
79 /// @brief Mark the current swapchain configuration as dirty, forcing it to be
80 /// recreated on the next frame.
81 void UpdateSurfaceSize(const ISize& size) const;
82
83 void InitializeCommonlyUsedShadersIfNeeded() const override;
84
85 const vk::Device& GetDevice() const;
86
87 const std::shared_ptr<ContextVK>& GetParent() const;
88
89 private:
90 std::shared_ptr<ContextVK> parent_;
91 std::shared_ptr<SwapchainVK> swapchain_;
92 };
93
94 } // namespace impeller
95
96 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_CONTEXT_VK_H_
impeller::Context::BackendType
BackendType
Definition: context.h:47
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:106
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
command_queue.h
impeller::SurfaceContextVK::~SurfaceContextVK
~SurfaceContextVK() override
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::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
vk.h
impeller::SurfaceContextVK
Definition: surface_context_vk.h:31
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
backend_cast.h
impeller::SurfaceContextVK::DescribeGpuModel
std::string DescribeGpuModel() const override
Definition: surface_context_vk.cc:24
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:45
impeller::BackendCast
Definition: backend_cast.h:11
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
context.h
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
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: aiks_blend_unittests.cc:18
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