diff --git a/gfx/drivers_context/cocoa_gl_ctx.m b/gfx/drivers_context/cocoa_gl_ctx.m index f50cd76d89..cb4437ee34 100644 --- a/gfx/drivers_context/cocoa_gl_ctx.m +++ b/gfx/drivers_context/cocoa_gl_ctx.m @@ -41,77 +41,11 @@ #include "../../configuration.h" #include "../../verbosity.h" -#if defined(HAVE_COCOATOUCH) -#define GLContextClass EAGLContext -#define GLFrameworkID CFSTR("com.apple.opengles") -#define RAScreen UIScreen - -#ifndef UIUserInterfaceIdiomTV -#define UIUserInterfaceIdiomTV 2 -#endif - -#ifndef UIUserInterfaceIdiomCarPlay -#define UIUserInterfaceIdiomCarPlay 3 -#endif - -@interface EAGLContext (OSXCompat) @end -@implementation EAGLContext (OSXCompat) -+ (void)clearCurrentContext { [EAGLContext setCurrentContext:nil]; } -- (void)makeCurrentContext { [EAGLContext setCurrentContext:self]; } -@end - -#else - -@interface NSScreen (IOSCompat) @end -@implementation NSScreen (IOSCompat) -- (CGRect)bounds -{ - CGRect cgrect = NSRectToCGRect(self.frame); - return CGRectMake(0, 0, CGRectGetWidth(cgrect), CGRectGetHeight(cgrect)); -} -- (float) scale { return 1.0f; } -@end - -#define GLContextClass NSOpenGLContext -#define GLFrameworkID CFSTR("com.apple.opengl") -#define RAScreen NSScreen -#endif - -static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE; - typedef struct cocoa_ctx_data { bool core_hw_context_enable; } cocoa_ctx_data_t; -#if defined(HAVE_COCOATOUCH) - -static GLKView *g_view; -UIView *g_pause_indicator_view; -#endif - -static GLContextClass* g_hw_ctx; -static GLContextClass* g_context; - -static int g_fast_forward_skips; -static bool g_is_syncing = true; -static bool g_use_hw_ctx = false; - -#if defined(HAVE_COCOA) -static NSOpenGLPixelFormat* g_format; - -void *glcontext_get_ptr(void) -{ - return g_context; -} -#endif - -static unsigned g_minor = 0; -static unsigned g_major = 0; - -/* forward declaration */ -void *nsview_get_ptr(void); - #include "cocoa_gl_shared.h" static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver) @@ -271,40 +205,6 @@ static void cocoagl_gfx_ctx_swap_buffers(void *data, void *data2) g_fast_forward_skips = g_is_syncing ? 0 : 3; } -static gfx_ctx_proc_t cocoagl_gfx_ctx_get_proc_address(const char *symbol_name) -{ - return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID), - (BRIDGE CFStringRef)BOXSTRING(symbol_name) - ); -} - -static void cocoagl_gfx_ctx_check_window(void *data, bool *quit, - bool *resize, unsigned *width, unsigned *height, bool is_shutdown) -{ - unsigned new_width, new_height; - - *quit = false; - - cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height); - if (new_width != *width || new_height != *height) - { - *width = new_width; - *height = new_height; - *resize = true; - } -} - -static void cocoagl_gfx_ctx_bind_hw_render(void *data, bool enable) -{ - (void)data; - g_use_hw_ctx = enable; - - if (enable) - [g_hw_ctx makeCurrentContext]; - else - [g_context makeCurrentContext]; -} - const gfx_ctx_driver_t gfx_ctx_cocoagl = { cocoagl_gfx_ctx_init, cocoagl_gfx_ctx_destroy, diff --git a/gfx/drivers_context/cocoa_gl_ctx_metal.m b/gfx/drivers_context/cocoa_gl_ctx_metal.m index 38e5b6b891..02e65a026d 100644 --- a/gfx/drivers_context/cocoa_gl_ctx_metal.m +++ b/gfx/drivers_context/cocoa_gl_ctx_metal.m @@ -43,45 +43,6 @@ #include "../common/vulkan_common.h" #endif -#if defined(HAVE_COCOATOUCH) -#define GLContextClass EAGLContext -#define GLFrameworkID CFSTR("com.apple.opengles") -#define RAScreen UIScreen - -#ifndef UIUserInterfaceIdiomTV -#define UIUserInterfaceIdiomTV 2 -#endif - -#ifndef UIUserInterfaceIdiomCarPlay -#define UIUserInterfaceIdiomCarPlay 3 -#endif - - -@interface EAGLContext (OSXCompat) @end -@implementation EAGLContext (OSXCompat) -+ (void)clearCurrentContext { [EAGLContext setCurrentContext:nil]; } -- (void)makeCurrentContext { [EAGLContext setCurrentContext:self]; } -@end - -#else - -@interface NSScreen (IOSCompat) @end -@implementation NSScreen (IOSCompat) -- (CGRect)bounds -{ - CGRect cgrect = NSRectToCGRect(self.frame); - return CGRectMake(0, 0, CGRectGetWidth(cgrect), CGRectGetHeight(cgrect)); -} -- (float) scale { return 1.0f; } -@end - -#define GLContextClass NSOpenGLContext -#define GLFrameworkID CFSTR("com.apple.opengl") -#define RAScreen NSScreen -#endif - -static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE; - typedef struct cocoa_ctx_data { bool core_hw_context_enable; @@ -93,34 +54,6 @@ typedef struct cocoa_ctx_data unsigned height; } cocoa_ctx_data_t; -#if defined(HAVE_COCOATOUCH) - -static GLKView *g_view; -UIView *g_pause_indicator_view; -#endif - -static GLContextClass* g_hw_ctx; -static GLContextClass* g_context; - -static int g_fast_forward_skips; -static bool g_is_syncing = true; -static bool g_use_hw_ctx = false; - -#if defined(HAVE_COCOA_METAL) -static NSOpenGLPixelFormat* g_format; - -void *glcontext_get_ptr(void) -{ - return (BRIDGE void *)g_context; -} -#endif - -static unsigned g_minor = 0; -static unsigned g_major = 0; - -/* forward declaration */ -void *nsview_get_ptr(void); - #include "cocoa_gl_shared.h" static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver) @@ -399,23 +332,6 @@ static void cocoagl_gfx_ctx_swap_buffers(void *data, void *data2) } } -static gfx_ctx_proc_t cocoagl_gfx_ctx_get_proc_address(const char *symbol_name) -{ - switch (cocoagl_api) - { - case GFX_CTX_OPENGL_API: - case GFX_CTX_OPENGL_ES_API: - return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName( - CFBundleGetBundleWithIdentifier(GLFrameworkID), - (BRIDGE CFStringRef)BOXSTRING(symbol_name) - ); - case GFX_CTX_NONE: - default: - break; - } - - return NULL; -} static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned height) { @@ -457,60 +373,6 @@ static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned heig return true; } -static void cocoagl_gfx_ctx_check_window(void *data, bool *quit, - bool *resize, unsigned *width, unsigned *height, bool is_shutdown) -{ - unsigned new_width, new_height; -#ifdef HAVE_VULKAN - cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; -#endif - - *quit = false; - - switch (cocoagl_api) - { - case GFX_CTX_OPENGL_API: - case GFX_CTX_OPENGL_ES_API: - break; - case GFX_CTX_VULKAN_API: -#ifdef HAVE_VULKAN - *resize = cocoa_ctx->vk.need_new_swapchain; -#endif - break; - case GFX_CTX_NONE: - default: - break; - } - - cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height); - if (new_width != *width || new_height != *height) - { - *width = new_width; - *height = new_height; - *resize = true; - } -} - -static void cocoagl_gfx_ctx_bind_hw_render(void *data, bool enable) -{ - (void)data; - switch (cocoagl_api) - { - case GFX_CTX_OPENGL_API: - case GFX_CTX_OPENGL_ES_API: - g_use_hw_ctx = enable; - - if (enable) - [g_hw_ctx makeCurrentContext]; - else - [g_context makeCurrentContext]; - break; - case GFX_CTX_NONE: - default: - break; - } -} - const gfx_ctx_driver_t gfx_ctx_cocoagl = { .init = cocoagl_gfx_ctx_init, .destroy = cocoagl_gfx_ctx_destroy, diff --git a/gfx/drivers_context/cocoa_gl_shared.h b/gfx/drivers_context/cocoa_gl_shared.h index 84260e1c99..f9a88940e0 100644 --- a/gfx/drivers_context/cocoa_gl_shared.h +++ b/gfx/drivers_context/cocoa_gl_shared.h @@ -1,3 +1,68 @@ +static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE; + +#if defined(HAVE_COCOATOUCH) +static GLKView *g_view; +UIView *g_pause_indicator_view; +#endif + +static GLContextClass* g_hw_ctx; +static GLContextClass* g_context; + +static int g_fast_forward_skips; +static bool g_is_syncing = true; +static bool g_use_hw_ctx = false; + +static unsigned g_minor = 0; +static unsigned g_major = 0; + +#if defined(HAVE_COCOATOUCH) +#define GLContextClass EAGLContext +#define GLFrameworkID CFSTR("com.apple.opengles") +#define RAScreen UIScreen + +#ifndef UIUserInterfaceIdiomTV +#define UIUserInterfaceIdiomTV 2 +#endif + +#ifndef UIUserInterfaceIdiomCarPlay +#define UIUserInterfaceIdiomCarPlay 3 +#endif + + +@interface EAGLContext (OSXCompat) @end +@implementation EAGLContext (OSXCompat) ++ (void)clearCurrentContext { [EAGLContext setCurrentContext:nil]; } +- (void)makeCurrentContext { [EAGLContext setCurrentContext:self]; } +@end + +#else + +@interface NSScreen (IOSCompat) @end +@implementation NSScreen (IOSCompat) +- (CGRect)bounds +{ + CGRect cgrect = NSRectToCGRect(self.frame); + return CGRectMake(0, 0, CGRectGetWidth(cgrect), CGRectGetHeight(cgrect)); +} +- (float) scale { return 1.0f; } +@end + +#define GLContextClass NSOpenGLContext +#define GLFrameworkID CFSTR("com.apple.opengl") +#define RAScreen NSScreen +#endif + +/* forward declaration */ +void *nsview_get_ptr(void); + +#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL) +static NSOpenGLPixelFormat* g_format; + +void *glcontext_get_ptr(void) +{ + return (BRIDGE void *)g_context; +} +#endif static uint32_t cocoagl_gfx_ctx_get_flags(void *data) { @@ -367,3 +432,75 @@ static void cocoagl_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned *width = CGRectGetWidth(size) * screenscale; *height = CGRectGetHeight(size) * screenscale; } + +static gfx_ctx_proc_t cocoagl_gfx_ctx_get_proc_address(const char *symbol_name) +{ + switch (cocoagl_api) + { + case GFX_CTX_OPENGL_API: + case GFX_CTX_OPENGL_ES_API: + return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName( + CFBundleGetBundleWithIdentifier(GLFrameworkID), + (BRIDGE CFStringRef)BOXSTRING(symbol_name) + ); + case GFX_CTX_NONE: + default: + break; + } + + return NULL; +} + +static void cocoagl_gfx_ctx_bind_hw_render(void *data, bool enable) +{ + (void)data; + switch (cocoagl_api) + { + case GFX_CTX_OPENGL_API: + case GFX_CTX_OPENGL_ES_API: + g_use_hw_ctx = enable; + + if (enable) + [g_hw_ctx makeCurrentContext]; + else + [g_context makeCurrentContext]; + break; + case GFX_CTX_NONE: + default: + break; + } +} + +static void cocoagl_gfx_ctx_check_window(void *data, bool *quit, + bool *resize, unsigned *width, unsigned *height, bool is_shutdown) +{ + unsigned new_width, new_height; +#ifdef HAVE_VULKAN + cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data; +#endif + + *quit = false; + + switch (cocoagl_api) + { + case GFX_CTX_OPENGL_API: + case GFX_CTX_OPENGL_ES_API: + break; + case GFX_CTX_VULKAN_API: +#ifdef HAVE_VULKAN + *resize = cocoa_ctx->vk.need_new_swapchain; +#endif + break; + case GFX_CTX_NONE: + default: + break; + } + + cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height); + if (new_width != *width || new_height != *height) + { + *width = new_width; + *height = new_height; + *resize = true; + } +}