mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
This reverts commit 18a6880900637cac7ebd26ca810c2b9f2382a5db.
This commit is contained in:
parent
18a6880900
commit
7ea1d7d0da
@ -79,7 +79,7 @@
|
||||
_inflightSemaphore = dispatch_semaphore_create(MAX_INFLIGHT);
|
||||
_device = d;
|
||||
_layer = layer;
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
_layer.framebufferOnly = NO;
|
||||
_layer.displaySyncEnabled = YES;
|
||||
#endif
|
||||
@ -170,17 +170,17 @@
|
||||
|
||||
- (void)setDisplaySyncEnabled:(bool)displaySyncEnabled
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
_layer.displaySyncEnabled = displaySyncEnabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (bool)displaySyncEnabled
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
return NO;
|
||||
#else
|
||||
#ifdef OSX
|
||||
return _layer.displaySyncEnabled;
|
||||
#else
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -650,7 +650,7 @@
|
||||
|
||||
if (_blitCommandBuffer)
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
if (_captureEnabled)
|
||||
{
|
||||
id<MTLBlitCommandEncoder> bce = [_blitCommandBuffer blitCommandEncoder];
|
||||
@ -745,7 +745,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
|
||||
- (void)commitRanges
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
BufferNode *n;
|
||||
for (n = _head; n != nil; n = n.next)
|
||||
{
|
||||
|
@ -23,14 +23,13 @@
|
||||
#else
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#include <GLKit/GLKit.h>
|
||||
#else
|
||||
#ifdef OSX
|
||||
#include <OpenGL/CGLTypes.h>
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <AppKit/NSScreen.h>
|
||||
#include <AppKit/NSOpenGL.h>
|
||||
#elif defined(HAVE_COCOATOUCH)
|
||||
#include <GLKit/GLKit.h>
|
||||
#endif
|
||||
|
||||
#include <retro_assert.h>
|
||||
@ -58,12 +57,12 @@
|
||||
|
||||
typedef struct cocoa_ctx_data
|
||||
{
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifndef OSX
|
||||
int fast_forward_skips;
|
||||
#endif
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifndef OSX
|
||||
bool is_syncing;
|
||||
#endif
|
||||
bool core_hw_context_enable;
|
||||
@ -128,6 +127,13 @@ static void cocoa_gl_gfx_ctx_set_flags(void *data, uint32_t flags)
|
||||
cocoa_ctx->core_hw_context_enable = true;
|
||||
}
|
||||
|
||||
#if defined(OSX)
|
||||
void cocoa_gl_gfx_ctx_update(void)
|
||||
{
|
||||
[g_ctx update];
|
||||
[g_hw_ctx update];
|
||||
}
|
||||
#else
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
void *glkitview_init(void)
|
||||
{
|
||||
@ -145,13 +151,9 @@ void glkitview_bind_fbo(void)
|
||||
if (glk_view)
|
||||
[glk_view bindDrawable];
|
||||
}
|
||||
#else
|
||||
void cocoa_gl_gfx_ctx_update(void)
|
||||
{
|
||||
[g_ctx update];
|
||||
[g_hw_ctx update];
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
static void cocoa_gl_gfx_ctx_destroy(void *data)
|
||||
{
|
||||
@ -159,10 +161,7 @@ static void cocoa_gl_gfx_ctx_destroy(void *data)
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return;
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
#else
|
||||
#ifdef OSX
|
||||
[GLContextClass clearCurrentContext];
|
||||
[g_ctx clearDrawable];
|
||||
RELEASE(g_ctx);
|
||||
@ -170,8 +169,9 @@ static void cocoa_gl_gfx_ctx_destroy(void *data)
|
||||
[g_hw_ctx clearDrawable];
|
||||
RELEASE(g_hw_ctx);
|
||||
[GLContextClass clearCurrentContext];
|
||||
#else
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
#endif
|
||||
|
||||
g_ctx = nil;
|
||||
|
||||
free(cocoa_ctx);
|
||||
@ -189,18 +189,7 @@ static void cocoa_gl_gfx_ctx_input_driver(void *data,
|
||||
*input_data = NULL;
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
/* iOS */
|
||||
static void cocoa_gl_gfx_ctx_get_video_size(void *data,
|
||||
unsigned* width, unsigned* height)
|
||||
{
|
||||
float screenscale = cocoa_screen_get_native_scale();
|
||||
CGRect size = glk_view.bounds;
|
||||
*width = CGRectGetWidth(size) * screenscale;
|
||||
*height = CGRectGetHeight(size) * screenscale;
|
||||
}
|
||||
#else
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
/* NOTE: convertRectToBacking only available on MacOS X 10.7 and up.
|
||||
* Therefore, make specialized version of this function instead of
|
||||
* going through a selector for every call. */
|
||||
@ -217,7 +206,7 @@ static void cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up(void *data,
|
||||
*width = CGRectGetWidth(size);
|
||||
*height = CGRectGetHeight(size);
|
||||
}
|
||||
#else
|
||||
#elif defined(OSX)
|
||||
static void cocoa_gl_gfx_ctx_get_video_size(void *data,
|
||||
unsigned* width, unsigned* height)
|
||||
{
|
||||
@ -229,7 +218,16 @@ static void cocoa_gl_gfx_ctx_get_video_size(void *data,
|
||||
*width = CGRectGetWidth(size);
|
||||
*height = CGRectGetHeight(size);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
/* iOS */
|
||||
static void cocoa_gl_gfx_ctx_get_video_size(void *data,
|
||||
unsigned* width, unsigned* height)
|
||||
{
|
||||
float screenscale = cocoa_screen_get_native_scale();
|
||||
CGRect size = glk_view.bounds;
|
||||
*width = CGRectGetWidth(size) * screenscale;
|
||||
*height = CGRectGetHeight(size) * screenscale;
|
||||
}
|
||||
#endif
|
||||
|
||||
static gfx_ctx_proc_t cocoa_gl_gfx_ctx_get_proc_address(const char *symbol_name)
|
||||
@ -246,17 +244,26 @@ static void cocoa_gl_gfx_ctx_bind_hw_render(void *data, bool enable)
|
||||
|
||||
cocoa_ctx->use_hw_ctx = enable;
|
||||
|
||||
#ifdef HAVE_COCOATOUCH
|
||||
#ifdef OSX
|
||||
if (enable)
|
||||
[EAGLContext setCurrentContext:g_hw_ctx];
|
||||
{
|
||||
[g_hw_ctx makeCurrentContext];
|
||||
}
|
||||
else
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
{
|
||||
[g_ctx makeCurrentContext];
|
||||
}
|
||||
#else
|
||||
if (enable)
|
||||
[g_hw_ctx makeCurrentContext];
|
||||
{
|
||||
[EAGLContext setCurrentContext:g_hw_ctx];
|
||||
}
|
||||
else
|
||||
[g_ctx makeCurrentContext];
|
||||
{
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit,
|
||||
@ -266,7 +273,7 @@ static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit,
|
||||
|
||||
*quit = false;
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH)
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height);
|
||||
#else
|
||||
cocoa_gl_gfx_ctx_get_video_size(data, &new_width, &new_height);
|
||||
@ -283,30 +290,30 @@ static void cocoa_gl_gfx_ctx_check_window(void *data, bool *quit,
|
||||
static void cocoa_gl_gfx_ctx_swap_interval(void *data, int i)
|
||||
{
|
||||
unsigned interval = (unsigned)i;
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
GLint value = interval ? 1 : 0;
|
||||
[g_ctx setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
||||
#else
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
/* < No way to disable Vsync on iOS? */
|
||||
/* Just skip presents so fast forward still works. */
|
||||
cocoa_ctx->is_syncing = interval ? true : false;
|
||||
cocoa_ctx->fast_forward_skips = interval ? 0 : 3;
|
||||
#else
|
||||
GLint value = interval ? 1 : 0;
|
||||
[g_ctx setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cocoa_gl_gfx_ctx_swap_buffers(void *data)
|
||||
{
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
[g_ctx flushBuffer];
|
||||
[g_hw_ctx flushBuffer];
|
||||
#else
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
if (!(--cocoa_ctx->fast_forward_skips < 0))
|
||||
return;
|
||||
if (glk_view)
|
||||
[glk_view display];
|
||||
cocoa_ctx->fast_forward_skips = cocoa_ctx->is_syncing ? 0 : 3;
|
||||
#else
|
||||
[g_ctx flushBuffer];
|
||||
[g_hw_ctx flushBuffer];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -320,51 +327,7 @@ static bool cocoa_gl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api,
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
|
||||
if (cocoa_ctx->use_hw_ctx)
|
||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
glk_view.context = g_ctx;
|
||||
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
|
||||
/* TODO: Maybe iOS users should be able to
|
||||
* show/hide the status bar here? */
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *cocoa_gl_gfx_ctx_init(void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
cocoa_ctx->is_syncing = true;
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
/* The Metal build supports both the OpenGL
|
||||
* and Metal video drivers */
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return cocoa_ctx;
|
||||
}
|
||||
#else
|
||||
#ifdef OSX
|
||||
static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
@ -446,10 +409,10 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||
}
|
||||
|
||||
[g_ctx setView:g_view];
|
||||
#ifdef HAVE_COCOATOUCH
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
#else
|
||||
#ifdef OSX
|
||||
[g_ctx makeCurrentContext];
|
||||
#else
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
#endif
|
||||
|
||||
/* TODO/FIXME: Screen mode support. */
|
||||
@ -486,12 +449,66 @@ static void *cocoa_gl_gfx_ctx_init(void *video_driver)
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
#ifndef OSX
|
||||
cocoa_ctx->is_syncing = true;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL];
|
||||
#endif
|
||||
|
||||
return cocoa_ctx;
|
||||
}
|
||||
#else
|
||||
static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
|
||||
if (cocoa_ctx->use_hw_ctx)
|
||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
glk_view.context = g_ctx;
|
||||
|
||||
#ifdef OSX
|
||||
[g_ctx makeCurrentContext];
|
||||
#else
|
||||
[EAGLContext setCurrentContext:g_ctx];
|
||||
#endif
|
||||
|
||||
/* TODO: Maybe iOS users should be able to
|
||||
* show/hide the status bar here? */
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *cocoa_gl_gfx_ctx_init(void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
#ifndef OSX
|
||||
cocoa_ctx->is_syncing = true;
|
||||
#endif
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
/* The Metal build supports both the OpenGL
|
||||
* and Metal video drivers */
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return cocoa_ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COCOA_METAL
|
||||
@ -508,7 +525,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = {
|
||||
cocoa_gl_gfx_ctx_bind_api,
|
||||
cocoa_gl_gfx_ctx_swap_interval,
|
||||
cocoa_gl_gfx_ctx_set_video_mode,
|
||||
#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH)
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
cocoa_gl_gfx_ctx_get_video_size_osx10_7_and_up,
|
||||
#else
|
||||
cocoa_gl_gfx_ctx_get_video_size,
|
||||
@ -519,7 +536,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = {
|
||||
NULL, /* get_video_output_next */
|
||||
cocoa_get_metrics,
|
||||
NULL, /* translate_aspect */
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
cocoa_update_title,
|
||||
#else
|
||||
NULL, /* update_title */
|
||||
|
@ -23,7 +23,7 @@
|
||||
#else
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#endif
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
#include <AppKit/NSScreen.h>
|
||||
#endif
|
||||
|
||||
@ -96,7 +96,7 @@ static void cocoa_vk_gfx_ctx_input_driver(void *data,
|
||||
*input_data = NULL;
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH)
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
/* NOTE: convertRectToBacking only available on MacOS X 10.7 and up.
|
||||
* Therefore, make specialized version of this function instead of
|
||||
* going through a selector for every call. */
|
||||
@ -113,7 +113,7 @@ static void cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up(void *data,
|
||||
*width = CGRectGetWidth(size);
|
||||
*height = CGRectGetHeight(size);
|
||||
}
|
||||
#elif !defined(HAVE_COCOATOUCH)
|
||||
#elif defined(OSX)
|
||||
static void cocoa_vk_gfx_ctx_get_video_size(void *data,
|
||||
unsigned* width, unsigned* height)
|
||||
{
|
||||
@ -144,7 +144,7 @@ static void cocoa_vk_gfx_ctx_check_window(void *data, bool *quit,
|
||||
|
||||
*resize = cocoa_ctx->vk.need_new_swapchain;
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH)
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height);
|
||||
#else
|
||||
cocoa_vk_gfx_ctx_get_video_size(data, &new_width, &new_height);
|
||||
@ -201,7 +201,7 @@ static void *cocoa_vk_gfx_ctx_get_context_data(void *data)
|
||||
return &cocoa_ctx->vk.context;
|
||||
}
|
||||
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
@ -261,7 +261,7 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
|
||||
static void *cocoa_vk_gfx_ctx_init(void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
@ -272,7 +272,7 @@ static void *cocoa_vk_gfx_ctx_init(void *video_driver)
|
||||
free(cocoa_ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return cocoa_ctx;
|
||||
}
|
||||
#else
|
||||
@ -289,7 +289,7 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
|
||||
static void *cocoa_vk_gfx_ctx_init(void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
@ -330,7 +330,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoavk = {
|
||||
cocoa_vk_gfx_ctx_bind_api,
|
||||
cocoa_vk_gfx_ctx_swap_interval,
|
||||
cocoa_vk_gfx_ctx_set_video_mode,
|
||||
#if MAC_OS_X_VERSION_10_7 && !defined(HAVE_COCOATOUCH)
|
||||
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
|
||||
cocoa_vk_gfx_ctx_get_video_size_osx10_7_and_up,
|
||||
#else
|
||||
cocoa_vk_gfx_ctx_get_video_size,
|
||||
@ -341,7 +341,7 @@ const gfx_ctx_driver_t gfx_ctx_cocoavk = {
|
||||
NULL, /* get_video_output_next */
|
||||
cocoa_get_metrics,
|
||||
NULL, /* translate_aspect */
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
cocoa_update_title,
|
||||
#else
|
||||
NULL, /* update_title */
|
||||
|
@ -28,6 +28,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOATOUCH) || defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
|
||||
|
||||
#include "../ui/drivers/cocoa/cocoa_common.m"
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL_ES)
|
||||
#include "../gfx/drivers_context/cocoa_gl_ctx.m"
|
||||
@ -35,16 +36,17 @@
|
||||
#if defined(HAVE_VULKAN)
|
||||
#include "../gfx/drivers_context/cocoa_vk_ctx.m"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#include "../ui/drivers/ui_cocoatouch.m"
|
||||
#else
|
||||
#if defined(OSX)
|
||||
#include "../ui/drivers/cocoa/ui_cocoa_window.m"
|
||||
#include "../ui/drivers/cocoa/ui_cocoa_browser_window.m"
|
||||
#include "../ui/drivers/cocoa/ui_cocoa_application.m"
|
||||
#include "../ui/drivers/cocoa/ui_cocoa_msg_window.m"
|
||||
#include "../ui/drivers/ui_cocoa.m"
|
||||
#else
|
||||
#include "../ui/drivers/ui_cocoatouch.m"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MFI
|
||||
|
@ -35,7 +35,7 @@
|
||||
/* TODO/FIXME -
|
||||
* fix game focus toggle */
|
||||
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
/* Forward declaration */
|
||||
float cocoa_screen_get_backing_scale_factor(void);
|
||||
#endif
|
||||
|
@ -8,9 +8,20 @@
|
||||
|
||||
#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
|
||||
@interface WindowListener : NSResponder<NSWindowDelegate>
|
||||
@end
|
||||
|
||||
@implementation WindowListener
|
||||
|
||||
/* Similarly to SDL, we'll respond to key events by doing nothing so we don't beep.
|
||||
*/
|
||||
- (void)flagsChanged:(NSEvent *)event { }
|
||||
- (void)keyDown:(NSEvent *)event { }
|
||||
- (void)keyUp:(NSEvent *)event { }
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH)
|
||||
@protocol ApplePlatform
|
||||
|
||||
@ -30,6 +41,9 @@
|
||||
- (bool)setDisableDisplaySleep:(bool)disable;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH)
|
||||
extern id<ApplePlatform> apple_platform;
|
||||
|
||||
id<ApplePlatform> apple_platform;
|
||||
|
@ -45,7 +45,7 @@ void *glkitview_init(void);
|
||||
|
||||
@implementation CocoaView
|
||||
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#if defined(OSX)
|
||||
#ifdef HAVE_COCOA_METAL
|
||||
- (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)newScale fromWindow:(NSWindow *)window { return YES; }
|
||||
#endif
|
||||
@ -67,36 +67,86 @@ void *glkitview_init(void);
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#if defined(OSX)
|
||||
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
NSArray *array = [NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil];
|
||||
[self registerForDraggedTypes:array];
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOA)
|
||||
ui_window_cocoa_t cocoa_view;
|
||||
cocoa_view.data = (CocoaView*)self;
|
||||
#elif defined(HAVE_COCOATOUCH)
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
self.view = [UIView new];
|
||||
#else
|
||||
self.view = (BRIDGE GLKView*)glkitview_init();
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showNativeMenu)];
|
||||
swipe.numberOfTouchesRequired = 4;
|
||||
swipe.direction = UISwipeGestureRecognizerDirectionDown;
|
||||
[self.view addGestureRecognizer:swipe];
|
||||
#endif
|
||||
#else
|
||||
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
NSArray *array = [NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil];
|
||||
[self registerForDraggedTypes:array];
|
||||
|
||||
ui_window_cocoa_t cocoa_view;
|
||||
cocoa_view.data = (CocoaView*)self;
|
||||
|
||||
video_driver_display_type_set(RARCH_DISPLAY_OSX);
|
||||
video_driver_display_set(0);
|
||||
video_driver_display_userdata_set((uintptr_t)self);
|
||||
|
||||
#if defined(OSX)
|
||||
video_driver_display_type_set(RARCH_DISPLAY_OSX);
|
||||
video_driver_display_set(0);
|
||||
video_driver_display_userdata_set((uintptr_t)self);
|
||||
#elif TARGET_OS_IOS
|
||||
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showNativeMenu)];
|
||||
swipe.numberOfTouchesRequired = 4;
|
||||
swipe.direction = UISwipeGestureRecognizerDirectionDown;
|
||||
[self.view addGestureRecognizer:swipe];
|
||||
#endif
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
#if defined(OSX)
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
/* forward declarations */
|
||||
#if defined(HAVE_OPENGL)
|
||||
void cocoa_gl_gfx_ctx_update(void);
|
||||
cocoa_gl_gfx_ctx_update();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Stop the annoying sound when pressing a key. */
|
||||
- (BOOL)acceptsFirstResponder { return YES; }
|
||||
- (BOOL)isFlipped { return YES; }
|
||||
- (void)keyDown:(NSEvent*)theEvent { }
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
|
||||
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
|
||||
{
|
||||
if (sourceDragMask & NSDragOperationCopy)
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
|
||||
if ( [[pboard types] containsObject:NSURLPboardType])
|
||||
{
|
||||
NSURL *fileURL = [NSURL URLFromPasteboard:pboard];
|
||||
NSString *s = [fileURL path];
|
||||
if (s != nil)
|
||||
{
|
||||
RARCH_LOG("Drop name is: %s\n", [s UTF8String]);
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender { [self setNeedsDisplay: YES]; }
|
||||
|
||||
#elif TARGET_OS_IOS
|
||||
-(void) showNativeMenu
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@ -216,6 +266,7 @@ void *glkitview_init(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COCOATOUCH
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
#if TARGET_OS_IOS
|
||||
@ -260,53 +311,6 @@ void *glkitview_init(void);
|
||||
}];
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
/* forward declarations */
|
||||
#if defined(HAVE_OPENGL)
|
||||
void cocoa_gl_gfx_ctx_update(void);
|
||||
cocoa_gl_gfx_ctx_update();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Stop the annoying sound when pressing a key. */
|
||||
- (BOOL)acceptsFirstResponder { return YES; }
|
||||
- (BOOL)isFlipped { return YES; }
|
||||
- (void)keyDown:(NSEvent*)theEvent { }
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
|
||||
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
|
||||
{
|
||||
if (sourceDragMask & NSDragOperationCopy)
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
|
||||
if ( [[pboard types] containsObject:NSURLPboardType])
|
||||
{
|
||||
NSURL *fileURL = [NSURL URLFromPasteboard:pboard];
|
||||
NSString *s = [fileURL path];
|
||||
if (s != nil)
|
||||
{
|
||||
RARCH_LOG("Drop name is: %s\n", [s UTF8String]);
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender { [self setNeedsDisplay: YES]; }
|
||||
#endif
|
||||
|
||||
@end
|
||||
@ -342,7 +346,7 @@ bool cocoa_has_focus(void *data)
|
||||
|
||||
void cocoa_show_mouse(void *data, bool state)
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
if (state)
|
||||
[NSCursor unhide];
|
||||
else
|
||||
@ -350,7 +354,26 @@ void cocoa_show_mouse(void *data, bool state)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
/* NOTE: backingScaleFactor only available on MacOS X 10.7 and up. */
|
||||
float cocoa_screen_get_backing_scale_factor(void)
|
||||
{
|
||||
static float
|
||||
backing_scale_def = 0.0f;
|
||||
if (backing_scale_def == 0.0f)
|
||||
{
|
||||
RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen();
|
||||
if (!screen)
|
||||
return 1.0f;
|
||||
backing_scale_def = [screen backingScaleFactor];
|
||||
}
|
||||
return backing_scale_def;
|
||||
}
|
||||
#else
|
||||
float cocoa_screen_get_backing_scale_factor(void) { return 1.0f; }
|
||||
#endif
|
||||
#else
|
||||
static float get_from_selector(
|
||||
Class obj_class, id obj_id, SEL selector, CGFloat *ret)
|
||||
{
|
||||
@ -392,30 +415,11 @@ float cocoa_screen_get_native_scale(void)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
/* NOTE: backingScaleFactor only available on MacOS X 10.7 and up. */
|
||||
float cocoa_screen_get_backing_scale_factor(void)
|
||||
{
|
||||
static float
|
||||
backing_scale_def = 0.0f;
|
||||
if (backing_scale_def == 0.0f)
|
||||
{
|
||||
RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen();
|
||||
if (!screen)
|
||||
return 1.0f;
|
||||
backing_scale_def = [screen backingScaleFactor];
|
||||
}
|
||||
return backing_scale_def;
|
||||
}
|
||||
#else
|
||||
float cocoa_screen_get_backing_scale_factor(void) { return 1.0f; }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void *nsview_get_ptr(void)
|
||||
{
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
#if defined(OSX)
|
||||
video_driver_display_type_set(RARCH_DISPLAY_OSX);
|
||||
video_driver_display_set(0);
|
||||
video_driver_display_userdata_set((uintptr_t)g_instance);
|
||||
@ -437,7 +441,62 @@ CocoaView *cocoaview_get(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
#ifdef OSX
|
||||
void cocoa_update_title(void *data)
|
||||
{
|
||||
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
||||
|
||||
if (window)
|
||||
{
|
||||
char title[128];
|
||||
|
||||
title[0] = '\0';
|
||||
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
|
||||
if (title[0])
|
||||
window->set_title((void*)video_driver_display_userdata_get(), title);
|
||||
}
|
||||
}
|
||||
|
||||
bool cocoa_get_metrics(
|
||||
void *data, enum display_metric_types type,
|
||||
float *value)
|
||||
{
|
||||
RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen();
|
||||
NSDictionary *desc = [screen deviceDescription];
|
||||
CGSize display_physical_size = CGDisplayScreenSize(
|
||||
[[desc objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
||||
|
||||
float physical_width = display_physical_size.width;
|
||||
float physical_height = display_physical_size.height;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DISPLAY_METRIC_MM_WIDTH:
|
||||
*value = physical_width;
|
||||
break;
|
||||
case DISPLAY_METRIC_MM_HEIGHT:
|
||||
*value = physical_height;
|
||||
break;
|
||||
case DISPLAY_METRIC_DPI:
|
||||
{
|
||||
NSSize disp_pixel_size = [[desc objectForKey:NSDeviceSize] sizeValue];
|
||||
float dispwidth = disp_pixel_size.width;
|
||||
float scale = cocoa_screen_get_backing_scale_factor();
|
||||
float dpi = (dispwidth / physical_width) * 25.4f * scale;
|
||||
*value = dpi;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_METRIC_NONE:
|
||||
default:
|
||||
*value = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool cocoa_get_metrics(
|
||||
void *data, enum display_metric_types type,
|
||||
float *value)
|
||||
@ -493,72 +552,4 @@ bool cocoa_get_metrics(
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
void cocoa_update_title(void *data)
|
||||
{
|
||||
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
||||
|
||||
if (window)
|
||||
{
|
||||
char title[128];
|
||||
|
||||
title[0] = '\0';
|
||||
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
|
||||
if (title[0])
|
||||
window->set_title((void*)video_driver_display_userdata_get(), title);
|
||||
}
|
||||
}
|
||||
|
||||
bool cocoa_get_metrics(
|
||||
void *data, enum display_metric_types type,
|
||||
float *value)
|
||||
{
|
||||
RAScreen *screen = (BRIDGE RAScreen*)cocoa_screen_get_chosen();
|
||||
NSDictionary *desc = [screen deviceDescription];
|
||||
CGSize display_physical_size = CGDisplayScreenSize(
|
||||
[[desc objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
||||
|
||||
float physical_width = display_physical_size.width;
|
||||
float physical_height = display_physical_size.height;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DISPLAY_METRIC_MM_WIDTH:
|
||||
*value = physical_width;
|
||||
break;
|
||||
case DISPLAY_METRIC_MM_HEIGHT:
|
||||
*value = physical_height;
|
||||
break;
|
||||
case DISPLAY_METRIC_DPI:
|
||||
{
|
||||
NSSize disp_pixel_size = [[desc objectForKey:NSDeviceSize] sizeValue];
|
||||
float dispwidth = disp_pixel_size.width;
|
||||
float scale = cocoa_screen_get_backing_scale_factor();
|
||||
float dpi = (dispwidth / physical_width) * 25.4f * scale;
|
||||
*value = dpi;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_METRIC_NONE:
|
||||
default:
|
||||
*value = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
|
||||
@implementation WindowListener
|
||||
|
||||
/* Similarly to SDL, we'll respond to key events
|
||||
* by doing nothing so we don't beep.
|
||||
*/
|
||||
- (void)flagsChanged:(NSEvent *)event { }
|
||||
- (void)keyDown:(NSEvent *)event { }
|
||||
- (void)keyUp:(NSEvent *)event { }
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user