[Bf-blender-cvs] [66e70fe299e] master: GHOST: initial Wayland support

Christian Rauch noreply at git.blender.org
Thu Apr 30 06:27:59 CEST 2020


Commit: 66e70fe299e15124d9250a6a24e591cbb733713a
Author: Christian Rauch
Date:   Thu Apr 30 13:46:42 2020 +1000
Branches: master
https://developer.blender.org/rB66e70fe299e15124d9250a6a24e591cbb733713a

GHOST: initial Wayland support

Usable with the CMake option 'WITH_GHOST_WAYLAND'

The following functionality is working:

- Building with X11 and Wayland at the same time,
  wayland is used when available.
- Keyboard, pointer handling.
- Cursor handling.
- Dedicated off-screen windows.
- Drag & drop.
- Copy & paste.
- Pointer grabbing.

See D6567 for further details.

===================================================================

M	CMakeLists.txt
M	build_files/cmake/macros.cmake
M	build_files/cmake/platform/platform_unix.cmake
M	intern/ghost/CMakeLists.txt
M	intern/ghost/intern/GHOST_ISystem.cpp
A	intern/ghost/intern/GHOST_SystemWayland.cpp
A	intern/ghost/intern/GHOST_SystemWayland.h
A	intern/ghost/intern/GHOST_WindowWayland.cpp
A	intern/ghost/intern/GHOST_WindowWayland.h

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f0ff3d1427..1201ddda333 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -207,6 +207,10 @@ mark_as_advanced(WITH_GHOST_DEBUG)
 option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
 mark_as_advanced(WITH_GHOST_SDL)
 
+if(UNIX AND NOT APPLE)
+  option(WITH_GHOST_WAYLAND   "Enable building Blender against Wayland for windowing" OFF)
+endif()
+
 if(WITH_X11)
   option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
 endif()
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 6287da55580..d99e46ce76e 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -440,6 +440,14 @@ function(SETUP_LIBDIRS)
       link_directories(${HDF5_LIBPATH})
     endif()
 
+    if(WITH_GHOST_WAYLAND)
+      link_directories(
+        ${wayland-client_LIBRARY_DIRS}
+        ${wayland-egl_LIBRARY_DIRS}
+        ${xkbcommon_LIBRARY_DIRS}
+        ${wayland-cursor_LIBRARY_DIRS})
+    endif()
+
     if(WIN32 AND NOT UNIX)
       link_directories(${PTHREADS_LIBPATH})
     endif()
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index 8a89ce40432..0bd33b93dcf 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -504,6 +504,26 @@ if(WITH_SYSTEM_AUDASPACE)
   endif()
 endif()
 
+if(WITH_GHOST_WAYLAND)
+  find_package(PkgConfig)
+  pkg_check_modules(wayland-client REQUIRED wayland-client>=1.12)
+  pkg_check_modules(wayland-egl REQUIRED wayland-egl)
+  pkg_check_modules(wayland-scanner REQUIRED wayland-scanner)
+  pkg_check_modules(xkbcommon REQUIRED xkbcommon)
+  pkg_check_modules(wayland-cursor REQUIRED wayland-cursor)
+
+  set(WITH_GL_EGL ON)
+
+  if(WITH_GHOST_WAYLAND)
+    list(APPEND PLATFORM_LINKLIBS
+      ${wayland-client_LIBRARIES}
+      ${wayland-egl_LIBRARIES}
+      ${xkbcommon_LIBRARIES}
+      ${wayland-cursor_LIBRARIES}
+    )
+  endif()
+endif()
+
 if(WITH_X11)
   find_package(X11 REQUIRED)
 
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index cb795bbbc51..601f7f58d7f 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -177,73 +177,141 @@ elseif(APPLE AND NOT WITH_X11)
     )
   endif()
 
-elseif(WITH_X11)
-  list(APPEND INC_SYS
-    ${X11_X11_INCLUDE_PATH}
-  )
-
-  list(APPEND SRC
-    intern/GHOST_DisplayManagerX11.cpp
-    intern/GHOST_SystemX11.cpp
-    intern/GHOST_TaskbarX11.cpp
-    intern/GHOST_WindowX11.cpp
-
-    intern/GHOST_DisplayManagerX11.h
-    intern/GHOST_IconX11.h
-    intern/GHOST_SystemX11.h
-    intern/GHOST_TaskbarX11.h
-    intern/GHOST_WindowX11.h
-  )
+elseif(WITH_X11 OR WITH_GHOST_WAYLAND)
+  if(WITH_X11)
+    list(APPEND INC_SYS
+      ${X11_X11_INCLUDE_PATH}
+    )
 
