xref: /aosp_15_r20/external/swiftshader/src/WSI/VkSwapchainKHR.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 // Copyright 2019 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SWIFTSHADER_VKSWAPCHAINKHR_HPP
16 #define SWIFTSHADER_VKSWAPCHAINKHR_HPP
17 
18 #include "VkSurfaceKHR.hpp"
19 #include "Vulkan/VkImage.hpp"
20 #include "Vulkan/VkObject.hpp"
21 
22 #include <vector>
23 
24 namespace vk {
25 
26 class Fence;
27 class BinarySemaphore;
28 
29 class SwapchainKHR : public Object<SwapchainKHR, VkSwapchainKHR>
30 {
31 public:
32 	SwapchainKHR(const VkSwapchainCreateInfoKHR *pCreateInfo, void *mem);
33 
34 	void destroy(const VkAllocationCallbacks *pAllocator);
35 
36 	static size_t ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR *pCreateInfo);
37 
38 	void retire();
39 
40 	VkResult createImages(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo);
41 
42 	uint32_t getImageCount() const;
43 	VkResult getImages(uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) const;
44 
45 	VkResult getNextImage(uint64_t timeout, BinarySemaphore *semaphore, Fence *fence, uint32_t *pImageIndex);
46 
47 	VkResult present(uint32_t index);
getImage(uint32_t imageIndex)48 	const PresentImage &getImage(uint32_t imageIndex) { return images[imageIndex]; }
49 
50 	VkResult releaseImages(uint32_t imageIndexCount, const uint32_t *pImageIndices);
51 
52 private:
53 	void releaseImage(uint32_t index);
54 
55 	SurfaceKHR *surface = nullptr;
56 	PresentImage *images = nullptr;
57 	uint32_t imageCount = 0;
58 	bool retired = false;
59 
60 	void resetImages();
61 };
62 
Cast(VkSwapchainKHR object)63 static inline SwapchainKHR *Cast(VkSwapchainKHR object)
64 {
65 	return SwapchainKHR::Cast(object);
66 }
67 
68 }  // namespace vk
69 
70 #endif  // SWIFTSHADER_VKSWAPCHAINKHR_HPP
71