forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulkan_swapchain.h
97 lines (77 loc) · 3.12 KB
/
vulkan_swapchain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_
#define FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_
#include <memory>
#include <utility>
#include <vector>
#include "flutter/fml/compiler_specific.h"
#include "flutter/fml/macros.h"
#include "flutter/vulkan/vulkan_handle.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace vulkan {
class VulkanProcTable;
class VulkanDevice;
class VulkanSurface;
class VulkanBackbuffer;
class VulkanImage;
class VulkanSwapchain {
public:
VulkanSwapchain(const VulkanProcTable& vk,
const VulkanDevice& device,
const VulkanSurface& surface,
GrContext* skia_context,
std::unique_ptr<VulkanSwapchain> old_swapchain,
uint32_t queue_family_index);
~VulkanSwapchain();
bool IsValid() const;
enum class AcquireStatus {
/// A valid SkSurface was acquired successfully from the swapchain.
Success,
/// The underlying surface of the swapchain was permanently lost. This is an
/// unrecoverable error. The entire surface must be recreated along with the
/// swapchain.
ErrorSurfaceLost,
/// The swapchain surface is out-of-date with the underlying surface. The
/// swapchain must be recreated.
ErrorSurfaceOutOfDate,
};
using AcquireResult = std::pair<AcquireStatus, sk_sp<SkSurface>>;
/// Acquire an SkSurface from the swapchain for the caller to render into for
/// later submission via |Submit|. There must not be consecutive calls to
/// |AcquireFrame| without and interleaving |Submit|.
AcquireResult AcquireSurface();
/// Submit a previously acquired. There must not be consecutive calls to
/// |Submit| without and interleaving |AcquireFrame|.
FML_WARN_UNUSED_RESULT
bool Submit();
SkISize GetSize() const;
private:
const VulkanProcTable& vk;
const VulkanDevice& device_;
VkSurfaceCapabilitiesKHR capabilities_;
VkSurfaceFormatKHR surface_format_;
VulkanHandle<VkSwapchainKHR> swapchain_;
std::vector<std::unique_ptr<VulkanBackbuffer>> backbuffers_;
std::vector<std::unique_ptr<VulkanImage>> images_;
std::vector<sk_sp<SkSurface>> surfaces_;
VkPipelineStageFlagBits current_pipeline_stage_;
size_t current_backbuffer_index_;
size_t current_image_index_;
bool valid_;
std::vector<VkImage> GetImages() const;
bool CreateSwapchainImages(GrContext* skia_context,
SkColorType color_type,
sk_sp<SkColorSpace> color_space);
sk_sp<SkSurface> CreateSkiaSurface(GrContext* skia_context,
VkImage image,
const SkISize& size,
SkColorType color_type,
sk_sp<SkColorSpace> color_space) const;
VulkanBackbuffer* GetNextBackbuffer();
FML_DISALLOW_COPY_AND_ASSIGN(VulkanSwapchain);
};
} // namespace vulkan
#endif // FLUTTER_VULKAN_VULKAN_SWAPCHAIN_H_