working on adding wsi extensions
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 13 Sep 2017 19:26:34 +0000 (12:26 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 13 Sep 2017 19:26:34 +0000 (12:26 -0700)
21 files changed:
.dockerignore
CMakeLists.txt
Dockerfile
cmake/FindWayland.cmake [new file with mode: 0644]
cmake/FindX11_XCB.cmake [new file with mode: 0644]
cmake/FindXCB.cmake [new file with mode: 0644]
src/demo/demo.cpp
src/image/image.h
src/pipeline/pipeline.h
src/spirv_to_llvm/spirv_to_llvm.h
src/vulkan/CMakeLists.txt
src/vulkan/api_objects.h
src/vulkan/find-xlib-macros.sh [new file with mode: 0755]
src/vulkan/remove_xlib_macros.h [new file with mode: 0644]
src/vulkan/util.h
src/vulkan/vulkan.cpp
src/vulkan_icd/CMakeLists.txt
src/vulkan_icd/vulkan_icd.h
src/vulkan_icd/wsi.cpp [new file with mode: 0644]
src/vulkan_icd/wsi.h [new file with mode: 0644]
src/vulkan_icd/x11_wsi.cpp [new file with mode: 0644]

index 25073262477e27dd9e9667d125ef5d3640c6d21b..d69532d76a2b0699f21872195447a9c007d825c6 100644 (file)
@@ -3,4 +3,4 @@
 !docker-build-scripts
 !src
 !test-files
-
+!cmake
index b697454a9b4ac00f8844e346dd48995674efd396..61d2bbc429e3aacff9aa2716af3d0603a76c86a4 100644 (file)
@@ -20,6 +20,8 @@
 #
 cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
 
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
+
 set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_C_VISIBILITY_PRESET hidden)
@@ -28,20 +30,23 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
 project(kazan CXX C)
 if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
-  message(FATAL_ERROR "compiler is not clang")
+    message(FATAL_ERROR "compiler is not clang")
 endif()
 if(NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
-  message(FATAL_ERROR "compiler is not clang")
+    message(FATAL_ERROR "compiler is not clang")
 endif()
 
 find_package(LLVM REQUIRED CONFIG)
 if(LLVM_PACKAGE_VERSION VERSION_LESS 4.0)
-  message(FATAL_ERROR "unsupported version of llvm; requires version 4.0 or greater")
+    message(FATAL_ERROR "unsupported version of llvm; requires version 4.0 or greater")
 endif()
 if(NOT LLVM_ENABLE_THREADS)
-  message(FATAL_ERROR "llvm was not built multi-threaded")
+    message(FATAL_ERROR "llvm was not built multi-threaded")
 endif()
 include_directories(${LLVM_INCLUDE_DIRS})
 add_definitions(${LLVM_DEFINITIONS})
+if(WIN32)
+    add_definitions(NOMINMAX)
+endif()
 add_compile_options(-Wall -ftemplate-depth=1024 -Werror "-Wno-error=#warnings")
 add_subdirectory(src)
index 93280cec528ea5c84f18f5e3330b75f39b94ddf0..4cfba7f22baf4cc673ef056822353a00c47eb894 100644 (file)
@@ -1,5 +1,5 @@
 FROM ubuntu:xenial
-RUN apt-get update -q && apt-get dist-upgrade -qy && apt-get install -qy clang-4.0 build-essential cmake ninja-build llvm-4.0-dev libsdl2-dev curl imagemagick && apt-get clean -y
+RUN apt-get update -q && apt-get dist-upgrade -qy && apt-get install -qy clang-4.0 build-essential cmake ninja-build llvm-4.0-dev libsdl2-dev curl imagemagick libxcb-shm0-dev libxcb1-dev libx11-dev libx11-xcb-dev && apt-get clean -y
 WORKDIR /build
 COPY . /build
 RUN ./docker-build-scripts/build.sh
diff --git a/cmake/FindWayland.cmake b/cmake/FindWayland.cmake
new file mode 100644 (file)
index 0000000..f93218b
--- /dev/null
@@ -0,0 +1,66 @@
+# Try to find Wayland on a Unix system
+#
+# This will define:
+#
+#   WAYLAND_FOUND       - True if Wayland is found
+#   WAYLAND_LIBRARIES   - Link these to use Wayland
+#   WAYLAND_INCLUDE_DIR - Include directory for Wayland
+#   WAYLAND_DEFINITIONS - Compiler flags for using Wayland
+#
+# In addition the following more fine grained variables will be defined:
+#
+#   WAYLAND_CLIENT_FOUND  WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
+#   WAYLAND_SERVER_FOUND  WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
+#   WAYLAND_EGL_FOUND     WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
+#
+# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+IF (NOT WIN32)
+  IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES)
+    # In the cache already
+    SET(WAYLAND_FIND_QUIETLY TRUE)
+  ENDIF ()
+
+  # Use pkg-config to get the directories and then use these values
+  # in the FIND_PATH() and FIND_LIBRARY() calls
+  FIND_PACKAGE(PkgConfig)
+  PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor)
+
+  SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS})
+
+  FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR  NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR  NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  FIND_PATH(WAYLAND_EGL_INCLUDE_DIR     NAMES wayland-egl.h    HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+  FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR  NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
+
+  FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  FIND_LIBRARY(WAYLAND_EGL_LIBRARIES    NAMES wayland-egl      HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+  FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
+
+  set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR})
+
+  set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})
+
+  list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR)
+
+  include(FindPackageHandleStandardArgs)
+
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT  DEFAULT_MSG  WAYLAND_CLIENT_LIBRARIES  WAYLAND_CLIENT_INCLUDE_DIR)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER  DEFAULT_MSG  WAYLAND_SERVER_LIBRARIES  WAYLAND_SERVER_INCLUDE_DIR)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL     DEFAULT_MSG  WAYLAND_EGL_LIBRARIES     WAYLAND_EGL_INCLUDE_DIR)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR  DEFAULT_MSG  WAYLAND_CURSOR_LIBRARIES  WAYLAND_CURSOR_INCLUDE_DIR)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND         DEFAULT_MSG  WAYLAND_LIBRARIES         WAYLAND_INCLUDE_DIR)
+
+  MARK_AS_ADVANCED(
+        WAYLAND_INCLUDE_DIR         WAYLAND_LIBRARIES
+        WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
+        WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
+        WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
+        WAYLAND_CURSOR_INCLUDE_DIR  WAYLAND_CURSOR_LIBRARIES
+  )
+
+ENDIF ()
diff --git a/cmake/FindX11_XCB.cmake b/cmake/FindX11_XCB.cmake
new file mode 100644 (file)
index 0000000..7611b08
--- /dev/null
@@ -0,0 +1,31 @@
+# - Try to find libX11-xcb
+# Once done this will define
+#
+# X11_XCB_FOUND - system has libX11-xcb
+# X11_XCB_LIBRARIES - Link these to use libX11-xcb
+# X11_XCB_INCLUDE_DIR - the libX11-xcb include dir
+# X11_XCB_DEFINITIONS - compiler switches required for using libX11-xcb
+
+# Copyright (c) 2011 Fredrik Höglund <fredrik@kde.org>
+# Copyright (c) 2008 Helio Chissini de Castro, <helio@kde.org>
+# Copyright (c) 2007 Matthias Kretz, <kretz@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+IF (NOT WIN32)
+  # use pkg-config to get the directories and then use these values
+  # in the FIND_PATH() and FIND_LIBRARY() calls
+  FIND_PACKAGE(PkgConfig)
+  PKG_CHECK_MODULES(PKG_X11_XCB QUIET x11-xcb)
+
+  SET(X11_XCB_DEFINITIONS ${PKG_X11_XCB_CFLAGS})
+
+  FIND_PATH(X11_XCB_INCLUDE_DIR NAMES X11/Xlib-xcb.h HINTS ${PKG_X11_XCB_INCLUDE_DIRS})
+  FIND_LIBRARY(X11_XCB_LIBRARIES NAMES X11-xcb HINTS ${PKG_X11_XCB_LIBRARY_DIRS})
+
+  include(FindPackageHandleStandardArgs)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(X11_XCB DEFAULT_MSG X11_XCB_LIBRARIES X11_XCB_INCLUDE_DIR)
+
+  MARK_AS_ADVANCED(X11_XCB_INCLUDE_DIR X11_XCB_LIBRARIES)
+ENDIF (NOT WIN32)
diff --git a/cmake/FindXCB.cmake b/cmake/FindXCB.cmake
new file mode 100644 (file)
index 0000000..a2e2757
--- /dev/null
@@ -0,0 +1,51 @@
+# - FindXCB
+#
+# Copyright 2015 Valve Coporation
+
+find_package(PkgConfig)
+
+if(NOT XCB_FIND_COMPONENTS)
+    set(XCB_FIND_COMPONENTS xcb)
+endif()
+
+include(FindPackageHandleStandardArgs)
+set(XCB_FOUND true)
+set(XCB_INCLUDE_DIRS "")
+set(XCB_LIBRARIES "")
+foreach(comp ${XCB_FIND_COMPONENTS})
+    # component name
+    string(TOUPPER ${comp} compname)
+    string(REPLACE "-" "_" compname ${compname})
+    # header name
+    string(REPLACE "xcb-" "" headername xcb/${comp}.h)
+    # library name
+    set(libname ${comp})
+
+    pkg_check_modules(PC_${comp} QUIET ${comp})
+
+    find_path(${compname}_INCLUDE_DIR NAMES ${headername}
+        HINTS
+        ${PC_${comp}_INCLUDEDIR}
+        ${PC_${comp}_INCLUDE_DIRS}
+        )
+
+    find_library(${compname}_LIBRARY NAMES ${libname}
+        HINTS
+        ${PC_${comp}_LIBDIR}
+        ${PC_${comp}_LIBRARY_DIRS}
+        )
+
+    find_package_handle_standard_args(${comp}
+        FOUND_VAR ${comp}_FOUND
+        REQUIRED_VARS ${compname}_INCLUDE_DIR ${compname}_LIBRARY)
+    mark_as_advanced(${compname}_INCLUDE_DIR ${compname}_LIBRARY)
+
+    list(APPEND XCB_INCLUDE_DIRS ${${compname}_INCLUDE_DIR})
+    list(APPEND XCB_LIBRARIES ${${compname}_LIBRARY})
+
+    if(NOT ${comp}_FOUND)
+        set(XCB_FOUND false)
+    endif()
+endforeach()
+
+list(REMOVE_DUPLICATES XCB_INCLUDE_DIRS)
index cedf22774eb704dd2542416f534387b325aab59b..f304c977bf149422e22a0bd25055f41670e20c10 100644 (file)
@@ -35,6 +35,7 @@
 #include "util/string_view.h"
 #include "pipeline/pipeline.h"
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
 #include "util/void_t.h"
 
 #if SDL_MAJOR_VERSION != 2
