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 
14 
15 namespace impeller {
16 
17 class ContextVK;
18 class Surface;
19 class KHRSwapchainVK;
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  std::unique_ptr<Surface> AcquireNextSurface();
76 
77  /// @brief Mark the current swapchain configuration as dirty, forcing it to be
78  /// recreated on the next frame.
79  void UpdateSurfaceSize(const ISize& size) const;
80 
81  void InitializeCommonlyUsedShadersIfNeeded() const override;
82 
83 #ifdef FML_OS_ANDROID
84  vk::UniqueSurfaceKHR CreateAndroidSurface(ANativeWindow* window) const;
85 #endif // FML_OS_ANDROID
86 
87  const vk::Device& GetDevice() const;
88 
89  const ContextVK& GetParent() const;
90 
91  private:
92  std::shared_ptr<ContextVK> parent_;
93  std::shared_ptr<KHRSwapchainVK> swapchain_;
94 };
95 
96 } // namespace impeller
97 
98 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_CONTEXT_VK_H_
impeller::Context::BackendType
BackendType
Definition: context.h:48
impeller::SurfaceContextVK::GetParent
const ContextVK & GetParent() const
Definition: surface_context_vk.cc:130
impeller::SurfaceContextVK::AcquireNextSurface
std::unique_ptr< Surface > AcquireNextSurface()
Definition: surface_context_vk.cc:80
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::InitializeCommonlyUsedShadersIfNeeded
void InitializeCommonlyUsedShadersIfNeeded() const override
Definition: surface_context_vk.cc:126
impeller::SurfaceContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: surface_context_vk.cc:122
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< int64_t >
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:95
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::ContextVK
Definition: context_vk.h:42
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:46
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_blur_unittests.cc:20
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