Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
vulkan_swapchain.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_VULKAN_VULKAN_SWAPCHAIN_H_
6#define FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_
7
8#include <memory>
9#include <utility>
10#include <vector>
11
12#include "flutter/fml/compiler_specific.h"
13#include "flutter/fml/macros.h"
14#include "flutter/vulkan/procs/vulkan_handle.h"
17
18namespace vulkan {
19
20class VulkanProcTable;
21class VulkanDevice;
22class VulkanSurface;
23class VulkanBackbuffer;
24class VulkanImage;
25
27 public:
29 const VulkanDevice& device,
31 GrDirectContext* skia_context,
32 std::unique_ptr<VulkanSwapchain> old_swapchain,
33 uint32_t queue_family_index);
34
36
37 bool IsValid() const;
38
39 enum class AcquireStatus {
40 /// A valid SkSurface was acquired successfully from the swapchain.
41 Success,
42 /// The underlying surface of the swapchain was permanently lost. This is an
43 /// unrecoverable error. The entire surface must be recreated along with the
44 /// swapchain.
46 /// The swapchain surface is out-of-date with the underlying surface. The
47 /// swapchain must be recreated.
49 };
50 using AcquireResult = std::pair<AcquireStatus, sk_sp<SkSurface>>;
51
52 /// Acquire an SkSurface from the swapchain for the caller to render into for
53 /// later submission via |Submit|. There must not be consecutive calls to
54 /// |AcquireFrame| without and interleaving |Submit|.
56
57 /// Submit a previously acquired. There must not be consecutive calls to
58 /// |Submit| without and interleaving |AcquireFrame|.
59 [[nodiscard]] bool Submit();
60
61 SkISize GetSize() const;
62
63#if FML_OS_ANDROID
64 private:
65 const VulkanProcTable& vk;
66 const VulkanDevice& device_;
67 VkSurfaceCapabilitiesKHR capabilities_;
68 VkSurfaceFormatKHR surface_format_;
70 std::vector<std::unique_ptr<VulkanBackbuffer>> backbuffers_;
71 std::vector<std::unique_ptr<VulkanImage>> images_;
72 std::vector<sk_sp<SkSurface>> surfaces_;
73 VkPipelineStageFlagBits current_pipeline_stage_;
74 size_t current_backbuffer_index_;
75 size_t current_image_index_;
76 bool valid_;
77
78 std::vector<VkImage> GetImages() const;
79
80 bool CreateSwapchainImages(GrDirectContext* skia_context,
82 const sk_sp<SkColorSpace>& color_space,
83 VkImageUsageFlags usage_flags);
84
85 sk_sp<SkSurface> CreateSkiaSurface(GrDirectContext* skia_context,
86 VkImage image,
87 VkImageUsageFlags usage_flags,
88 const SkISize& size,
90 sk_sp<SkColorSpace> color_space) const;
91
92 VulkanBackbuffer* GetNextBackbuffer();
93#endif // FML_OS_ANDROID
94
96};
97
98} // namespace vulkan
99
100#endif // FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_
SkColorType
Definition SkColorType.h:19
std::pair< AcquireStatus, sk_sp< SkSurface > > AcquireResult
FML_DISALLOW_COPY_AND_ASSIGN(VulkanSwapchain)
@ Success
A valid SkSurface was acquired successfully from the swapchain.
VkDevice device
Definition main.cc:53
uint32_t queue_family_index
Definition main.cc:54
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
uint32_t color_type
VkFlags VkImageUsageFlags
VkPipelineStageFlagBits