Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [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_XCBSURFACEKHR_HPP |
| 16 | #define SWIFTSHADER_XCBSURFACEKHR_HPP |
| 17 | |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 18 | #include "VkSurfaceKHR.hpp" |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 19 | #include "Vulkan/VkObject.hpp" |
Nicolas Capens | 2490b1a | 2020-07-13 14:33:01 -0400 | [diff] [blame] | 20 | |
| 21 | #include <vulkan/vulkan_xcb.h> |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 22 | #include <xcb/xcb.h> |
Peng Huang | 87c78ac | 2021-12-23 10:49:44 +0000 | [diff] [blame] | 23 | #include <xcb/shm.h> |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 24 | |
| 25 | #include <unordered_map> |
| 26 | |
| 27 | namespace vk { |
| 28 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 29 | class XcbSurfaceKHR : public SurfaceKHR, public ObjectBase<XcbSurfaceKHR, VkSurfaceKHR> |
| 30 | { |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 31 | public: |
Nicolas Capens | fc8dd5b | 2021-10-25 12:06:17 -0400 | [diff] [blame] | 32 | static bool isSupported(); |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 33 | XcbSurfaceKHR(const VkXcbSurfaceCreateInfoKHR *pCreateInfo, void *mem); |
| 34 | |
| 35 | void destroySurface(const VkAllocationCallbacks *pAllocator) override; |
| 36 | |
| 37 | static size_t ComputeRequiredAllocationSize(const VkXcbSurfaceCreateInfoKHR *pCreateInfo); |
| 38 | |
Antonio Maiorano | 5128643 | 2021-02-19 09:56:47 -0500 | [diff] [blame] | 39 | VkResult getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const override; |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 40 | |
Peng Huang | 87c78ac | 2021-12-23 10:49:44 +0000 | [diff] [blame] | 41 | virtual void* allocateImageMemory(PresentImage *image, const VkMemoryAllocateInfo &allocateInfo) override; |
| 42 | virtual void releaseImageMemory(PresentImage *image) override; |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 43 | virtual void attachImage(PresentImage *image) override; |
| 44 | virtual void detachImage(PresentImage *image) override; |
| 45 | VkResult present(PresentImage *image) override; |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 46 | |
| 47 | private: |
Peng Huang | 433b1bf | 2021-12-26 14:23:21 +0000 | [diff] [blame^] | 48 | xcb_connection_t *connection = nullptr; |
| 49 | xcb_window_t window = XCB_NONE; |
| 50 | bool mitSHM = false; |
| 51 | xcb_gcontext_t gc = XCB_NONE; |
| 52 | int windowDepth = 0; |
| 53 | mutable bool surfaceLost = false; |
Peng Huang | 87c78ac | 2021-12-23 10:49:44 +0000 | [diff] [blame] | 54 | struct SHMPixmap { |
Peng Huang | 433b1bf | 2021-12-26 14:23:21 +0000 | [diff] [blame^] | 55 | xcb_shm_seg_t shmseg = XCB_NONE; |
| 56 | void *shmaddr = nullptr; |
| 57 | xcb_pixmap_t pixmap = XCB_NONE; |
Peng Huang | 87c78ac | 2021-12-23 10:49:44 +0000 | [diff] [blame] | 58 | }; |
| 59 | std::unordered_map<PresentImage *, SHMPixmap> pixmaps; |
| 60 | // std::unordered_map<PresentImage *, uint32_t> graphicsContexts; |
Ben Clayton | a9af883 | 2019-08-14 13:09:43 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Ben Clayton | 45c697a | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 63 | } // namespace vk |
Sean Risser | 08762e3 | 2021-05-05 14:28:24 -0400 | [diff] [blame] | 64 | #endif // SWIFTSHADER_XCBSURFACEKHR_HPP |