| 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/core/runtime_types.h"
12 #include "impeller/renderer/backend/vulkan/vk.h"
13 #include "impeller/renderer/command_queue.h"
14 #include "impeller/renderer/context.h"
15
16 namespace impeller {
17
18 class ContextVK;
19 class Surface;
20 class SwapchainVK;
21
22 /// For Vulkan, there is both a ContextVK that implements Context and a
23 /// SurfaceContextVK that also implements Context and takes a ContextVK as its
24 /// parent. There is a one to many relationship between ContextVK and
25 /// SurfaceContextVK.
26 ///
27 /// Most operations in this class are delegated to the parent ContextVK.
28 /// This class specifically manages swapchains and creation of VkSurfaces on
29 /// Android. By maintaining the swapchain this way, it is possible to have
30 /// multiple surfaces sharing the same ContextVK without stepping on each
31 /// other's swapchains.
32 class SurfaceContextVK : public Context,
33 public BackendCast<SurfaceContextVK, Context> {
34 public:
35 explicit SurfaceContextVK(const std::shared_ptr<ContextVK>& parent);
36
37 // |Context|
38 ~SurfaceContextVK() override;
39
40 // |Context|
41 BackendType GetBackendType() const override;
42
43 // |Context|
44 std::string DescribeGpuModel() const override;
45
46 // |Context|
47 bool IsValid() const override;
48
49 // |Context|
50 std::shared_ptr<Allocator> GetResourceAllocator() const override;
51
52 // |Context|
53 std::shared_ptr<ShaderLibrary> GetShaderLibrary() const override;
54
55 // |Context|
56 std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const override;
57
58 // |Context|
59 std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const override;
60
61 // |Context|
62 std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override;
63
64 // |Context|
65 const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
66
67 // |Context|
68 std::shared_ptr<CommandQueue> GetCommandQueue() const override;
69
70 // |Context|
71 std::shared_ptr<const IdleWaiter> GetIdleWaiter() const override;
72
73 // |Context|
74 RuntimeStageBackend GetRuntimeStageBackend() const override;
75
76 // |Context|
77 bool SubmitOnscreen(std::shared_ptr<CommandBuffer> cmd_buffer) override;
78
79 // |Context|
80 void Shutdown() override;
81
82 [[nodiscard]] bool SetWindowSurface(vk::UniqueSurfaceKHR surface,
83 const ISize& size);
84
85 [[nodiscard]] bool SetSwapchain(std::shared_ptr<SwapchainVK> swapchain);
86
87 std::unique_ptr<Surface> AcquireNextSurface();
88
89 /// @brief Performs frame incrementing processes like AcquireNextSurface but
90 /// without the surface.
91 ///
92 /// Used by the embedder.h implementations.
93 void MarkFrameEnd();
94
95 /// @brief Mark the current swapchain configuration as dirty, forcing it to be
96 /// recreated on the next frame.
97 void UpdateSurfaceSize(const ISize& size) const;
98
99 /// @brief Can be called when the surface is destroyed to reduce memory usage.
100 void TeardownSwapchain();
101
102 // |Context|
103 void InitializeCommonlyUsedShadersIfNeeded() const override;
104
105 // |Context|
106 void DisposeThreadLocalCachedResources() override;
107
108 const vk::Device& GetDevice() const;
109
110 const std::shared_ptr<ContextVK>& GetParent() const;
111
112 bool EnqueueCommandBuffer(
113 std::shared_ptr<CommandBuffer> command_buffer) override;
114
115 bool FlushCommandBuffers() override;
116
117 private:
118 std::shared_ptr<ContextVK> parent_;
119 std::shared_ptr<SwapchainVK> swapchain_;
120 };
121
122 } // namespace impeller
123
124 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_CONTEXT_VK_H_
backend_cast.h
impeller::BackendCast
Definition: backend_cast.h:11
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::Context::BackendType
BackendType
Definition: context.h:49
impeller::SurfaceContextVK
Definition: surface_context_vk.h:33
impeller::SurfaceContextVK::SetWindowSurface
bool SetWindowSurface(vk::UniqueSurfaceKHR surface, const ISize &size)
Definition: surface_context_vk.cc:70
impeller::SurfaceContextVK::SurfaceContextVK
SurfaceContextVK(const std::shared_ptr< ContextVK > &parent)
Definition: surface_context_vk.cc:16
impeller::SurfaceContextVK::GetRuntimeStageBackend
RuntimeStageBackend GetRuntimeStageBackend() const override
Retrieve the runtime stage for this context type.
Definition: surface_context_vk.cc:145
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:45
impeller::SurfaceContextVK::MarkFrameEnd
void MarkFrameEnd()
Performs frame incrementing processes like AcquireNextSurface but without the surface.
Definition: surface_context_vk.cc:101
impeller::SurfaceContextVK::TeardownSwapchain
void TeardownSwapchain()
Can be called when the surface is destroyed to reduce memory usage.
Definition: surface_context_vk.cc:75
impeller::SurfaceContextVK::EnqueueCommandBuffer
bool EnqueueCommandBuffer(std::shared_ptr< CommandBuffer > command_buffer) override
Enqueue command_buffer for submission by the end of the frame.
Definition: surface_context_vk.cc:130
impeller::SurfaceContextVK::SubmitOnscreen
bool SubmitOnscreen(std::shared_ptr< CommandBuffer > cmd_buffer) override
Submit the command buffer that renders to the onscreen surface.
Definition: surface_context_vk.cc:139
impeller::SurfaceContextVK::GetParent
const std::shared_ptr< ContextVK > & GetParent() const
Definition: surface_context_vk.cc:126
impeller::SurfaceContextVK::SetSwapchain
bool SetSwapchain(std::shared_ptr< SwapchainVK > swapchain)
Definition: surface_context_vk.cc:82
impeller::SurfaceContextVK::FlushCommandBuffers
bool FlushCommandBuffers() override
Flush all pending command buffers.
Definition: surface_context_vk.cc:135
impeller::SurfaceContextVK::~SurfaceContextVK
~SurfaceContextVK() override
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:57
impeller::SurfaceContextVK::GetBackendType
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
Definition: surface_context_vk.cc:21
impeller::SurfaceContextVK::DescribeGpuModel
std::string DescribeGpuModel() const override
Definition: surface_context_vk.cc:25
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:29
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:110
impeller::SurfaceContextVK::AcquireNextSurface
std::unique_ptr< Surface > AcquireNextSurface()
Definition: surface_context_vk.cc:91
impeller::SurfaceContextVK::GetIdleWaiter
std::shared_ptr< const IdleWaiter > GetIdleWaiter() const override
Definition: surface_context_vk.cc:62
impeller::SurfaceContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: surface_context_vk.cc:114
impeller::SurfaceContextVK::DisposeThreadLocalCachedResources
void DisposeThreadLocalCachedResources() override
Definition: surface_context_vk.cc:122
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:41
impeller::SurfaceContextVK::GetCommandQueue
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
Definition: surface_context_vk.cc:53
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:66
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:49
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:37
impeller::SurfaceContextVK::InitializeCommonlyUsedShadersIfNeeded
void InitializeCommonlyUsedShadersIfNeeded() const override
Definition: surface_context_vk.cc:118
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:33
command_queue.h
impeller
Definition: allocation.cc:12
impeller::RuntimeStageBackend
RuntimeStageBackend
Definition: runtime_types.h:16
context.h
runtime_types.h
impeller::TSize
Definition: size.h:25
vk.h