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 
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|
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 
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_
To do anything rendering related with Impeller, you need a context.
Definition: context.h:65
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.
void TeardownSwapchain()
Can be called when the surface is destroyed to reduce memory usage.
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.