Vulkan SDK for Android 1.1.1 Mali Developer Center
png_swapchain.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 DMABUF_SWAPCHAIN_HPP
22 #define DMABUF_SWAPCHAIN_HPP
23 
24 #include "libvulkan-stub.h"
25 #include <condition_variable>
26 #include <mutex>
27 #include <queue>
28 #include <string>
29 #include <thread>
30 
31 #include "framework/common.hpp"
32 
33 namespace MaliSDK
34 {
35 
41 {
42 public:
48  Result init(const char *pBasePath, unsigned swapchainImagesCount);
49 
51  ~PNGSwapchain();
52 
55  inline unsigned getNumImages() const
56  {
57  return swapchainImagesCount;
58  }
59 
72  void present(unsigned index, VkDevice device, VkDeviceMemory memory, unsigned width, unsigned height,
73  unsigned numFences, VkFence *fences, bool coherent);
74 
79  unsigned acquire();
80 
81 private:
82  std::thread worker;
83  unsigned swapchainImagesCount;
84  std::string basePath;
85 
86  struct Command
87  {
88  VkDevice device;
89  VkDeviceMemory memory;
90  VkFence *fences;
91  unsigned numFences;
92  unsigned index;
93  unsigned width;
94  unsigned height;
95  bool coherent;
96  };
97 
98  std::queue<unsigned> vacant;
99  std::queue<Command> ready;
100 
101  std::condition_variable cond;
102  std::mutex lock;
103  bool dead = false;
104 
105  void join();
106 
107  unsigned displayed = 0;
108 
109  void threadEntry();
110 
111  void dump(const Command &cmd, unsigned sequenceCount);
112 };
113 }
114 
115 #endif
Result init(const char *pBasePath, unsigned swapchainImagesCount)
Initialize the swapchain.
~PNGSwapchain()
Destructor.
unsigned getNumImages() const
Gets number of images in the swapchain.
This class implements a swapchain outside the Vulkan API. Its main purpose is debugging without a scr...
void present(unsigned index, VkDevice device, VkDeviceMemory memory, unsigned width, unsigned height, unsigned numFences, VkFence *fences, bool coherent)
Dump image for a swapchain index to disk.
unsigned acquire()
Acquire a new swapchain index. When acquire returns the image is ready to be presented into...