| 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 |  | 
|---|
| 18 | #include "Vulkan/VkObject.hpp" | 
|---|
| 19 | #include "Vulkan/VkImage.hpp" | 
|---|
| 20 | #include <Vulkan/VulkanPlatform.h> | 
|---|
| 21 |  | 
|---|
| 22 | #include <vector> | 
|---|
| 23 |  | 
|---|
| 24 | namespace vk | 
|---|
| 25 | { | 
|---|
| 26 |  | 
|---|
| 27 | enum PresentImageStatus | 
|---|
| 28 | { | 
|---|
| 29 | NONEXISTENT,  // Image wasn't created | 
|---|
| 30 | AVAILABLE, | 
|---|
| 31 | DRAWING, | 
|---|
| 32 | PRESENTING, | 
|---|
| 33 | }; | 
|---|
| 34 |  | 
|---|
| 35 | class DeviceMemory; | 
|---|
| 36 | class Image; | 
|---|
| 37 | class SwapchainKHR; | 
|---|
| 38 |  | 
|---|
| 39 | class PresentImage | 
|---|
| 40 | { | 
|---|
| 41 | public: | 
|---|
| 42 | VkResult allocateImage(VkDevice device, const VkImageCreateInfo& createInfo); | 
|---|
| 43 | VkResult allocateAndBindImageMemory(VkDevice device, const VkMemoryAllocateInfo& allocateInfo); | 
|---|
| 44 | void clear(); | 
|---|
| 45 | VkImage asVkImage() const; | 
|---|
| 46 |  | 
|---|
| 47 | const Image* getImage() const { return image; } | 
|---|
| 48 | DeviceMemory* getImageMemory() const { return imageMemory; } | 
|---|
| 49 | bool isAvailable() const { return (imageStatus == AVAILABLE); } | 
|---|
| 50 | bool exists() const { return (imageStatus != NONEXISTENT); } | 
|---|
| 51 | void setStatus(PresentImageStatus status) { imageStatus = status; } | 
|---|
| 52 |  | 
|---|
| 53 | private: | 
|---|
| 54 | Image* image = nullptr; | 
|---|
| 55 | DeviceMemory* imageMemory = nullptr; | 
|---|
| 56 | PresentImageStatus imageStatus = NONEXISTENT; | 
|---|
| 57 | }; | 
|---|
| 58 |  | 
|---|
| 59 | class SurfaceKHR | 
|---|
| 60 | { | 
|---|
| 61 | public: | 
|---|
| 62 | virtual ~SurfaceKHR() = default; | 
|---|
| 63 |  | 
|---|
| 64 | operator VkSurfaceKHR() | 
|---|
| 65 | { | 
|---|
| 66 | return vk::TtoVkT<SurfaceKHR, VkSurfaceKHR>(this); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | static inline SurfaceKHR* Cast(VkSurfaceKHR object) | 
|---|
| 70 | { | 
|---|
| 71 | return vk::VkTtoT<SurfaceKHR, VkSurfaceKHR>(object); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | void destroy(const VkAllocationCallbacks* pAllocator) | 
|---|
| 75 | { | 
|---|
| 76 | destroySurface(pAllocator); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | virtual void destroySurface(const VkAllocationCallbacks* pAllocator) = 0; | 
|---|
| 80 |  | 
|---|
| 81 | virtual void getSurfaceCapabilities(VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) const; | 
|---|
| 82 |  | 
|---|
| 83 | uint32_t getSurfaceFormatsCount() const; | 
|---|
| 84 | VkResult getSurfaceFormats(uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats) const; | 
|---|
| 85 |  | 
|---|
| 86 | uint32_t getPresentModeCount() const; | 
|---|
| 87 | VkResult getPresentModes(uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes) const; | 
|---|
| 88 |  | 
|---|
| 89 | VkResult getPresentRectangles(uint32_t *pRectCount, VkRect2D *pRects) const; | 
|---|
| 90 |  | 
|---|
| 91 | virtual void attachImage(PresentImage* image) = 0; | 
|---|
| 92 | virtual void detachImage(PresentImage* image) = 0; | 
|---|
| 93 | virtual VkResult present(PresentImage* image) = 0; | 
|---|
| 94 |  | 
|---|
| 95 | void associateSwapchain(SwapchainKHR* swapchain); | 
|---|
| 96 | void disassociateSwapchain(); | 
|---|
| 97 | bool hasAssociatedSwapchain(); | 
|---|
| 98 |  | 
|---|
| 99 | private: | 
|---|
| 100 | SwapchainKHR* associatedSwapchain = nullptr; | 
|---|
| 101 | }; | 
|---|
| 102 |  | 
|---|
| 103 | static inline SurfaceKHR* Cast(VkSurfaceKHR object) | 
|---|
| 104 | { | 
|---|
| 105 | return SurfaceKHR::Cast(object); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | #endif //SWIFTSHADER_VKSURFACEKHR_HPP_ | 
|---|
| 111 |  | 
|---|