From b4a2216049f00a2966188195463646cd380d77cc Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sat, 29 Oct 2022 19:36:50 +0200 Subject: [PATCH] (Context drivers) Cleanups; use flags instead of booleans etc. --- gfx/drivers_context/mali_fbdev_ctx.c | 4 +-- gfx/drivers_context/uwp_egl_ctx.c | 2 +- gfx/drivers_context/vivante_fbdev_ctx.c | 3 +-- gfx/drivers_context/wayland_ctx.c | 4 +-- gfx/drivers_context/wgl_ctx.c | 35 ++++++++++++++----------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c index 87a1137354..0efc70c76d 100644 --- a/gfx/drivers_context/mali_fbdev_ctx.c +++ b/gfx/drivers_context/mali_fbdev_ctx.c @@ -67,8 +67,8 @@ enum gfx_ctx_mali_fbdev_flags GFX_CTX_MALI_FBDEV_FLAG_GLES3 = (1 << 3) }; -mali_ctx_data_t *gfx_ctx_mali_fbdev_global=NULL; -static uint8_t mali_flags=0; +static mali_ctx_data_t *gfx_ctx_mali_fbdev_global = NULL; +static uint8_t mali_flags = 0; static int gfx_ctx_mali_fbdev_get_vinfo(void *data) { diff --git a/gfx/drivers_context/uwp_egl_ctx.c b/gfx/drivers_context/uwp_egl_ctx.c index 0ae9d559c4..3151f75cfb 100644 --- a/gfx/drivers_context/uwp_egl_ctx.c +++ b/gfx/drivers_context/uwp_egl_ctx.c @@ -56,7 +56,7 @@ /* TODO/FIXME - static globals */ static egl_ctx_data_t uwp_egl; #ifdef HAVE_DYNAMIC -static dylib_t dll_handle = NULL; /* Handle to libGLESv2.dll */ +static dylib_t dll_handle = NULL; /* Handle to libGLESv2.dll */ #endif typedef struct gfx_ctx_cgl_data diff --git a/gfx/drivers_context/vivante_fbdev_ctx.c b/gfx/drivers_context/vivante_fbdev_ctx.c index 32b90f607f..5165cc057b 100644 --- a/gfx/drivers_context/vivante_fbdev_ctx.c +++ b/gfx/drivers_context/vivante_fbdev_ctx.c @@ -33,10 +33,9 @@ typedef struct #ifdef HAVE_EGL egl_ctx_data_t egl; #endif - EGLNativeWindowType native_window; - bool resize; unsigned width, height; + bool resize; } vivante_ctx_data_t; static void gfx_ctx_vivante_destroy(void *data) diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 6784e0f62c..e12a4533ef 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -46,8 +46,6 @@ #include "../common/egl_common.h" #endif -static enum gfx_ctx_api wl_api = GFX_CTX_NONE; - #ifndef EGL_OPENGL_ES3_BIT_KHR #define EGL_OPENGL_ES3_BIT_KHR 0x0040 #endif @@ -56,6 +54,8 @@ static enum gfx_ctx_api wl_api = GFX_CTX_NONE; #define EGL_PLATFORM_WAYLAND_KHR 0x31D8 #endif +static enum gfx_ctx_api wl_api = GFX_CTX_NONE; + /* Shell surface callbacks. */ static void xdg_toplevel_handle_configure(void *data, struct xdg_toplevel *toplevel, diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index b5cf002c1c..e3b2cc4b48 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -86,13 +86,18 @@ static BOOL (APIENTRY *p_swap_interval)(int); +enum wgl_flags +{ + WGL_FLAG_USE_HW_CTX = (1 << 0), + WGL_FLAG_CORE_HW_CTX_ENABLE = (1 << 1), + WGL_FLAG_ADAPTIVE_VSYNC = (1 << 2) +}; + /* TODO/FIXME - static globals */ static HGLRC win32_hrc; static HGLRC win32_hw_hrc; static HDC win32_hdc; -static bool win32_use_hw_ctx = false; -static bool win32_core_hw_context_enable = false; -static bool wgl_adaptive_vsync = false; +static uint8_t wgl_flags; #ifdef HAVE_EGL static egl_ctx_data_t win32_egl; #endif @@ -303,7 +308,7 @@ static void create_gl_context(HWND hwnd, bool *quit) break; } - if (win32_use_hw_ctx) + if (wgl_flags & WGL_FLAG_USE_HW_CTX) { win32_hw_hrc = pcreate_context(win32_hdc, context, attribs); @@ -353,7 +358,7 @@ static void create_gl_context(HWND hwnd, bool *quit) if (wgl_has_extension("WGL_EXT_swap_control_tear", extensions)) { RARCH_LOG("[WGL]: Adaptive VSync supported.\n"); - wgl_adaptive_vsync = true; + wgl_flags |= WGL_FLAG_ADAPTIVE_VSYNC; } } } @@ -597,12 +602,13 @@ static void gfx_ctx_wgl_destroy(void *data) if (wgl) free(wgl); - wgl_adaptive_vsync = false; - win32_core_hw_context_enable = false; - g_win32_flags &= ~WIN32_CMN_FLAG_INITED; win32_major = 0; win32_minor = 0; p_swap_interval = NULL; + wgl_flags &= ~(WGL_FLAG_CORE_HW_CTX_ENABLE + | WGL_FLAG_ADAPTIVE_VSYNC + ); + g_win32_flags &= ~WIN32_CMN_FLAG_INITED; } @@ -744,7 +750,7 @@ static void gfx_ctx_wgl_bind_hw_render(void *data, bool enable) { case GFX_CTX_OPENGL_API: #if (defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)) && !defined(HAVE_OPENGLES) - win32_use_hw_ctx = enable; + wgl_flags |= WGL_FLAG_USE_HW_CTX; if (win32_hdc) { @@ -775,10 +781,10 @@ static uint32_t gfx_ctx_wgl_get_flags(void *data) switch (win32_api) { case GFX_CTX_OPENGL_API: - if (wgl_adaptive_vsync) + if (wgl_flags & WGL_FLAG_ADAPTIVE_VSYNC) BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC); - if (win32_core_hw_context_enable) + if (wgl_flags & WGL_FLAG_CORE_HW_CTX_ENABLE) BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT); if (string_is_equal(video_driver_get_ident(), "gl1")) { } @@ -791,7 +797,7 @@ static uint32_t gfx_ctx_wgl_get_flags(void *data) else { #ifdef HAVE_CG - if (!win32_core_hw_context_enable) + if (!(wgl_flags & WGL_FLAG_CORE_HW_CTX_ENABLE)) BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG); #endif #ifdef HAVE_GLSL @@ -825,10 +831,9 @@ static void gfx_ctx_wgl_set_flags(void *data, uint32_t flags) case GFX_CTX_OPENGL_API: #if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) if (BIT32_GET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC)) - wgl_adaptive_vsync = true; - + wgl_flags |= WGL_FLAG_ADAPTIVE_VSYNC; if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT)) - win32_core_hw_context_enable = true; + wgl_flags |= WGL_FLAG_CORE_HW_CTX_ENABLE; #endif break; case GFX_CTX_NONE: