blob: a6892d4d01a0e8e2ce0bcbbb201f5a0c621c74bc [file] [log] [blame]
Ben Claytona9af8832019-08-14 13:09:43 +01001// 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 Claytona9af8832019-08-14 13:09:43 +010018#include "VkSurfaceKHR.hpp"
Ben Clayton45c697a2019-12-17 20:38:03 +000019#include "Vulkan/VkObject.hpp"
Nicolas Capens2490b1a2020-07-13 14:33:01 -040020
21#include <vulkan/vulkan_xcb.h>
Ben Clayton45c697a2019-12-17 20:38:03 +000022#include <xcb/xcb.h>
Peng Huang87c78ac2021-12-23 10:49:44 +000023#include <xcb/shm.h>
Ben Claytona9af8832019-08-14 13:09:43 +010024
25#include <unordered_map>
26
27namespace vk {
28
Ben Clayton45c697a2019-12-17 20:38:03 +000029class XcbSurfaceKHR : public SurfaceKHR, public ObjectBase<XcbSurfaceKHR, VkSurfaceKHR>
30{
Ben Claytona9af8832019-08-14 13:09:43 +010031public:
Nicolas Capensfc8dd5b2021-10-25 12:06:17 -040032 static bool isSupported();
Ben Claytona9af8832019-08-14 13:09:43 +010033 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 Maiorano51286432021-02-19 09:56:47 -050039 VkResult getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const override;
Ben Claytona9af8832019-08-14 13:09:43 +010040
Peng Huang87c78ac2021-12-23 10:49:44 +000041 virtual void* allocateImageMemory(PresentImage *image, const VkMemoryAllocateInfo &allocateInfo) override;
42 virtual void releaseImageMemory(PresentImage *image) override;
Ben Clayton45c697a2019-12-17 20:38:03 +000043 virtual void attachImage(PresentImage *image) override;
44 virtual void detachImage(PresentImage *image) override;
45 VkResult present(PresentImage *image) override;
Ben Claytona9af8832019-08-14 13:09:43 +010046
47private:
Peng Huang433b1bf2021-12-26 14:23:21 +000048 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 Huang87c78ac2021-12-23 10:49:44 +000054 struct SHMPixmap {
Peng Huang433b1bf2021-12-26 14:23:21 +000055 xcb_shm_seg_t shmseg = XCB_NONE;
56 void *shmaddr = nullptr;
57 xcb_pixmap_t pixmap = XCB_NONE;
Peng Huang87c78ac2021-12-23 10:49:44 +000058 };
59 std::unordered_map<PresentImage *, SHMPixmap> pixmaps;
60 // std::unordered_map<PresentImage *, uint32_t> graphicsContexts;
Ben Claytona9af8832019-08-14 13:09:43 +010061};
62
Ben Clayton45c697a2019-12-17 20:38:03 +000063} // namespace vk
Sean Risser08762e32021-05-05 14:28:24 -040064#endif // SWIFTSHADER_XCBSURFACEKHR_HPP