Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 1 | // Copyright 2018 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_VKSURFACEKHR_HPP_ |
| 16 | #define SWIFTSHADER_VKSURFACEKHR_HPP_ |
| 17 | |
Nicolas Capens | d354537 | 2019-08-09 13:59:18 -0400 | [diff] [blame] | 18 | #include "Vulkan/VkImage.hpp" |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 19 | #include "Vulkan/VkObject.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 20 | #include "Vulkan/VulkanPlatform.hpp" |
Nicolas Capens | d354537 | 2019-08-09 13:59:18 -0400 | [diff] [blame] | 21 | |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 24 | namespace vk { |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 25 | |
Hernan Liatis | f945a5e | 2019-03-06 15:31:04 -0800 | [diff] [blame] | 26 | enum PresentImageStatus |
| 27 | { |
Nicolas Capens | d354537 | 2019-08-09 13:59:18 -0400 | [diff] [blame] | 28 | NONEXISTENT, // Image wasn't created |
Hernan Liatis | f945a5e | 2019-03-06 15:31:04 -0800 | [diff] [blame] | 29 | AVAILABLE, |
| 30 | DRAWING, |
| 31 | PRESENTING, |
| 32 | }; |
| 33 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 34 | class DeviceMemory; |
| 35 | class Image; |
| 36 | class SwapchainKHR; |
| 37 | |
| 38 | class PresentImage |
Hernan Liatis | f945a5e | 2019-03-06 15:31:04 -0800 | [diff] [blame] | 39 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 40 | public: |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 41 | VkResult createImage(VkDevice device, const VkImageCreateInfo &createInfo); |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 42 | VkResult allocateAndBindImageMemory(VkDevice device, const VkMemoryAllocateInfo &allocateInfo); |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 43 | void release(); |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 44 | VkImage asVkImage() const; |
| 45 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 46 | const Image *getImage() const { return image; } |
| 47 | DeviceMemory *getImageMemory() const { return imageMemory; } |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 48 | bool isAvailable() const { return (imageStatus == AVAILABLE); } |
| 49 | bool exists() const { return (imageStatus != NONEXISTENT); } |
| 50 | void setStatus(PresentImageStatus status) { imageStatus = status; } |
| 51 | |
| 52 | private: |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 53 | Image *image = nullptr; |
| 54 | DeviceMemory *imageMemory = nullptr; |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 55 | PresentImageStatus imageStatus = NONEXISTENT; |
Hernan Liatis | f945a5e | 2019-03-06 15:31:04 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 58 | class SurfaceKHR |
| 59 | { |
| 60 | public: |
Ben Clayton | caf6031 | 2019-05-21 15:31:12 +0100 | [diff] [blame] | 61 | virtual ~SurfaceKHR() = default; |
| 62 | |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 63 | operator VkSurfaceKHR() |
| 64 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 65 | return vk::TtoVkT<SurfaceKHR, VkSurfaceKHR>(this); |
| 66 | } |
| 67 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 68 | static inline SurfaceKHR *Cast(VkSurfaceKHR object) |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 69 | { |
| 70 | return vk::VkTtoT<SurfaceKHR, VkSurfaceKHR>(object); |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 73 | void destroy(const VkAllocationCallbacks *pAllocator) |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 74 | { |
| 75 | destroySurface(pAllocator); |
| 76 | } |
| 77 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 78 | virtual void destroySurface(const VkAllocationCallbacks *pAllocator) = 0; |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 79 | |
Shahbaz Youssefi | ea3fc74 | 2022-10-23 22:41:06 -0400 | [diff] [blame] | 80 | virtual VkResult getSurfaceCapabilities(const void *pSurfaceInfoPNext, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, void *pSurfaceCapabilitiesPNext) const = 0; |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 81 | |
Shahbaz Youssefi | ea3fc74 | 2022-10-23 22:41:06 -0400 | [diff] [blame] | 82 | uint32_t getSurfaceFormatsCount(const void *pSurfaceInfoPNext) const; |
| 83 | VkResult getSurfaceFormats(const void *pSurfaceInfoPNext, uint32_t *pSurfaceFormatCount, VkSurfaceFormat2KHR *pSurfaceFormats) const; |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 84 | |
| 85 | uint32_t getPresentModeCount() const; |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 86 | VkResult getPresentModes(uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) const; |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 87 | |
Chris Forbes | b52384b | 2019-08-28 12:01:29 -0700 | [diff] [blame] | 88 | VkResult getPresentRectangles(uint32_t *pRectCount, VkRect2D *pRects) const; |
| 89 | |
Peng Huang | 87c78ac | 2021-12-23 10:49:44 +0000 | [diff] [blame] | 90 | virtual void* allocateImageMemory(PresentImage *image, const VkMemoryAllocateInfo &allocateInfo) { return nullptr; } |
| 91 | virtual void releaseImageMemory(PresentImage *image) {} |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 92 | virtual void attachImage(PresentImage *image) = 0; |
| 93 | virtual void detachImage(PresentImage *image) = 0; |
| 94 | virtual VkResult present(PresentImage *image) = 0; |
Hernan Liatis | 6b12a50 | 2019-03-01 15:06:13 -0800 | [diff] [blame] | 95 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 96 | void associateSwapchain(SwapchainKHR *swapchain); |
Hernan Liatis | 43be716 | 2019-03-08 17:57:41 -0800 | [diff] [blame] | 97 | void disassociateSwapchain(); |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 98 | bool hasAssociatedSwapchain(); |
Hernan Liatis | 43be716 | 2019-03-08 17:57:41 -0800 | [diff] [blame] | 99 | |
Antonio Maiorano | 5128643 | 2021-02-19 09:56:47 -0500 | [diff] [blame] | 100 | protected: |
Shahbaz Youssefi | ea3fc74 | 2022-10-23 22:41:06 -0400 | [diff] [blame] | 101 | static void setCommonSurfaceCapabilities(const void *pSurfaceInfoPNext, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, void *pSurfaceCapabilitiesPNext); |
Antonio Maiorano | 5128643 | 2021-02-19 09:56:47 -0500 | [diff] [blame] | 102 | |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 103 | private: |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 104 | SwapchainKHR *associatedSwapchain = nullptr; |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 107 | static inline SurfaceKHR *Cast(VkSurfaceKHR object) |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 108 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 109 | return SurfaceKHR::Cast(object); |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 112 | } // namespace vk |
Hernan Liatis | c6eb41b | 2019-02-22 11:12:59 -0800 | [diff] [blame] | 113 | |
Sean Risser | 08762e3 | 2021-05-05 14:28:24 -0400 | [diff] [blame] | 114 | #endif // SWIFTSHADER_VKSURFACEKHR_HPP_ |