Skip to content

Commit

Permalink
Merge pull request #69449 from Riteo/x11-dynwrapper
Browse files Browse the repository at this point in the history
Load X11 dynamically
  • Loading branch information
akien-mga committed Dec 3, 2022
2 parents 82b1cd6 + 2dd5a79 commit e80356b
Show file tree
Hide file tree
Showing 21 changed files with 12,818 additions and 28 deletions.
15 changes: 8 additions & 7 deletions platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ def configure(env: "Environment"):
## Dependencies

if env["x11"]:
env.ParseConfig("pkg-config x11 --cflags --libs")
env.ParseConfig("pkg-config xcursor --cflags --libs")
env.ParseConfig("pkg-config xinerama --cflags --libs")
env.ParseConfig("pkg-config xext --cflags --libs")
env.ParseConfig("pkg-config xrandr --cflags --libs")
env.ParseConfig("pkg-config xrender --cflags --libs")
env.ParseConfig("pkg-config xi --cflags --libs")
# Only cflags, we dlopen the libraries.
env.ParseConfig("pkg-config x11 --cflags")
env.ParseConfig("pkg-config xcursor --cflags")
env.ParseConfig("pkg-config xinerama --cflags")
env.ParseConfig("pkg-config xext --cflags")
env.ParseConfig("pkg-config xrandr --cflags")
env.ParseConfig("pkg-config xrender --cflags")
env.ParseConfig("pkg-config xi --cflags")

if env["touch"]:
env.Append(CPPDEFINES=["TOUCH_ENABLED"])
Expand Down
8 changes: 8 additions & 0 deletions platform/linuxbsd/x11/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ Import("env")
source_files = [
"display_server_x11.cpp",
"key_mapping_x11.cpp",
"dynwrappers/xlib-so_wrap.c",
"dynwrappers/xcursor-so_wrap.c",
"dynwrappers/xinerama-so_wrap.c",
"dynwrappers/xinput2-so_wrap.c",
"dynwrappers/xrandr-so_wrap.c",
"dynwrappers/xrender-so_wrap.c",
"dynwrappers/xext-so_wrap.c",
]

if env["vulkan"]:
source_files.append("vulkan_context_x11.cpp")

if env["opengl3"]:
env.Append(CPPDEFINES=["GLAD_GLX_NO_X11"])
source_files.append(["gl_manager_x11.cpp", "detect_prime_x11.cpp", "#thirdparty/glad/glx.c"])

objects = []
Expand Down
12 changes: 5 additions & 7 deletions platform/linuxbsd/x11/detect_prime_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#include "thirdparty/glad/glad/gl.h"
#include "thirdparty/glad/glad/glx.h"

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "dynwrappers/xlib-so_wrap.h"

#include <cstring>

Expand Down Expand Up @@ -89,6 +88,10 @@ void create_context() {
None
};

if (gladLoaderLoadGLX(x11_display, XScreenNumberOfScreen(XDefaultScreenOfDisplay(x11_display))) == 0) {
print_verbose("Unable to load GLX, GPU detection skipped.");
quick_exit(1);
}
int fbcount;
GLXFBConfig fbconfig = nullptr;
XVisualInfo *vi = nullptr;
Expand Down Expand Up @@ -189,11 +192,6 @@ int detect_prime() {
setenv("DRI_PRIME", "1", 1);
}

if (gladLoaderLoadGLX(NULL, 0) == 0) {
print_verbose("Unable to load GLX, GPU detection skipped.");
quick_exit(1);
}

create_context();

PFNGLGETSTRINGPROC glGetString = (PFNGLGETSTRINGPROC)glXGetProcAddressARB((GLubyte *)"glGetString");
Expand Down
47 changes: 41 additions & 6 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@
#include <sys/types.h>
#include <unistd.h>

#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xinerama.h>
#include <X11/extensions/shape.h>

// ICCCM
#define WM_NormalState 1L // window normal state
#define WM_IconicState 3L // window minimized
Expand Down Expand Up @@ -4710,6 +4705,46 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
}

DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, Error &r_error) {
#ifdef DEBUG_ENABLED
int dylibloader_verbose = 1;
#else
int dylibloader_verbose = 0;
#endif
if (initialize_xlib(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xlib dynamically.");
}

if (initialize_xcursor(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load XCursor dynamically.");
}

if (initialize_xext(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xext dynamically.");
}

if (initialize_xinerama(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xinerama dynamically.");
}

if (initialize_xrandr(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xrandr dynamically.");
}

if (initialize_xrender(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xrender dynamically.");
}

if (initialize_xinput2(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xinput2 dynamically.");
}

Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);

r_error = OK;
Expand Down Expand Up @@ -4910,7 +4945,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode

gl_manager = memnew(GLManager_X11(p_resolution, opengl_api_type));

if (gl_manager->initialize() != OK) {
if (gl_manager->initialize(x11_display) != OK) {
memdelete(gl_manager);
gl_manager = nullptr;
r_error = ERR_UNAVAILABLE;
Expand Down
14 changes: 11 additions & 3 deletions platform/linuxbsd/x11/display_server_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,20 @@
#include "../freedesktop_screensaver.h"
#endif

#include <X11/Xcursor/Xcursor.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
#include <X11/extensions/Xrandr.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#include "dynwrappers/xlib-so_wrap.h"

#include "dynwrappers/xcursor-so_wrap.h"
#include "dynwrappers/xext-so_wrap.h"
#include "dynwrappers/xinerama-so_wrap.h"
#include "dynwrappers/xinput2-so_wrap.h"
#include "dynwrappers/xrandr-so_wrap.h"
#include "dynwrappers/xrender-so_wrap.h"

typedef struct _xrr_monitor_info {
Atom name;
Bool primary = false;
Expand Down
Loading

0 comments on commit e80356b

Please sign in to comment.