From 8bd4b9d2f90ca62de609be3dd07564f70edc44ad Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 5 Aug 2014 20:33:50 -0400 Subject: [PATCH 01/19] Remove support for Wayland Yes, this is a fancy new feature, but our Wayland support was particularly bitrotten, and ideally this would be handled by a platform layer like SDL. If not, we can always add this back in when GLInterface has caught up. We might be able to even support wxWidgets and GL together with subsurfaces! --- CMakeLists.txt | 30 +- Source/Core/DolphinWX/CMakeLists.txt | 6 - Source/Core/DolphinWX/GLInterface/EGL.cpp | 5 - Source/Core/DolphinWX/GLInterface/EGL.h | 6 - .../Core/DolphinWX/GLInterface/GLInterface.h | 58 +-- .../Core/DolphinWX/GLInterface/Platform.cpp | 177 +------- .../DolphinWX/GLInterface/Wayland_Util.cpp | 404 ------------------ .../Core/DolphinWX/GLInterface/Wayland_Util.h | 29 -- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 4 - Source/Core/DolphinWX/MainNoGUI.cpp | 47 +- .../ControllerInterface.cpp | 9 +- 11 files changed, 17 insertions(+), 758 deletions(-) delete mode 100644 Source/Core/DolphinWX/GLInterface/Wayland_Util.cpp delete mode 100644 Source/Core/DolphinWX/GLInterface/Wayland_Util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index be92b6c222..0d5159b000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ cmake_minimum_required(VERSION 2.8) option(ANDROID "Enables a build for Android" OFF) option(USE_EGL "Enables EGL OpenGL Interface" OFF) option(TRY_X11 "Enables X11 Support" ON) -option(TRY_WAYLAND "Enables Wayland Support" OFF) option(USE_UPNP "Enables UPnP port mapping support" ON) option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF) option(ENABLE_PCH "Use PCH to speed up compilation" ON) @@ -324,7 +323,6 @@ if(ANDROID) message("Building for Android") add_definitions(-DANDROID) set(USE_X11 0) - set(USE_WAYLAND 0) set(USE_UPNP 0) set(USE_EGL 1) endif() @@ -407,26 +405,8 @@ if(NOT ANDROID) endif(OPENAL_FOUND) set(USE_X11 0) - set(USE_WAYLAND 0) if(UNIX AND NOT APPLE) - # Note: The convention is to check TRY_X11 or TRY_WAYLAND where needed. - # This is where we detect platforms and set the variables accordingly. - pkg_check_modules(WAYLAND wayland-egl wayland-client wayland-cursor) - if(TRY_WAYLAND AND WAYLAND_FOUND) - pkg_check_modules(XKBCOMMON xkbcommon) - if(XKBCOMMON_FOUND) - set(USE_WAYLAND 1) - add_definitions(-DHAVE_WAYLAND) - include_directories(${WAYLAND_INCLUDE_DIR}) - message("Wayland support enabled") - endif(XKBCOMMON_FOUND) - else() - set(USE_WAYLAND 0) - message("Wayland support disabled") - add_definitions(-DHAVE_WAYLAND=0) - endif(TRY_WAYLAND AND WAYLAND_FOUND) - # Note: We do not need to explicitly check for X11 as it is done in the cmake # FindOpenGL module on linux. if(TRY_X11 AND X11_FOUND) @@ -441,19 +421,13 @@ if(NOT ANDROID) add_definitions(-DHAVE_X11=0) endif(TRY_X11 AND X11_FOUND) - if (NOT USE_WAYLAND AND NOT USE_X11) + if (NOT USE_X11) message(FATAL_ERROR "\n" "No suitable display platform found\n" - "Requires wayland or x11 to run") + "Requires x11 to run") endif() endif() - # For now Wayland and EGL are tied to each other. - # The alternative would be an shm path - if(USE_WAYLAND) - set(USE_EGL 1) - endif() - if(USE_X11) check_lib(XRANDR Xrandr) if(XRANDR_FOUND) diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 9717e50a4b..82ef1236a1 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -10,9 +10,6 @@ if(NOT ANDROID) if(USE_X11) set(LIBS ${LIBS} ${XRANDR_LIBRARIES}) endif() - if(USE_WAYLAND) - set(LIBS ${LIBS} ${WAYLAND_LIBRARIES} ${XKBCOMMON_LIBRARIES}) - endif() link_directories(${CMAKE_PREFIX_PATH}/lib) else() @@ -78,9 +75,6 @@ set(ANDROID_SRCS Android/ButtonManager.cpp if(USE_EGL) set(SRCS ${SRCS} GLInterface/Platform.cpp GLInterface/EGL.cpp) - if(USE_WAYLAND) - set(SRCS ${SRCS} GLInterface/Wayland_Util.cpp) - endif() if(USE_X11) set(SRCS ${SRCS} GLInterface/X11_Util.cpp) endif() diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index 440e4bab03..d336a8e63f 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -93,9 +93,6 @@ bool cInterfaceEGL::Create(void *&window_handle) const char *s; EGLint egl_major, egl_minor; - if (!Platform.SelectDisplay()) - return false; - GLWin.egl_dpy = Platform.EGLGetDisplay(); if (!GLWin.egl_dpy) @@ -104,8 +101,6 @@ bool cInterfaceEGL::Create(void *&window_handle) return false; } - GLWin.platform = Platform.platform; - if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) { INFO_LOG(VIDEO, "Error: eglInitialize() failed\n"); diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index e2994f3b96..5a66a41f79 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -17,18 +17,12 @@ private: #if HAVE_X11 cXInterface XInterface; #endif -#if HAVE_WAYLAND - cWaylandInterface WaylandInterface; -#endif public: - enum egl_platform platform; - bool SelectDisplay(void); bool Init(EGLConfig config, void *window_handle); EGLDisplay EGLGetDisplay(void); EGLNativeWindowType CreateWindow(void); void DestroyWindow(void); void UpdateFPSDisplay(const std::string& text); - void ToggleFullscreen(bool fullscreen); void SwapBuffers(); }; diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h index c57194140e..b837a671f4 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.h @@ -7,23 +7,11 @@ #include "Common/Thread.h" #if USE_EGL -// Currently Wayland/EGL and X11/EGL platforms are supported. -// The platform may be spelected at run time by setting the -// environment variable DOLPHIN_EGL_PLATFORM to "wayland" or "x11". - -enum egl_platform { - EGL_PLATFORM_NONE, - EGL_PLATFORM_WAYLAND, - EGL_PLATFORM_X11, - EGL_PLATFORM_ANDROID -}; +// Currently Android/EGL and X11/EGL platforms are supported. #if HAVE_X11 #include "DolphinWX/GLInterface/X11_Util.h" #endif -#if HAVE_WAYLAND -#include "DolphinWX/GLInterface/Wayland_Util.h" -#endif #include "DolphinWX/GLInterface/EGL.h" #elif defined(__APPLE__) @@ -37,55 +25,11 @@ enum egl_platform { #error Platform doesnt have a GLInterface #endif -#if HAVE_WAYLAND -struct geometry { - int width; - int height; -}; - -struct xkb { - struct xkb_context *context; - struct xkb_keymap *keymap; - struct xkb_state *state; - xkb_mod_mask_t control_mask; - xkb_mod_mask_t alt_mask; - xkb_mod_mask_t shift_mask; -}; -#endif - typedef struct { -#if HAVE_WAYLAND - struct wl_display *wl_display; - struct wl_registry *wl_registry; - struct wl_compositor *wl_compositor; - struct wl_shell *wl_shell; - struct wl_seat *wl_seat; - struct { - struct wl_pointer *wl_pointer; - uint32_t serial; - } pointer; - struct { - struct wl_keyboard *wl_keyboard; - struct xkb xkb; - uint32_t modifiers; - } keyboard; - struct wl_shm *wl_shm; - struct wl_cursor_theme *wl_cursor_theme; - struct wl_cursor *wl_cursor; - struct wl_surface *wl_cursor_surface; - struct geometry geometry, window_size; - struct wl_egl_window *wl_egl_native; - struct wl_surface *wl_surface; - struct wl_shell_surface *wl_shell_surface; - bool fullscreen, running; -#endif - - #if USE_EGL EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; - enum egl_platform platform; EGLNativeWindowType native_window; #elif HAVE_X11 GLXContext ctx; diff --git a/Source/Core/DolphinWX/GLInterface/Platform.cpp b/Source/Core/DolphinWX/GLInterface/Platform.cpp index 86b12858dc..cdd78e973d 100644 --- a/Source/Core/DolphinWX/GLInterface/Platform.cpp +++ b/Source/Core/DolphinWX/GLInterface/Platform.cpp @@ -6,130 +6,12 @@ #include "Core/Host.h" #include "DolphinWX/GLInterface/GLInterface.h" -bool cPlatform::SelectDisplay(void) -{ - enum egl_platform selected_platform = EGL_PLATFORM_NONE; - enum egl_platform desired_platform = EGL_PLATFORM_NONE; - char *platform_env = getenv("DOLPHIN_EGL_PLATFORM"); - - if (platform_env) - platform_env = strdup(platform_env); - - if (!platform_env) - printf("Running automatic platform detection\n"); - - // Try to select the platform set in the environment variable first -#if HAVE_WAYLAND - bool wayland_possible = WaylandInterface.ServerConnect(); - - if (platform_env && !strcmp(platform_env, "wayland")) - { - desired_platform = EGL_PLATFORM_WAYLAND; - if (wayland_possible) - selected_platform = EGL_PLATFORM_WAYLAND; - else - printf("Wayland display server connection failed\n"); - } -#endif - -#if HAVE_X11 - bool x11_possible = XInterface.ServerConnect(); - - if (platform_env && !strcmp(platform_env, "x11")) - { - desired_platform = EGL_PLATFORM_X11; - if ((selected_platform != EGL_PLATFORM_WAYLAND) && x11_possible) - selected_platform = EGL_PLATFORM_X11; - else - printf("X11 display server connection failed\n"); - } -#endif - // Fall back to automatic detection - if (selected_platform == EGL_PLATFORM_NONE) - { - if (platform_env && (desired_platform == EGL_PLATFORM_NONE)) { - printf("DOLPHIN_EGL_PLATFORM set to unrecognized platform \"%s\".\n" -#if HAVE_WAYLAND && !HAVE_X11 - "Note: Valid value is \"wayland\" (built without x11 support)\n", -#endif -#if HAVE_X11 && !HAVE_WAYLAND - "Note: Valid values is \"x11\" (built without wayland support)\n", -#endif -#if HAVE_WAYLAND && HAVE_X11 - "Note: Valid values are \"wayland\" and \"x11\"\n", -#endif -#if !HAVE_WAYLAND && !HAVE_X11 - "Note: No Valid platform. Must be Android\n", -#endif - platform_env); - free(platform_env); - platform_env = nullptr; - } -#if HAVE_WAYLAND - if (wayland_possible) - { - selected_platform = EGL_PLATFORM_WAYLAND; - platform_env = strdup("wayland"); - } -#endif -#if HAVE_X11 - if ((selected_platform != EGL_PLATFORM_WAYLAND) && x11_possible) - { - selected_platform = EGL_PLATFORM_X11; - platform_env = strdup("x11"); - } -#endif -#ifdef ANDROID - selected_platform = EGL_PLATFORM_ANDROID; -#endif - if (selected_platform == EGL_PLATFORM_NONE) - { - printf("FATAL: Failed to find suitable platform for display connection\n"); - goto out; - } - } - - printf("Using EGL Native Display Platform: %s\n", platform_env); -out: - cPlatform::platform = selected_platform; - free(platform_env); -#if HAVE_WAYLAND - if (selected_platform != EGL_PLATFORM_WAYLAND) { - if (GLWin.wl_display) - wl_display_disconnect(GLWin.wl_display); - } - -#endif -#if HAVE_X11 - if (selected_platform != EGL_PLATFORM_X11) { - if (GLWin.dpy) - { - XCloseDisplay(GLWin.dpy); - } - } -#endif -#if ANDROID - selected_platform = EGL_PLATFORM_ANDROID; -#endif - if (selected_platform == EGL_PLATFORM_NONE) - return false; - - return true; -} - bool cPlatform::Init(EGLConfig config, void *window_handle) { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - if (!WaylandInterface.Initialize(config)) - return false; -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - if (!XInterface.Initialize(config, window_handle)) - return false; -#endif -#ifdef ANDROID + if (!XInterface.Initialize(config, window_handle)) + return false; +#elif ANDROID EGLint format; eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry((EGLNativeWindowType)Host_GetRenderHandle(), 0, 0, format); @@ -142,15 +24,9 @@ bool cPlatform::Init(EGLConfig config, void *window_handle) EGLDisplay cPlatform::EGLGetDisplay(void) { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - return (EGLDisplay) WaylandInterface.EGLGetDisplay(); -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - return (EGLDisplay) XInterface.EGLGetDisplay(); -#endif -#ifdef ANDROID + return (EGLDisplay) XInterface.EGLGetDisplay(); +#elif ANDROID return eglGetDisplay(EGL_DEFAULT_DISPLAY); #endif return nullptr; @@ -158,13 +34,8 @@ EGLDisplay cPlatform::EGLGetDisplay(void) EGLNativeWindowType cPlatform::CreateWindow(void) { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - return (EGLNativeWindowType) WaylandInterface.CreateWindow(); -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - return (EGLNativeWindowType) XInterface.CreateWindow(); + return (EGLNativeWindowType) XInterface.CreateWindow(); #endif #ifdef ANDROID return (EGLNativeWindowType)Host_GetRenderHandle(); @@ -174,52 +45,24 @@ EGLNativeWindowType cPlatform::CreateWindow(void) void cPlatform::DestroyWindow(void) { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - WaylandInterface.DestroyWindow(); -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - XInterface.DestroyWindow(); + XInterface.DestroyWindow(); #endif } void cPlatform::UpdateFPSDisplay(const std::string& text) { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - WaylandInterface.UpdateFPSDisplay(text); -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - XInterface.UpdateFPSDisplay(text); -#endif -} - -void -cPlatform::ToggleFullscreen(bool fullscreen) -{ -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - WaylandInterface.ToggleFullscreen(fullscreen); -#endif -#if HAVE_X11 - // Only wayland uses this function + XInterface.UpdateFPSDisplay(text); #endif } void cPlatform::SwapBuffers() { -#if HAVE_WAYLAND - if (cPlatform::platform == EGL_PLATFORM_WAYLAND) - WaylandInterface.SwapBuffers(); -#endif #if HAVE_X11 - if (cPlatform::platform == EGL_PLATFORM_X11) - XInterface.SwapBuffers(); -#endif -#if ANDROID + XInterface.SwapBuffers(); +#elif ANDROID eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); #endif } diff --git a/Source/Core/DolphinWX/GLInterface/Wayland_Util.cpp b/Source/Core/DolphinWX/GLInterface/Wayland_Util.cpp deleted file mode 100644 index 577d8a5a13..0000000000 --- a/Source/Core/DolphinWX/GLInterface/Wayland_Util.cpp +++ /dev/null @@ -1,404 +0,0 @@ -// Copyright (C) 2013 Scott Moreau -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include - -#include "Core/Core.h" -#include "Core/State.h" -#include "DolphinWX/GLInterface/GLInterface.h" - -static void -hide_cursor(void) -{ - if (!GLWin.pointer.wl_pointer) - return; - - wl_pointer_set_cursor(GLWin.pointer.wl_pointer, - GLWin.pointer.serial, nullptr, 0, 0); -} - -static void -handle_ping(void *data, struct wl_shell_surface *wl_shell_surface, - uint32_t serial) -{ - wl_shell_surface_pong(wl_shell_surface, serial); -} - -static void -handle_configure(void *data, struct wl_shell_surface *wl_shell_surface, - uint32_t edges, int32_t width, int32_t height) -{ - if (GLWin.wl_egl_native) - wl_egl_window_resize(GLWin.wl_egl_native, width, height, 0, 0); - - GLWin.geometry.width = width; - GLWin.geometry.height = height; - - GLInterface->SetBackBufferDimensions(width, height); - - if (!GLWin.fullscreen) - GLWin.window_size = GLWin.geometry; -} - -static void -handle_popup_done(void *data, struct wl_shell_surface *wl_shell_surface) -{ -} - -static const struct wl_shell_surface_listener shell_surface_listener = { - handle_ping, - handle_configure, - handle_popup_done -}; - -static void -pointer_handle_enter(void *data, struct wl_pointer *pointer, - uint32_t serial, struct wl_surface *surface, - wl_fixed_t sx, wl_fixed_t sy) -{ - GLWin.pointer.serial = serial; - - hide_cursor(); -} - -static void -pointer_handle_leave(void *data, struct wl_pointer *pointer, - uint32_t serial, struct wl_surface *surface) -{ -} - -static void -pointer_handle_motion(void *data, struct wl_pointer *pointer, - uint32_t time, wl_fixed_t sx, wl_fixed_t sy) -{ -} - -static void -pointer_handle_button(void *data, struct wl_pointer *wl_pointer, - uint32_t serial, uint32_t time, uint32_t button, - uint32_t state) -{ -} - -static void -pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, - uint32_t time, uint32_t axis, wl_fixed_t value) -{ -} - -static const struct wl_pointer_listener pointer_listener = { - pointer_handle_enter, - pointer_handle_leave, - pointer_handle_motion, - pointer_handle_button, - pointer_handle_axis, -}; - -static void -toggle_fullscreen(bool fullscreen) -{ - GLWin.fullscreen = fullscreen; - - if (fullscreen) { - wl_shell_surface_set_fullscreen(GLWin.wl_shell_surface, - WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, - 0, nullptr); - } else { - wl_shell_surface_set_toplevel(GLWin.wl_shell_surface); - handle_configure(nullptr, GLWin.wl_shell_surface, 0, - GLWin.window_size.width, - GLWin.window_size.height); - } -} - -static void -keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, - uint32_t format, int fd, uint32_t size) -{ - char *map_str; - - if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { - close(fd); - return; - } - - map_str = (char *) mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0); - if (map_str == MAP_FAILED) { - close(fd); - return; - } - - GLWin.keyboard.xkb.keymap = xkb_map_new_from_string(GLWin.keyboard.xkb.context, - map_str, - XKB_KEYMAP_FORMAT_TEXT_V1, - (xkb_keymap_compile_flags) 0); - munmap(map_str, size); - close(fd); - - if (!GLWin.keyboard.xkb.keymap) { - fprintf(stderr, "failed to compile keymap\n"); - return; - } - - GLWin.keyboard.xkb.state = xkb_state_new(GLWin.keyboard.xkb.keymap); - if (!GLWin.keyboard.xkb.state) { - fprintf(stderr, "failed to create XKB state\n"); - xkb_map_unref(GLWin.keyboard.xkb.keymap); - GLWin.keyboard.xkb.keymap = nullptr; - return; - } - - GLWin.keyboard.xkb.control_mask = - 1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Control"); - GLWin.keyboard.xkb.alt_mask = - 1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Mod1"); - GLWin.keyboard.xkb.shift_mask = - 1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Shift"); -} - -static void -keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, - uint32_t serial, struct wl_surface *surface, - struct wl_array *keys) -{ -} - -static void -keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, - uint32_t serial, struct wl_surface *surface) -{ -} - -static void -keyboard_handle_key(void *data, struct wl_keyboard *keyboard, - uint32_t serial, uint32_t time, uint32_t key, - uint32_t state) -{ - if (state == WL_KEYBOARD_KEY_STATE_RELEASED) - return; - - if (key == KEY_ESC) { - Core::Stop(); - GLWin.running = 0; - } else if ((key == KEY_P) || - ((key == KEY_ENTER) && (GLWin.keyboard.modifiers == 0))) - Core::SetState((Core::GetState() == Core::CORE_RUN) ? - Core::CORE_PAUSE : Core::CORE_RUN); - else if (key == KEY_F) - toggle_fullscreen(!GLWin.fullscreen); - else if ((key == KEY_ENTER) && (GLWin.keyboard.modifiers == MOD_ALT_MASK)) - toggle_fullscreen(!GLWin.fullscreen); - else if (key >= KEY_F1 && key <= KEY_F8) { - int slot_number = key - KEY_F1 + 1; - if (GLWin.keyboard.modifiers == MOD_SHIFT_MASK) - State::Save(slot_number); - else - State::Load(slot_number); - } - else if (key == KEY_F9) - Core::SaveScreenShot(); - else if (key == KEY_F11) - State::LoadLastSaved(); - else if (key == KEY_F12) { - if (GLWin.keyboard.modifiers == MOD_SHIFT_MASK) - State::UndoLoadState(); - else - State::UndoSaveState(); - } -} - -static void -keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, - uint32_t serial, uint32_t mods_depressed, - uint32_t mods_latched, uint32_t mods_locked, - uint32_t group) -{ - xkb_mod_mask_t mask; - - xkb_state_update_mask(GLWin.keyboard.xkb.state, mods_depressed, mods_latched, - mods_locked, 0, 0, group); - mask = xkb_state_serialize_mods(GLWin.keyboard.xkb.state, - (xkb_state_component) - (XKB_STATE_DEPRESSED | - XKB_STATE_LATCHED)); - GLWin.keyboard.modifiers = 0; - if (mask & GLWin.keyboard.xkb.control_mask) - GLWin.keyboard.modifiers |= MOD_CONTROL_MASK; - if (mask & GLWin.keyboard.xkb.alt_mask) - GLWin.keyboard.modifiers |= MOD_ALT_MASK; - if (mask & GLWin.keyboard.xkb.shift_mask) - GLWin.keyboard.modifiers |= MOD_SHIFT_MASK; -} - -static const struct wl_keyboard_listener keyboard_listener = { - keyboard_handle_keymap, - keyboard_handle_enter, - keyboard_handle_leave, - keyboard_handle_key, - keyboard_handle_modifiers, -}; - -static void -seat_handle_capabilities(void *data, struct wl_seat *seat, - uint32_t caps) -{ - struct wl_pointer *wl_pointer = nullptr; - struct wl_keyboard *wl_keyboard = nullptr; - - if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl_pointer) { - wl_pointer = wl_seat_get_pointer(seat); - wl_pointer_add_listener(wl_pointer, &pointer_listener, 0); - } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl_pointer) { - wl_pointer_destroy(wl_pointer); - wl_pointer = nullptr; - } - - GLWin.pointer.wl_pointer = wl_pointer; - - if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl_keyboard) { - wl_keyboard = wl_seat_get_keyboard(seat); - wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, 0); - } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl_keyboard) { - wl_keyboard_destroy(wl_keyboard); - wl_keyboard = nullptr; - } - - GLWin.keyboard.wl_keyboard = wl_keyboard; -} - -static const struct wl_seat_listener seat_listener = { - seat_handle_capabilities, -}; - -static void -registry_handle_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) -{ - if (strcmp(interface, "wl_compositor") == 0) { - GLWin.wl_compositor = (wl_compositor *) - wl_registry_bind(registry, name, - &wl_compositor_interface, 1); - } else if (strcmp(interface, "wl_shell") == 0) { - GLWin.wl_shell = (wl_shell *) wl_registry_bind(registry, name, - &wl_shell_interface, 1); - } else if (strcmp(interface, "wl_seat") == 0) { - GLWin.wl_seat = (wl_seat *) wl_registry_bind(registry, name, - &wl_seat_interface, 1); - wl_seat_add_listener(GLWin.wl_seat, &seat_listener, 0); - } else if (strcmp(interface, "wl_shm") == 0) { - GLWin.wl_shm = (wl_shm *) wl_registry_bind(registry, name, - &wl_shm_interface, 1); - GLWin.wl_cursor_theme = (wl_cursor_theme *) wl_cursor_theme_load(nullptr, 32, GLWin.wl_shm); - GLWin.wl_cursor = (wl_cursor *) - wl_cursor_theme_get_cursor(GLWin.wl_cursor_theme, "left_ptr"); - } -} - -static void -registry_handle_global_remove(void *data, struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - registry_handle_global, - registry_handle_global_remove -}; - -bool cWaylandInterface::ServerConnect(void) -{ - GLWin.wl_display = wl_display_connect(nullptr); - - if (!GLWin.wl_display) - return false; - - return true; -} - -bool cWaylandInterface::Initialize(void *config) -{ - if (!GLWin.wl_display) { - printf("Error: couldn't open wayland display\n"); - return false; - } - - GLWin.pointer.wl_pointer = nullptr; - GLWin.keyboard.wl_keyboard = nullptr; - - GLWin.keyboard.xkb.context = xkb_context_new((xkb_context_flags) 0); - if (GLWin.keyboard.xkb.context == nullptr) { - fprintf(stderr, "Failed to create XKB context\n"); - return nullptr; - } - - GLWin.wl_registry = wl_display_get_registry(GLWin.wl_display); - wl_registry_add_listener(GLWin.wl_registry, - ®istry_listener, nullptr); - - while (!GLWin.wl_compositor) - wl_display_dispatch(GLWin.wl_display); - - GLWin.wl_cursor_surface = - wl_compositor_create_surface(GLWin.wl_compositor); - - return true; -} - -void *cWaylandInterface::EGLGetDisplay(void) -{ - return eglGetDisplay(GLWin.wl_display); -} - -void *cWaylandInterface::CreateWindow(void) -{ - GLWin.window_size.width = 640; - GLWin.window_size.height = 480; - GLWin.fullscreen = true; - - GLWin.wl_surface = wl_compositor_create_surface(GLWin.wl_compositor); - GLWin.wl_shell_surface = wl_shell_get_shell_surface(GLWin.wl_shell, - GLWin.wl_surface); - - wl_shell_surface_add_listener(GLWin.wl_shell_surface, - &shell_surface_listener, 0); - - GLWin.wl_egl_native = wl_egl_window_create(GLWin.wl_surface, - GLWin.window_size.width, - GLWin.window_size.height); - - return GLWin.wl_egl_native; -} - -void cWaylandInterface::DestroyWindow(void) -{ - wl_egl_window_destroy(GLWin.wl_egl_native); - - wl_shell_surface_destroy(GLWin.wl_shell_surface); - wl_surface_destroy(GLWin.wl_surface); -} - -void cWaylandInterface::UpdateFPSDisplay(const std::string& text) -{ - wl_shell_surface_set_title(GLWin.wl_shell_surface, text.c_str()); -} - -void cWaylandInterface::ToggleFullscreen(bool fullscreen) -{ - toggle_fullscreen(fullscreen); -} - -void cWaylandInterface::SwapBuffers() -{ - struct wl_region *region; - - region = wl_compositor_create_region(GLWin.wl_compositor); - wl_region_add(region, 0, 0, - GLWin.geometry.width, - GLWin.geometry.height); - wl_surface_set_opaque_region(GLWin.wl_surface, region); - wl_region_destroy(region); - - eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); -} diff --git a/Source/Core/DolphinWX/GLInterface/Wayland_Util.h b/Source/Core/DolphinWX/GLInterface/Wayland_Util.h deleted file mode 100644 index 53caf62f79..0000000000 --- a/Source/Core/DolphinWX/GLInterface/Wayland_Util.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2013 Scott Moreau -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include -#include -#include - -#define MOD_SHIFT_MASK 0x01 -#define MOD_ALT_MASK 0x02 -#define MOD_CONTROL_MASK 0x04 - - -class cWaylandInterface -{ -public: - bool ServerConnect(void); - bool Initialize(void *config); - void *EGLGetDisplay(void); - void *CreateWindow(void); - void DestroyWindow(void); - void UpdateFPSDisplay(const std::string& text); - void ToggleFullscreen(bool fullscreen); - void SwapBuffers(); -}; diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 32ab4699e2..e42a744713 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -53,11 +53,7 @@ bool cXInterface::Initialize(void *config, void *window_handle) void *cXInterface::EGLGetDisplay(void) { -#if HAVE_WAYLAND - return eglGetDisplay((wl_display *) GLWin.dpy); -#else return eglGetDisplay(GLWin.dpy); -#endif } void *cXInterface::CreateWindow(void) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 9befeb4b59..0b9e2f783b 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -29,10 +29,6 @@ #include "DolphinWX/X11Utils.h" #endif -#if HAVE_WAYLAND -#include -#endif - #ifdef USE_EGL #include "DolphinWX/GLInterface/GLInterface.h" #endif @@ -262,23 +258,6 @@ static void X11_MainLoop() } #endif -#if HAVE_WAYLAND -static void Wayland_MainLoop() -{ - // Wait for display to be initialized - while (!GLWin.wl_display) - usleep(20000); - - GLWin.running = 1; - - while (GLWin.running) - wl_display_dispatch(GLWin.wl_display); - - if (GLWin.wl_display) - wl_display_disconnect(GLWin.wl_display); -} -#endif - int main(int argc, char* argv[]) { #ifdef __APPLE__ @@ -330,34 +309,12 @@ int main(int argc, char* argv[]) m_LocalCoreStartupParameter.m_strVideoBackend); WiimoteReal::LoadSettings(); -#if USE_EGL - GLWin.platform = EGL_PLATFORM_NONE; -#endif -#if HAVE_WAYLAND - GLWin.wl_display = nullptr; -#endif - // No use running the loop when booting fails if (BootManager::BootCore(argv[optind])) { -#if USE_EGL - while (GLWin.platform == EGL_PLATFORM_NONE) - usleep(20000); -#endif -#if HAVE_WAYLAND - if (GLWin.platform == EGL_PLATFORM_WAYLAND) - Wayland_MainLoop(); -#endif #if HAVE_X11 -#if USE_EGL - if (GLWin.platform == EGL_PLATFORM_X11) - { -#endif - XInitThreads(); - X11_MainLoop(); -#if USE_EGL - } -#endif + XInitThreads(); + X11_MainLoop(); #endif #ifdef __APPLE__ while (running) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 366485daa2..d90b3bf02a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -57,15 +57,10 @@ void ControllerInterface::Initialize() ciface::XInput::Init(m_devices); #endif #ifdef CIFACE_USE_XLIB -#if USE_EGL - if (GLWin.platform == EGL_PLATFORM_X11) -#endif - { - ciface::Xlib::Init(m_devices, m_hwnd); + ciface::Xlib::Init(m_devices, m_hwnd); #ifdef CIFACE_USE_X11_XINPUT2 - ciface::XInput2::Init(m_devices, m_hwnd); + ciface::XInput2::Init(m_devices, m_hwnd); #endif - } #endif #ifdef CIFACE_USE_OSX ciface::OSX::Init(m_devices, m_hwnd); From 12f073c56b30adf6b9d1536b1af1cb73a4561b90 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 5 Aug 2014 20:45:18 -0400 Subject: [PATCH 02/19] Remove support for EGL under X11 Now, the only supported EGL platform is Android. We might eventually add back support for EGL/X11 or EGL/Wayland, but it will have to be architected differently. --- Source/Core/DolphinWX/CMakeLists.txt | 7 +- Source/Core/DolphinWX/GLInterface/EGL.cpp | 20 ++-- Source/Core/DolphinWX/GLInterface/EGL.h | 18 ---- .../Core/DolphinWX/GLInterface/GLInterface.h | 12 +-- .../Core/DolphinWX/GLInterface/Platform.cpp | 68 ------------- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 99 ------------------- Source/Core/DolphinWX/GLInterface/X11_Util.h | 16 --- Source/Core/DolphinWX/MainNoGUI.cpp | 4 - 8 files changed, 14 insertions(+), 230 deletions(-) delete mode 100644 Source/Core/DolphinWX/GLInterface/Platform.cpp diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 82ef1236a1..65013d0d8c 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -73,11 +73,7 @@ set(ANDROID_SRCS Android/ButtonManager.cpp MainAndroid.cpp) if(USE_EGL) - set(SRCS ${SRCS} GLInterface/Platform.cpp - GLInterface/EGL.cpp) - if(USE_X11) - set(SRCS ${SRCS} GLInterface/X11_Util.cpp) - endif() + set(SRCS ${SRCS} GLInterface/EGL.cpp) else() if(WIN32) set(SRCS ${SRCS} GLInterface/WGL.cpp) @@ -86,7 +82,6 @@ else() else() set(SRCS ${SRCS} GLInterface/GLX.cpp GLInterface/X11_Util.cpp) - endif() endif() set(SRCS ${SRCS} GLInterface/GLInterface.cpp) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index d336a8e63f..2c124332cf 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -9,11 +9,10 @@ // Show the current FPS void cInterfaceEGL::UpdateFPSDisplay(const std::string& text) { - Platform.UpdateFPSDisplay(text); } void cInterfaceEGL::Swap() { - Platform.SwapBuffers(); + eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); } void cInterfaceEGL::SwapInterval(int Interval) { @@ -93,7 +92,7 @@ bool cInterfaceEGL::Create(void *&window_handle) const char *s; EGLint egl_major, egl_minor; - GLWin.egl_dpy = Platform.EGLGetDisplay(); + GLWin.egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!GLWin.egl_dpy) { @@ -157,8 +156,14 @@ bool cInterfaceEGL::Create(void *&window_handle) else eglBindAPI(EGL_OPENGL_ES_API); - if (!Platform.Init(config, window_handle)) - return false; + EGLint format; + eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); + ANativeWindow_setBuffersGeometry((EGLNativeWindowType)Host_GetRenderHandle(), 0, 0, format); + int none, width, height; + Host_GetRenderWindowSize(none, none, width, height); + GLWin.width = width; + GLWin.height = height; + GLInterface->SetBackBufferDimensions(width, height); s = eglQueryString(GLWin.egl_dpy, EGL_VERSION); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); @@ -179,7 +184,7 @@ bool cInterfaceEGL::Create(void *&window_handle) exit(1); } - GLWin.native_window = Platform.CreateWindow(); + GLWin.native_window = Host_GetRenderHandle(); GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, GLWin.native_window, nullptr); if (!GLWin.egl_surf) @@ -188,8 +193,6 @@ bool cInterfaceEGL::Create(void *&window_handle) exit(1); } - Platform.ToggleFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen); - window_handle = (void *)GLWin.native_window; return true; } @@ -201,7 +204,6 @@ bool cInterfaceEGL::MakeCurrent() // Close backend void cInterfaceEGL::Shutdown() { - Platform.DestroyWindow(); if (GLWin.egl_ctx && !eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx)) NOTICE_LOG(VIDEO, "Could not release drawing context."); if (GLWin.egl_ctx) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 5a66a41f79..bcf5d8cd75 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -10,29 +10,11 @@ #include "Core/ConfigManager.h" #include "VideoBackends/OGL/GLInterfaceBase.h" - -class cPlatform -{ -private: -#if HAVE_X11 - cXInterface XInterface; -#endif -public: - bool Init(EGLConfig config, void *window_handle); - EGLDisplay EGLGetDisplay(void); - EGLNativeWindowType CreateWindow(void); - void DestroyWindow(void); - void UpdateFPSDisplay(const std::string& text); - void SwapBuffers(); -}; - class cInterfaceEGL : public cInterfaceBase { private: - cPlatform Platform; void DetectMode(); public: - friend class cPlatform; void SwapInterval(int Interval); void Swap(); void SetMode(u32 mode) { s_opengl_mode = mode; } diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h index b837a671f4..acc62fcfc8 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.h @@ -7,12 +7,6 @@ #include "Common/Thread.h" #if USE_EGL -// Currently Android/EGL and X11/EGL platforms are supported. - -#if HAVE_X11 -#include "DolphinWX/GLInterface/X11_Util.h" -#endif - #include "DolphinWX/GLInterface/EGL.h" #elif defined(__APPLE__) #include "DolphinWX/GLInterface/AGL.h" @@ -31,13 +25,11 @@ typedef struct { EGLContext egl_ctx; EGLDisplay egl_dpy; EGLNativeWindowType native_window; -#elif HAVE_X11 - GLXContext ctx; -#endif -#if defined(__APPLE__) +#elif defined(__APPLE__) NSView *cocoaWin; NSOpenGLContext *cocoaCtx; #elif HAVE_X11 + GLXContext ctx; int screen; Window win; Window parent; diff --git a/Source/Core/DolphinWX/GLInterface/Platform.cpp b/Source/Core/DolphinWX/GLInterface/Platform.cpp deleted file mode 100644 index cdd78e973d..0000000000 --- a/Source/Core/DolphinWX/GLInterface/Platform.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2014 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" - -bool cPlatform::Init(EGLConfig config, void *window_handle) -{ -#if HAVE_X11 - if (!XInterface.Initialize(config, window_handle)) - return false; -#elif ANDROID - EGLint format; - eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry((EGLNativeWindowType)Host_GetRenderHandle(), 0, 0, format); - int none, width, height; - Host_GetRenderWindowSize(none, none, width, height); - GLInterface->SetBackBufferDimensions(width, height); -#endif - return true; -} - -EGLDisplay cPlatform::EGLGetDisplay(void) -{ -#if HAVE_X11 - return (EGLDisplay) XInterface.EGLGetDisplay(); -#elif ANDROID - return eglGetDisplay(EGL_DEFAULT_DISPLAY); -#endif - return nullptr; -} - -EGLNativeWindowType cPlatform::CreateWindow(void) -{ -#if HAVE_X11 - return (EGLNativeWindowType) XInterface.CreateWindow(); -#endif -#ifdef ANDROID - return (EGLNativeWindowType)Host_GetRenderHandle(); -#endif - return 0; -} - -void cPlatform::DestroyWindow(void) -{ -#if HAVE_X11 - XInterface.DestroyWindow(); -#endif -} - -void cPlatform::UpdateFPSDisplay(const std::string& text) -{ -#if HAVE_X11 - XInterface.UpdateFPSDisplay(text); -#endif -} - -void -cPlatform::SwapBuffers() -{ -#if HAVE_X11 - XInterface.SwapBuffers(); -#elif ANDROID - eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); -#endif -} diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index e42a744713..2c13563529 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -6,104 +6,6 @@ #include "DolphinWX/GLInterface/GLInterface.h" #include "VideoCommon/VideoConfig.h" -#if USE_EGL -bool cXInterface::ServerConnect(void) -{ - GLWin.dpy = XOpenDisplay(nullptr); - - if (!GLWin.dpy) - return false; - - return true; -} - -bool cXInterface::Initialize(void *config, void *window_handle) -{ - XVisualInfo visTemplate; - int num_visuals; - EGLint vid; - - if (!GLWin.dpy) { - printf("Error: couldn't open X display\n"); - return false; - } - - if (!eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - GLWin.vi = XGetVisualInfo(GLWin.dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!GLWin.vi) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - GLWin.evdpy = XOpenDisplay(nullptr); - GLWin.parent = (Window) window_handle; - GLWin.screen = DefaultScreen(GLWin.dpy); - - if (GLWin.parent == 0) - GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen); - - return true; -} - -void *cXInterface::EGLGetDisplay(void) -{ - return eglGetDisplay(GLWin.dpy); -} - -void *cXInterface::CreateWindow(void) -{ - Atom wmProtocols[1]; - - // Setup window attributes - GLWin.attr.colormap = XCreateColormap(GLWin.evdpy, - GLWin.parent, GLWin.vi->visual, AllocNone); - GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask; - GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen); - GLWin.attr.border_pixel = 0; - - // Create the window - GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent, - 0, 0, 1, 1, 0, - GLWin.vi->depth, InputOutput, GLWin.vi->visual, - CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr); - wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True); - XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1); - XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, nullptr, 0, nullptr); - XMapRaised(GLWin.evdpy, GLWin.win); - XSync(GLWin.evdpy, True); - - GLWin.xEventThread = std::thread(&cXInterface::XEventThread, this); - - return (void *) GLWin.win; -} - -void cXInterface::DestroyWindow(void) -{ - XDestroyWindow(GLWin.evdpy, GLWin.win); - GLWin.win = 0; - if (GLWin.xEventThread.joinable()) - GLWin.xEventThread.join(); - XFreeColormap(GLWin.evdpy, GLWin.attr.colormap); -} - -void cXInterface::UpdateFPSDisplay(const std::string& text) -{ - XStoreName(GLWin.evdpy, GLWin.win, text.c_str()); -} - -void cXInterface::SwapBuffers() -{ - eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); -} - -void cXInterface::XEventThread() -#else void cX11Window::CreateXWindow(void) { Atom wmProtocols[1]; @@ -139,7 +41,6 @@ void cX11Window::DestroyXWindow(void) } void cX11Window::XEventThread() -#endif { while (GLWin.win) { diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.h b/Source/Core/DolphinWX/GLInterface/X11_Util.h index be187906bb..d8c293378c 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.h +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.h @@ -9,21 +9,6 @@ #include #include -#if USE_EGL -class cXInterface -{ -private: - void XEventThread(); -public: - bool ServerConnect(void); - bool Initialize(void *config, void *window_handle); - void *EGLGetDisplay(void); - void *CreateWindow(void); - void DestroyWindow(void); - void UpdateFPSDisplay(const std::string& text); - void SwapBuffers(); -}; -#else class cX11Window { private: @@ -32,4 +17,3 @@ public: void CreateXWindow(void); void DestroyXWindow(void); }; -#endif diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 0b9e2f783b..8c091a0391 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -29,10 +29,6 @@ #include "DolphinWX/X11Utils.h" #endif -#ifdef USE_EGL -#include "DolphinWX/GLInterface/GLInterface.h" -#endif - #ifdef __APPLE__ #import #endif From e3a9ba30e379730a60aa569f653165d51e72b7c1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 5 Aug 2014 23:44:25 -0400 Subject: [PATCH 03/19] GLX: Remove evdpy / dpy split Move to one display. There's no reason to have two displays here -- the comment stated that one should touch GLX and one should touch window events, and that they should be touched from different threads, but the current code wasn't this careful. Just use one Display connection. --- .../Core/DolphinWX/GLInterface/GLInterface.h | 4 +-- Source/Core/DolphinWX/GLInterface/GLX.cpp | 4 +-- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 26 +++++++++---------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h index acc62fcfc8..bcd0286f41 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.h @@ -33,9 +33,7 @@ typedef struct { int screen; Window win; Window parent; - // dpy used for glx stuff, evdpy for window events etc. - // evdpy is to be used by XEventThread only - Display *dpy, *evdpy; + Display *dpy; XVisualInfo *vi; XSetWindowAttributes attr; std::thread xEventThread; diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index 320d0f884a..022efda2cb 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -15,7 +15,7 @@ static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; // Show the current FPS void cInterfaceGLX::UpdateFPSDisplay(const std::string& text) { - XStoreName(GLWin.evdpy, GLWin.win, text.c_str()); + XStoreName(GLWin.dpy, GLWin.win, text.c_str()); } void cInterfaceGLX::SwapInterval(int Interval) @@ -65,7 +65,6 @@ bool cInterfaceGLX::Create(void *&window_handle) None }; GLWin.dpy = XOpenDisplay(nullptr); - GLWin.evdpy = XOpenDisplay(nullptr); GLWin.parent = (Window)window_handle; GLWin.screen = DefaultScreen(GLWin.dpy); if (GLWin.parent == 0) @@ -134,7 +133,6 @@ void cInterfaceGLX::Shutdown() { glXDestroyContext(GLWin.dpy, GLWin.ctx); XCloseDisplay(GLWin.dpy); - XCloseDisplay(GLWin.evdpy); GLWin.ctx = nullptr; } } diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 2c13563529..b460c19b2e 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -11,33 +11,33 @@ void cX11Window::CreateXWindow(void) Atom wmProtocols[1]; // Setup window attributes - GLWin.attr.colormap = XCreateColormap(GLWin.evdpy, + GLWin.attr.colormap = XCreateColormap(GLWin.dpy, GLWin.parent, GLWin.vi->visual, AllocNone); GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask; - GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen); + GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen); GLWin.attr.border_pixel = 0; // Create the window - GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent, + GLWin.win = XCreateWindow(GLWin.dpy, GLWin.parent, 0, 0, 1, 1, 0, GLWin.vi->depth, InputOutput, GLWin.vi->visual, CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr); - wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True); - XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1); - XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, nullptr, 0, nullptr); - XMapRaised(GLWin.evdpy, GLWin.win); - XSync(GLWin.evdpy, True); + wmProtocols[0] = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True); + XSetWMProtocols(GLWin.dpy, GLWin.win, wmProtocols, 1); + XSetStandardProperties(GLWin.dpy, GLWin.win, "GPU", "GPU", None, nullptr, 0, nullptr); + XMapRaised(GLWin.dpy, GLWin.win); + XSync(GLWin.dpy, True); GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this); } void cX11Window::DestroyXWindow(void) { - XUnmapWindow(GLWin.evdpy, GLWin.win); + XUnmapWindow(GLWin.dpy, GLWin.win); GLWin.win = 0; if (GLWin.xEventThread.joinable()) GLWin.xEventThread.join(); - XFreeColormap(GLWin.evdpy, GLWin.attr.colormap); + XFreeColormap(GLWin.dpy, GLWin.attr.colormap); } void cX11Window::XEventThread() @@ -45,16 +45,16 @@ void cX11Window::XEventThread() while (GLWin.win) { XEvent event; - for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--) + for (int num_events = XPending(GLWin.dpy); num_events > 0; num_events--) { - XNextEvent(GLWin.evdpy, &event); + XNextEvent(GLWin.dpy, &event); switch (event.type) { case ConfigureNotify: GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); break; case ClientMessage: if ((unsigned long) event.xclient.data.l[0] == - XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", False)) + XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", False)) Host_Message(WM_USER_STOP); break; default: From 09eb30ea3bc37554bc6894b597b326731158bb86 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 00:34:31 -0400 Subject: [PATCH 04/19] MainNoGUI: Remove old OS X backend that doesn't work, rearchitect --- Source/Core/DolphinWX/MainNoGUI.cpp | 226 +++++++++++++++------------- 1 file changed, 118 insertions(+), 108 deletions(-) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 8c091a0391..2b966876e2 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -18,24 +18,26 @@ #include "Core/Core.h" #include "Core/CoreParameter.h" #include "Core/Host.h" +#include "Core/State.h" #include "Core/HW/Wiimote.h" #include "Core/PowerPC/PowerPC.h" #include "VideoCommon/VideoBackendBase.h" -#if HAVE_X11 -#include -#include "Core/State.h" -#include "DolphinWX/X11Utils.h" -#endif - -#ifdef __APPLE__ -#import -#endif - static bool rendererHasFocus = true; static bool running = true; +class Platform +{ +public: + virtual void Init() = 0; + virtual void MainLoop() = 0; + virtual void Shutdown() = 0; + virtual ~Platform() {}; +}; + +static Platform* platform; + void Host_NotifyMapLoaded() {} void Host_RefreshDSPDebuggerWindow() {} @@ -121,54 +123,67 @@ void Host_SetWiiMoteConnectionState(int _State) {} void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {} #if HAVE_X11 -static void X11_MainLoop() +#include +#include "DolphinWX/X11Utils.h" + +class PlatformX11 : public Platform { - bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; - while (!Core::IsRunning()) - updateMainFrameEvent.Wait(); - - Display *dpy = XOpenDisplay(0); - Window win = (Window)Core::GetWindowHandle(); - XSelectInput(dpy, win, KeyPressMask | FocusChangeMask); - - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver) - X11Utils::InhibitScreensaver(dpy, win, true); - -#if defined(HAVE_XRANDR) && HAVE_XRANDR - X11Utils::XRRConfiguration *XRRConfig = new X11Utils::XRRConfiguration(dpy, win); -#endif - + Display *dpy; Cursor blankCursor = None; - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) - { - // make a blank cursor - Pixmap Blank; - XColor DummyColor; - char ZeroData[1] = {0}; - Blank = XCreateBitmapFromData (dpy, win, ZeroData, 1, 1); - blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0); - XFreePixmap (dpy, Blank); - XDefineCursor(dpy, win, blankCursor); - } - - if (fullscreen) - { - X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE); #if defined(HAVE_XRANDR) && HAVE_XRANDR - XRRConfig->ToggleDisplayMode(True); + X11Utils::XRRConfiguration *XRRConfig; #endif + + void Init() override + { + XInitThreads(); + dpy = XOpenDisplay(NULL); } - // The actual loop - while (running) + void MainLoop() override { - XEvent event; - KeySym key; - for (int num_events = XPending(dpy); num_events > 0; num_events--) + Window win = (Window)Core::GetWindowHandle(); + XSelectInput(dpy, win, KeyPressMask | FocusChangeMask); + + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver) + X11Utils::InhibitScreensaver(dpy, win, true); + +#if defined(HAVE_XRANDR) && HAVE_XRANDR + XRRConfig = new X11Utils::XRRConfiguration(dpy, win); +#endif + + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) { - XNextEvent(dpy, &event); - switch (event.type) + // make a blank cursor + Pixmap Blank; + XColor DummyColor; + char ZeroData[1] = {0}; + Blank = XCreateBitmapFromData (dpy, win, ZeroData, 1, 1); + blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0); + XFreePixmap (dpy, Blank); + XDefineCursor(dpy, win, blankCursor); + } + + bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; + + if (fullscreen) + { + X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE); +#if defined(HAVE_XRANDR) && HAVE_XRANDR + XRRConfig->ToggleDisplayMode(True); +#endif + } + + // The actual loop + while (running) + { + XEvent event; + KeySym key; + for (int num_events = XPending(dpy); num_events > 0; num_events--) { + XNextEvent(dpy, &event); + switch (event.type) + { case KeyPress: key = XLookupKeysym((XKeyEvent*)&event, 0); if (key == XK_Escape) @@ -217,7 +232,7 @@ static void X11_MainLoop() case FocusIn: rendererHasFocus = true; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor && - Core::GetState() != Core::CORE_PAUSE) + Core::GetState() != Core::CORE_PAUSE) XDefineCursor(dpy, win, blankCursor); break; case FocusOut: @@ -225,44 +240,47 @@ static void X11_MainLoop() if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); break; + } } + if (!fullscreen) + { + Window winDummy; + unsigned int borderDummy, depthDummy; + XGetGeometry(dpy, win, &winDummy, + &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, + &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos, + (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, + (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, + &borderDummy, &depthDummy); + } + usleep(100000); } - if (!fullscreen) - { - Window winDummy; - unsigned int borderDummy, depthDummy; - XGetGeometry(dpy, win, &winDummy, - &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, - &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos, - (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, - (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, - &borderDummy, &depthDummy); - } - usleep(100000); } + void Shutdown() override + { #if defined(HAVE_XRANDR) && HAVE_XRANDR - delete XRRConfig; + delete XRRConfig; #endif - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver) - X11Utils::InhibitScreensaver(dpy, win, false); - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) - XFreeCursor(dpy, blankCursor); - XCloseDisplay(dpy); - Core::Stop(); -} + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) + XFreeCursor(dpy, blankCursor); + + XCloseDisplay(dpy); + } +}; #endif +static Platform* GetPlatform() +{ +#if HAVE_X11 + return new PlatformX11(); +#endif + return nullptr; +} + int main(int argc, char* argv[]) { -#ifdef __APPLE__ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEvent *event = [[NSEvent alloc] init]; - [NSApplication sharedApplication]; - [NSApp activateIgnoringOtherApps: YES]; - [NSApp finishLaunching]; -#endif int ch, help = 0; struct option longopts[] = { { "exec", no_argument, nullptr, 'e' }, @@ -298,6 +316,13 @@ int main(int argc, char* argv[]) return 1; } + platform = GetPlatform(); + if (!platform) + { + fprintf(stderr, "No platform found\n"); + return 1; + } + LogManager::Init(); SConfig::Init(); VideoBackend::PopulateList(); @@ -305,45 +330,30 @@ int main(int argc, char* argv[]) m_LocalCoreStartupParameter.m_strVideoBackend); WiimoteReal::LoadSettings(); - // No use running the loop when booting fails - if (BootManager::BootCore(argv[optind])) + platform->Init(); + + if (!BootManager::BootCore(argv[optind])) { -#if HAVE_X11 - XInitThreads(); - X11_MainLoop(); -#endif -#ifdef __APPLE__ - while (running) - { - event = [NSApp nextEventMatchingMask: NSAnyEventMask - untilDate: [NSDate distantFuture] - inMode: NSDefaultRunLoopMode dequeue: YES]; - - if ([event type] == NSKeyDown && - [event modifierFlags] & NSCommandKeyMask && - [[event characters] UTF8String][0] == 'q') - { - Core::Stop(); - break; - } - - if ([event type] != NSKeyDown) - [NSApp sendEvent: event]; - } - - [event release]; - [pool release]; -#else - while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) - updateMainFrameEvent.Wait(); -#endif + fprintf(stderr, "Could not boot %s\n", argv[optind]); + return 1; } + while (!Core::IsRunning()) + updateMainFrameEvent.Wait(); + + platform->MainLoop(); + Core::Stop(); + while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) + updateMainFrameEvent.Wait(); + + platform->Shutdown(); Core::Shutdown(); WiimoteReal::Shutdown(); VideoBackend::ClearList(); SConfig::Shutdown(); LogManager::Shutdown(); + delete platform; + return 0; } From 2eacf229edc78351a69739c587c46f93baed13da Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:16:28 -0400 Subject: [PATCH 05/19] X11Utils: Simplify the Fullscreen interface Since we only use the toggle action, only keep that. --- Source/Core/DolphinWX/MainNoGUI.cpp | 4 ++-- Source/Core/DolphinWX/X11Utils.cpp | 8 ++------ Source/Core/DolphinWX/X11Utils.h | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 2b966876e2..24d3875349 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -168,7 +168,7 @@ class PlatformX11 : public Platform if (fullscreen) { - X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE); + X11Utils::ToggleFullscreen(dpy); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(True); #endif @@ -204,7 +204,7 @@ class PlatformX11 : public Platform else if ((key == XK_Return) && (event.xkey.state & Mod1Mask)) { fullscreen = !fullscreen; - X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE); + X11Utils::ToggleFullscreen(dpy); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(fullscreen); #endif diff --git a/Source/Core/DolphinWX/X11Utils.cpp b/Source/Core/DolphinWX/X11Utils.cpp index b1e1ddb0ff..d011a03556 100644 --- a/Source/Core/DolphinWX/X11Utils.cpp +++ b/Source/Core/DolphinWX/X11Utils.cpp @@ -24,12 +24,8 @@ extern char **environ; namespace X11Utils { -void EWMH_Fullscreen(Display *dpy, int action) +void ToggleFullscreen(Display *dpy) { - _assert_(action == _NET_WM_STATE_REMOVE || - action == _NET_WM_STATE_ADD || - action == _NET_WM_STATE_TOGGLE); - Window win = (Window)Core::GetWindowHandle(); // Init X event structure for _NET_WM_STATE_FULLSCREEN client message @@ -38,7 +34,7 @@ void EWMH_Fullscreen(Display *dpy, int action) event.xclient.message_type = XInternAtom(dpy, "_NET_WM_STATE", False); event.xclient.window = win; event.xclient.format = 32; - event.xclient.data.l[0] = action; + event.xclient.data.l[0] = _NET_WM_STATE_TOGGLE; event.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); // Send the event diff --git a/Source/Core/DolphinWX/X11Utils.h b/Source/Core/DolphinWX/X11Utils.h index d0b5dc0292..461dfa470d 100644 --- a/Source/Core/DolphinWX/X11Utils.h +++ b/Source/Core/DolphinWX/X11Utils.h @@ -34,7 +34,7 @@ namespace X11Utils { -void EWMH_Fullscreen(Display *dpy, int action); +void ToggleFullscreen(Display *dpy); #if defined(HAVE_WX) && HAVE_WX Window XWindowFromHandle(void *Handle); Display *XDisplayFromHandle(void *Handle); From 071e175a1d1449e078d2279578dbe9a82dbcba93 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:17:21 -0400 Subject: [PATCH 06/19] X11Utils: Explicitly pass the window to fullscreen into ToggleFullscreen MainNoGUI is going to create its own window soon, and we need to fullscreen that one instead of the GLX window. --- Source/Core/DolphinWX/MainNoGUI.cpp | 4 ++-- Source/Core/DolphinWX/X11Utils.cpp | 4 +--- Source/Core/DolphinWX/X11Utils.h | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 24d3875349..4f8d98d110 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -168,7 +168,7 @@ class PlatformX11 : public Platform if (fullscreen) { - X11Utils::ToggleFullscreen(dpy); + X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(True); #endif @@ -204,7 +204,7 @@ class PlatformX11 : public Platform else if ((key == XK_Return) && (event.xkey.state & Mod1Mask)) { fullscreen = !fullscreen; - X11Utils::ToggleFullscreen(dpy); + X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(fullscreen); #endif diff --git a/Source/Core/DolphinWX/X11Utils.cpp b/Source/Core/DolphinWX/X11Utils.cpp index d011a03556..0072a740cd 100644 --- a/Source/Core/DolphinWX/X11Utils.cpp +++ b/Source/Core/DolphinWX/X11Utils.cpp @@ -24,10 +24,8 @@ extern char **environ; namespace X11Utils { -void ToggleFullscreen(Display *dpy) +void ToggleFullscreen(Display *dpy, Window win) { - Window win = (Window)Core::GetWindowHandle(); - // Init X event structure for _NET_WM_STATE_FULLSCREEN client message XEvent event; event.xclient.type = ClientMessage; diff --git a/Source/Core/DolphinWX/X11Utils.h b/Source/Core/DolphinWX/X11Utils.h index 461dfa470d..b68a1babe6 100644 --- a/Source/Core/DolphinWX/X11Utils.h +++ b/Source/Core/DolphinWX/X11Utils.h @@ -34,7 +34,7 @@ namespace X11Utils { -void ToggleFullscreen(Display *dpy); +void ToggleFullscreen(Display *dpy, Window win); #if defined(HAVE_WX) && HAVE_WX Window XWindowFromHandle(void *Handle); Display *XDisplayFromHandle(void *Handle); From 0dd7f6f5ea816db6dbaf9d7ed424ddb8a58e0847 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:11:50 -0400 Subject: [PATCH 07/19] MainNoGUI: Supply a window in Host_GetRenderHandle Our existing code was relying on the GLX backend to create the GLX window properly, and for the rest of the code to patch that up, sort of. If we rely on Host_GetRenderHandle() returning a valid window, we can do a lot better about this. Create a simple window inside MainNoGUI to make this happen. --- Source/Core/DolphinWX/GLInterface/GLX.cpp | 2 -- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 3 +-- Source/Core/DolphinWX/MainNoGUI.cpp | 20 ++++++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index 022efda2cb..c7eb3eb239 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -67,8 +67,6 @@ bool cInterfaceGLX::Create(void *&window_handle) GLWin.dpy = XOpenDisplay(nullptr); GLWin.parent = (Window)window_handle; GLWin.screen = DefaultScreen(GLWin.dpy); - if (GLWin.parent == 0) - GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen); glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion); NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion); diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index b460c19b2e..610fd67949 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -13,7 +13,7 @@ void cX11Window::CreateXWindow(void) // Setup window attributes GLWin.attr.colormap = XCreateColormap(GLWin.dpy, GLWin.parent, GLWin.vi->visual, AllocNone); - GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask; + GLWin.attr.event_mask = StructureNotifyMask; GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen); GLWin.attr.border_pixel = 0; @@ -24,7 +24,6 @@ void cX11Window::CreateXWindow(void) CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr); wmProtocols[0] = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True); XSetWMProtocols(GLWin.dpy, GLWin.win, wmProtocols, 1); - XSetStandardProperties(GLWin.dpy, GLWin.win, "GPU", "GPU", None, nullptr, 0, nullptr); XMapRaised(GLWin.dpy, GLWin.win); XSync(GLWin.dpy, True); diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 4f8d98d110..74e9cc00a0 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -52,9 +52,10 @@ void Host_Message(int Id) } } +void* windowHandle; void* Host_GetRenderHandle() { - return nullptr; + return windowHandle; } void Host_UpdateTitle(const std::string& title){}; @@ -129,6 +130,7 @@ void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {} class PlatformX11 : public Platform { Display *dpy; + Window win; Cursor blankCursor = None; #if defined(HAVE_XRANDR) && HAVE_XRANDR X11Utils::XRRConfiguration *XRRConfig; @@ -138,12 +140,17 @@ class PlatformX11 : public Platform { XInitThreads(); dpy = XOpenDisplay(NULL); - } - void MainLoop() override - { - Window win = (Window)Core::GetWindowHandle(); + win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), + SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, + SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos, + SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, + SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, + 0, 0, BlackPixel(dpy, 0)); XSelectInput(dpy, win, KeyPressMask | FocusChangeMask); + XMapRaised(dpy, win); + XFlush(dpy); + windowHandle = (void *) win; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver) X11Utils::InhibitScreensaver(dpy, win, true); @@ -163,7 +170,10 @@ class PlatformX11 : public Platform XFreePixmap (dpy, Blank); XDefineCursor(dpy, win, blankCursor); } + } + void MainLoop() override + { bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; if (fullscreen) From d6f4f4df421cc1c8fe06ef345f65826d5cc7815d Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 14:58:34 -0400 Subject: [PATCH 08/19] MainNoGUI: Move a majority of the event handling from the GLX backend The only reason the GLX backend handled this at all was because MainNoGUI didn't make its own window before. This is unused in DolphinWX builds. --- Source/Core/DolphinWX/GLInterface/X11_Util.cpp | 11 +---------- Source/Core/DolphinWX/MainNoGUI.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 610fd67949..79d0d76b8b 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -8,8 +8,6 @@ void cX11Window::CreateXWindow(void) { - Atom wmProtocols[1]; - // Setup window attributes GLWin.attr.colormap = XCreateColormap(GLWin.dpy, GLWin.parent, GLWin.vi->visual, AllocNone); @@ -22,9 +20,7 @@ void cX11Window::CreateXWindow(void) 0, 0, 1, 1, 0, GLWin.vi->depth, InputOutput, GLWin.vi->visual, CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr); - wmProtocols[0] = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True); - XSetWMProtocols(GLWin.dpy, GLWin.win, wmProtocols, 1); - XMapRaised(GLWin.dpy, GLWin.win); + XMapWindow(GLWin.dpy, GLWin.win); XSync(GLWin.dpy, True); GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this); @@ -51,11 +47,6 @@ void cX11Window::XEventThread() case ConfigureNotify: GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); break; - case ClientMessage: - if ((unsigned long) event.xclient.data.l[0] == - XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", False)) - Host_Message(WM_USER_STOP); - break; default: break; } diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 74e9cc00a0..9231b3ef3a 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -148,6 +148,9 @@ class PlatformX11 : public Platform SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, 0, 0, BlackPixel(dpy, 0)); XSelectInput(dpy, win, KeyPressMask | FocusChangeMask); + Atom wmProtocols[1]; + wmProtocols[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", True); + XSetWMProtocols(dpy, win, wmProtocols, 1); XMapRaised(dpy, win); XFlush(dpy); windowHandle = (void *) win; @@ -250,6 +253,10 @@ class PlatformX11 : public Platform if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); break; + case ClientMessage: + if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False)) + running = false; + break; } } if (!fullscreen) From e7471958e42791ed88afcf2eb951de6c66d3ec40 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:22:13 -0400 Subject: [PATCH 09/19] X11_Util: Resize the GLX window by listening to events on the parent We now have two cases: the GLX window is parented into a frame, or it's parented into the MainNoGUI host. In both cases, the GLX window should be locked to the size of the parent, so just sync it up based on that. --- Source/Core/DolphinWX/FrameTools.cpp | 7 ------- Source/Core/DolphinWX/GLInterface/X11_Util.cpp | 5 +++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 04f2e4dd1e..039b6370a3 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -840,13 +840,6 @@ void CFrame::OnRenderParentResize(wxSizeEvent& event) SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth = width; SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight = height; } -#if defined(HAVE_X11) && HAVE_X11 - wxRect client_rect = m_RenderParent->GetClientRect(); - XMoveResizeWindow(X11Utils::XDisplayFromHandle(GetHandle()), - (Window) Core::GetWindowHandle(), - client_rect.x, client_rect.y, - client_rect.width, client_rect.height); -#endif m_LogWindow->Refresh(); m_LogWindow->Update(); } diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 79d0d76b8b..21096fbb1a 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -11,7 +11,6 @@ void cX11Window::CreateXWindow(void) // Setup window attributes GLWin.attr.colormap = XCreateColormap(GLWin.dpy, GLWin.parent, GLWin.vi->visual, AllocNone); - GLWin.attr.event_mask = StructureNotifyMask; GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen); GLWin.attr.border_pixel = 0; @@ -19,7 +18,8 @@ void cX11Window::CreateXWindow(void) GLWin.win = XCreateWindow(GLWin.dpy, GLWin.parent, 0, 0, 1, 1, 0, GLWin.vi->depth, InputOutput, GLWin.vi->visual, - CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr); + CWBorderPixel | CWBackPixel | CWColormap, &GLWin.attr); + XSelectInput(GLWin.dpy, GLWin.parent, StructureNotifyMask); XMapWindow(GLWin.dpy, GLWin.win); XSync(GLWin.dpy, True); @@ -45,6 +45,7 @@ void cX11Window::XEventThread() XNextEvent(GLWin.dpy, &event); switch (event.type) { case ConfigureNotify: + XResizeWindow(GLWin.dpy, GLWin.win, event.xconfigure.width, event.xconfigure.height); GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); break; default: From e2e3f2a20bb3667fc0830e2d0f63af2ddf71cd54 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 10:23:28 -0400 Subject: [PATCH 10/19] EGL: Stop the window_handle shuffling as well --- Source/Core/DolphinWX/GLInterface/EGL.cpp | 9 ++++----- Source/Core/DolphinWX/GLInterface/GLInterface.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index 2c124332cf..b36aed38a5 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -156,9 +156,11 @@ bool cInterfaceEGL::Create(void *&window_handle) else eglBindAPI(EGL_OPENGL_ES_API); + EGLNativeWindowType native_window = window_handle; + EGLint format; eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry((EGLNativeWindowType)Host_GetRenderHandle(), 0, 0, format); + ANativeWindow_setBuffersGeometry(native_window, 0, 0, format); int none, width, height; Host_GetRenderWindowSize(none, none, width, height); GLWin.width = width; @@ -184,16 +186,13 @@ bool cInterfaceEGL::Create(void *&window_handle) exit(1); } - GLWin.native_window = Host_GetRenderHandle(); - - GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, GLWin.native_window, nullptr); + GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, native_window, nullptr); if (!GLWin.egl_surf) { INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n"); exit(1); } - window_handle = (void *)GLWin.native_window; return true; } diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h index bcd0286f41..ee894b34dc 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.h @@ -24,7 +24,6 @@ typedef struct { EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; - EGLNativeWindowType native_window; #elif defined(__APPLE__) NSView *cocoaWin; NSOpenGLContext *cocoaCtx; From 6e312dce91f3b5cbb895f2d60d7eea294fdbc2d5 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:24:08 -0400 Subject: [PATCH 11/19] Core: Remove Core::GetWindowHandle Finally, it's unused. Whoa. --- Source/Core/Core/Core.cpp | 5 ----- Source/Core/Core/Core.h | 3 --- Source/Core/DolphinWX/Frame.cpp | 8 -------- Source/Core/DolphinWX/FrameTools.cpp | 12 ------------ 4 files changed, 28 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 91a2299afd..b37ac0a3e6 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -138,11 +138,6 @@ void DisplayMessage(const std::string& message, int time_in_ms) } } -void *GetWindowHandle() -{ - return g_pWindowHandle; -} - bool IsRunning() { return (GetState() != CORE_UNINITIALIZED) || g_bHwInit; diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index 1a079ac8ed..4e8918e44e 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -59,9 +59,6 @@ void SaveScreenShot(); void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); -void* GetWindowHandle(); - - // This displays messages in a user-visible way. void DisplayMessage(const std::string& message, int time_in_ms); diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index e9edc83517..b710ba07cb 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -2,14 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. - -// CFrame is the main parent window. Inside CFrame there is an m_Panel that is -// the parent for the rendering window (when we render to the main window). In -// Windows the rendering window is created by giving CreateWindow() -// m_Panel->GetHandle() as parent window and creating a new child window to -// m_Panel. The new child window handle that is returned by CreateWindow() can -// be accessed from Core::GetWindowHandle(). - #ifdef __APPLE__ #include #endif diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 039b6370a3..a9334686fc 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -2,18 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. - -/* -1.1 Windows - -CFrame is the main parent window. Inside CFrame there is m_Panel which is the -parent for the rendering window (when we render to the main window). In Windows -the rendering window is created by giving CreateWindow() m_Panel->GetHandle() -as parent window and creating a new child window to m_Panel. The new child -window handle that is returned by CreateWindow() can be accessed from -Core::GetWindowHandle(). -*/ - #include #include #include From 7ca8d8dfc7e9bf3b09f9cab929c98f9e607c298b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 00:44:21 -0400 Subject: [PATCH 12/19] Core: Don't pass through a reference to the window handle Now that MainNoGUI is properly architected and GLX doesn't need to sometimes craft its own windows sometimes which we have to thread back into MainNoGUI, we don't need to thread the window handle that GLX creates at all. This removes the reference to pass back here, and the g_pWindowHandle always be the same as the window returned by Host_GetRenderHandle(). A future cleanup could remove g_pWindowHandle entirely. --- Source/Core/Core/Core.cpp | 3 --- Source/Core/DolphinWX/GLInterface/AGL.cpp | 2 +- Source/Core/DolphinWX/GLInterface/AGL.h | 2 +- Source/Core/DolphinWX/GLInterface/EGL.cpp | 2 +- Source/Core/DolphinWX/GLInterface/EGL.h | 2 +- Source/Core/DolphinWX/GLInterface/GLX.cpp | 3 +-- Source/Core/DolphinWX/GLInterface/GLX.h | 2 +- Source/Core/DolphinWX/GLInterface/WGL.cpp | 2 +- Source/Core/DolphinWX/GLInterface/WGL.h | 2 +- Source/Core/DolphinWX/MainNoGUI.cpp | 11 ++++++++++- Source/Core/VideoBackends/D3D/VideoBackend.h | 2 +- Source/Core/VideoBackends/D3D/main.cpp | 2 +- Source/Core/VideoBackends/OGL/GLInterfaceBase.h | 2 +- Source/Core/VideoBackends/OGL/VideoBackend.h | 2 +- Source/Core/VideoBackends/OGL/main.cpp | 2 +- Source/Core/VideoBackends/Software/SWmain.cpp | 2 +- Source/Core/VideoBackends/Software/VideoBackend.h | 2 +- Source/Core/VideoCommon/VideoBackendBase.h | 2 +- 18 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index b37ac0a3e6..16ae870ae8 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -208,9 +208,6 @@ bool Init() !!SConfig::GetInstance().m_SYSCONF->GetData("IPL.AR")); } - // g_pWindowHandle is first the m_Panel handle, - // then it is updated to the render window handle, - // within g_video_backend->Initialize() g_pWindowHandle = Host_GetRenderHandle(); // Start the emu thread diff --git a/Source/Core/DolphinWX/GLInterface/AGL.cpp b/Source/Core/DolphinWX/GLInterface/AGL.cpp index 1abb97019d..6f79a8bec0 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/AGL.cpp @@ -16,7 +16,7 @@ void cInterfaceAGL::Swap() // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -bool cInterfaceAGL::Create(void *&window_handle) +bool cInterfaceAGL::Create(void *window_handle) { // FIXME: Get rid of the explicit use of wxPanel here. This shouldn't be necessary. GLWin.cocoaWin = reinterpret_cast(((wxPanel*)window_handle)->GetHandle()); diff --git a/Source/Core/DolphinWX/GLInterface/AGL.h b/Source/Core/DolphinWX/GLInterface/AGL.h index 490691338d..7def0dd2d2 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.h +++ b/Source/Core/DolphinWX/GLInterface/AGL.h @@ -14,7 +14,7 @@ class cInterfaceAGL : public cInterfaceBase { public: void Swap(); - bool Create(void *&window_handle); + bool Create(void *window_handle); bool MakeCurrent(); bool ClearCurrent(); void Shutdown(); diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index b36aed38a5..8c58e9432e 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -87,7 +87,7 @@ err_exit: // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -bool cInterfaceEGL::Create(void *&window_handle) +bool cInterfaceEGL::Create(void *window_handle) { const char *s; EGLint egl_major, egl_minor; diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index bcf5d8cd75..63772f192b 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -20,7 +20,7 @@ public: void SetMode(u32 mode) { s_opengl_mode = mode; } void UpdateFPSDisplay(const std::string& text); void* GetFuncAddress(const std::string& name); - bool Create(void *&window_handle); + bool Create(void *window_handle); bool MakeCurrent(); void Shutdown(); }; diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index c7eb3eb239..69c376f4f2 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -37,7 +37,7 @@ void cInterfaceGLX::Swap() // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -bool cInterfaceGLX::Create(void *&window_handle) +bool cInterfaceGLX::Create(void *window_handle) { int glxMajorVersion, glxMinorVersion; @@ -102,7 +102,6 @@ bool cInterfaceGLX::Create(void *&window_handle) } XWindow.CreateXWindow(); - window_handle = (void *)GLWin.win; return true; } diff --git a/Source/Core/DolphinWX/GLInterface/GLX.h b/Source/Core/DolphinWX/GLInterface/GLX.h index 1ded9ec331..f48e27de79 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.h +++ b/Source/Core/DolphinWX/GLInterface/GLX.h @@ -19,7 +19,7 @@ public: void Swap() override; void UpdateFPSDisplay(const std::string& text) override; void* GetFuncAddress(const std::string& name) override; - bool Create(void *&window_handle) override; + bool Create(void *window_handle); bool MakeCurrent() override; bool ClearCurrent() override; void Shutdown() override; diff --git a/Source/Core/DolphinWX/GLInterface/WGL.cpp b/Source/Core/DolphinWX/GLInterface/WGL.cpp index 39e18f9105..295d21a2bc 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/WGL.cpp @@ -63,7 +63,7 @@ void cInterfaceWGL::UpdateFPSDisplay(const std::string& text) // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -bool cInterfaceWGL::Create(void *&window_handle) +bool cInterfaceWGL::Create(void *window_handle) { if (window_handle == nullptr) return false; diff --git a/Source/Core/DolphinWX/GLInterface/WGL.h b/Source/Core/DolphinWX/GLInterface/WGL.h index e3bea0b044..3c9c7373fa 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.h +++ b/Source/Core/DolphinWX/GLInterface/WGL.h @@ -14,7 +14,7 @@ public: void Swap(); void UpdateFPSDisplay(const std::string& text); void* GetFuncAddress(const std::string& name); - bool Create(void *&window_handle); + bool Create(void *window_handle); bool MakeCurrent(); bool ClearCurrent(); void Shutdown(); diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 9231b3ef3a..cca5d6ffb8 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -31,6 +31,7 @@ class Platform { public: virtual void Init() = 0; + virtual void SetTitle(const std::string &title) = 0; virtual void MainLoop() = 0; virtual void Shutdown() = 0; virtual ~Platform() {}; @@ -58,7 +59,10 @@ void* Host_GetRenderHandle() return windowHandle; } -void Host_UpdateTitle(const std::string& title){}; +void Host_UpdateTitle(const std::string& title) +{ + platform->SetTitle(title); +} void Host_UpdateDisasmDialog(){} @@ -175,6 +179,11 @@ class PlatformX11 : public Platform } } + void SetTitle(const std::string &string) override + { + XStoreName(dpy, win, string.c_str()); + } + void MainLoop() override { bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; diff --git a/Source/Core/VideoBackends/D3D/VideoBackend.h b/Source/Core/VideoBackends/D3D/VideoBackend.h index fd58ab1ff4..4f529ff9f0 100644 --- a/Source/Core/VideoBackends/D3D/VideoBackend.h +++ b/Source/Core/VideoBackends/D3D/VideoBackend.h @@ -8,7 +8,7 @@ namespace DX11 class VideoBackend : public VideoBackendHardware { - bool Initialize(void *&) override; + bool Initialize(void *) override; void Shutdown() override; std::string GetName() const override; diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index 42c492b793..4bbaa894d7 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -141,7 +141,7 @@ void VideoBackend::ShowConfig(void *hParent) Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_dx11"); } -bool VideoBackend::Initialize(void *&window_handle) +bool VideoBackend::Initialize(void *window_handle) { if (window_handle == nullptr) return false; diff --git a/Source/Core/VideoBackends/OGL/GLInterfaceBase.h b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h index bfddeb0c70..70a4cf56e7 100644 --- a/Source/Core/VideoBackends/OGL/GLInterfaceBase.h +++ b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h @@ -29,7 +29,7 @@ public: virtual void SetMode(u32 mode) { s_opengl_mode = GLInterfaceMode::MODE_OPENGL; } virtual u32 GetMode() { return s_opengl_mode; } virtual void* GetFuncAddress(const std::string& name) { return nullptr; } - virtual bool Create(void *&window_handle) { return true; } + virtual bool Create(void *window_handle) { return true; } virtual bool MakeCurrent() { return true; } virtual bool ClearCurrent() { return true; } virtual void Shutdown() {} diff --git a/Source/Core/VideoBackends/OGL/VideoBackend.h b/Source/Core/VideoBackends/OGL/VideoBackend.h index 3a8aed0dd4..ab043395f6 100644 --- a/Source/Core/VideoBackends/OGL/VideoBackend.h +++ b/Source/Core/VideoBackends/OGL/VideoBackend.h @@ -8,7 +8,7 @@ namespace OGL class VideoBackend : public VideoBackendHardware { - bool Initialize(void *&) override; + bool Initialize(void *) override; void Shutdown() override; std::string GetName() const override; diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index c40704d049..1a378eb74f 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -155,7 +155,7 @@ void VideoBackend::ShowConfig(void *_hParent) Host_ShowVideoConfig(_hParent, GetDisplayName(), "gfx_opengl"); } -bool VideoBackend::Initialize(void *&window_handle) +bool VideoBackend::Initialize(void *window_handle) { InitializeShared(); InitBackendInfo(); diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index 4892daeeee..4d4784b61d 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -71,7 +71,7 @@ void VideoSoftware::ShowConfig(void *hParent) Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_software"); } -bool VideoSoftware::Initialize(void *&window_handle) +bool VideoSoftware::Initialize(void *window_handle) { g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str()); diff --git a/Source/Core/VideoBackends/Software/VideoBackend.h b/Source/Core/VideoBackends/Software/VideoBackend.h index dbfe1c7cab..19c555632e 100644 --- a/Source/Core/VideoBackends/Software/VideoBackend.h +++ b/Source/Core/VideoBackends/Software/VideoBackend.h @@ -10,7 +10,7 @@ namespace SW class VideoSoftware : public VideoBackend { - bool Initialize(void *&) override; + bool Initialize(void *window_handle) override; void Shutdown() override; std::string GetName() const override; diff --git a/Source/Core/VideoCommon/VideoBackendBase.h b/Source/Core/VideoCommon/VideoBackendBase.h index 7bcbbfef0f..5c361e8115 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.h +++ b/Source/Core/VideoCommon/VideoBackendBase.h @@ -72,7 +72,7 @@ public: virtual unsigned int PeekMessages() = 0; - virtual bool Initialize(void *&) = 0; + virtual bool Initialize(void *window_handle) = 0; virtual void Shutdown() = 0; virtual void RunLoop(bool enable) = 0; From 63f1a169696a9b9b519f3be4ee47ee7253f645a7 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 6 Aug 2014 22:38:39 -0400 Subject: [PATCH 13/19] Core: Remove UpdateFPSDisplay This is effectively unused, as the window handles that we pass to the GLInterface are window handles for the frame which isn't ever a real toplevel window. Host_UpdateTitle is what actually sets the proper title on the render window. --- Source/Core/Core/Core.cpp | 3 --- Source/Core/DolphinWX/GLInterface/EGL.cpp | 3 --- Source/Core/DolphinWX/GLInterface/EGL.h | 1 - Source/Core/DolphinWX/GLInterface/GLX.cpp | 6 ------ Source/Core/DolphinWX/GLInterface/GLX.h | 1 - Source/Core/DolphinWX/GLInterface/WGL.cpp | 6 ------ Source/Core/DolphinWX/GLInterface/WGL.h | 1 - Source/Core/VideoBackends/D3D/VideoBackend.h | 1 - Source/Core/VideoBackends/D3D/main.cpp | 6 ------ Source/Core/VideoBackends/OGL/GLInterfaceBase.h | 1 - Source/Core/VideoBackends/OGL/GLUtil.cpp | 6 ------ Source/Core/VideoBackends/OGL/VideoBackend.h | 1 - Source/Core/VideoBackends/Software/SWmain.cpp | 6 ------ Source/Core/VideoBackends/Software/VideoBackend.h | 1 - Source/Core/VideoCommon/Debugger.cpp | 4 ---- Source/Core/VideoCommon/VideoBackendBase.h | 2 -- 16 files changed, 49 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 16ae870ae8..a72115de56 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -694,9 +694,6 @@ void UpdateTitle() std::string SMessage = StringFromFormat("%s | %s", SSettings.c_str(), SFPS.c_str()); std::string TMessage = StringFromFormat("%s | %s", scm_rev_str, SMessage.c_str()); - // Show message - g_video_backend->UpdateFPSDisplay(SMessage); - // Update the audio timestretcher with the current speed if (soundStream) { diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index 8c58e9432e..b6b52ead0a 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -7,9 +7,6 @@ #include "VideoCommon/RenderBase.h" // Show the current FPS -void cInterfaceEGL::UpdateFPSDisplay(const std::string& text) -{ -} void cInterfaceEGL::Swap() { eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 63772f192b..480029419a 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -18,7 +18,6 @@ public: void SwapInterval(int Interval); void Swap(); void SetMode(u32 mode) { s_opengl_mode = mode; } - void UpdateFPSDisplay(const std::string& text); void* GetFuncAddress(const std::string& name); bool Create(void *window_handle); bool MakeCurrent(); diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index 69c376f4f2..0365e5d8b9 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -12,12 +12,6 @@ typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval); static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; -// Show the current FPS -void cInterfaceGLX::UpdateFPSDisplay(const std::string& text) -{ - XStoreName(GLWin.dpy, GLWin.win, text.c_str()); -} - void cInterfaceGLX::SwapInterval(int Interval) { if (glXSwapIntervalSGI) diff --git a/Source/Core/DolphinWX/GLInterface/GLX.h b/Source/Core/DolphinWX/GLInterface/GLX.h index f48e27de79..2e811fd323 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.h +++ b/Source/Core/DolphinWX/GLInterface/GLX.h @@ -17,7 +17,6 @@ public: friend class cX11Window; void SwapInterval(int Interval) override; void Swap() override; - void UpdateFPSDisplay(const std::string& text) override; void* GetFuncAddress(const std::string& name) override; bool Create(void *window_handle); bool MakeCurrent() override; diff --git a/Source/Core/DolphinWX/GLInterface/WGL.cpp b/Source/Core/DolphinWX/GLInterface/WGL.cpp index 295d21a2bc..5783999274 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/WGL.cpp @@ -55,12 +55,6 @@ bool cInterfaceWGL::PeekMessages() return TRUE; } -// Show the current FPS -void cInterfaceWGL::UpdateFPSDisplay(const std::string& text) -{ - SetWindowTextA(m_window_handle, text.c_str()); -} - // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() bool cInterfaceWGL::Create(void *window_handle) diff --git a/Source/Core/DolphinWX/GLInterface/WGL.h b/Source/Core/DolphinWX/GLInterface/WGL.h index 3c9c7373fa..ea0c22c9d1 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.h +++ b/Source/Core/DolphinWX/GLInterface/WGL.h @@ -12,7 +12,6 @@ class cInterfaceWGL : public cInterfaceBase public: void SwapInterval(int Interval); void Swap(); - void UpdateFPSDisplay(const std::string& text); void* GetFuncAddress(const std::string& name); bool Create(void *window_handle); bool MakeCurrent(); diff --git a/Source/Core/VideoBackends/D3D/VideoBackend.h b/Source/Core/VideoBackends/D3D/VideoBackend.h index 4f529ff9f0..d28f1b545f 100644 --- a/Source/Core/VideoBackends/D3D/VideoBackend.h +++ b/Source/Core/VideoBackends/D3D/VideoBackend.h @@ -19,7 +19,6 @@ class VideoBackend : public VideoBackendHardware void ShowConfig(void* parent) override; - void UpdateFPSDisplay(const std::string&) override; unsigned int PeekMessages() override; void* m_window_handle; diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index 4bbaa894d7..38edd04668 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -51,12 +51,6 @@ unsigned int VideoBackend::PeekMessages() return TRUE; } -void VideoBackend::UpdateFPSDisplay(const std::string& text) -{ - std::string str = StringFromFormat("%s | D3D | %s", scm_rev_str, text.c_str()); - SetWindowTextA((HWND)m_window_handle, str.c_str()); -} - std::string VideoBackend::GetName() const { return "D3D"; diff --git a/Source/Core/VideoBackends/OGL/GLInterfaceBase.h b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h index 70a4cf56e7..b274182042 100644 --- a/Source/Core/VideoBackends/OGL/GLInterfaceBase.h +++ b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h @@ -25,7 +25,6 @@ protected: u32 s_opengl_mode; public: virtual void Swap() {} - virtual void UpdateFPSDisplay(const std::string& text) {} virtual void SetMode(u32 mode) { s_opengl_mode = GLInterfaceMode::MODE_OPENGL; } virtual u32 GetMode() { return s_opengl_mode; } virtual void* GetFuncAddress(const std::string& name) { return nullptr; } diff --git a/Source/Core/VideoBackends/OGL/GLUtil.cpp b/Source/Core/VideoBackends/OGL/GLUtil.cpp index e0eb748019..d2ffdaf803 100644 --- a/Source/Core/VideoBackends/OGL/GLUtil.cpp +++ b/Source/Core/VideoBackends/OGL/GLUtil.cpp @@ -26,12 +26,6 @@ unsigned int VideoBackend::PeekMessages() return GLInterface->PeekMessages(); } -// Show the current FPS -void VideoBackend::UpdateFPSDisplay(const std::string& text) -{ - return GLInterface->UpdateFPSDisplay(StringFromFormat("%s | %s | %s", scm_rev_str, GetDisplayName().c_str(), text.c_str())); -} - } void InitInterface() { diff --git a/Source/Core/VideoBackends/OGL/VideoBackend.h b/Source/Core/VideoBackends/OGL/VideoBackend.h index ab043395f6..28ac91c848 100644 --- a/Source/Core/VideoBackends/OGL/VideoBackend.h +++ b/Source/Core/VideoBackends/OGL/VideoBackend.h @@ -19,7 +19,6 @@ class VideoBackend : public VideoBackendHardware void ShowConfig(void* parent) override; - void UpdateFPSDisplay(const std::string&) override; unsigned int PeekMessages() override; }; diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index 4d4784b61d..7cbc278029 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -372,10 +372,4 @@ unsigned int VideoSoftware::PeekMessages() return GLInterface->PeekMessages(); } -// Show the current FPS -void VideoSoftware::UpdateFPSDisplay(const std::string& text) -{ - GLInterface->UpdateFPSDisplay(StringFromFormat("%s | Software | %s", scm_rev_str, text.c_str())); -} - } diff --git a/Source/Core/VideoBackends/Software/VideoBackend.h b/Source/Core/VideoBackends/Software/VideoBackend.h index 19c555632e..4ade7bed9a 100644 --- a/Source/Core/VideoBackends/Software/VideoBackend.h +++ b/Source/Core/VideoBackends/Software/VideoBackend.h @@ -48,7 +48,6 @@ class VideoSoftware : public VideoBackend void RegisterCPMMIO(MMIO::Mapping* mmio, u32 base) override; - void UpdateFPSDisplay(const std::string&) override; unsigned int PeekMessages() override; void PauseAndLock(bool doLock, bool unpauseOnUnlock=true) override; diff --git a/Source/Core/VideoCommon/Debugger.cpp b/Source/Core/VideoCommon/Debugger.cpp index b5dcca740f..41e263c1e1 100644 --- a/Source/Core/VideoCommon/Debugger.cpp +++ b/Source/Core/VideoCommon/Debugger.cpp @@ -14,8 +14,6 @@ #include "VideoCommon/VertexShaderGen.h" #include "VideoCommon/VideoConfig.h" -//void UpdateFPSDisplay(const char *text); - GFXDebuggerBase *g_pdebugger = nullptr; volatile bool GFXDebuggerPauseFlag = false; // if true, the GFX thread will be spin locked until it's false again volatile PauseEvent GFXDebuggerToPauseAtNext = NOT_PAUSE; // Event which will trigger spin locking the GFX thread @@ -57,8 +55,6 @@ void GFXDebuggerCheckAndPause(bool update) g_pdebugger->OnPause(); while ( GFXDebuggerPauseFlag ) { - g_video_backend->UpdateFPSDisplay("Paused by Video Debugger"); - if (update) GFXDebuggerUpdateScreen(); SLEEP(5); } diff --git a/Source/Core/VideoCommon/VideoBackendBase.h b/Source/Core/VideoCommon/VideoBackendBase.h index 5c361e8115..b1fe931888 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.h +++ b/Source/Core/VideoCommon/VideoBackendBase.h @@ -68,8 +68,6 @@ public: virtual void EmuStateChange(EMUSTATE_CHANGE) = 0; - virtual void UpdateFPSDisplay(const std::string&) = 0; - virtual unsigned int PeekMessages() = 0; virtual bool Initialize(void *window_handle) = 0; From 2d974b60864e0917881d687e29a328c032888a03 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 09:49:45 -0400 Subject: [PATCH 14/19] GLInterface: Destroy GLWin Everything is now safely tucked inside each individual GLInterface. --- .../Core/DolphinWX/Android/ButtonManager.cpp | 4 +- Source/Core/DolphinWX/DolphinWX.vcxproj | 3 +- .../Core/DolphinWX/DolphinWX.vcxproj.filters | 1 - Source/Core/DolphinWX/GLInterface/AGL.cpp | 39 ++++++------ Source/Core/DolphinWX/GLInterface/AGL.h | 3 + Source/Core/DolphinWX/GLInterface/EGL.cpp | 59 +++++++++---------- Source/Core/DolphinWX/GLInterface/EGL.h | 3 + .../DolphinWX/GLInterface/GLInterface.cpp | 13 +++- .../Core/DolphinWX/GLInterface/GLInterface.h | 42 ------------- Source/Core/DolphinWX/GLInterface/GLX.cpp | 44 +++++++------- Source/Core/DolphinWX/GLInterface/GLX.h | 5 ++ Source/Core/DolphinWX/GLInterface/WGL.cpp | 2 +- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 57 ++++++++++-------- Source/Core/DolphinWX/GLInterface/X11_Util.h | 9 ++- .../ControllerInterface.cpp | 4 -- 15 files changed, 141 insertions(+), 147 deletions(-) delete mode 100644 Source/Core/DolphinWX/GLInterface/GLInterface.h diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index c6d70f3c5e..8d6d241a36 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -4,8 +4,10 @@ #include +#include "Common/FileUtil.h" +#include "Common/IniFile.h" +#include "Common/Thread.h" #include "DolphinWX/Android/ButtonManager.h" -#include "DolphinWX/GLInterface/GLInterface.h" namespace ButtonManager { diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index 4f2b7cb0e0..c6b38f7f9b 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -1,4 +1,4 @@ - + @@ -100,7 +100,6 @@ - diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters index e9aa9317c1..e85ffbb88c 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters @@ -282,7 +282,6 @@ GUI - GUI\Video diff --git a/Source/Core/DolphinWX/GLInterface/AGL.cpp b/Source/Core/DolphinWX/GLInterface/AGL.cpp index 6f79a8bec0..c82ea0bc2c 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/AGL.cpp @@ -4,14 +4,15 @@ #include -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/AGL.h" + #include "VideoCommon/RenderBase.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoConfig.h" void cInterfaceAGL::Swap() { - [GLWin.cocoaCtx flushBuffer]; + [cocoaCtx flushBuffer]; } // Create rendering window. @@ -19,13 +20,13 @@ void cInterfaceAGL::Swap() bool cInterfaceAGL::Create(void *window_handle) { // FIXME: Get rid of the explicit use of wxPanel here. This shouldn't be necessary. - GLWin.cocoaWin = reinterpret_cast(((wxPanel*)window_handle)->GetHandle()); - NSSize size = [GLWin.cocoaWin frame].size; + cocoaWin = reinterpret_cast(((wxPanel*)window_handle)->GetHandle()); + NSSize size = [cocoaWin frame].size; // Enable high-resolution display support. - [GLWin.cocoaWin setWantsBestResolutionOpenGLSurface:YES]; + [cocoaWin setWantsBestResolutionOpenGLSurface:YES]; - NSWindow *window = [GLWin.cocoaWin window]; + NSWindow *window = [cocoaWin window]; float scale = [window backingScaleFactor]; size.width *= scale; @@ -43,21 +44,21 @@ bool cInterfaceAGL::Create(void *window_handle) return false; } - GLWin.cocoaCtx = [[NSOpenGLContext alloc] + cocoaCtx = [[NSOpenGLContext alloc] initWithFormat: fmt shareContext: nil]; [fmt release]; - if (GLWin.cocoaCtx == nil) { + if (cocoaCtx == nil) { ERROR_LOG(VIDEO, "failed to create context"); return false; } - if (GLWin.cocoaWin == nil) { + if (cocoaWin == nil) { ERROR_LOG(VIDEO, "failed to create window"); return false; } - [window makeFirstResponder:GLWin.cocoaWin]; - [GLWin.cocoaCtx setView: GLWin.cocoaWin]; + [window makeFirstResponder:cocoaWin]; + [cocoaCtx setView: cocoaWin]; [window makeKeyAndOrderFront: nil]; return true; @@ -65,7 +66,7 @@ bool cInterfaceAGL::Create(void *window_handle) bool cInterfaceAGL::MakeCurrent() { - [GLWin.cocoaCtx makeCurrentContext]; + [cocoaCtx makeCurrentContext]; return true; } @@ -79,15 +80,15 @@ bool cInterfaceAGL::ClearCurrent() // Close backend void cInterfaceAGL::Shutdown() { - [GLWin.cocoaCtx clearDrawable]; - [GLWin.cocoaCtx release]; - GLWin.cocoaCtx = nil; + [cocoaCtx clearDrawable]; + [cocoaCtx release]; + cocoaCtx = nil; } void cInterfaceAGL::Update() { - NSWindow *window = [GLWin.cocoaWin window]; - NSSize size = [GLWin.cocoaWin frame].size; + NSWindow *window = [cocoaWin window]; + NSSize size = [cocoaWin frame].size; float scale = [window backingScaleFactor]; size.width *= scale; @@ -100,11 +101,11 @@ void cInterfaceAGL::Update() s_backbuffer_width = size.width; s_backbuffer_height = size.height; - [GLWin.cocoaCtx update]; + [cocoaCtx update]; } void cInterfaceAGL::SwapInterval(int interval) { - [GLWin.cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval]; + [cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval]; } diff --git a/Source/Core/DolphinWX/GLInterface/AGL.h b/Source/Core/DolphinWX/GLInterface/AGL.h index 7def0dd2d2..8ab0dedc0c 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.h +++ b/Source/Core/DolphinWX/GLInterface/AGL.h @@ -12,6 +12,9 @@ class cInterfaceAGL : public cInterfaceBase { +private: + NSView *cocoaWin; + NSOpenGLContext *cocoaCtx; public: void Swap(); bool Create(void *window_handle); diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index b6b52ead0a..f5f93eec99 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -3,17 +3,18 @@ // Refer to the license.txt file included. #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/EGL.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/RenderBase.h" // Show the current FPS void cInterfaceEGL::Swap() { - eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); + eglSwapBuffers(egl_dpy, egl_surf); } void cInterfaceEGL::SwapInterval(int Interval) { - eglSwapInterval(GLWin.egl_dpy, Interval); + eglSwapInterval(egl_dpy, Interval); } void* cInterfaceEGL::GetFuncAddress(const std::string& name) @@ -39,7 +40,7 @@ void cInterfaceEGL::DetectMode() EGL_NONE }; // Get how many configs there are - if (!eglChooseConfig( GLWin.egl_dpy, attribs, nullptr, 0, &num_configs)) + if (!eglChooseConfig( egl_dpy, attribs, nullptr, 0, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); goto err_exit; @@ -48,7 +49,7 @@ void cInterfaceEGL::DetectMode() config = new EGLConfig[num_configs]; // Get all the configurations - if (!eglChooseConfig(GLWin.egl_dpy, attribs, config, num_configs, &num_configs)) + if (!eglChooseConfig(egl_dpy, attribs, config, num_configs, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); goto err_exit; @@ -58,7 +59,7 @@ void cInterfaceEGL::DetectMode() { EGLint attribVal; bool ret; - ret = eglGetConfigAttrib(GLWin.egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal); + ret = eglGetConfigAttrib(egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal); if (ret) { if (attribVal & EGL_OPENGL_BIT) @@ -89,15 +90,15 @@ bool cInterfaceEGL::Create(void *window_handle) const char *s; EGLint egl_major, egl_minor; - GLWin.egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (!GLWin.egl_dpy) + if (!egl_dpy) { INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n"); return false; } - if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { INFO_LOG(VIDEO, "Error: eglInitialize() failed\n"); return false; @@ -142,7 +143,7 @@ bool cInterfaceEGL::Create(void *window_handle) break; } - if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); exit(1); @@ -153,38 +154,36 @@ bool cInterfaceEGL::Create(void *window_handle) else eglBindAPI(EGL_OPENGL_ES_API); - EGLNativeWindowType native_window = window_handle; + EGLNativeWindowType native_window = (EGLNativeWindowType) window_handle; EGLint format; - eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); + eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(native_window, 0, 0, format); int none, width, height; Host_GetRenderWindowSize(none, none, width, height); - GLWin.width = width; - GLWin.height = height; GLInterface->SetBackBufferDimensions(width, height); - s = eglQueryString(GLWin.egl_dpy, EGL_VERSION); + s = eglQueryString(egl_dpy, EGL_VERSION); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_VENDOR); + s = eglQueryString(egl_dpy, EGL_VENDOR); INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS); + s = eglQueryString(egl_dpy, EGL_EXTENSIONS); INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS); + s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", s); - GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!GLWin.egl_ctx) + egl_ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); + if (!egl_ctx) { INFO_LOG(VIDEO, "Error: eglCreateContext failed\n"); exit(1); } - GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, native_window, nullptr); - if (!GLWin.egl_surf) + egl_surf = eglCreateWindowSurface(egl_dpy, config, native_window, nullptr); + if (!egl_surf) { INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n"); exit(1); @@ -195,22 +194,22 @@ bool cInterfaceEGL::Create(void *window_handle) bool cInterfaceEGL::MakeCurrent() { - return eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx); + return eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx); } // Close backend void cInterfaceEGL::Shutdown() { - if (GLWin.egl_ctx && !eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx)) + if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) NOTICE_LOG(VIDEO, "Could not release drawing context."); - if (GLWin.egl_ctx) + if (egl_ctx) { - eglMakeCurrent(GLWin.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (!eglDestroyContext(GLWin.egl_dpy, GLWin.egl_ctx)) + eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (!eglDestroyContext(egl_dpy, egl_ctx)) NOTICE_LOG(VIDEO, "Could not destroy drawing context."); - if (!eglDestroySurface(GLWin.egl_dpy, GLWin.egl_surf)) + if (!eglDestroySurface(egl_dpy, egl_surf)) NOTICE_LOG(VIDEO, "Could not destroy window surface."); - if (!eglTerminate(GLWin.egl_dpy)) + if (!eglTerminate(egl_dpy)) NOTICE_LOG(VIDEO, "Could not destroy display connection."); - GLWin.egl_ctx = nullptr; + egl_ctx = nullptr; } } diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 480029419a..5b48b0b272 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -14,6 +14,9 @@ class cInterfaceEGL : public cInterfaceBase { private: void DetectMode(); + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; public: void SwapInterval(int Interval); void Swap(); diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp index bb9ce669e2..14b5bfd392 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp @@ -2,10 +2,19 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "DolphinWX/GLInterface/GLInterface.h" #include "VideoBackends/OGL/GLInterfaceBase.h" -GLWindow GLWin; +#if USE_EGL +#include "DolphinWX/GLInterface/EGL.h" +#elif defined(__APPLE__) +#include "DolphinWX/GLInterface/AGL.h" +#elif defined(_WIN32) +#include "DolphinWX/GLInterface/WGL.h" +#elif HAVE_X11 +#include "DolphinWX/GLInterface/GLX.h" +#else +#error Platform doesnt have a GLInterface +#endif cInterfaceBase* HostGL_CreateGLInterface() { diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h deleted file mode 100644 index ee894b34dc..0000000000 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include "Common/Thread.h" - -#if USE_EGL -#include "DolphinWX/GLInterface/EGL.h" -#elif defined(__APPLE__) -#include "DolphinWX/GLInterface/AGL.h" -#elif defined(_WIN32) -#include "DolphinWX/GLInterface/WGL.h" -#elif HAVE_X11 -#include "DolphinWX/GLInterface/GLX.h" -#include -#else -#error Platform doesnt have a GLInterface -#endif - -typedef struct { -#if USE_EGL - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; -#elif defined(__APPLE__) - NSView *cocoaWin; - NSOpenGLContext *cocoaCtx; -#elif HAVE_X11 - GLXContext ctx; - int screen; - Window win; - Window parent; - Display *dpy; - XVisualInfo *vi; - XSetWindowAttributes attr; - std::thread xEventThread; -#endif -} GLWindow; - -extern GLWindow GLWin; diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index 0365e5d8b9..acfcab6a69 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -4,7 +4,7 @@ #include -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/GLX.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoConfig.h" @@ -26,7 +26,7 @@ void* cInterfaceGLX::GetFuncAddress(const std::string& name) void cInterfaceGLX::Swap() { - glXSwapBuffers(GLWin.dpy, GLWin.win); + glXSwapBuffers(dpy, win); } // Create rendering window. @@ -58,26 +58,25 @@ bool cInterfaceGLX::Create(void *window_handle) GLX_DOUBLEBUFFER, None }; - GLWin.dpy = XOpenDisplay(nullptr); - GLWin.parent = (Window)window_handle; - GLWin.screen = DefaultScreen(GLWin.dpy); + dpy = XOpenDisplay(nullptr); + int screen = DefaultScreen(dpy); - glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion); + glXQueryVersion(dpy, &glxMajorVersion, &glxMinorVersion); NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion); // Get an appropriate visual - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl); - if (GLWin.vi == nullptr) + vi = glXChooseVisual(dpy, screen, attrListDbl); + if (vi == nullptr) { - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListSgl); - if (GLWin.vi != nullptr) + vi = glXChooseVisual(dpy, screen, attrListSgl); + if (vi != nullptr) { ERROR_LOG(VIDEO, "Only single buffered visual!"); } else { - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDefault); - if (GLWin.vi == nullptr) + vi = glXChooseVisual(dpy, screen, attrListDefault); + if (vi == nullptr) { ERROR_LOG(VIDEO, "Could not choose visual (glXChooseVisual)"); return false; @@ -88,20 +87,23 @@ bool cInterfaceGLX::Create(void *window_handle) NOTICE_LOG(VIDEO, "Got double buffered visual!"); // Create a GLX context. - GLWin.ctx = glXCreateContext(GLWin.dpy, GLWin.vi, nullptr, GL_TRUE); - if (!GLWin.ctx) + ctx = glXCreateContext(dpy, vi, nullptr, GL_TRUE); + if (!ctx) { PanicAlert("Unable to create GLX context."); return false; } - XWindow.CreateXWindow(); + XWindow.Initialize(dpy); + + Window parent = (Window)window_handle; + win = XWindow.CreateXWindow(parent, vi); return true; } bool cInterfaceGLX::MakeCurrent() { - bool success = glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx); + bool success = glXMakeCurrent(dpy, win, ctx); if (success) { // load this function based on the current bound context @@ -112,7 +114,7 @@ bool cInterfaceGLX::MakeCurrent() bool cInterfaceGLX::ClearCurrent() { - return glXMakeCurrent(GLWin.dpy, None, nullptr); + return glXMakeCurrent(dpy, None, nullptr); } @@ -120,11 +122,11 @@ bool cInterfaceGLX::ClearCurrent() void cInterfaceGLX::Shutdown() { XWindow.DestroyXWindow(); - if (GLWin.ctx) + if (ctx) { - glXDestroyContext(GLWin.dpy, GLWin.ctx); - XCloseDisplay(GLWin.dpy); - GLWin.ctx = nullptr; + glXDestroyContext(dpy, ctx); + XCloseDisplay(dpy); + ctx = nullptr; } } diff --git a/Source/Core/DolphinWX/GLInterface/GLX.h b/Source/Core/DolphinWX/GLInterface/GLX.h index 2e811fd323..0aa9c71a59 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.h +++ b/Source/Core/DolphinWX/GLInterface/GLX.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "DolphinWX/GLInterface/X11_Util.h" #include "VideoBackends/OGL/GLInterfaceBase.h" @@ -13,6 +14,10 @@ class cInterfaceGLX : public cInterfaceBase { private: cX11Window XWindow; + Display *dpy; + Window win; + GLXContext ctx; + XVisualInfo *vi; public: friend class cX11Window; void SwapInterval(int Interval) override; diff --git a/Source/Core/DolphinWX/GLInterface/WGL.cpp b/Source/Core/DolphinWX/GLInterface/WGL.cpp index 5783999274..89a6a381b1 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/WGL.cpp @@ -6,7 +6,7 @@ #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/WGL.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VertexShaderManager.h" diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 21096fbb1a..0842a34d65 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -2,50 +2,61 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include "Common/Thread.h" #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/X11_Util.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/VideoConfig.h" -void cX11Window::CreateXWindow(void) +void cX11Window::Initialize(Display *_dpy) { + dpy = _dpy; +} + +Window cX11Window::CreateXWindow(Window parent, XVisualInfo *vi) +{ + XSetWindowAttributes attr; + + colormap = XCreateColormap(dpy, parent, vi->visual, AllocNone); + // Setup window attributes - GLWin.attr.colormap = XCreateColormap(GLWin.dpy, - GLWin.parent, GLWin.vi->visual, AllocNone); - GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen); - GLWin.attr.border_pixel = 0; + attr.colormap = colormap; + attr.background_pixel = BlackPixel(dpy, 0); + attr.border_pixel = 0; // Create the window - GLWin.win = XCreateWindow(GLWin.dpy, GLWin.parent, - 0, 0, 1, 1, 0, - GLWin.vi->depth, InputOutput, GLWin.vi->visual, - CWBorderPixel | CWBackPixel | CWColormap, &GLWin.attr); - XSelectInput(GLWin.dpy, GLWin.parent, StructureNotifyMask); - XMapWindow(GLWin.dpy, GLWin.win); - XSync(GLWin.dpy, True); + win = XCreateWindow(dpy, parent, + 0, 0, 1, 1, 0, + vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWBackPixel | CWColormap, &attr); + XSelectInput(dpy, parent, StructureNotifyMask); + XMapWindow(dpy, win); + XSync(dpy, True); - GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this); + xEventThread = std::thread(&cX11Window::XEventThread, this); + + return win; } void cX11Window::DestroyXWindow(void) { - XUnmapWindow(GLWin.dpy, GLWin.win); - GLWin.win = 0; - if (GLWin.xEventThread.joinable()) - GLWin.xEventThread.join(); - XFreeColormap(GLWin.dpy, GLWin.attr.colormap); + XUnmapWindow(dpy, win); + if (xEventThread.joinable()) + xEventThread.join(); + XFreeColormap(dpy, colormap); } void cX11Window::XEventThread() { - while (GLWin.win) + while (win) { XEvent event; - for (int num_events = XPending(GLWin.dpy); num_events > 0; num_events--) + for (int num_events = XPending(dpy); num_events > 0; num_events--) { - XNextEvent(GLWin.dpy, &event); + XNextEvent(dpy, &event); switch (event.type) { case ConfigureNotify: - XResizeWindow(GLWin.dpy, GLWin.win, event.xconfigure.width, event.xconfigure.height); + XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height); GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); break; default: diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.h b/Source/Core/DolphinWX/GLInterface/X11_Util.h index d8c293378c..6913dd2f4c 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.h +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -13,7 +14,13 @@ class cX11Window { private: void XEventThread(); + std::thread xEventThread; + Colormap colormap; public: - void CreateXWindow(void); + void Initialize(Display *dpy); + Window CreateXWindow(Window parent, XVisualInfo *vi); void DestroyXWindow(void); + + Display *dpy; + Window win; }; diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index d90b3bf02a..6d9d3b82a2 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -5,10 +5,6 @@ #include "Common/Thread.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" -#if USE_EGL -#include "DolphinWX/GLInterface/GLInterface.h" -#endif - #ifdef CIFACE_USE_XINPUT #include "InputCommon/ControllerInterface/XInput/XInput.h" #endif From e39543b963b6f2347c35aa7373dd491051488855 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 10:54:42 -0400 Subject: [PATCH 15/19] X11_Util: Don't specify a background pixel This causes flickering when resizing the window, which looks horrid and we shouldn't do it. --- Source/Core/DolphinWX/GLInterface/X11_Util.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 0842a34d65..5c78a7adf8 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -21,14 +21,12 @@ Window cX11Window::CreateXWindow(Window parent, XVisualInfo *vi) // Setup window attributes attr.colormap = colormap; - attr.background_pixel = BlackPixel(dpy, 0); - attr.border_pixel = 0; // Create the window win = XCreateWindow(dpy, parent, 0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual, - CWBorderPixel | CWBackPixel | CWColormap, &attr); + CWColormap, &attr); XSelectInput(dpy, parent, StructureNotifyMask); XMapWindow(dpy, win); XSync(dpy, True); From 271efb450c71c872658a424cd633c20a3174e3a0 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 10:31:27 -0400 Subject: [PATCH 16/19] Add back X11 support to EGL Refactor the EGL backend to provide a platform separation here, which is better abstracted away than the old EGL/X11 implementation. --- Source/Core/DolphinWX/CMakeLists.txt | 22 +++++++----- Source/Core/DolphinWX/GLInterface/EGL.cpp | 14 +++----- Source/Core/DolphinWX/GLInterface/EGL.h | 6 +++- .../Core/DolphinWX/GLInterface/EGLAndroid.cpp | 29 ++++++++++++++++ .../Core/DolphinWX/GLInterface/EGLAndroid.h | 15 ++++++++ Source/Core/DolphinWX/GLInterface/EGLX11.cpp | 34 +++++++++++++++++++ Source/Core/DolphinWX/GLInterface/EGLX11.h | 21 ++++++++++++ .../DolphinWX/GLInterface/GLInterface.cpp | 16 ++++++--- 8 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp create mode 100644 Source/Core/DolphinWX/GLInterface/EGLAndroid.h create mode 100644 Source/Core/DolphinWX/GLInterface/EGLX11.cpp create mode 100644 Source/Core/DolphinWX/GLInterface/EGLX11.h diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 65013d0d8c..ebe9940c3d 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -74,16 +74,22 @@ set(ANDROID_SRCS Android/ButtonManager.cpp if(USE_EGL) set(SRCS ${SRCS} GLInterface/EGL.cpp) -else() - if(WIN32) - set(SRCS ${SRCS} GLInterface/WGL.cpp) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(SRCS ${SRCS} GLInterface/AGL.cpp) - else() - set(SRCS ${SRCS} GLInterface/GLX.cpp - GLInterface/X11_Util.cpp) + if(ANDROID) + set(SRCS ${SRCS} GLInterface/EGLAndroid.cpp) + elseif(USE_X11) + set(SRCS ${SRCS} GLInterface/EGLX11.cpp) endif() endif() + +if(WIN32) + set(SRCS ${SRCS} GLInterface/WGL.cpp) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(SRCS ${SRCS} GLInterface/AGL.cpp) +elseif(USE_X11) + set(SRCS ${SRCS} GLInterface/GLX.cpp + GLInterface/X11_Util.cpp) +endif() + set(SRCS ${SRCS} GLInterface/GLInterface.cpp) set(NOGUI_SRCS MainNoGUI.cpp) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index f5f93eec99..c65759f736 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "Core/Host.h" #include "DolphinWX/GLInterface/EGL.h" #include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/RenderBase.h" @@ -90,7 +89,7 @@ bool cInterfaceEGL::Create(void *window_handle) const char *s; EGLint egl_major, egl_minor; - egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + egl_dpy = OpenDisplay(); if (!egl_dpy) { @@ -154,14 +153,8 @@ bool cInterfaceEGL::Create(void *window_handle) else eglBindAPI(EGL_OPENGL_ES_API); - EGLNativeWindowType native_window = (EGLNativeWindowType) window_handle; - - EGLint format; - eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry(native_window, 0, 0, format); - int none, width, height; - Host_GetRenderWindowSize(none, none, width, height); - GLInterface->SetBackBufferDimensions(width, height); + EGLNativeWindowType host_window = (EGLNativeWindowType) window_handle; + EGLNativeWindowType native_window = InitializePlatform(host_window, config); s = eglQueryString(egl_dpy, EGL_VERSION); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); @@ -199,6 +192,7 @@ bool cInterfaceEGL::MakeCurrent() // Close backend void cInterfaceEGL::Shutdown() { + ShutdownPlatform(); if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) NOTICE_LOG(VIDEO, "Could not release drawing context."); if (egl_ctx) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 5b48b0b272..1ed8ab59a0 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -12,11 +12,15 @@ class cInterfaceEGL : public cInterfaceBase { -private: +protected: void DetectMode(); EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; + + virtual EGLDisplay OpenDisplay() = 0; + virtual EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) = 0; + virtual void ShutdownPlatform() = 0; public: void SwapInterval(int Interval); void Swap(); diff --git a/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp b/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp new file mode 100644 index 0000000000..f4989f6da4 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp @@ -0,0 +1,29 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "Core/Host.h" +#include "DolphinWX/GLInterface/EGLAndroid.h" + +EGLDisplay cInterfaceEGLAndroid::OpenDisplay() +{ + return eglGetDisplay(EGL_DEFAULT_DISPLAY); +} + +EGLNativeWindowType cInterfaceEGLAndroid::InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) +{ + EGLint format; + eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); + ANativeWindow_setBuffersGeometry(host_window, 0, 0, format); + + int none, width, height; + Host_GetRenderWindowSize(none, none, width, height); + GLInterface->SetBackBufferDimensions(width, height); + + return host_window; +} + +void cInterfaceEGLAndroid::ShutdownPlatform() +{ +} + diff --git a/Source/Core/DolphinWX/GLInterface/EGLAndroid.h b/Source/Core/DolphinWX/GLInterface/EGLAndroid.h new file mode 100644 index 0000000000..e79a5a5ec8 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLAndroid.h @@ -0,0 +1,15 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "DolphinWX/GLInterface/EGL.h" + +class cInterfaceEGLAndroid : public cInterfaceEGL +{ +protected: + EGLDisplay OpenDisplay() override; + EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) override; + void ShutdownPlatform() override; +}; diff --git a/Source/Core/DolphinWX/GLInterface/EGLX11.cpp b/Source/Core/DolphinWX/GLInterface/EGLX11.cpp new file mode 100644 index 0000000000..f8f686f147 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLX11.cpp @@ -0,0 +1,34 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "DolphinWX/GLInterface/EGLX11.h" + +EGLDisplay cInterfaceEGLX11::OpenDisplay() +{ + dpy = XOpenDisplay(nullptr); + XWindow.Initialize(dpy); + return eglGetDisplay(dpy); +} + +EGLNativeWindowType cInterfaceEGLX11::InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) +{ + EGLint vid; + eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid); + + XVisualInfo visTemplate; + visTemplate.visualid = vid; + + XVisualInfo *vi; + int nVisuals; + vi = XGetVisualInfo(dpy, VisualIDMask, &visTemplate, &nVisuals); + + return (EGLNativeWindowType) XWindow.CreateXWindow((Window) host_window, vi); +} + +void cInterfaceEGLX11::ShutdownPlatform() +{ + XWindow.DestroyXWindow(); + XCloseDisplay(dpy); +} + diff --git a/Source/Core/DolphinWX/GLInterface/EGLX11.h b/Source/Core/DolphinWX/GLInterface/EGLX11.h new file mode 100644 index 0000000000..be897d6b3a --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLX11.h @@ -0,0 +1,21 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "DolphinWX/GLInterface/EGL.h" +#include "DolphinWX/GLInterface/X11_Util.h" + +class cInterfaceEGLX11 : public cInterfaceEGL +{ +private: + cX11Window XWindow; + Display *dpy; +protected: + EGLDisplay OpenDisplay() override; + EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) override; + void ShutdownPlatform() override; +}; diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp index 14b5bfd392..0c8ea8673b 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp @@ -4,28 +4,36 @@ #include "VideoBackends/OGL/GLInterfaceBase.h" -#if USE_EGL -#include "DolphinWX/GLInterface/EGL.h" +#ifdef ANDROID +#include "DolphinWX/GLInterface/EGLAndroid.h" #elif defined(__APPLE__) #include "DolphinWX/GLInterface/AGL.h" #elif defined(_WIN32) #include "DolphinWX/GLInterface/WGL.h" #elif HAVE_X11 +#if defined(USE_EGL) && USE_EGL +#include "DolphinWX/GLInterface/EGLX11.h" +#else #include "DolphinWX/GLInterface/GLX.h" +#endif #else #error Platform doesnt have a GLInterface #endif cInterfaceBase* HostGL_CreateGLInterface() { - #if defined(USE_EGL) && USE_EGL - return new cInterfaceEGL; + #ifdef ANDROID + return new cInterfaceEGLAndroid; #elif defined(__APPLE__) return new cInterfaceAGL; #elif defined(_WIN32) return new cInterfaceWGL; #elif defined(HAVE_X11) && HAVE_X11 + #if defined(USE_EGL) && USE_EGL + return new cInterfaceEGLX11; + #else return new cInterfaceGLX; + #endif #else return nullptr; #endif From 4a16211bae97a42c24ed43cf4174df03d180ac4a Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 19 Aug 2014 10:07:59 -0400 Subject: [PATCH 17/19] Core: Don't display messages in the titlebar / statusbar We already put them on-screen, that should be good enough. --- Source/Core/Core/Core.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index a72115de56..c16e9529fa 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -126,16 +126,6 @@ void DisplayMessage(const std::string& message, int time_in_ms) } g_video_backend->Video_AddMessage(message, time_in_ms); - - if (_CoreParameter.bRenderToMain && - SConfig::GetInstance().m_InterfaceStatusbar) - { - Host_UpdateStatusBar(message); - } - else - { - Host_UpdateTitle(message); - } } bool IsRunning() From 3bad4bcfdb17d1dacb8900f0d13294da21d82fde Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 19 Aug 2014 10:09:33 -0400 Subject: [PATCH 18/19] PPCSymbolDB: Don't show any messages in the status bar These don't really help anybody. We don't even have a status bar in MainNoGUI -- status bar text should be controlled by the UI, not the core code! --- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index a63c586d97..829b0beab5 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -279,9 +279,6 @@ bool PPCSymbolDB::SaveMap(const std::string& filename, bool WithCodes) const mapFile.c_str()).c_str(), "Confirm", wxYES_NO)) return false; } - if (WithCodes) - Host_UpdateStatusBar("Saving code, please stand by ..."); - // Make a file File::IOFile f(mapFile, "w"); if (!f) @@ -342,8 +339,6 @@ bool PPCSymbolDB::SaveMap(const std::string& filename, bool WithCodes) const fprintf(f.GetHandle(), "\n"); } } - // --------------- - Host_UpdateStatusBar(StringFromFormat("Saved %s", mapFile.c_str()).c_str()); return true; } From 6dbafa92389f52c6bd0140b4525b563fe74af0f2 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 19 Aug 2014 10:17:33 -0400 Subject: [PATCH 19/19] Core: Move the titlebar / statusbar abstraction to DolphinWX The concept of a "title bar" / "status bar" shouldn't be a core concept, so remove the Host_UpdateStatusBar function, and move the code handles whether to update the status bar or titlebar into DolphinWX. --- Source/Core/Core/Core.cpp | 12 +----------- Source/Core/Core/Host.h | 1 - Source/Core/DolphinWX/Frame.cpp | 18 ++++++++++++++++-- Source/Core/DolphinWX/Frame.h | 1 + Source/Core/DolphinWX/Main.cpp | 11 ----------- Source/Core/DolphinWX/MainAndroid.cpp | 2 -- Source/Core/DolphinWX/MainNoGUI.cpp | 2 -- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index c16e9529fa..8a0cc0a274 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -682,7 +682,6 @@ void UpdateTitle() } // This is our final "frame counter" string std::string SMessage = StringFromFormat("%s | %s", SSettings.c_str(), SFPS.c_str()); - std::string TMessage = StringFromFormat("%s | %s", scm_rev_str, SMessage.c_str()); // Update the audio timestretcher with the current speed if (soundStream) @@ -691,16 +690,7 @@ void UpdateTitle() pMixer->UpdateSpeed((float)Speed / 100); } - if (_CoreParameter.bRenderToMain && - SConfig::GetInstance().m_InterfaceStatusbar) - { - Host_UpdateStatusBar(SMessage); - Host_UpdateTitle(scm_rev_str); - } - else - { - Host_UpdateTitle(TMessage); - } + Host_UpdateTitle(SMessage); } void Shutdown() diff --git a/Source/Core/Core/Host.h b/Source/Core/Core/Host.h index 480846baeb..7a493bc96a 100644 --- a/Source/Core/Core/Host.h +++ b/Source/Core/Core/Host.h @@ -37,7 +37,6 @@ void Host_SetWiiMoteConnectionState(int _State); void Host_SysMessage(const char *fmt, ...); void Host_UpdateDisasmDialog(); void Host_UpdateMainFrame(); -void Host_UpdateStatusBar(const std::string& text, int Filed = 0); void Host_UpdateTitle(const std::string& title); void Host_ShowVideoConfig(void* parent, const std::string& backend_name, const std::string& config_name); diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index b710ba07cb..126cb3ea74 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -628,6 +628,21 @@ WXLRESULT CFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } #endif +void CFrame::UpdateTitle(const std::string &str) +{ + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain && + SConfig::GetInstance().m_InterfaceStatusbar) + { + GetStatusBar()->SetStatusText(str, 0); + m_RenderFrame->SetTitle(scm_rev_str); + } + else + { + std::string titleStr = StringFromFormat("%s | %s", scm_rev_str, str.c_str()); + m_RenderFrame->SetTitle(titleStr); + } +} + void CFrame::OnHostMessage(wxCommandEvent& event) { switch (event.GetId()) @@ -642,8 +657,7 @@ void CFrame::OnHostMessage(wxCommandEvent& event) break; case IDM_UPDATETITLE: - if (m_RenderFrame != nullptr) - m_RenderFrame->SetTitle(event.GetString()); + SetTitle(event.GetString()); break; case IDM_WINDOWSIZEREQUEST: diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index d54f1e54e0..1ca67caa5e 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -126,6 +126,7 @@ public: void UpdateWiiMenuChoice(wxMenuItem *WiiMenuItem=nullptr); void PopulateSavedPerspectives(); static void ConnectWiimote(int wm_idx, bool connect); + void UpdateTitle(const std::string &str); const CGameListCtrl *GetGameListCtrl() const; diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 1f40da2d9a..774e1bfc0a 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -607,17 +607,6 @@ void Host_SetStartupDebuggingParameters() StartUp.bEnableDebugging = main_frame->g_pCodeWindow ? true : false; // RUNNING_DEBUG } -void Host_UpdateStatusBar(const std::string& text, int Field) -{ - wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATESTATUSBAR); - // Set the event string - event.SetString(StrToWxStr(text)); - // Update statusbar field - event.SetInt(Field); - // Post message - main_frame->GetEventHandler()->AddPendingEvent(event); -} - void Host_SetWiiMoteConnectionState(int _State) { static int currentState = -1; diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index e6f3a3bbea..67cf2619ab 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -104,8 +104,6 @@ bool Host_RendererHasFocus() void Host_ConnectWiimote(int wm_idx, bool connect) {} -void Host_UpdateStatusBar(const std::string& text, int filed){} - void Host_SysMessage(const char *fmt, ...) { va_list args; diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index cca5d6ffb8..da55da9fbe 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -102,8 +102,6 @@ bool Host_RendererHasFocus() void Host_ConnectWiimote(int wm_idx, bool connect) {} -void Host_UpdateStatusBar(const std::string& text, int filed){} - void Host_SysMessage(const char *fmt, ...) { va_list list;