index f0504e0704533d22bafbfa3f7caa12e0f3dc813c..60657b912d5a064ed628fc1984684d4ece42ad7f 100644 (file)
@@ -24,6 +24,7 @@
 #define IMAGE_IMAGE_H_
 
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
 #include <memory>
 #include <cassert>
 #include <cstdint>
index e17d933e9351100571002343c9427cabf39657f8..b3554569d5b7672c35de921db9d5ba8fda671cba 100644 (file)
@@ -30,6 +30,7 @@
 #include <cstring>
 #include "llvm_wrapper/llvm_wrapper.h"
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
 #include "spirv/spirv.h"
 #include "image/image.h"
 
index 45c2b5854353afc6c7be0eb64e15bd0a970364a7..d24fbb58f67ff87def8e40656d5f19385f60b11d 100644 (file)
@@ -35,6 +35,7 @@
 #include "llvm_wrapper/llvm_wrapper.h"
 #include "util/string_view.h"
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
 
 namespace kazan
 {
index 0a259c335f0ee9ff88c6bcc0e9887b5be6ec5d9d..aba5ee03d7c2b3dc2d5966bd54e5d03ad0af3bef 100644 (file)
@@ -24,8 +24,39 @@ set(sources vulkan.cpp
 add_library(kazan_vulkan STATIC ${sources})
 target_compile_definitions(kazan_vulkan PUBLIC VK_NO_PROTOTYPES)
 if(UNIX AND NOT CYGWIN AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
+    set(USE_X11 1)
+    # set(USE_WAYLAND 1) # wayland support is not implemented yet
+elseif(WIN32)
+    set(USE_WIN32 1)
+endif()
+
+if(USE_X11)
     target_compile_definitions(kazan_vulkan PUBLIC VK_USE_PLATFORM_XCB_KHR)
+    target_compile_definitions(kazan_vulkan PUBLIC VK_USE_PLATFORM_XLIB_KHR)
+
+    message("CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH})
+
+    find_package(XCB REQUIRED COMPONENTS xcb xcb-shm)
+    target_include_directories(kazan_vulkan PUBLIC ${XCB_INCLUDE_DIRS})
+    target_link_libraries(kazan_vulkan ${XCB_LIBRARIES})
+
+    find_package(X11_XCB REQUIRED)
+    target_include_directories(kazan_vulkan PUBLIC ${X11_XCB_INCLUDE_DIRS})
+    target_link_libraries(kazan_vulkan ${X11_XCB_LIBRARIES})
+
+    find_package(X11 REQUIRED)
+    target_include_directories(kazan_vulkan PUBLIC ${X11_INCLUDE_DIRS})
+    target_link_libraries(kazan_vulkan ${X11_LIBRARIES})
+endif()
+
+if(USE_WAYLAND)
     target_compile_definitions(kazan_vulkan PUBLIC VK_USE_PLATFORM_WAYLAND_KHR)
-elseif(WIN32)
+    find_package(Wayland REQUIRED)
+    target_include_directories(kazan_vulkan PUBLIC ${WAYLAND_INCLUDE_DIR})
+    target_link_libraries(kazan_vulkan ${WAYLAND_LIBRARIES})
+    target_compile_definitions(kazan_vulkan ${WAYLAND_DEFINITIONS})
+endif()
+
+if(USE_WIN32)
     target_compile_definitions(kazan_vulkan PUBLIC VK_USE_PLATFORM_WIN32_KHR)
 endif()
index 661404111e1b7ff2918cbc57662ab955b4ebaac2..3dd97a6d92abe4e78224ba06ddab7941e43c9133 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "vulkan/vulkan.h"
 #include "vulkan/vk_icd.h"
+#include "vulkan/remove_xlib_macros.h"
 #include "util/enum.h"
 #include "util/string_view.h"
 #include "util/variant.h"
diff --git a/src/vulkan/find-xlib-macros.sh b/src/vulkan/find-xlib-macros.sh
new file mode 100755 (executable)
index 0000000..6e705c4
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Copyright 2017 Jacob Lifshay
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+printf "#include <X11/Xlib.h>\n#include <X11/Xlib-xcb.h>\n" |
+clang++ -std=c++14 -E -dD -x c++ -o - - |
+grep '^#' |
+{
+    mapfile -t lines
+    filename=""
+    for line in "${lines[@]}"; do
+        if [[ "$line" =~ ^'# '[0-9]+' "'([^\"]*)'"'.* ]]; then # line number indicator
+            filename="${BASH_REMATCH[1]}"
+        elif [[ "$line" =~ ^'#define '([a-zA-Z0-9_]+) ]]; then
+            macro="${BASH_REMATCH[1]}"
+            if [[ ! "$filename" =~ ^'/usr/include/X11' || "$macro" =~ ^'_'[A-Z] || "$macro" =~ '__' || "$macro" =~ '_H'$ ]]; then
+                continue
+            fi
+            echo "$macro"
+        fi
+    done
+} |
+sort |
+sed 's/\(.*\)/#ifdef \1\n#undef \1\n#endif/'
diff --git a/src/vulkan/remove_xlib_macros.h b/src/vulkan/remove_xlib_macros.h
new file mode 100644 (file)
index 0000000..9c340ce
--- /dev/null
@@ -0,0 +1,1565 @@
+/*
+ * Copyright 2017 Jacob Lifshay
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+#ifndef VULKAN_REMOVE_XLIB_MACROS_H_
+#define VULKAN_REMOVE_XLIB_MACROS_H_
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+
+// include Xlib to prevent later inclusions from redefining all the macros
+
+#include <X11/Xlib.h>
+#include <X11/Xlib-xcb.h>
+
+// remove all the Xlib macros that clutter everything up; list generated by find-xlib-macros.sh
+
+#ifdef Above
+#undef Above
+#endif
+#ifdef AllPlanes
+#undef AllPlanes
+#endif
+#ifdef AllTemporary
+#undef AllTemporary
+#endif
+#ifdef AllocAll
+#undef AllocAll
+#endif
+#ifdef AllocNone
+#undef AllocNone
+#endif
+#ifdef AllowExposures
+#undef AllowExposures
+#endif
+#ifdef AlreadyGrabbed
+#undef AlreadyGrabbed
+#endif
+#ifdef Always
+#undef Always
+#endif
+#ifdef AnyButton
+#undef AnyButton
+#endif
+#ifdef AnyKey
+#undef AnyKey
+#endif
+#ifdef AnyModifier
+#undef AnyModifier
+#endif
+#ifdef AnyPropertyType
+#undef AnyPropertyType
+#endif
+#ifdef ArcChord
+#undef ArcChord
+#endif
+#ifdef ArcPieSlice
+#undef ArcPieSlice
+#endif
+#ifdef AsyncBoth
+#undef AsyncBoth
+#endif
+#ifdef AsyncKeyboard
+#undef AsyncKeyboard
+#endif
+#ifdef AsyncPointer
+#undef AsyncPointer
+#endif
+#ifdef AutoRepeatModeDefault
+#undef AutoRepeatModeDefault
+#endif
+#ifdef AutoRepeatModeOff
+#undef AutoRepeatModeOff
+#endif
+#ifdef AutoRepeatModeOn
+#undef AutoRepeatModeOn
+#endif
+#ifdef BadAccess
+#undef BadAccess
+#endif
+#ifdef BadAlloc
+#undef BadAlloc
+#endif
+#ifdef BadAtom
+#undef BadAtom
+#endif
+#ifdef BadColor
+#undef BadColor
+#endif
+#ifdef BadCursor
+#undef BadCursor
+#endif
+#ifdef BadDrawable
+#undef BadDrawable
+#endif
+#ifdef BadFont
+#undef BadFont
+#endif
+#ifdef BadGC
+#undef BadGC
+#endif
+#ifdef BadIDChoice
+#undef BadIDChoice
+#endif
+#ifdef BadImplementation
+#undef BadImplementation
+#endif
+#ifdef BadLength
+#undef BadLength
+#endif
+#ifdef BadMatch
+#undef BadMatch
+#endif
+#ifdef BadName
+#undef BadName
+#endif
+#ifdef BadPixmap
+#undef BadPixmap
+#endif
+#ifdef BadRequest
+#undef BadRequest
+#endif
+#ifdef BadValue
+#undef BadValue
+#endif
+#ifdef BadWindow
+#undef BadWindow
+#endif
+#ifdef Below
+#undef Below
+#endif
+#ifdef BitmapBitOrder
+#undef BitmapBitOrder
+#endif
+#ifdef BitmapPad
+#undef BitmapPad
+#endif
+#ifdef BitmapUnit
+#undef BitmapUnit
+#endif
+#ifdef BlackPixel
+#undef BlackPixel
+#endif
+#ifdef BlackPixelOfScreen
+#undef BlackPixelOfScreen
+#endif
+#ifdef Bool
+#undef Bool
+#endif
+#ifdef BottomIf
+#undef BottomIf
+#endif
+#ifdef Button1
+#undef Button1
+#endif
+#ifdef Button1Mask
+#undef Button1Mask
+#endif
+#ifdef Button1MotionMask
+#undef Button1MotionMask
+#endif
+#ifdef Button2
+#undef Button2
+#endif
+#ifdef Button2Mask
+#undef Button2Mask
+#endif
+#ifdef Button2MotionMask
+#undef Button2MotionMask
+#endif
+#ifdef Button3
+#undef Button3
+#endif
+#ifdef Button3Mask
+#undef Button3Mask
+#endif
+#ifdef Button3MotionMask
+#undef Button3MotionMask
+#endif
+#ifdef Button4
+#undef Button4
+#endif
+#ifdef Button4Mask
+#undef Button4Mask
+#endif
+#ifdef Button4MotionMask
+#undef Button4MotionMask
+#endif
+#ifdef Button5
+#undef Button5
+#endif
+#ifdef Button5Mask
+#undef Button5Mask
+#endif
+#ifdef Button5MotionMask
+#undef Button5MotionMask
+#endif
+#ifdef ButtonMotionMask
+#undef ButtonMotionMask
+#endif
+#ifdef ButtonPress
+#undef ButtonPress
+#endif
+#ifdef ButtonPressMask
+#undef ButtonPressMask
+#endif
+#ifdef ButtonRelease
+#undef ButtonRelease
+#endif
+#ifdef ButtonReleaseMask
+#undef ButtonReleaseMask
+#endif
+#ifdef CWBackPixel
+#undef CWBackPixel
+#endif
+#ifdef CWBackPixmap
+#undef CWBackPixmap
+#endif
+#ifdef CWBackingPixel
+#undef CWBackingPixel
+#endif
+#ifdef CWBackingPlanes
+#undef CWBackingPlanes
+#endif
+#ifdef CWBackingStore
+#undef CWBackingStore
+#endif
+#ifdef CWBitGravity
+#undef CWBitGravity
+#endif
+#ifdef CWBorderPixel
+#undef CWBorderPixel
+#endif
+#ifdef CWBorderPixmap
+#undef CWBorderPixmap
+#endif
+#ifdef CWBorderWidth
+#undef CWBorderWidth
+#endif
+#ifdef CWColormap
+#undef CWColormap
+#endif
+#ifdef CWCursor
+#undef CWCursor
+#endif
+#ifdef CWDontPropagate
+#undef CWDontPropagate
+#endif
+#ifdef CWEventMask
+#undef CWEventMask
+#endif
+#ifdef CWHeight
+#undef CWHeight
+#endif
+#ifdef CWOverrideRedirect
+#undef CWOverrideRedirect
+#endif
+#ifdef CWSaveUnder
+#undef CWSaveUnder
+#endif
+#ifdef CWSibling
+#undef CWSibling
+#endif
+#ifdef CWStackMode
+#undef CWStackMode
+#endif
+#ifdef CWWidth
+#undef CWWidth
+#endif
+#ifdef CWWinGravity
+#undef CWWinGravity
+#endif
+#ifdef CWX
+#undef CWX
+#endif
+#ifdef CWY
+#undef CWY
+#endif
+#ifdef CapButt
+#undef CapButt
+#endif
+#ifdef CapNotLast
+#undef CapNotLast
+#endif
+#ifdef CapProjecting
+#undef CapProjecting
+#endif
+#ifdef CapRound
+#undef CapRound
+#endif
+#ifdef CellsOfScreen
+#undef CellsOfScreen
+#endif
+#ifdef CenterGravity
+#undef CenterGravity
+#endif
+#ifdef CirculateNotify
+#undef CirculateNotify
+#endif
+#ifdef CirculateRequest
+#undef CirculateRequest
+#endif
+#ifdef ClientMessage
+#undef ClientMessage
+#endif
+#ifdef ClipByChildren
+#undef ClipByChildren
+#endif
+#ifdef ColormapChangeMask
+#undef ColormapChangeMask
+#endif
+#ifdef ColormapInstalled
+#undef ColormapInstalled
+#endif
+#ifdef ColormapNotify
+#undef ColormapNotify
+#endif
+#ifdef ColormapUninstalled
+#undef ColormapUninstalled
+#endif
+#ifdef Complex
+#undef Complex
+#endif
+#ifdef ConfigureNotify
+#undef ConfigureNotify
+#endif
+#ifdef ConfigureRequest
+#undef ConfigureRequest
+#endif
+#ifdef ConnectionNumber
+#undef ConnectionNumber
+#endif
+#ifdef ControlMapIndex
+#undef ControlMapIndex
+#endif
+#ifdef ControlMask
+#undef ControlMask
+#endif
+#ifdef Convex
+#undef Convex
+#endif
+#ifdef CoordModeOrigin
+#undef CoordModeOrigin
+#endif
+#ifdef CoordModePrevious
+#undef CoordModePrevious
+#endif
+#ifdef CopyFromParent
+#undef CopyFromParent
+#endif
+#ifdef CreateNotify
+#undef CreateNotify
+#endif
+#ifdef CurrentTime
+#undef CurrentTime
+#endif
+#ifdef CursorShape
+#undef CursorShape
+#endif
+#ifdef DefaultBlanking
+#undef DefaultBlanking
+#endif
+#ifdef DefaultColormap
+#undef DefaultColormap
+#endif
+#ifdef DefaultColormapOfScreen
+#undef DefaultColormapOfScreen
+#endif
+#ifdef DefaultDepth
+#undef DefaultDepth
+#endif
+#ifdef DefaultDepthOfScreen
+#undef DefaultDepthOfScreen
+#endif
+#ifdef DefaultExposures
+#undef DefaultExposures
+#endif
+#ifdef DefaultGC
+#undef DefaultGC
+#endif
+#ifdef DefaultGCOfScreen
+#undef DefaultGCOfScreen
+#endif
+#ifdef DefaultRootWindow
+#undef DefaultRootWindow
+#endif
+#ifdef DefaultScreen
+#undef DefaultScreen
+#endif
+#ifdef DefaultScreenOfDisplay
+#undef DefaultScreenOfDisplay
+#endif
+#ifdef DefaultVisual
+#undef DefaultVisual
+#endif
+#ifdef DefaultVisualOfScreen
+#undef DefaultVisualOfScreen
+#endif
+#ifdef DestroyAll
+#undef DestroyAll
+#endif
+#ifdef DestroyNotify
+#undef DestroyNotify
+#endif
+#ifdef DirectColor
+#undef DirectColor
+#endif
+#ifdef DisableAccess
+#undef DisableAccess
+#endif
+#ifdef DisableScreenInterval
+#undef DisableScreenInterval
+#endif
+#ifdef DisableScreenSaver
+#undef DisableScreenSaver
+#endif
+#ifdef DisplayCells
+#undef DisplayCells
+#endif
+#ifdef DisplayHeight
+#undef DisplayHeight
+#endif
+#ifdef DisplayHeightMM
+#undef DisplayHeightMM
+#endif
+#ifdef DisplayOfScreen
+#undef DisplayOfScreen
+#endif
+#ifdef DisplayPlanes
+#undef DisplayPlanes
+#endif
+#ifdef DisplayString
+#undef DisplayString
+#endif
+#ifdef DisplayWidth
+#undef DisplayWidth
+#endif
+#ifdef DisplayWidthMM
+#undef DisplayWidthMM
+#endif
+#ifdef DoBlue
+#undef DoBlue
+#endif
+#ifdef DoGreen
+#undef DoGreen
+#endif
+#ifdef DoRed
+#undef DoRed
+#endif
+#ifdef DoesBackingStore
+#undef DoesBackingStore
+#endif
+#ifdef DoesSaveUnders
+#undef DoesSaveUnders
+#endif
+#ifdef DontAllowExposures
+#undef DontAllowExposures
+#endif
+#ifdef DontPreferBlanking
+#undef DontPreferBlanking
+#endif
+#ifdef EastGravity
+#undef EastGravity
+#endif
+#ifdef EnableAccess
+#undef EnableAccess
+#endif
+#ifdef EnterNotify
+#undef EnterNotify
+#endif
+#ifdef EnterWindowMask
+#undef EnterWindowMask
+#endif
+#ifdef EvenOddRule
+#undef EvenOddRule
+#endif
+#ifdef EventMaskOfScreen
+#undef EventMaskOfScreen
+#endif
+#ifdef Expose
+#undef Expose
+#endif
+#ifdef ExposureMask
+#undef ExposureMask
+#endif
+#ifdef FUNCPROTO
+#undef FUNCPROTO
+#endif
+#ifdef False
+#undef False
+#endif
+#ifdef FamilyChaos
+#undef FamilyChaos
+#endif
+#ifdef FamilyDECnet
+#undef FamilyDECnet
+#endif
+#ifdef FamilyInternet
+#undef FamilyInternet
+#endif
+#ifdef FamilyInternet6
+#undef FamilyInternet6
+#endif
+#ifdef FamilyServerInterpreted
+#undef FamilyServerInterpreted
+#endif
+#ifdef FillOpaqueStippled
+#undef FillOpaqueStippled
+#endif
+#ifdef FillSolid
+#undef FillSolid
+#endif
+#ifdef FillStippled
+#undef FillStippled
+#endif
+#ifdef FillTiled
+#undef FillTiled
+#endif
+#ifdef FirstExtensionError
+#undef FirstExtensionError
+#endif
+#ifdef FocusChangeMask
+#undef FocusChangeMask
+#endif
+#ifdef FocusIn
+#undef FocusIn
+#endif
+#ifdef FocusOut
+#undef FocusOut
+#endif
+#ifdef FontChange
+#undef FontChange
+#endif
+#ifdef FontLeftToRight
+#undef FontLeftToRight
+#endif
+#ifdef FontRightToLeft
+#undef FontRightToLeft
+#endif
+#ifdef ForgetGravity
+#undef ForgetGravity
+#endif
+#ifdef GCArcMode
+#undef GCArcMode
+#endif
+#ifdef GCBackground
+#undef GCBackground
+#endif
+#ifdef GCCapStyle
+#undef GCCapStyle
+#endif
+#ifdef GCClipMask
+#undef GCClipMask
+#endif
+#ifdef GCClipXOrigin
+#undef GCClipXOrigin
+#endif
+#ifdef GCClipYOrigin
+#undef GCClipYOrigin
+#endif
+#ifdef GCDashList
+#undef GCDashList
+#endif
+#ifdef GCDashOffset
+#undef GCDashOffset
+#endif
+#ifdef GCFillRule
+#undef GCFillRule
+#endif
+#ifdef GCFillStyle
+#undef GCFillStyle
+#endif
+#ifdef GCFont
+#undef GCFont
+#endif
+#ifdef GCForeground
+#undef GCForeground
+#endif
+#ifdef GCFunction
+#undef GCFunction
+#endif
+#ifdef GCGraphicsExposures
+#undef GCGraphicsExposures
+#endif
+#ifdef GCJoinStyle
+#undef GCJoinStyle
+#endif
+#ifdef GCLastBit
+#undef GCLastBit
+#endif
+#ifdef GCLineStyle
+#undef GCLineStyle
+#endif
+#ifdef GCLineWidth
+#undef GCLineWidth
+#endif
+#ifdef GCPlaneMask
+#undef GCPlaneMask
+#endif
+#ifdef GCStipple
+#undef GCStipple
+#endif
+#ifdef GCSubwindowMode
+#undef GCSubwindowMode
+#endif
+#ifdef GCTile
+#undef GCTile
+#endif
+#ifdef GCTileStipXOrigin
+#undef GCTileStipXOrigin
+#endif
+#ifdef GCTileStipYOrigin
+#undef GCTileStipYOrigin
+#endif
+#ifdef GXand
+#undef GXand
+#endif
+#ifdef GXandInverted
+#undef GXandInverted
+#endif
+#ifdef GXandReverse
+#undef GXandReverse
+#endif
+#ifdef GXclear
+#undef GXclear
+#endif
+#ifdef GXcopy
+#undef GXcopy
+#endif
+#ifdef GXcopyInverted
+#undef GXcopyInverted
+#endif
+#ifdef GXequiv
+#undef GXequiv
+#endif
+#ifdef GXinvert
+#undef GXinvert
+#endif
+#ifdef GXnand
+#undef GXnand
+#endif
+#ifdef GXnoop
+#undef GXnoop
+#endif
+#ifdef GXnor
+#undef GXnor
+#endif
+#ifdef GXor
+#undef GXor
+#endif
+#ifdef GXorInverted
+#undef GXorInverted
+#endif
+#ifdef GXorReverse
+#undef GXorReverse
+#endif
+#ifdef GXset
+#undef GXset
+#endif
+#ifdef GXxor
+#undef GXxor
+#endif
+#ifdef GenericEvent
+#undef GenericEvent
+#endif
+#ifdef GrabFrozen
+#undef GrabFrozen
+#endif
+#ifdef GrabInvalidTime
+#undef GrabInvalidTime
+#endif
+#ifdef GrabModeAsync
+#undef GrabModeAsync
+#endif
+#ifdef GrabModeSync
+#undef GrabModeSync
+#endif
+#ifdef GrabNotViewable
+#undef GrabNotViewable
+#endif
+#ifdef GrabSuccess
+#undef GrabSuccess
+#endif
+#ifdef GraphicsExpose
+#undef GraphicsExpose
+#endif
+#ifdef GravityNotify
+#undef GravityNotify
+#endif
+#ifdef GrayScale
+#undef GrayScale
+#endif
+#ifdef HeightMMOfScreen
+#undef HeightMMOfScreen
+#endif
+#ifdef HeightOfScreen
+#undef HeightOfScreen
+#endif
+#ifdef HostDelete
+#undef HostDelete
+#endif
+#ifdef HostInsert
+#undef HostInsert
+#endif
+#ifdef ImageByteOrder
+#undef ImageByteOrder
+#endif
+#ifdef IncludeInferiors
+#undef IncludeInferiors
+#endif
+#ifdef InputFocus
+#undef InputFocus
+#endif
+#ifdef InputOnly
+#undef InputOnly
+#endif
+#ifdef InputOutput
+#undef InputOutput
+#endif
+#ifdef IsUnmapped
+#undef IsUnmapped
+#endif
+#ifdef IsUnviewable
+#undef IsUnviewable
+#endif
+#ifdef IsViewable
+#undef IsViewable
+#endif
+#ifdef JoinBevel
+#undef JoinBevel
+#endif
+#ifdef JoinMiter
+#undef JoinMiter
+#endif
+#ifdef JoinRound
+#undef JoinRound
+#endif
+#ifdef KBAutoRepeatMode
+#undef KBAutoRepeatMode
+#endif
+#ifdef KBBellDuration
+#undef KBBellDuration
+#endif
+#ifdef KBBellPercent
+#undef KBBellPercent
+#endif
+#ifdef KBBellPitch
+#undef KBBellPitch
+#endif
+#ifdef KBKey
+#undef KBKey
+#endif
+#ifdef KBKeyClickPercent
+#undef KBKeyClickPercent
+#endif
+#ifdef KBLed
+#undef KBLed
+#endif
+#ifdef KBLedMode
+#undef KBLedMode
+#endif
+#ifdef KeyPress
+#undef KeyPress
+#endif
+#ifdef KeyPressMask
+#undef KeyPressMask
+#endif
+#ifdef KeyRelease
+#undef KeyRelease
+#endif
+#ifdef KeyReleaseMask
+#undef KeyReleaseMask
+#endif
+#ifdef KeymapNotify
+#undef KeymapNotify
+#endif
+#ifdef KeymapStateMask
+#undef KeymapStateMask
+#endif
+#ifdef LASTEvent
+#undef LASTEvent
+#endif
+#ifdef LSBFirst
+#undef LSBFirst
+#endif
+#ifdef LastExtensionError
+#undef LastExtensionError
+#endif
+#ifdef LastKnownRequestProcessed
+#undef LastKnownRequestProcessed
+#endif
+#ifdef LeaveNotify
+#undef LeaveNotify
+#endif
+#ifdef LeaveWindowMask
+#undef LeaveWindowMask
+#endif
+#ifdef LedModeOff
+#undef LedModeOff
+#endif
+#ifdef LedModeOn
+#undef LedModeOn
+#endif
+#ifdef LineDoubleDash
+#undef LineDoubleDash
+#endif
+#ifdef LineOnOffDash
+#undef LineOnOffDash
+#endif
+#ifdef LineSolid
+#undef LineSolid
+#endif
+#ifdef LockMapIndex
+#undef LockMapIndex
+#endif
+#ifdef LockMask
+#undef LockMask
+#endif
+#ifdef LowerHighest
+#undef LowerHighest
+#endif
+#ifdef MSBFirst
+#undef MSBFirst
+#endif
+#ifdef MapNotify
+#undef MapNotify
+#endif
+#ifdef MapRequest
+#undef MapRequest
+#endif
+#ifdef MappingBusy
+#undef MappingBusy
+#endif
+#ifdef MappingFailed
+#undef MappingFailed
+#endif
+#ifdef MappingKeyboard
+#undef MappingKeyboard
+#endif
+#ifdef MappingModifier
+#undef MappingModifier
+#endif
+#ifdef MappingNotify
+#undef MappingNotify
+#endif
+#ifdef MappingPointer
+#undef MappingPointer
+#endif
+#ifdef MappingSuccess
+#undef MappingSuccess
+#endif
+#ifdef MaxCmapsOfScreen
+#undef MaxCmapsOfScreen
+#endif
+#ifdef MinCmapsOfScreen
+#undef MinCmapsOfScreen
+#endif
+#ifdef Mod1MapIndex
+#undef Mod1MapIndex
+#endif
+#ifdef Mod1Mask
+#undef Mod1Mask
+#endif
+#ifdef Mod2MapIndex
+#undef Mod2MapIndex
+#endif
+#ifdef Mod2Mask
+#undef Mod2Mask
+#endif
+#ifdef Mod3MapIndex
+#undef Mod3MapIndex
+#endif
+#ifdef Mod3Mask
+#undef Mod3Mask
+#endif
+#ifdef Mod4MapIndex
+#undef Mod4MapIndex
+#endif
+#ifdef Mod4Mask
+#undef Mod4Mask
+#endif
+#ifdef Mod5MapIndex
+#undef Mod5MapIndex
+#endif
+#ifdef Mod5Mask
+#undef Mod5Mask
+#endif
+#ifdef MotionNotify
+#undef MotionNotify
+#endif
+#ifdef NARROWPROTO
+#undef NARROWPROTO
+#endif
+#ifdef NeedFunctionPrototypes
+#undef NeedFunctionPrototypes
+#endif
+#ifdef NeedNestedPrototypes
+#undef NeedNestedPrototypes
+#endif
+#ifdef NeedVarargsPrototypes
+#undef NeedVarargsPrototypes
+#endif
+#ifdef NeedWidePrototypes
+#undef NeedWidePrototypes
+#endif
+#ifdef NextRequest
+#undef NextRequest
+#endif
+#ifdef NoEventMask
+#undef NoEventMask
+#endif
+#ifdef NoExpose
+#undef NoExpose
+#endif
+#ifdef NoSymbol
+#undef NoSymbol
+#endif
+#ifdef Nonconvex
+#undef Nonconvex
+#endif
+#ifdef None
+#undef None
+#endif
+#ifdef NorthEastGravity
+#undef NorthEastGravity
+#endif
+#ifdef NorthGravity
+#undef NorthGravity
+#endif
+#ifdef NorthWestGravity
+#undef NorthWestGravity
+#endif
+#ifdef NotUseful
+#undef NotUseful
+#endif
+#ifdef NotifyAncestor
+#undef NotifyAncestor
+#endif
+#ifdef NotifyDetailNone
+#undef NotifyDetailNone
+#endif
+#ifdef NotifyGrab
+#undef NotifyGrab
+#endif
+#ifdef NotifyHint
+#undef NotifyHint
+#endif
+#ifdef NotifyInferior
+#undef NotifyInferior
+#endif
+#ifdef NotifyNonlinear
+#undef NotifyNonlinear
+#endif
+#ifdef NotifyNonlinearVirtual
+#undef NotifyNonlinearVirtual
+#endif
+#ifdef NotifyNormal
+#undef NotifyNormal
+#endif
+#ifdef NotifyPointer
+#undef NotifyPointer
+#endif
+#ifdef NotifyPointerRoot
+#undef NotifyPointerRoot
+#endif
+#ifdef NotifyUngrab
+#undef NotifyUngrab
+#endif
+#ifdef NotifyVirtual
+#undef NotifyVirtual
+#endif
+#ifdef NotifyWhileGrabbed
+#undef NotifyWhileGrabbed
+#endif
+#ifdef Opposite
+#undef Opposite
+#endif
+#ifdef OwnerGrabButtonMask
+#undef OwnerGrabButtonMask
+#endif
+#ifdef ParentRelative
+#undef ParentRelative
+#endif
+#ifdef PlaceOnBottom
+#undef PlaceOnBottom
+#endif
+#ifdef PlaceOnTop
+#undef PlaceOnTop
+#endif
+#ifdef PlanesOfScreen
+#undef PlanesOfScreen
+#endif
+#ifdef PointerMotionHintMask
+#undef PointerMotionHintMask
+#endif
+#ifdef PointerMotionMask
+#undef PointerMotionMask
+#endif
+#ifdef PointerRoot
+#undef PointerRoot
+#endif
+#ifdef PointerWindow
+#undef PointerWindow
+#endif
+#ifdef PreferBlanking
+#undef PreferBlanking
+#endif
+#ifdef PropModeAppend
+#undef PropModeAppend
+#endif
+#ifdef PropModePrepend
+#undef PropModePrepend
+#endif
+#ifdef PropModeReplace
+#undef PropModeReplace
+#endif
+#ifdef PropertyChangeMask
+#undef PropertyChangeMask
+#endif
+#ifdef PropertyDelete
+#undef PropertyDelete
+#endif
+#ifdef PropertyNewValue
+#undef PropertyNewValue
+#endif
+#ifdef PropertyNotify
+#undef PropertyNotify
+#endif
+#ifdef ProtocolRevision
+#undef ProtocolRevision
+#endif
+#ifdef ProtocolVersion
+#undef ProtocolVersion
+#endif
+#ifdef PseudoColor
+#undef PseudoColor
+#endif
+#ifdef QLength
+#undef QLength
+#endif
+#ifdef QueuedAfterFlush
+#undef QueuedAfterFlush
+#endif
+#ifdef QueuedAfterReading
+#undef QueuedAfterReading
+#endif
+#ifdef QueuedAlready
+#undef QueuedAlready
+#endif
+#ifdef RaiseLowest
+#undef RaiseLowest
+#endif
+#ifdef ReparentNotify
+#undef ReparentNotify
+#endif
+#ifdef ReplayKeyboard
+#undef ReplayKeyboard
+#endif
+#ifdef ReplayPointer
+#undef ReplayPointer
+#endif
+#ifdef ResizeRedirectMask
+#undef ResizeRedirectMask
+#endif
+#ifdef ResizeRequest
+#undef ResizeRequest
+#endif
+#ifdef RetainPermanent
+#undef RetainPermanent
+#endif
+#ifdef RetainTemporary
+#undef RetainTemporary
+#endif
+#ifdef RevertToNone
+#undef RevertToNone
+#endif
+#ifdef RevertToParent
+#undef RevertToParent
+#endif
+#ifdef RevertToPointerRoot
+#undef RevertToPointerRoot
+#endif
+#ifdef RootWindow
+#undef RootWindow
+#endif
+#ifdef RootWindowOfScreen
+#undef RootWindowOfScreen
+#endif
+#ifdef ScreenCount
+#undef ScreenCount
+#endif
+#ifdef ScreenOfDisplay
+#undef ScreenOfDisplay
+#endif
+#ifdef ScreenSaverActive
+#undef ScreenSaverActive
+#endif
+#ifdef ScreenSaverReset
+#undef ScreenSaverReset
+#endif
+#ifdef SelectionClear
+#undef SelectionClear
+#endif
+#ifdef SelectionNotify
+#undef SelectionNotify
+#endif
+#ifdef SelectionRequest
+#undef SelectionRequest
+#endif
+#ifdef ServerVendor
+#undef ServerVendor
+#endif
+#ifdef SetModeDelete
+#undef SetModeDelete
+#endif
+#ifdef SetModeInsert
+#undef SetModeInsert
+#endif
+#ifdef ShiftMapIndex
+#undef ShiftMapIndex
+#endif
+#ifdef ShiftMask
+#undef ShiftMask
+#endif
+#ifdef SouthEastGravity
+#undef SouthEastGravity
+#endif
+#ifdef SouthGravity
+#undef SouthGravity
+#endif
+#ifdef SouthWestGravity
+#undef SouthWestGravity
+#endif
+#ifdef StaticColor
+#undef StaticColor
+#endif
+#ifdef StaticGravity
+#undef StaticGravity
+#endif
+#ifdef StaticGray
+#undef StaticGray
+#endif
+#ifdef Status
+#undef Status
+#endif
+#ifdef StippleShape
+#undef StippleShape
+#endif
+#ifdef StructureNotifyMask
+#undef StructureNotifyMask
+#endif
+#ifdef SubstructureNotifyMask
+#undef SubstructureNotifyMask
+#endif
+#ifdef SubstructureRedirectMask
+#undef SubstructureRedirectMask
+#endif
+#ifdef Success
+#undef Success
+#endif
+#ifdef SyncBoth
+#undef SyncBoth
+#endif
+#ifdef SyncKeyboard
+#undef SyncKeyboard
+#endif
+#ifdef SyncPointer
+#undef SyncPointer
+#endif
+#ifdef TileShape
+#undef TileShape
+#endif
+#ifdef TopIf
+#undef TopIf
+#endif
+#ifdef True
+#undef True
+#endif
+#ifdef TrueColor
+#undef TrueColor
+#endif
+#ifdef UnmapGravity
+#undef UnmapGravity
+#endif
+#ifdef UnmapNotify
+#undef UnmapNotify
+#endif
+#ifdef Unsorted
+#undef Unsorted
+#endif
+#ifdef VendorRelease
+#undef VendorRelease
+#endif
+#ifdef VisibilityChangeMask
+#undef VisibilityChangeMask
+#endif
+#ifdef VisibilityFullyObscured
+#undef VisibilityFullyObscured
+#endif
+#ifdef VisibilityNotify
+#undef VisibilityNotify
+#endif
+#ifdef VisibilityPartiallyObscured
+#undef VisibilityPartiallyObscured
+#endif
+#ifdef VisibilityUnobscured
+#undef VisibilityUnobscured
+#endif
+#ifdef WestGravity
+#undef WestGravity
+#endif
+#ifdef WhenMapped
+#undef WhenMapped
+#endif
+#ifdef WhitePixel
+#undef WhitePixel
+#endif
+#ifdef WhitePixelOfScreen
+#undef WhitePixelOfScreen
+#endif
+#ifdef WidthMMOfScreen
+#undef WidthMMOfScreen
+#endif
+#ifdef WidthOfScreen
+#undef WidthOfScreen
+#endif
+#ifdef WindingRule
+#undef WindingRule
+#endif
+#ifdef XAllocID
+#undef XAllocID
+#endif
+#ifdef XBufferOverflow
+#undef XBufferOverflow
+#endif
+#ifdef XIMHighlight
+#undef XIMHighlight
+#endif
+#ifdef XIMHotKeyStateOFF
+#undef XIMHotKeyStateOFF
+#endif
+#ifdef XIMHotKeyStateON
+#undef XIMHotKeyStateON
+#endif
+#ifdef XIMInitialState
+#undef XIMInitialState
+#endif
+#ifdef XIMPreeditArea
+#undef XIMPreeditArea
+#endif
+#ifdef XIMPreeditCallbacks
+#undef XIMPreeditCallbacks
+#endif
+#ifdef XIMPreeditDisable
+#undef XIMPreeditDisable
+#endif
+#ifdef XIMPreeditEnable
+#undef XIMPreeditEnable
+#endif
+#ifdef XIMPreeditNone
+#undef XIMPreeditNone
+#endif
+#ifdef XIMPreeditNothing
+#undef XIMPreeditNothing
+#endif
+#ifdef XIMPreeditPosition
+#undef XIMPreeditPosition
+#endif
+#ifdef XIMPreeditUnKnown
+#undef XIMPreeditUnKnown
+#endif
+#ifdef XIMPreserveState
+#undef XIMPreserveState
+#endif
+#ifdef XIMPrimary
+#undef XIMPrimary
+#endif
+#ifdef XIMReverse
+#undef XIMReverse
+#endif
+#ifdef XIMSecondary
+#undef XIMSecondary
+#endif
+#ifdef XIMStatusArea
+#undef XIMStatusArea
+#endif
+#ifdef XIMStatusCallbacks
+#undef XIMStatusCallbacks
+#endif
+#ifdef XIMStatusNone
+#undef XIMStatusNone
+#endif
+#ifdef XIMStatusNothing
+#undef XIMStatusNothing
+#endif
+#ifdef XIMStringConversionBottomEdge
+#undef XIMStringConversionBottomEdge
+#endif
+#ifdef XIMStringConversionBuffer
+#undef XIMStringConversionBuffer
+#endif
+#ifdef XIMStringConversionChar
+#undef XIMStringConversionChar
+#endif
+#ifdef XIMStringConversionConcealed
+#undef XIMStringConversionConcealed
+#endif
+#ifdef XIMStringConversionLeftEdge
+#undef XIMStringConversionLeftEdge
+#endif
+#ifdef XIMStringConversionLine
+#undef XIMStringConversionLine
+#endif
+#ifdef XIMStringConversionRetrieval
+#undef XIMStringConversionRetrieval
+#endif
+#ifdef XIMStringConversionRightEdge
+#undef XIMStringConversionRightEdge
+#endif
+#ifdef XIMStringConversionSubstitution
+#undef XIMStringConversionSubstitution
+#endif
+#ifdef XIMStringConversionTopEdge
+#undef XIMStringConversionTopEdge
+#endif
+#ifdef XIMStringConversionWord
+#undef XIMStringConversionWord
+#endif
+#ifdef XIMStringConversionWrapped
+#undef XIMStringConversionWrapped
+#endif
+#ifdef XIMTertiary
+#undef XIMTertiary
+#endif
+#ifdef XIMUnderline
+#undef XIMUnderline
+#endif
+#ifdef XIMVisibleToBackword
+#undef XIMVisibleToBackword
+#endif
+#ifdef XIMVisibleToCenter
+#undef XIMVisibleToCenter
+#endif
+#ifdef XIMVisibleToForward
+#undef XIMVisibleToForward
+#endif
+#ifdef XLookupBoth
+#undef XLookupBoth
+#endif
+#ifdef XLookupChars
+#undef XLookupChars
+#endif
+#ifdef XLookupKeySym
+#undef XLookupKeySym
+#endif
+#ifdef XLookupNone
+#undef XLookupNone
+#endif
+#ifdef XNArea
+#undef XNArea
+#endif
+#ifdef XNAreaNeeded
+#undef XNAreaNeeded
+#endif
+#ifdef XNBackground
+#undef XNBackground
+#endif
+#ifdef XNBackgroundPixmap
+#undef XNBackgroundPixmap
+#endif
+#ifdef XNBaseFontName
+#undef XNBaseFontName
+#endif
+#ifdef XNClientWindow
+#undef XNClientWindow
+#endif
+#ifdef XNColormap
+#undef XNColormap
+#endif
+#ifdef XNContextualDrawing
+#undef XNContextualDrawing
+#endif
+#ifdef XNCursor
+#undef XNCursor
+#endif
+#ifdef XNDefaultString
+#undef XNDefaultString
+#endif
+#ifdef XNDestroyCallback
+#undef XNDestroyCallback
+#endif
+#ifdef XNDirectionalDependentDrawing
+#undef XNDirectionalDependentDrawing
+#endif
+#ifdef XNFilterEvents
+#undef XNFilterEvents
+#endif
+#ifdef XNFocusWindow
+#undef XNFocusWindow
+#endif
+#ifdef XNFontInfo
+#undef XNFontInfo
+#endif
+#ifdef XNFontSet
+#undef XNFontSet
+#endif
+#ifdef XNForeground
+#undef XNForeground
+#endif
+#ifdef XNGeometryCallback
+#undef XNGeometryCallback
+#endif
+#ifdef XNHotKey
+#undef XNHotKey
+#endif
+#ifdef XNHotKeyState
+#undef XNHotKeyState
+#endif
+#ifdef XNInputStyle
+#undef XNInputStyle
+#endif
+#ifdef XNLineSpace
+#undef XNLineSpace
+#endif
+#ifdef XNMissingCharSet
+#undef XNMissingCharSet
+#endif
+#ifdef XNOMAutomatic
+#undef XNOMAutomatic
+#endif
+#ifdef XNOrientation
+#undef XNOrientation
+#endif
+#ifdef XNPreeditAttributes
+#undef XNPreeditAttributes
+#endif
+#ifdef XNPreeditCaretCallback
+#undef XNPreeditCaretCallback
+#endif
+#ifdef XNPreeditDoneCallback
+#undef XNPreeditDoneCallback
+#endif
+#ifdef XNPreeditDrawCallback
+#undef XNPreeditDrawCallback
+#endif
+#ifdef XNPreeditStartCallback
+#undef XNPreeditStartCallback
+#endif
+#ifdef XNPreeditState
+#undef XNPreeditState
+#endif
+#ifdef XNPreeditStateNotifyCallback
+#undef XNPreeditStateNotifyCallback
+#endif
+#ifdef XNQueryICValuesList
+#undef XNQueryICValuesList
+#endif
+#ifdef XNQueryIMValuesList
+#undef XNQueryIMValuesList
+#endif
+#ifdef XNQueryInputStyle
+#undef XNQueryInputStyle
+#endif
+#ifdef XNQueryOrientation
+#undef XNQueryOrientation
+#endif
+#ifdef XNR6PreeditCallback
+#undef XNR6PreeditCallback
+#endif
+#ifdef XNRequiredCharSet
+#undef XNRequiredCharSet
+#endif
+#ifdef XNResetState
+#undef XNResetState
+#endif
+#ifdef XNResourceClass
+#undef XNResourceClass
+#endif
+#ifdef XNResourceName
+#undef XNResourceName
+#endif
+#ifdef XNSeparatorofNestedList
+#undef XNSeparatorofNestedList
+#endif
+#ifdef XNSpotLocation
+#undef XNSpotLocation
+#endif
+#ifdef XNStatusAttributes
+#undef XNStatusAttributes
+#endif
+#ifdef XNStatusDoneCallback
+#undef XNStatusDoneCallback
+#endif
+#ifdef XNStatusDrawCallback
+#undef XNStatusDrawCallback
+#endif
+#ifdef XNStatusStartCallback
+#undef XNStatusStartCallback
+#endif
+#ifdef XNStdColormap
+#undef XNStdColormap
+#endif
+#ifdef XNStringConversion
+#undef XNStringConversion
+#endif
+#ifdef XNStringConversionCallback
+#undef XNStringConversionCallback
+#endif
+#ifdef XNVaNestedList
+#undef XNVaNestedList
+#endif
+#ifdef XNVisiblePosition
+#undef XNVisiblePosition
+#endif
+#ifdef XYBitmap
+#undef XYBitmap
+#endif
+#ifdef XYPixmap
+#undef XYPixmap
+#endif
+#ifdef X_HAVE_UTF8_STRING
+#undef X_HAVE_UTF8_STRING
+#endif
+#ifdef X_PROTOCOL
+#undef X_PROTOCOL
+#endif
+#ifdef X_PROTOCOL_REVISION
+#undef X_PROTOCOL_REVISION
+#endif
+#ifdef XlibSpecificationRelease
+#undef XlibSpecificationRelease
+#endif
+#ifdef YSorted
+#undef YSorted
+#endif
+#ifdef YXBanded
+#undef YXBanded
+#endif
+#ifdef YXSorted
+#undef YXSorted
+#endif
+#ifdef ZPixmap
+#undef ZPixmap
+#endif
+
+#endif // VK_USE_PLATFORM_XLIB_KHR
+
+#endif // VULKAN_REMOVE_XLIB_MACROS_H_
index 3095e2c42f7525d37d9909b9f9a06e52652d7c16..e1a66dfbd4bf1d3a028cc5a2d63dd43ef1fde578 100644 (file)
@@ -24,6 +24,7 @@
 #define VULKAN_UTIL_H_
 
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
 #include "spirv/spirv.h"
 #include "util/enum.h"
 
index db2858c72fdd6ed12e9e5f28fa65a5a6f711041e..9c5564a1e4421ecde677a973ef98c8fd6332f0c5 100644 (file)
@@ -21,3 +21,4 @@
  *
  */
 #include "vulkan/vulkan.h"
+#include "vulkan/remove_xlib_macros.h"
index 35fecad7fd0cbd6f7198e4e89989603e4e4ac09e..8b7dd20e3b7e3c41c60d4f4a5aff526503155be9 100644 (file)
@@ -19,7 +19,9 @@
 # SOFTWARE.
 #
 cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
-set(sources vulkan_icd.cpp)
+set(sources vulkan_icd.cpp
+            wsi.cpp
+            x11_wsi.cpp)
 add_library(kazan_vulkan_icd MODULE ${sources})
 target_link_libraries(kazan_vulkan_icd
                       kazan_vulkan
index d3ebc13bbb6b3bb601fedf1faeef94e3f8a30508..55e8b1ff805e0e2831e2cb2d6e204273913967a1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "vulkan/vulkan.h"
 #include "vulkan/vk_icd.h"
+#include "vulkan/remove_xlib_macros.h"
 #include "vulkan/api_objects.h"
 #include <type_traits>
 #include <cstdint>
diff --git a/src/vulkan_icd/wsi.cpp b/src/vulkan_icd/wsi.cpp
new file mode 100644 (file)
index 0000000..7f051aa
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017 Jacob Lifshay
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+#include "wsi.h"
+#include <initializer_list>
+
+namespace kazan
+{
+namespace vulkan_icd
+{
+Wsi::Wsi_list Wsi::get_all() noexcept
+{
+    static const std::initializer_list<const Wsi *> wsi_list = {
+#ifdef VK_USE_PLATFORM_XCB_KHR
+        &Xcb_wsi::get(),
+#endif
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+        &Xlib_wsi::get(),
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+        &Wayland_wsi::get(),
+#endif
+#ifdef VK_USE_PLATFORM_MIR_KHR
+        &Mir_wsi::get(),
+#endif
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+        &Android_wsi::get(),
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+        &Win32_wsi::get(),
+#endif
+    };
+    return Wsi_list(wsi_list.begin(), wsi_list.size());
+}
+}
+}
diff --git a/src/vulkan_icd/wsi.h b/src/vulkan_icd/wsi.h
new file mode 100644 (file)
index 0000000..0ffd007
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2017 Jacob Lifshay
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+#ifndef VULKAN_ICD_WSI_H_
+#define VULKAN_ICD_WSI_H_
+
+#include "vulkan/vulkan.h"
+#include "vulkan/vk_icd.h"
+#include "vulkan/remove_xlib_macros.h"
+#include <type_traits>
+#include <cstdint>
+
+namespace kazan
+{
+namespace vulkan_icd
+{
+struct Wsi
+{
+    class Wsi_list
+    {
+    public:
+        typedef const Wsi *value_type;
+        typedef const value_type &reference;
+        typedef const value_type &const_reference;
+        typedef const value_type *pointer;
+        typedef const value_type *const_pointer;
+        typedef const value_type *iterator;
+        typedef const value_type *const_iterator;
+
+    private:
+        pointer start;
+        std::size_t count;
+
+    public:
+        constexpr explicit Wsi_list(pointer start, std::size_t count) noexcept : start(start),
+                                                                                 count(count)
+        {
+        }
+        constexpr std::size_t size() const noexcept
+        {
+            return count;
+        }
+        constexpr pointer data() const noexcept
+        {
+            return start;
+        }
+        constexpr const_iterator begin() const noexcept
+        {
+            return start;
+        }
+        constexpr const_iterator end() const noexcept
+        {
+            return start + count;
+        }
+    };
+    static Wsi_list get_all() noexcept;
+    static const Wsi *find(VkIcdWsiPlatform surface_platform) noexcept
+    {
+        for(auto *wsi : get_all())
+            if(wsi->surface_platform == surface_platform)
+                return wsi;
+        return nullptr;
+    }
+    VkIcdWsiPlatform surface_platform;
+    constexpr explicit Wsi(VkIcdWsiPlatform surface_platform) noexcept
+        : surface_platform(surface_platform)
+    {
+    }
+    virtual void destroy_surface(VkIcdSurfaceBase *surface) const noexcept = 0;
+    virtual VkResult get_surface_support(VkIcdSurfaceBase *surface, VkBool32 &supported) const = 0;
+};
+
+static_assert(std::is_trivially_destructible<Wsi>::value,
+              "Wsi objects are statically allocated, so we want them to be trivially destructible");
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+struct Xcb_wsi final : public Wsi
+{
+    typedef VkIcdSurfaceXcb Surface_type;
+    constexpr Xcb_wsi() noexcept : Wsi(VK_ICD_WSI_PLATFORM_XCB)
+    {
+    }
+    struct Implementation;
+    VkIcdSurfaceBase *create_surface(const VkXcbSurfaceCreateInfoKHR &create_info) const;
+    virtual void destroy_surface(VkIcdSurfaceBase *surface) const noexcept override;
+    virtual VkResult get_surface_support(VkIcdSurfaceBase *surface, VkBool32 &supported) const override;
+    static const Xcb_wsi &get() noexcept;
+};
+#endif
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+struct Xlib_wsi final : public Wsi
+{
+    typedef VkIcdSurfaceXlib Surface_type;
+    constexpr Xlib_wsi() noexcept : Wsi(VK_ICD_WSI_PLATFORM_XLIB)
+    {
+    }
+    struct Implementation;
+    VkIcdSurfaceBase *create_surface(const VkXlibSurfaceCreateInfoKHR &create_info) const;
+    virtual void destroy_surface(VkIcdSurfaceBase *surface) const noexcept override;
+    virtual VkResult get_surface_support(VkIcdSurfaceBase *surface, VkBool32 &supported) const override;
+    static const Xlib_wsi &get() noexcept;
+};
+#endif
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+#error Wayland wsi is not implemented
+struct Wayland_wsi final : public Wsi
+{
+    typedef VkIcdSurfaceWayland Surface_type;
+    constexpr Wayland_wsi() noexcept : Wsi(VK_ICD_WSI_PLATFORM_WAYLAND)
+    {
+    }
+    struct Implementation;
+    VkIcdSurfaceBase *create_surface(const VkWaylandSurfaceCreateInfoKHR &create_info) const;
+    virtual void destroy_surface(VkIcdSurfaceBase *surface) const noexcept override;
+    virtual VkResult get_surface_support(VkIcdSurfaceBase *surface, VkBool32 &supported) const override;
+    static const Wayland_wsi &get() noexcept;
+};
+#endif
+
+#ifdef VK_USE_PLATFORM_MIR_KHR
+#error Mir wsi is not implemented
+#endif
+
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+#error Android wsi is not implemented
+#endif
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#error Win32 wsi is not implemented
+struct Win32_wsi final : public Wsi
+{
+    typedef VkIcdSurfaceWin32 Surface_type;
+    constexpr Win32_wsi() noexcept : Wsi(VK_ICD_WSI_PLATFORM_WIN32)
+    {
+    }
+    struct Implementation;
+    VkIcdSurfaceBase *create_surface(const VkWin32SurfaceCreateInfoKHR &create_info) const;
+    virtual void destroy_surface(VkIcdSurfaceBase *surface) const noexcept override;
+    virtual VkResult get_surface_support(VkIcdSurfaceBase *surface, VkBool32 &supported) const override;
+    static const Win32_wsi &get() noexcept;
+};
+#endif
+}
+}
+
+#endif // VULKAN_ICD_WSI_H_
diff --git a/src/vulkan_icd/x11_wsi.cpp b/src/vulkan_icd/x11_wsi.cpp
new file mode 100644 (file)
index 0000000..9cdd390
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+ * Copyright 2017 Jacob Lifshay
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+#include "wsi.h"
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+#include <xcb/xcb.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <xcb/shm.h>
+#include <xcb/present.h>
+#include <cassert>
+#include <cstdlib>
+#include <memory>
+#include "util/optional.h"
+
+namespace kazan
+{
+namespace vulkan_icd
+{
+struct Xcb_wsi::Implementation
+{
+    template <typename T = void>
+    struct Free_functor
+    {
+        void operator()(T *p) noexcept
+        {
+            std::free(p);
+        }
+    };
+    typedef std::unique_ptr<xcb_query_extension_reply_t, Free_functor<xcb_query_extension_reply_t>>
+        Query_extension_reply;
+    typedef std::unique_ptr<xcb_get_geometry_reply_t, Free_functor<xcb_get_geometry_reply_t>>
+        Get_geometry_reply;
+    typedef std::unique_ptr<xcb_get_window_attributes_reply_t,
+                            Free_functor<xcb_get_window_attributes_reply_t>>
+        Get_window_attributes_reply;
+    typedef std::unique_ptr<xcb_query_tree_reply_t, Free_functor<xcb_query_tree_reply_t>>
+        Query_tree_reply;
+    typedef std::unique_ptr<xcb_shm_query_version_reply_t,
+                            Free_functor<xcb_shm_query_version_reply_t>> Shm_query_version_reply;
+    typedef std::unique_ptr<xcb_generic_error_t, Free_functor<xcb_generic_error_t>> Generic_error;
+    template <typename Id_type,
+              xcb_void_cookie_t (*free_function)(xcb_connection_t *connection, Id_type id)>
+    class Server_object
+    {
+    private:
+        Id_type value;
+        xcb_connection_t *connection;
+
+    public:
+        constexpr Server_object() noexcept : value(), connection()
+        {
+        }
+        constexpr Server_object(std::nullptr_t) noexcept : value(), connection()
+        {
+        }
+        constexpr Server_object(Id_type value, xcb_connection_t *connection) noexcept
+            : value(value),
+              connection(connection)
+        {
+            assert(connection);
+        }
+        void swap(Server_object &other) noexcept
+        {
+            using std::swap;
+            swap(value, other.value);
+            swap(connection, other.connection);
+        }
+        Server_object(Server_object &&rt) noexcept : value(), connection()
+        {
+            swap(rt);
+        }
+        Server_object &operator=(Server_object rt) noexcept
+        {
+            swap(rt);
+            return *this;
+        }
+        ~Server_object() noexcept
+        {
+            if(connection)
+                free_function(connection, value);
+        }
+        Id_type get() const noexcept
+        {
+            return value;
+        }
+    };
+    typedef Server_object<xcb_gcontext_t, &xcb_free_gc> Gc;
+    typedef Server_object<xcb_pixmap_t, &xcb_free_pixmap> Pixmap;
+    typedef Server_object<xcb_shm_seg_t, &xcb_shm_detach> Server_shm_seg;
+    class Shared_memory_segment
+    {
+    private:
+        int value;
+
+    public:
+        constexpr Shared_memory_segment() noexcept : value(-1)
+        {
+        }
+        constexpr Shared_memory_segment(std::nullptr_t) noexcept : Shared_memory_segment()
+        {
+        }
+        explicit Shared_memory_segment(int value) noexcept : value(value)
+        {
+        }
+        static Shared_memory_segment create(std::size_t size, int flags = IPC_CREAT | 0777)
+        {
+            Shared_memory_segment retval(shmget(IPC_PRIVATE, size, flags));
+            if(!retval)
+                throw std::runtime_error("shmget failed");
+            return retval;
+        }
+        void swap(Shared_memory_segment &other) noexcept
+        {
+            using std::swap;
+            swap(value, other.value);
+        }
+        Shared_memory_segment(Shared_memory_segment &&rt) noexcept : Shared_memory_segment()
+        {
+            swap(rt);
+        }
+        Shared_memory_segment &operator=(Shared_memory_segment rt) noexcept
+        {
+            swap(rt);
+            return *this;
+        }
+        ~Shared_memory_segment() noexcept
+        {
+            if(*this)
+                shmctl(value, IPC_RMID, nullptr);
+        }
+        explicit operator bool() const noexcept
+        {
+            return value != -1;
+        }
+        std::shared_ptr<void> map()
+        {
+            assert(*this);
+            void *memory = shmat(value, nullptr, 0);
+            if(memory == reinterpret_cast<void *>(-1))
+                throw std::runtime_error("shmat failed");
+            return std::shared_ptr<void>(memory,
+                                         [](void *memory) noexcept
+                                         {
+                                             shmdt(memory);
+                                         });
+        }
+        int get() const noexcept
+        {
+            return value;
+        }
+    };
+    struct Start_setup_results
+    {
+        enum class Status
+        {
+            Bad_surface,
+            No_support,
+            Success,
+        };
+        Status status;
+    };
+    static Start_setup_results start_setup(xcb_connection_t *connection, xcb_window_t window)
+    {
+#warning implement start_setup
+        assert(!"implement start_setup");
+        return {
+            .status = Start_setup_results::Status::No_support,
+        };
+    }
+};
+
+VkIcdSurfaceBase *Xcb_wsi::create_surface(const VkXcbSurfaceCreateInfoKHR &create_info) const
+{
+    assert(create_info.sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
+    assert(create_info.flags == 0);
+    return reinterpret_cast<VkIcdSurfaceBase *>(new Surface_type{
+        .base =
+            {
+                .platform = VK_ICD_WSI_PLATFORM_XCB,
+            },
+        .connection = create_info.connection,
+        .window = create_info.window,
+    });
+}
+
+void Xcb_wsi::destroy_surface(VkIcdSurfaceBase *surface) const noexcept
+{
+    delete reinterpret_cast<Surface_type *>(surface);
+}
+
+VkResult Xcb_wsi::get_surface_support(VkIcdSurfaceBase *surface_, VkBool32 &supported) const
+{
+    auto &surface = *reinterpret_cast<Surface_type *>(surface_);
+    switch(Implementation::start_setup(surface.connection, surface.window).status)
+    {
+    case Implementation::Start_setup_results::Status::Bad_surface:
+        return VK_ERROR_SURFACE_LOST_KHR;
+    case Implementation::Start_setup_results::Status::No_support:
+        supported = false;
+        return VK_SUCCESS;
+    case Implementation::Start_setup_results::Status::Success:
+        supported = true;
+        return VK_SUCCESS;
+    }
+    assert(!"unreachable");
+    return {};
+}
+
+const Xcb_wsi &Xcb_wsi::get() noexcept
+{
+    static const Xcb_wsi retval{};
+    return retval;
+}
+}
+}
+#endif
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+#ifndef VK_USE_PLATFORM_XCB_KHR
+#error can't Xlib WSI interface depends on XCB WSI interface for the implementation
+#endif
+#include <X11/Xlib-xcb.h>
+
+namespace kazan
+{
+namespace vulkan_icd
+{
+struct Xlib_wsi::Implementation : public Xcb_wsi::Implementation
+{
+};
+
+VkIcdSurfaceBase *Xlib_wsi::create_surface(const VkXlibSurfaceCreateInfoKHR &create_info) const
+{
+    assert(create_info.sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
+    assert(create_info.flags == 0);
+    return reinterpret_cast<VkIcdSurfaceBase *>(new Surface_type{
+        .base =
+            {
+                .platform = VK_ICD_WSI_PLATFORM_XLIB,
+            },
+        .dpy = create_info.dpy,
+        .window = create_info.window,
+    });
+}
+
+void Xlib_wsi::destroy_surface(VkIcdSurfaceBase *surface) const noexcept
+{
+    delete reinterpret_cast<Surface_type *>(surface);
+}
+
+VkResult Xlib_wsi::get_surface_support(VkIcdSurfaceBase *surface_, VkBool32 &supported) const
+{
+    auto &surface = *reinterpret_cast<Surface_type *>(surface_);
+    switch(Implementation::start_setup(XGetXCBConnection(surface.dpy),
+                                       static_cast<xcb_window_t>(surface.window))
+               .status)
+    {
+    case Implementation::Start_setup_results::Status::Bad_surface:
+        return VK_ERROR_SURFACE_LOST_KHR;
+    case Implementation::Start_setup_results::Status::No_support:
+        supported = false;
+        return VK_SUCCESS;
+    case Implementation::Start_setup_results::Status::Success:
+        supported = true;
+        return VK_SUCCESS;
+    }
+    assert(!"unreachable");
+    return {};
+}
+
+const Xlib_wsi &Xlib_wsi::get() noexcept
+{
+    static const Xlib_wsi retval{};
+    return retval;
+}
+}
+}
+#endif