Vulkan SDK for Android 1.1.1 Mali Developer Center
wsi.hpp
1 /* Copyright (c) 2016-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef PLATFORM_WSI_HPP
22 #define PLATFORM_WSI_HPP
23 
24 #include "framework/semaphore_manager.hpp"
25 #include "libvulkan-stub.h"
26 #include "platform.hpp"
27 
28 namespace MaliSDK
29 {
30 
36 class WSIPlatform : public Platform
37 {
38 public:
40  virtual ~WSIPlatform();
41 
45  virtual Result initialize() override;
46 
50  virtual void getCurrentSwapchain(std::vector<VkImage> *images, SwapchainDimensions *swapchain) override;
51 
54  virtual unsigned getNumSwapchainImages() const override;
55 
62  virtual Result acquireNextImage(unsigned *index) override;
63 
68  virtual Result presentImage(unsigned index) override;
69 
73  void terminate() override;
74 
75 protected:
84  Result initVulkan(const SwapchainDimensions &swapchain, const std::vector<const char *> &instanceExtensions,
85  const std::vector<const char *> &deviceExtensions);
86 
93  Result initSwapchain(const SwapchainDimensions &swapchain);
94 
96  void destroySwapchain();
97 
98 private:
99  SemaphoreManager *semaphoreManager = nullptr;
100 
101  VkSurfaceKHR surface = VK_NULL_HANDLE;
102  VkSwapchainKHR swapchain = VK_NULL_HANDLE;
103  SwapchainDimensions swapchainDimensions;
104  std::vector<VkImage> swapchainImages;
105 
106  virtual VkSurfaceKHR createSurface() = 0;
107  Result loadDeviceSymbols();
108  Result loadInstanceSymbols();
109 
110  bool validateExtensions(const std::vector<const char *> &required,
111  const std::vector<VkExtensionProperties> &available);
112 
113  VkDebugReportCallbackEXT debug_callback = VK_NULL_HANDLE;
114 };
115 }
116 
117 #endif
The SemaphoreManager keeps track of semaphores.
void destroySwapchain()
Explicit tears down the swapchain.
Definition: wsi.cpp:466
virtual Result acquireNextImage(unsigned *index) override
At start of a frame, acquire the next swapchain image to render into.
Definition: wsi.cpp:688
Describes the size and format of the swapchain.
Definition: platform.hpp:54
virtual ~WSIPlatform()
Destructor.
Definition: wsi.cpp:69
void terminate() override
Terminates the platform. Normally this would be handled by the destructor, but certain platforms need...
Definition: wsi.cpp:478
The platform class is to abstract the Vulkan implementation of a particular platform. It is not used directly by applications, but by the mainloop implementation which is OS specific.
Definition: platform.hpp:38
virtual void getCurrentSwapchain(std::vector< VkImage > *images, SwapchainDimensions *swapchain) override
Gets the current swapchain.
Definition: wsi.cpp:677
virtual Result initialize() override
Initialize the platform. Can be overriden by subclasses as long as they also call this method...
Definition: wsi.cpp:96
virtual unsigned getNumSwapchainImages() const override
Gets number of swapchain images used.
Definition: wsi.cpp:683
Result initVulkan(const SwapchainDimensions &swapchain, const std::vector< const char *> &instanceExtensions, const std::vector< const char *> &deviceExtensions)
Initializes the Vulkan device.
Definition: wsi.cpp:133
virtual Result presentImage(unsigned index) override
Presents an image to the swapchain.
Definition: wsi.cpp:728
Result initSwapchain(const SwapchainDimensions &swapchain)
Explicitly initializes the swapchain.
Definition: wsi.cpp:551
The WSI platform is a common platform for all platforms which support the VK_KHRSurface extension...
Definition: wsi.hpp:36