-  if(NOT WITH_GL_EGL)
     list(APPEND SRC
-      intern/GHOST_ContextGLX.cpp
-
-      intern/GHOST_ContextGLX.h
+      intern/GHOST_DisplayManagerX11.cpp
+      intern/GHOST_SystemX11.cpp
+      intern/GHOST_TaskbarX11.cpp
+      intern/GHOST_WindowX11.cpp
+
+      intern/GHOST_DisplayManagerX11.h
+      intern/GHOST_IconX11.h
+      intern/GHOST_SystemX11.h
+      intern/GHOST_TaskbarX11.h
+      intern/GHOST_WindowX11.h
     )
-  endif()
 
-  if(WITH_GHOST_XDND)
-    add_definitions(-DWITH_XDND)
+    if(NOT WITH_GL_EGL)
+      list(APPEND SRC
+        intern/GHOST_ContextGLX.cpp
 
-    list(APPEND LIB
-      extern_xdnd
-    )
+        intern/GHOST_ContextGLX.h
+      )
+    endif()
 
-    list(APPEND INC
-      ../../extern/xdnd
-    )
+    if(WITH_GHOST_XDND)
+      add_definitions(-DWITH_XDND)
 
-    list(APPEND SRC
-      intern/GHOST_DropTargetX11.cpp
+      list(APPEND LIB
+        extern_xdnd
+      )
 
-      intern/GHOST_DropTargetX11.h
-    )
+      list(APPEND INC
+        ../../extern/xdnd
+      )
+
+      list(APPEND SRC
+        intern/GHOST_DropTargetX11.cpp
+
+        intern/GHOST_DropTargetX11.h
+      )
+    endif()
+
+    if(X11_XF86keysym_INCLUDE_PATH)
+      add_definitions(-DWITH_XF86KEYSYM)
+      list(APPEND INC_SYS
+        ${X11_XF86keysym_INCLUDE_PATH}
+      )
+    endif()
+
+    if(WITH_X11_XF86VMODE)
+      add_definitions(-DWITH_X11_XF86VMODE)
+      list(APPEND INC_SYS
+        ${X11_xf86vmode_INCLUDE_PATH}
+      )
+    endif()
+
+    if(WITH_X11_XFIXES)
+      add_definitions(-DWITH_X11_XFIXES)
+      list(APPEND INC_SYS
+        ${X11_Xfixes_INCLUDE_PATH}
+      )
+    endif()
+
+    if(WITH_X11_ALPHA)
+      add_definitions(-DWITH_X11_ALPHA)
+    endif()
+
+    if(WITH_X11_XINPUT)
+      add_definitions(-DWITH_X11_XINPUT)
+      list(APPEND INC_SYS
+        ${X11_Xinput_INCLUDE_PATH}
+      )
+    endif()
+
+    add_definitions(-DWITH_X11)
   endif()
 
-  if(X11_XF86keysym_INCLUDE_PATH)
-    add_definitions(-DWITH_XF86KEYSYM)
+  if(WITH_GHOST_WAYLAND)
     list(APPEND INC_SYS
-      ${X11_XF86keysym_INCLUDE_PATH}
+      ${wayland-client_INCLUDE_DIRS}
+      ${wayland-egl_INCLUDE_DIRS}
+      ${xkbcommon_INCLUDE_DIRS}
+      ${wayland-cursor_INCLUDE_DIRS}
     )
-  endif()
 
