| 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 | |
| 19 | #include "Vulkan/VkObject.hpp" |
| 20 | #include "Vulkan/VkImage.hpp" |
| 21 | #include "VkSurfaceKHR.hpp" |
| 22 | |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace vk |
| 26 | { |
| 27 | |
| 28 | class Fence; |
| 29 | class Semaphore; |
| 30 | |
| 31 | class SwapchainKHR : public Object<SwapchainKHR, VkSwapchainKHR> |
| 32 | { |
| 33 | public: |
| 34 | SwapchainKHR(const VkSwapchainCreateInfoKHR* pCreateInfo, void* mem); |
| 35 | |
| 36 | void destroy(const VkAllocationCallbacks* pAllocator); |
| 37 | |
| 38 | static size_t ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR* pCreateInfo); |
| 39 | |
| 40 | void retire(); |
| 41 | |
| 42 | VkResult createImages(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo); |
| 43 | |
| 44 | uint32_t getImageCount() const; |
| 45 | VkResult getImages(uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) const; |
| 46 | |
| 47 | VkResult getNextImage(uint64_t timeout, Semaphore* semaphore, Fence* fence, uint32_t* pImageIndex); |
| 48 | |
| 49 | VkResult present(uint32_t index); |
| 50 | PresentImage const &getImage(uint32_t imageIndex) { return images[imageIndex]; } |
| 51 | |
| 52 | private: |
| 53 | SurfaceKHR* surface = nullptr; |
| 54 | PresentImage* images = nullptr; |
| 55 | uint32_t imageCount = 0; |
| 56 | bool retired = false; |
| 57 | |
| 58 | void resetImages(); |
| 59 | }; |
| 60 | |
| 61 | static inline SwapchainKHR* Cast(VkSwapchainKHR object) |
| 62 | { |
| 63 | return SwapchainKHR::Cast(object); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif //SWIFTSHADER_VKSWAPCHAINKHR_HPP |
| 69 | |