| 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 | |
| 18 | #include "VkSurfaceKHR.hpp" |
| 19 | #include "Vulkan/VkObject.hpp" |
| 20 | |
| 21 | #include <xcb/shm.h> |
| 22 | #include <xcb/xcb.h> |
| 23 | // XCB headers must be included before the Vulkan header. |
| 24 | #include <vulkan/vulkan_xcb.h> |
| 25 | |
| 26 | #include <unordered_map> |
| 27 | |
| 28 | namespace vk { |
| 29 | |
| 30 | class XcbSurfaceKHR : public SurfaceKHR, public ObjectBase<XcbSurfaceKHR, VkSurfaceKHR> |
| 31 | { |
| 32 | public: |
| 33 | static bool isSupported(); |
| 34 | XcbSurfaceKHR(const VkXcbSurfaceCreateInfoKHR *pCreateInfo, void *mem); |
| 35 | |
| 36 | void destroySurface(const VkAllocationCallbacks *pAllocator) override; |
| 37 | |
| 38 | static size_t ComputeRequiredAllocationSize(const VkXcbSurfaceCreateInfoKHR *pCreateInfo); |
| 39 | |
| 40 | VkResult getSurfaceCapabilities(const void *pSurfaceInfoPNext, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, void *pSurfaceCapabilitiesPNext) const override; |
| 41 | |
| 42 | virtual void *allocateImageMemory(PresentImage *image, const VkMemoryAllocateInfo &allocateInfo) override; |
| 43 | virtual void releaseImageMemory(PresentImage *image) override; |
| 44 | virtual void attachImage(PresentImage *image) override; |
| 45 | virtual void detachImage(PresentImage *image) override; |
| 46 | VkResult present(PresentImage *image) override; |
| 47 | |
| 48 | private: |
| 49 | xcb_connection_t *connection = nullptr; |
| 50 | xcb_window_t window = XCB_NONE; |
| 51 | bool mitSHM = false; |
| 52 | xcb_gcontext_t gc = XCB_NONE; |
| 53 | int windowDepth = 0; |
| 54 | mutable bool surfaceLost = false; |
| 55 | struct SHMPixmap |
| 56 | { |
| 57 | xcb_shm_seg_t shmseg = XCB_NONE; |
| 58 | void *shmaddr = nullptr; |
| 59 | xcb_pixmap_t pixmap = XCB_NONE; |
| 60 | }; |
| 61 | std::unordered_map<PresentImage *, SHMPixmap> pixmaps; |
| 62 | // std::unordered_map<PresentImage *, uint32_t> graphicsContexts; |
| 63 | }; |
| 64 | |
| 65 | } // namespace vk |
| 66 | #endif // SWIFTSHADER_XCBSURFACEKHR_HPP |
| 67 | |