| Flutter Impeller |

swapchain_impl_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 #pragma once
6
7 #include <memory>
8 #include <variant>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/renderer/backend/vulkan/vk.h"
12 #include "vulkan/vulkan_enums.hpp"
13
14 namespace impeller {
15
16 class Context;
17 class SwapchainImageVK;
18 class Surface;
19 struct FrameSynchronizer;
20
21 //------------------------------------------------------------------------------
22 /// @brief An instance of a swapchain that does NOT adapt to going out of
23 /// date with the underlying surface. Errors will be indicated when
24 /// the next drawable is acquired from this implementation of the
25 /// swapchain. If the error is due the swapchain going out of date,
26 /// the caller must recreate another instance by optionally
27 /// stealing this implementations guts.
28 ///
29 class SwapchainImplVK final
30 : public std::enable_shared_from_this<SwapchainImplVK> {
31 public:
32 static std::shared_ptr<SwapchainImplVK> Create(
33 const std::shared_ptr<Context>& context,
34 vk::UniqueSurfaceKHR surface,
35 vk::SwapchainKHR old_swapchain = VK_NULL_HANDLE,
36 vk::SurfaceTransformFlagBitsKHR last_transform =
37 vk::SurfaceTransformFlagBitsKHR::eIdentity);
38
39 ~SwapchainImplVK();
40
41 bool IsValid() const;
42
43 struct AcquireResult {
44 std::unique_ptr<Surface> surface;
45 bool out_of_date = false;
46
47 AcquireResult(bool p_out_of_date = false) : out_of_date(p_out_of_date) {}
48
49 AcquireResult(std::unique_ptr<Surface> p_surface)
50 : surface(std::move(p_surface)) {}
51 };
52
53 AcquireResult AcquireNextDrawable();
54
55 vk::Format GetSurfaceFormat() const;
56
57 vk::SurfaceTransformFlagBitsKHR GetLastTransform() const;
58
59 std::shared_ptr<Context> GetContext() const;
60
61 std::pair<vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR> DestroySwapchain();
62
63 private:
64 std::weak_ptr<Context> context_;
65 vk::UniqueSurfaceKHR surface_;
66 vk::Queue present_queue_ = {};
67 vk::Format surface_format_ = vk::Format::eUndefined;
68 vk::UniqueSwapchainKHR swapchain_;
69 std::vector<std::shared_ptr<SwapchainImageVK>> images_;
70 std::vector<std::unique_ptr<FrameSynchronizer>> synchronizers_;
71 size_t current_frame_ = 0u;
72 bool is_valid_ = false;
73 size_t current_transform_poll_count_ = 0u;
74 vk::SurfaceTransformFlagBitsKHR transform_if_changed_discard_swapchain_;
75
76 SwapchainImplVK(const std::shared_ptr<Context>& context,
77 vk::UniqueSurfaceKHR surface,
78 vk::SwapchainKHR old_swapchain,
79 vk::SurfaceTransformFlagBitsKHR last_transform);
80
81 bool Present(const std::shared_ptr<SwapchainImageVK>& image, uint32_t index);
82
83 void WaitIdle() const;
84
85 FML_DISALLOW_COPY_AND_ASSIGN(SwapchainImplVK);
86 };
87
88 } // namespace impeller
impeller::SwapchainImplVK::~SwapchainImplVK
~SwapchainImplVK()
Definition: swapchain_impl_vk.cc:291
impeller::SwapchainImplVK::AcquireResult::surface
std::unique_ptr< Surface > surface
Definition: swapchain_impl_vk.h:44
impeller::SwapchainImplVK
An instance of a swapchain that does NOT adapt to going out of date with the underlying surface....
Definition: swapchain_impl_vk.h:29
impeller::SwapchainImplVK::IsValid
bool IsValid() const
Definition: swapchain_impl_vk.cc:295
vk.h
impeller::SwapchainImplVK::GetContext
std::shared_ptr< Context > GetContext() const
Definition: swapchain_impl_vk.cc:324
impeller::SwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(std::unique_ptr< Surface > p_surface)
Definition: swapchain_impl_vk.h:49
impeller::SwapchainImplVK::GetSurfaceFormat
vk::Format GetSurfaceFormat() const
Definition: swapchain_impl_vk.cc:316
impeller::SwapchainImplVK::Create
static std::shared_ptr< SwapchainImplVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, vk::SwapchainKHR old_swapchain=VK_NULL_HANDLE, vk::SurfaceTransformFlagBitsKHR last_transform=vk::SurfaceTransformFlagBitsKHR::eIdentity)
Definition: swapchain_impl_vk.cc:130
impeller::SwapchainImplVK::AcquireResult::out_of_date
bool out_of_date
Definition: swapchain_impl_vk.h:45
impeller::SwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(bool p_out_of_date=false)
Definition: swapchain_impl_vk.h:47
impeller::SwapchainImplVK::AcquireResult
Definition: swapchain_impl_vk.h:43
std
Definition: comparable.h:98
impeller::SwapchainImplVK::AcquireNextDrawable
AcquireResult AcquireNextDrawable()
Definition: swapchain_impl_vk.cc:328
impeller::SwapchainImplVK::DestroySwapchain
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()
Definition: swapchain_impl_vk.cc:307
impeller
Definition: aiks_context.cc:10
impeller::SwapchainImplVK::GetLastTransform
vk::SurfaceTransformFlagBitsKHR GetLastTransform() const
Definition: swapchain_impl_vk.cc:320