• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Semaphore;
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, Semaphore *semaphore, Fence *fence, uint32_t *pImageIndex);
46 
47 	VkResult present(uint32_t index);
getImage(uint32_t imageIndex)48 	PresentImage const &getImage(uint32_t imageIndex) { return images[imageIndex]; }
49 
50 private:
51 	SurfaceKHR *surface = nullptr;
52 	PresentImage *images = nullptr;
53 	uint32_t imageCount = 0;
54 	bool retired = false;
55 
56 	void resetImages();
57 };
58 
Cast(VkSwapchainKHR object)59 static inline SwapchainKHR *Cast(VkSwapchainKHR object)
60 {
61 	return SwapchainKHR::Cast(object);
62 }
63 
64 }  // namespace vk
65 
66 #endif  //SWIFTSHADER_VKSWAPCHAINKHR_HPP
67