Vulkan SDK for Android 1.1.1 Mali Developer Center
png.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_PNG_HPP
22 #define PLATFORM_PNG_HPP
23 
24 #include "platform.hpp"
25 #include "platform/os/linux.hpp"
26 #include "png_swapchain.hpp"
27 #include <vector>
28 
29 namespace MaliSDK
30 {
34 class PNGPlatform : public Platform
35 {
36 public:
38  virtual ~PNGPlatform();
39 
42  virtual Result initialize() override;
43 
46  virtual SwapchainDimensions getPreferredSwapchain() override;
47 
54  virtual Result createWindow(const SwapchainDimensions &swapchain) override;
55 
59  virtual void getCurrentSwapchain(std::vector<VkImage> *images, SwapchainDimensions *swapchain) override;
60 
63  virtual unsigned getNumSwapchainImages() const override;
64 
71  virtual Result acquireNextImage(unsigned *index) override;
72 
77  virtual Result presentImage(unsigned index) override;
78 
81  virtual Status getWindowStatus() override;
82 
84  virtual void terminate() override;
85 
86 private:
87  PNGSwapchain *pngSwapchain = nullptr;
88 
89  SwapchainDimensions swapchainDimensions;
90  std::vector<VkImage> swapchainImages;
91  std::vector<VkDeviceMemory> swapchainMemory;
92  std::vector<VkBuffer> swapchainReadback;
93  std::vector<VkDeviceMemory> swapchainReadbackMemory;
94  bool swapchainCoherent = false;
95 
96  Result initVulkan(const SwapchainDimensions &dimensions);
97 
98  uint32_t findMemoryTypeFromRequirements(uint32_t deviceRequirements, uint32_t hostRequirements);
99  uint32_t findMemoryTypeFromRequirementsFallback(uint32_t deviceRequirements, uint32_t hostRequirements,
100  uint32_t hostRequirementsFallback);
101 
102  void imageMemoryBarrier(VkCommandBuffer cmd, VkImage image, VkAccessFlags srcAccessMask,
103  VkAccessFlags dstAccessMask, VkPipelineStageFlags srcStageMask,
104  VkPipelineStageFlags dstStageMask, VkImageLayout oldLayout, VkImageLayout newLayout);
105 
106  VkDebugReportCallbackEXT debug_callback = VK_NULL_HANDLE;
107 };
108 }
109 
110 #endif
virtual Result acquireNextImage(unsigned *index) override
At start of a frame, acquire the next swapchain image to render into.
Definition: png.cpp:230
Describes the size and format of the swapchain.
Definition: platform.hpp:54
virtual unsigned getNumSwapchainImages() const override
Gets number of swapchain images used.
Definition: png.cpp:225
virtual void terminate() override
Terminates the platform.
Definition: png.cpp:147
Status
Describes the status of the application lifecycle.
Definition: platform.hpp:65
The platform for a windowless PNG based platform. Instead of outputting to screen, the application dumps a stream of PNG files.
Definition: png.hpp:34
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 Result createWindow(const SwapchainDimensions &swapchain) override
Creates a window with desired swapchain dimensions.
Definition: png.cpp:214
virtual SwapchainDimensions getPreferredSwapchain() override
Gets the preferred swapchain size.
Definition: png.cpp:205
virtual void getCurrentSwapchain(std::vector< VkImage > *images, SwapchainDimensions *swapchain) override
Gets the current swapchain.
Definition: png.cpp:219
This class implements a swapchain outside the Vulkan API. Its main purpose is debugging without a scr...
virtual ~PNGPlatform()
Destructor.
Definition: png.cpp:200
virtual Result presentImage(unsigned index) override
Presents an image to the swapchain.
Definition: png.cpp:264
virtual Result initialize() override
Initialize the platform.
Definition: png.cpp:121
virtual Status getWindowStatus() override
Gets current window status.
Definition: png.cpp:116