-  if(WITH_X11_XF86VMODE)
-    add_definitions(-DWITH_X11_XF86VMODE)
-    list(APPEND INC_SYS
-      ${X11_xf86vmode_INCLUDE_PATH}
+    list(APPEND SRC
+      intern/GHOST_SystemWayland.cpp
+      intern/GHOST_WindowWayland.cpp
+
+      intern/GHOST_SystemWayland.h
+      intern/GHOST_WindowWayland.h
     )
-  endif()
 
-  if(WITH_X11_XFIXES)
-    add_definitions(-DWITH_X11_XFIXES)
-    list(APPEND INC_SYS
-      ${X11_Xfixes_INCLUDE_PATH}
+    pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner)
+    pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
+
+    # Generate protocols bindings.
+    macro(generate_protocol_bindings NAME PROT_DEF)
+      add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.h
+        COMMAND ${WAYLAND_SCANNER} client-header ${PROT_DEF} ${NAME}-client-protocol.h
+      )
+      add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.c
+        COMMAND ${WAYLAND_SCANNER} private-code ${PROT_DEF} ${NAME}-client-protocol.c
+        DEPENDS ${NAME}-client-protocol.h
+      )
+      list(APPEND SRC
+        ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.c
+        ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.h
+      )
+    endmacro()
+
+    include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+    # xdg-shell.
+    generate_protocol_bindings(
+      xdg-shell
+      "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml"
+    )
+    # Pointer-constraints.
+    generate_protocol_bindings(
+      pointer-constraints
+      "${WAYLAND_PROTOCOLS_DIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
+    )
+    # Relative-pointer.
+    generate_protocol_bindings(
+      relative-pointer
+      "${WAYLAND_PROTOCOLS_DIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
     )
-  endif()
 
-  if(WITH_X11_ALPHA)
-    add_definitions(-DWITH_X11_ALPHA)
+    add_definitions(-DWITH_GHOST_WAYLAND)
   endif()
 
   if(WITH_INPUT_NDOF)
diff --git a/intern/ghost/intern/GHOST_ISystem.cpp b/intern/ghost/intern/GHOST_ISystem.cpp
index 914f6712676..8041f7758d8 100644
--- a/intern/ghost/intern/GHOST_ISystem.cpp
+++ b/intern/ghost/intern/GHOST_ISystem.cpp
@@ -27,8 +27,13 @@
 
 #include "GHOST_ISystem.h"
 
-#ifdef WITH_X11
-#  include "GHOST_SystemX11.h"
+#if defined(WITH_X11) || defined(WITH_GHOST_WAYLAND)
+#  ifdef WITH_X11
+#    include "GHOST_SystemX11.h"
+#  endif
+#  ifdef WITH_GHOST_WAYLAND
+#    include "GHOST_SystemWayland.h"
+#  endif
 #else
 #  ifdef WITH_HEADLESS
 #    include "GHOST_SystemNULL.h"
@@ -49,8 +54,19 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
 {
   GHOST_TSuccess success;
   if (!m_system) {
-#ifdef WITH_X11
-    m_system = new GHOST_SystemX11();
+#if defined(WITH_X11) || defined(WITH_GHOST_WAYLAND)
+#  ifdef WITH_GHOST_WAYLAND
+    try {
+      m_system = new GHOST_SystemWayland();
+    }
+    catch (const std::exception &) {
+    }
+#  endif
+#  ifdef WITH_X11
+    if (!m_system) {
+      m_system = new GHOST_SystemX11();
+    }
+#  endif
 #else
 #  ifdef WITH_HEADLESS
     m_system = new GHOST_SystemNULL();
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
new file mode 100644
index 00000000000..706bd57b425
--- /dev/null
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -0,0 +1,1648 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#include "GHOST_SystemWayland.h"
+#include "GHOST_Event.h"
+#include "GHOST_EventButton.h"
+#include "GHOST_EventCursor.h"
+#include "GHOST_EventDragnDrop.h"
+#include "GHOST_EventKey.h"
+#include "GHOST_EventWheel.h"
+#include "GHOST_WindowManager.h"
+
+#include "GHOST_ContextEGL.h"
+
+#include <EGL/egl.h>
+#include <wayland-egl.h>
+
+#include <algorithm>
+#include <atomic>
+#include <exception>
+#include <thread>
+#include <unordered_map>
+#include <unordered_set>
+
+#include <pointer-constraints-client-protocol.h>
+#include <relative-pointer-client-protocol.h>
+#include <wayland-cursor.h>
+#include <xkbcommon/xkbcommon.h>
+
+#include <fcntl.h>
+#include <linux/input-event-codes.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include <cstring>
+
+struct output_t {
+  struct wl_output *output;
+  int32_t width, height;
+  int transform;
+  int scale;
+  std::string make;
+  std::string model;
+};
+
+struct buffer_t {
+  voi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list