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/macros.h"
14#include "third_party/skia/include/core/SkSize.h"
15#include "third_party/skia/include/core/SkSurface.h"
16
17namespace vulkan {
18
19class VulkanProcTable;
20class VulkanDevice;
21class VulkanSurface;
22class VulkanBackbuffer;
23class VulkanImage;
24
26 public:
28 const VulkanDevice& device,
30 GrDirectContext* skia_context,
31 std::unique_ptr<VulkanSwapchain> old_swapchain,
32 uint32_t queue_family_index);
33
35
36 bool IsValid() const;
37
38 enum class AcquireStatus {
39 /// A valid SkSurface was acquired successfully from the swapchain.
40 Success,
41 /// The underlying surface of the swapchain was permanently lost. This is an
42 /// unrecoverable error. The entire surface must be recreated along with the
43 /// swapchain.
45 /// The swapchain surface is out-of-date with the underlying surface. The
46 /// swapchain must be recreated.
48 };
49 using AcquireResult = std::pair<AcquireStatus, sk_sp<SkSurface>>;
50
51 /// Acquire an SkSurface from the swapchain for the caller to render into for
52 /// later submission via |Submit|. There must not be consecutive calls to
53 /// |AcquireFrame| without and interleaving |Submit|.
55
56 /// Submit a previously acquired. There must not be consecutive calls to
57 /// |Submit| without and interleaving |AcquireFrame|.
58 [[nodiscard]] bool Submit();
59
60 SkISize GetSize() const;
61
62#if FML_OS_ANDROID
63 private:
64 const VulkanProcTable& vk;
65 const VulkanDevice& device_;
66 VkSurfaceCapabilitiesKHR capabilities_;
67 VkSurfaceFormatKHR surface_format_;
69 std::vector<std::unique_ptr<VulkanBackbuffer>> backbuffers_;
70 std::vector<std::unique_ptr<VulkanImage>> images_;
71 std::vector<sk_sp<SkSurface>> surfaces_;
72 VkPipelineStageFlagBits current_pipeline_stage_;
73 size_t current_backbuffer_index_;
74 size_t current_image_index_;
75 bool valid_;
76
77 std::vector<VkImage> GetImages() const;
78
79 bool CreateSwapchainImages(GrDirectContext* skia_context,
80 SkColorType color_type,
81 const sk_sp<SkColorSpace>& color_space,
82 VkImageUsageFlags usage_flags);
83
84 sk_sp<SkSurface> CreateSkiaSurface(GrDirectContext* skia_context,
85 VkImage image,
86 VkImageUsageFlags usage_flags,
87 const SkISize& size,
88 SkColorType color_type,
89 sk_sp<SkColorSpace> color_space) const;
90
91 VulkanBackbuffer* GetNextBackbuffer();
92#endif // FML_OS_ANDROID
93
95};
96
97} // namespace vulkan
98
99#endif // FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_
std::pair< AcquireStatus, sk_sp< SkSurface > > AcquireResult
FML_DISALLOW_COPY_AND_ASSIGN(VulkanSwapchain)
@ Success
A valid SkSurface was acquired successfully from the swapchain.
FlutterVulkanImage * image
VkDevice device
Definition main.cc:69
uint32_t queue_family_index
Definition main.cc:70
VkSurfaceKHR surface
Definition main.cc:65
uint32_t color_type