Merge branch 'master' into rcheevos_runtime

This commit is contained in:
Jamiras 2020-09-15 09:09:30 -06:00
commit 9f992eb709
29 changed files with 511 additions and 316 deletions

View File

@ -1151,6 +1151,16 @@ static const unsigned turbo_default_btn = RETRO_DEVICE_ID_JOYPAD_B;
* gamepads, plug-and-play style. */
static const bool input_autodetect_enable = true;
/* Enables accelerometer/gyroscope/illuminance
* sensor input, if supported */
#if defined(ANDROID)
/* Hardware sensors cause substantial battery
* drain on Android... */
#define DEFAULT_INPUT_SENSORS_ENABLE false
#else
#define DEFAULT_INPUT_SENSORS_ENABLE true
#endif
/* Show the input descriptors set by the core instead
* of the default ones. */
static const bool input_descriptor_label_show = true;

View File

@ -1707,6 +1707,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("config_save_on_exit", &settings->bools.config_save_on_exit, true, DEFAULT_CONFIG_SAVE_ON_EXIT, false);
SETTING_BOOL("show_hidden_files", &settings->bools.show_hidden_files, true, DEFAULT_SHOW_HIDDEN_FILES, false);
SETTING_BOOL("input_autodetect_enable", &settings->bools.input_autodetect_enable, true, input_autodetect_enable, false);
SETTING_BOOL("input_sensors_enable", &settings->bools.input_sensors_enable, true, DEFAULT_INPUT_SENSORS_ENABLE, false);
SETTING_BOOL("audio_rate_control", &settings->bools.audio_rate_control, true, DEFAULT_RATE_CONTROL, false);
#ifdef HAVE_WASAPI
SETTING_BOOL("audio_wasapi_exclusive_mode", &settings->bools.audio_wasapi_exclusive_mode, true, DEFAULT_WASAPI_EXCLUSIVE_MODE, false);

View File

@ -496,6 +496,7 @@ typedef struct settings
/* Input */
bool input_remap_binds_enable;
bool input_autodetect_enable;
bool input_sensors_enable;
bool input_overlay_enable;
bool input_overlay_enable_autopreferred;
bool input_overlay_hide_in_menu;

View File

@ -138,9 +138,11 @@ struct android_app
/* Below are "private" implementation of RA code. */
bool unfocused;
unsigned accelerometer_event_rate;
unsigned gyroscope_event_rate;
ASensorManager *sensorManager;
ASensorEventQueue *sensorEventQueue;
const ASensor* accelerometerSensor;
const ASensor* gyroscopeSensor;
uint64_t sensor_state_mask;
char current_ime[PATH_MAX_LENGTH];
bool input_alive;

View File

@ -2335,7 +2335,8 @@ static void gl2_render_osd_background(gl_t *gl, const char *msg)
coords.lut_tex_coord = dummy;
coords.vertices = vertices_total;
video_driver_set_viewport(gl->video_width,
gl2_set_viewport(gl,
gl->video_width,
gl->video_height, true, false);
gl->shader->use(gl, gl->shader_data,
@ -2382,7 +2383,8 @@ static void gl2_render_osd_background(gl_t *gl, const char *msg)
free(dummy);
free(verts);
video_driver_set_viewport(gl->video_width,
gl2_set_viewport(gl,
gl->video_width,
gl->video_height, false, true);
}

View File

@ -52,9 +52,6 @@
typedef struct cocoa_ctx_data
{
bool is_syncing;
bool core_hw_context_enable;
bool use_hw_ctx;
#ifdef HAVE_VULKAN
gfx_ctx_vulkan_data_t vk;
int swap_interval;
@ -62,6 +59,9 @@ typedef struct cocoa_ctx_data
int fast_forward_skips;
unsigned width;
unsigned height;
bool is_syncing;
bool core_hw_context_enable;
bool use_hw_ctx;
} cocoa_ctx_data_t;
/* TODO/FIXME - static globals */
@ -97,23 +97,22 @@ static CocoaView* g_instance;
void *nsview_get_ptr(void)
{
#if defined(HAVE_COCOA)
video_driver_display_type_set(RARCH_DISPLAY_OSX);
video_driver_display_set(0);
video_driver_display_userdata_set((uintptr_t)g_instance);
video_driver_display_type_set(RARCH_DISPLAY_OSX);
video_driver_display_set(0);
video_driver_display_userdata_set((uintptr_t)g_instance);
#elif defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
video_driver_display_type_set(RARCH_DISPLAY_OSX);
video_driver_display_set(0);
video_driver_display_userdata_set((uintptr_t)g_instance);
video_driver_display_type_set(RARCH_DISPLAY_OSX);
video_driver_display_set(0);
video_driver_display_userdata_set((uintptr_t)g_instance);
#endif
return (BRIDGE void *)g_instance;
return (BRIDGE void *)g_instance;
}
void nsview_set_ptr(CocoaView *p)
{
g_instance = p;
}
void nsview_set_ptr(CocoaView *p) { g_instance = p; }
#if TARGET_OS_OSX
static SEL sel_flushBuffer;
static SEL updateSel;
static NSOpenGLPixelFormat* g_format;
void *glcontext_get_ptr(void)
@ -166,7 +165,6 @@ static uint32_t cocoagl_gfx_ctx_get_flags(void *data)
static void cocoagl_gfx_ctx_set_flags(void *data, uint32_t flags)
{
(void)flags;
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT))
@ -184,7 +182,7 @@ void *glkitview_init(void)
return (BRIDGE void *)((GLKView*)g_view);
#else
return nsview_get_ptr();
return nsview_get_ptr();
#endif
}
@ -196,7 +194,8 @@ void cocoagl_bind_game_view_fbo(void)
}
#endif
static float get_from_selector(Class obj_class, id obj_id, SEL selector, CGFloat *ret)
static float get_from_selector(
Class obj_class, id obj_id, SEL selector, CGFloat *ret)
{
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[obj_class instanceMethodSignatureForSelector:selector]];
@ -230,21 +229,16 @@ void *get_chosen_screen(void)
float get_backing_scale_factor(void)
{
static float
backing_scale_def = 0.0f;
#if TARGET_OS_OSX
RAScreen *screen = NULL;
#endif
backing_scale_def = 0.0f;
if (backing_scale_def != 0.0f)
return backing_scale_def;
backing_scale_def = 1.0f;
backing_scale_def = 1.0f;
#if TARGET_OS_OSX
screen = (BRIDGE RAScreen*)get_chosen_screen();
if (screen)
{
SEL selector = NSSelectorFromString(BOXSTRING("backingScaleFactor"));
if ([screen respondsToSelector:selector])
id nsscreen = objc_getClass("NSScreen");
SEL selector = sel_registerName("backingScaleFactor");
if (class_respondsToSelector(nsscreen, selector))
{
CGFloat ret;
#if defined(HAVE_COCOA_METAL)
@ -253,7 +247,7 @@ float get_backing_scale_factor(void)
CocoaView *g_view = g_instance;
#endif
backing_scale_def = (float)get_from_selector
([[g_view window] class], [g_view window], selector, &ret);
([[g_view window] class], [g_view window], selector, &ret);
}
}
#endif
@ -272,8 +266,8 @@ void cocoagl_gfx_ctx_update(void)
CGLUpdateContext(g_hw_ctx.CGLContextObj);
CGLUpdateContext(g_context.CGLContextObj);
#else
[g_hw_ctx update];
[g_context update];
((void (*)(id, SEL))objc_msgSend)(g_hw_ctx, updateSel);
((void (*)(id, SEL))objc_msgSend)(g_context, updateSel);
#endif
#endif
#endif
@ -336,8 +330,6 @@ static enum gfx_ctx_api cocoagl_gfx_ctx_get_api(void *data)
static void cocoagl_gfx_ctx_show_mouse(void *data, bool state)
{
(void)data;
#if TARGET_OS_OSX
if (state)
[NSCursor unhide];
@ -386,94 +378,87 @@ static void cocoagl_gfx_ctx_update_title(void *data)
}
#endif
static bool cocoagl_gfx_ctx_get_metrics(void *data, enum display_metric_types type,
float *value)
static bool cocoagl_gfx_ctx_get_metrics(
void *data, enum display_metric_types type,
float *value)
{
RAScreen *screen = (BRIDGE RAScreen*)get_chosen_screen();
RAScreen *screen = (BRIDGE RAScreen*)get_chosen_screen();
#if TARGET_OS_OSX
NSDictionary *description = [screen deviceDescription];
NSSize display_pixel_size = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize display_physical_size = CGDisplayScreenSize(
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
NSDictionary *description = [screen deviceDescription];
NSSize display_pixel_size = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize display_physical_size = CGDisplayScreenSize(
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
float display_width = display_pixel_size.width;
float display_height = display_pixel_size.height;
float physical_width = display_physical_size.width;
float physical_height = display_physical_size.height;
float scale = get_backing_scale_factor();
float dpi = (display_width/ physical_width) * 25.4f * scale;
float display_width = display_pixel_size.width;
float display_height = display_pixel_size.height;
float physical_width = display_physical_size.width;
float physical_height = display_physical_size.height;
float scale = get_backing_scale_factor();
float dpi = (display_width/ physical_width) * 25.4f * scale;
#elif defined(HAVE_COCOATOUCH)
float scale = cocoagl_gfx_ctx_get_native_scale();
CGRect screen_rect = [screen bounds];
float display_height = screen_rect.size.height;
float physical_width = screen_rect.size.width * scale;
float physical_height = screen_rect.size.height * scale;
float dpi = 160 * scale;
CGFloat maxSize = fmaxf(physical_width, physical_height);
NSInteger idiom_type = UI_USER_INTERFACE_IDIOM();
float scale = cocoagl_gfx_ctx_get_native_scale();
CGRect screen_rect = [screen bounds];
float display_height = screen_rect.size.height;
float physical_width = screen_rect.size.width * scale;
float physical_height = screen_rect.size.height * scale;
float dpi = 160 * scale;
CGFloat maxSize = fmaxf(physical_width, physical_height);
NSInteger idiom_type = UI_USER_INTERFACE_IDIOM();
switch (idiom_type)
{
case -1: /* UIUserInterfaceIdiomUnspecified */
/* TODO */
break;
case UIUserInterfaceIdiomPad:
dpi = 132 * scale;
break;
case UIUserInterfaceIdiomPhone:
if (maxSize >= 2208.0) {
// Larger iPhones: iPhone Plus, X, XR, XS, XS Max, 11, 11 Pro Max
dpi = 81 * scale;
} else {
dpi = 163 * scale;
}
break;
case UIUserInterfaceIdiomTV:
case UIUserInterfaceIdiomCarPlay:
/* TODO */
break;
}
switch (idiom_type)
{
case -1: /* UIUserInterfaceIdiomUnspecified */
/* TODO */
break;
case UIUserInterfaceIdiomPad:
dpi = 132 * scale;
break;
case UIUserInterfaceIdiomPhone:
/* Larger iPhones: iPhone Plus, X, XR, XS, XS Max, 11, 11 Pro Max */
if (maxSize >= 2208.0)
dpi = 81 * scale;
else
dpi = 163 * scale;
break;
case UIUserInterfaceIdiomTV:
case UIUserInterfaceIdiomCarPlay:
/* TODO */
break;
}
#endif
(void)display_height;
(void)display_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:
*value = dpi;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
switch (type)
{
case DISPLAY_METRIC_MM_WIDTH:
*value = physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = physical_height;
break;
case DISPLAY_METRIC_DPI:
*value = dpi;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
return true;
return true;
}
static bool cocoagl_gfx_ctx_has_focus(void *data)
{
(void)data;
#if defined(HAVE_COCOATOUCH)
return ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive);
return ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive);
#else
return [NSApp isActive];
return [NSApp isActive];
#endif
}
static bool cocoagl_gfx_ctx_suppress_screensaver(void *data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static bool cocoagl_gfx_ctx_suppress_screensaver(void *data, bool enable) { return false; }
static void cocoagl_gfx_ctx_input_driver(void *data,
const char *name,
@ -483,7 +468,8 @@ static void cocoagl_gfx_ctx_input_driver(void *data,
*input_data = NULL;
}
static void cocoagl_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height)
static void cocoagl_gfx_ctx_get_video_size(void *data,
unsigned* width, unsigned* height)
{
float screenscale = cocoagl_gfx_ctx_get_native_scale();
#if TARGET_OS_OSX
@ -558,7 +544,7 @@ static void cocoagl_gfx_ctx_check_window(void *data, bool *quit,
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
#endif
*quit = false;
*quit = false;
switch (cocoagl_api)
{
@ -567,7 +553,7 @@ static void cocoagl_gfx_ctx_check_window(void *data, bool *quit,
break;
case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
*resize = cocoa_ctx->vk.need_new_swapchain;
*resize = cocoa_ctx->vk.need_new_swapchain;
#endif
break;
case GFX_CTX_NONE:
@ -594,8 +580,9 @@ static void cocoagl_gfx_ctx_swap_interval(void *data, int i)
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
{
#if defined(HAVE_COCOATOUCH) // < No way to disable Vsync on iOS?
// Just skip presents so fast forward still works.
#if defined(HAVE_COCOATOUCH)
/* < 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;
#elif defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
@ -632,8 +619,8 @@ static void cocoagl_gfx_ctx_swap_buffers(void *data)
return;
#if TARGET_OS_OSX
[g_context flushBuffer];
[g_hw_ctx flushBuffer];
((id (*)(id, SEL))objc_msgSend)(g_context, sel_flushBuffer);
((id (*)(id, SEL))objc_msgSend)(g_hw_ctx, sel_flushBuffer);
#elif defined(HAVE_COCOATOUCH)
if (g_view)
[g_view display];
@ -663,7 +650,6 @@ static void cocoagl_gfx_ctx_swap_buffers(void *data)
static bool cocoagl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api,
unsigned major, unsigned minor)
{
(void)data;
switch (api)
{
#if defined(HAVE_COCOATOUCH)
@ -707,6 +693,8 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
#endif
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
#if TARGET_OS_OSX
static bool
has_went_fullscreen = false;
cocoa_ctx->width = width;
cocoa_ctx->height = height;
#endif
@ -726,7 +714,7 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAllowOfflineRenderers,
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
(NSOpenGLPixelFormatAttribute)16, /* 16 bit depth buffer */
0, /* profile */
0, /* profile enum */
(NSOpenGLPixelFormatAttribute)0
@ -756,18 +744,18 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
/* NSOpenGLFPAAllowOfflineRenderers is
not supported on this OS version. */
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
}
#endif
if (cocoa_ctx->use_hw_ctx)
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(cocoa_ctx->use_hw_ctx) ? g_hw_ctx : nil];
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(cocoa_ctx->use_hw_ctx) ? g_hw_ctx : nil];
[g_context setView:g_view];
#else
if (cocoa_ctx->use_hw_ctx)
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_view.context = g_context;
#endif
@ -793,9 +781,7 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
}
#if TARGET_OS_OSX
static bool has_went_fullscreen = false;
/* TODO: Screen mode support. */
if (fullscreen)
{
if (!has_went_fullscreen)
@ -823,8 +809,8 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
has_went_fullscreen = fullscreen;
#endif
/* TODO: Maybe iOS users should be able to show/hide the status bar here? */
/* TODO: Maybe iOS users should be able to
* show/hide the status bar here? */
return true;
}
@ -843,11 +829,14 @@ static void *cocoagl_gfx_ctx_init(void *video_driver)
#if defined(HAVE_COCOATOUCH)
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];
/* the metal build supports both the OpenGL
* and Metal video drivers */
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
#endif
/* setViewType is not (yet?) defined for iOS */
#if 0
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
#endif
// setViewType is not (yet?) defined for iOS
// [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
break;
#elif defined(HAVE_COCOA_METAL)
case GFX_CTX_OPENGL_API:
@ -868,6 +857,11 @@ static void *cocoagl_gfx_ctx_init(void *video_driver)
default:
break;
}
#if TARGET_OS_OSX
sel_flushBuffer = sel_registerName("flushBuffer");
updateSel = sel_registerName("update");
#endif
return cocoa_ctx;
}
@ -889,20 +883,18 @@ static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned heig
cocoa_ctx->width = width;
cocoa_ctx->height = height;
if (vulkan_create_swapchain(&cocoa_ctx->vk,
if (!vulkan_create_swapchain(&cocoa_ctx->vk,
width, height, cocoa_ctx->swap_interval))
{
cocoa_ctx->vk.context.invalid_swapchain = true;
if (cocoa_ctx->vk.created_new_swapchain)
vulkan_acquire_next_image(&cocoa_ctx->vk);
}
else
{
RARCH_ERR("[macOS/Vulkan]: Failed to update swapchain.\n");
return false;
}
cocoa_ctx->vk.need_new_swapchain = false;
cocoa_ctx->vk.context.invalid_swapchain = true;
if (cocoa_ctx->vk.created_new_swapchain)
vulkan_acquire_next_image(&cocoa_ctx->vk);
cocoa_ctx->vk.need_new_swapchain = false;
#endif
break;
case GFX_CTX_NONE:

View File

@ -401,8 +401,10 @@ static void gl_raster_font_render_message(
}
}
static void gl_raster_font_setup_viewport(unsigned width, unsigned height,
gl_raster_t *font, bool full_screen)
static void gl_raster_font_setup_viewport(
gl_raster_t *font,
unsigned width, unsigned height,
bool full_screen)
{
video_driver_set_viewport(width, height, full_screen, false);
@ -484,7 +486,7 @@ static void gl_raster_font_render_msg(
if (font->block)
font->block->fullscreen = full_screen;
else
gl_raster_font_setup_viewport(width, height, font, full_screen);
gl_raster_font_setup_viewport(font, width, height, full_screen);
if (font->gl)
{
@ -542,7 +544,7 @@ static void gl_raster_font_flush_block(unsigned width, unsigned height,
if (!font || !block || !block->carr.coords.vertices)
return;
gl_raster_font_setup_viewport(width, height, font, block->fullscreen);
gl_raster_font_setup_viewport(font, width, height, block->fullscreen);
gl_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords);
if (font->gl)

View File

@ -1634,16 +1634,6 @@ bool gfx_display_get_update_pending(void)
return false;
}
void gfx_display_set_viewport(unsigned width, unsigned height)
{
video_driver_set_viewport(width, height, true, false);
}
void gfx_display_unset_viewport(unsigned width, unsigned height)
{
video_driver_set_viewport(width, height, false, true);
}
/* Checks if the display framebuffer has its 'dirty flag' set. This
* means that the current contents of the framebuffer has changed
* and that it has to be rendered to the screen. */

View File

@ -279,8 +279,6 @@ void gfx_display_set_framebuffer_pitch(size_t pitch);
bool gfx_display_get_msg_force(void);
void gfx_display_set_msg_force(bool state);
bool gfx_display_get_update_pending(void);
void gfx_display_set_viewport(unsigned width, unsigned height);
void gfx_display_unset_viewport(unsigned width, unsigned height);
bool gfx_display_get_framebuffer_dirty_flag(void);
void gfx_display_set_framebuffer_dirty_flag(void);
void gfx_display_unset_framebuffer_dirty_flag(void);

View File

@ -1321,7 +1321,7 @@ void gfx_widgets_frame(void *data)
p_dispwidget->gfx_widgets_frame_count++;
gfx_display_set_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, true, false);
/* Font setup */
gfx_widgets_font_bind(&p_dispwidget->gfx_widget_fonts.regular);
@ -1550,7 +1550,7 @@ void gfx_widgets_frame(void *data)
gfx_widgets_font_unbind(&p_dispwidget->gfx_widget_fonts.bold);
gfx_widgets_font_unbind(&p_dispwidget->gfx_widget_fonts.msg_queue);
gfx_display_unset_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, false, true);
}
bool gfx_widgets_init(uintptr_t widgets_active_ptr,

View File

@ -69,6 +69,10 @@
#include "../network/net_logger.c"
#endif
#if TARGET_OS_OSX
#include "../ui/drivers/cocoa/ui_cocoa_application.c"
#endif
/*============================================================
COMPATIBILITY
============================================================ */

View File

@ -39,7 +39,6 @@
#if TARGET_OS_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"
#endif

View File

@ -47,6 +47,7 @@
#define MAX_TOUCH 16
#define MAX_NUM_KEYBOARDS 3
#define DEFAULT_ASENSOR_EVENT_RATE 60
/* If using an SDK lower than 14 then add missing mouse button codes */
#if __ANDROID_API__ < 14
@ -153,6 +154,7 @@ typedef struct android_input
unsigned pads_connected;
unsigned pointer_count;
sensor_t accelerometer_state; /* float alignment */
sensor_t gyroscope_state; /* float alignment */
float mouse_x_prev, mouse_y_prev;
struct input_pointer pointer[MAX_TOUCH]; /* int16_t alignment */
char device_model[256];
@ -370,18 +372,27 @@ static void android_input_poll_main_cmd(void)
case APP_CMD_GAINED_FOCUS:
{
bool boolean = false;
bool boolean = false;
bool enable_accelerometer = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE)) &&
!android_app->accelerometerSensor;
bool enable_gyroscope = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_GYROSCOPE_ENABLE)) &&
!android_app->gyroscopeSensor;
rarch_ctl(RARCH_CTL_SET_PAUSED, &boolean);
rarch_ctl(RARCH_CTL_SET_IDLE, &boolean);
video_driver_unset_stub_frame();
if ((android_app->sensor_state_mask
& (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE))
&& !android_app->accelerometerSensor)
if (enable_accelerometer)
input_sensor_set_state(0,
RETRO_SENSOR_ACCELEROMETER_ENABLE,
android_app->accelerometer_event_rate);
if (enable_gyroscope)
input_sensor_set_state(0,
RETRO_SENSOR_GYROSCOPE_ENABLE,
android_app->gyroscope_event_rate);
}
slock_lock(android_app->mutex);
android_app->unfocused = false;
@ -390,20 +401,28 @@ static void android_input_poll_main_cmd(void)
break;
case APP_CMD_LOST_FOCUS:
{
bool boolean = true;
bool boolean = true;
bool disable_accelerometer = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE)) &&
android_app->accelerometerSensor;
bool disable_gyroscope = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_GYROSCOPE_ENABLE)) &&
android_app->gyroscopeSensor;
rarch_ctl(RARCH_CTL_SET_PAUSED, &boolean);
rarch_ctl(RARCH_CTL_SET_IDLE, &boolean);
video_driver_set_stub_frame();
/* Avoid draining battery while app is not being used. */
if ((android_app->sensor_state_mask
& (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE))
&& android_app->accelerometerSensor != NULL
)
if (disable_accelerometer)
input_sensor_set_state(0,
RETRO_SENSOR_ACCELEROMETER_DISABLE,
android_app->accelerometer_event_rate);
if (disable_gyroscope)
input_sensor_set_state(0,
RETRO_SENSOR_GYROSCOPE_DISABLE,
android_app->gyroscope_event_rate);
}
slock_lock(android_app->mutex);
android_app->unfocused = true;
@ -1225,18 +1244,44 @@ static void android_input_poll_input(android_input_t *android,
static void android_input_poll_user(android_input_t *android)
{
struct android_app *android_app = (struct android_app*)g_android;
bool poll_accelerometer = false;
bool poll_gyroscope = false;
if ((android_app->sensor_state_mask & (UINT64_C(1) <<
RETRO_SENSOR_ACCELEROMETER_ENABLE))
&& android_app->accelerometerSensor)
if (!android_app->sensorEventQueue)
return;
poll_accelerometer = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE)) &&
android_app->accelerometerSensor;
poll_gyroscope = (android_app->sensor_state_mask &
(UINT64_C(1) << RETRO_SENSOR_GYROSCOPE_ENABLE)) &&
android_app->gyroscopeSensor;
if (poll_accelerometer || poll_gyroscope)
{
ASensorEvent event;
while (ASensorEventQueue_getEvents(
android_app->sensorEventQueue, &event, 1) > 0)
android_app->sensorEventQueue, &event, 1) > 0)
{
android->accelerometer_state.x = event.acceleration.x;
android->accelerometer_state.y = event.acceleration.y;
android->accelerometer_state.z = event.acceleration.z;
switch (event.type)
{
case ASENSOR_TYPE_ACCELEROMETER:
android->accelerometer_state.x = event.acceleration.x;
android->accelerometer_state.y = event.acceleration.y;
android->accelerometer_state.z = event.acceleration.z;
break;
case ASENSOR_TYPE_GYROSCOPE:
/* ASensorEvent struct is mysterious - have to
* read the raw 'data' field to get rate of
* rotation... */
android->gyroscope_state.x = event.data[0];
android->gyroscope_state.y = event.data[1];
android->gyroscope_state.z = event.data[2];
break;
default:
break;
}
}
}
}
@ -1462,10 +1507,16 @@ static void android_input_free_input(void *data)
if (!android)
return;
if (android_app->sensorManager)
if (android_app->sensorManager &&
android_app->sensorEventQueue)
ASensorManager_destroyEventQueue(android_app->sensorManager,
android_app->sensorEventQueue);
android_app->sensorEventQueue = NULL;
android_app->accelerometerSensor = NULL;
android_app->gyroscopeSensor = NULL;
android_app->sensorManager = NULL;
android_app->input_alive = false;
#ifdef HAVE_DYNAMIC
@ -1489,22 +1540,39 @@ static uint64_t android_input_get_capabilities(void *data)
static void android_input_enable_sensor_manager(struct android_app *android_app)
{
android_app->sensorManager = ASensorManager_getInstance();
android_app->accelerometerSensor =
ASensorManager_getDefaultSensor(android_app->sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
android_app->sensorEventQueue =
ASensorManager_createEventQueue(android_app->sensorManager,
android_app->looper, LOOPER_ID_USER, NULL, NULL);
if (!android_app->sensorManager)
android_app->sensorManager = ASensorManager_getInstance();
if (android_app->sensorManager)
{
if (!android_app->accelerometerSensor)
android_app->accelerometerSensor =
ASensorManager_getDefaultSensor(android_app->sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
if (!android_app->gyroscopeSensor)
android_app->gyroscopeSensor =
ASensorManager_getDefaultSensor(android_app->sensorManager,
ASENSOR_TYPE_GYROSCOPE);
if (!android_app->sensorEventQueue)
android_app->sensorEventQueue =
ASensorManager_createEventQueue(android_app->sensorManager,
android_app->looper, LOOPER_ID_USER, NULL, NULL);
}
}
static bool android_input_set_sensor_state(void *data, unsigned port,
enum retro_sensor_action action, unsigned event_rate)
{
struct android_app *android_app = (struct android_app*)g_android;
android_input_t *android = (android_input_t*)data;
if (port > 0)
return false;
if (event_rate == 0)
event_rate = 60;
event_rate = DEFAULT_ASENSOR_EVENT_RATE;
switch (action)
{
@ -1512,28 +1580,74 @@ static bool android_input_set_sensor_state(void *data, unsigned port,
if (!android_app->accelerometerSensor)
android_input_enable_sensor_manager(android_app);
if (android_app->accelerometerSensor)
if (android_app->sensorEventQueue &&
android_app->accelerometerSensor)
{
ASensorEventQueue_enableSensor(android_app->sensorEventQueue,
android_app->accelerometerSensor);
/* Events per second (in microseconds). */
if (android_app->accelerometerSensor)
/* Events per second (in microseconds). */
ASensorEventQueue_setEventRate(android_app->sensorEventQueue,
android_app->accelerometerSensor, (1000L / event_rate)
* 1000);
}
android_app->accelerometer_event_rate = event_rate;
BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE);
BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE);
return true;
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
if (android_app->accelerometerSensor)
if (android_app->sensorEventQueue &&
android_app->accelerometerSensor)
ASensorEventQueue_disableSensor(android_app->sensorEventQueue,
android_app->accelerometerSensor);
android->accelerometer_state.x = 0.0f;
android->accelerometer_state.y = 0.0f;
android->accelerometer_state.z = 0.0f;
BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_ENABLE);
BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE);
return true;
case RETRO_SENSOR_GYROSCOPE_ENABLE:
if (!android_app->gyroscopeSensor)
android_input_enable_sensor_manager(android_app);
if (android_app->sensorEventQueue &&
android_app->gyroscopeSensor)
{
ASensorEventQueue_enableSensor(android_app->sensorEventQueue,
android_app->gyroscopeSensor);
/* Events per second (in microseconds). */
ASensorEventQueue_setEventRate(android_app->sensorEventQueue,
android_app->gyroscopeSensor, (1000L / event_rate)
* 1000);
}
android_app->gyroscope_event_rate = event_rate;
BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE);
BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE);
return true;
case RETRO_SENSOR_GYROSCOPE_DISABLE:
if (android_app->sensorEventQueue &&
android_app->gyroscopeSensor)
ASensorEventQueue_disableSensor(android_app->sensorEventQueue,
android_app->gyroscopeSensor);
android->gyroscope_state.x = 0.0f;
android->gyroscope_state.y = 0.0f;
android->gyroscope_state.z = 0.0f;
BIT64_CLEAR(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_ENABLE);
BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_GYROSCOPE_DISABLE);
return true;
default:
break;
}
@ -1542,10 +1656,13 @@ static bool android_input_set_sensor_state(void *data, unsigned port,
}
static float android_input_get_sensor_input(void *data,
unsigned port,unsigned id)
unsigned port, unsigned id)
{
android_input_t *android = (android_input_t*)data;
if (port > 0)
return 0.0f;
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
@ -1554,9 +1671,15 @@ static float android_input_get_sensor_input(void *data,
return android->accelerometer_state.y;
case RETRO_SENSOR_ACCELEROMETER_Z:
return android->accelerometer_state.z;
case RETRO_SENSOR_GYROSCOPE_X:
return android->gyroscope_state.x;
case RETRO_SENSOR_GYROSCOPE_Y:
return android->gyroscope_state.y;
case RETRO_SENSOR_GYROSCOPE_Z:
return android->gyroscope_state.z;
}
return 0;
return 0.0f;
}
input_driver_t input_android = {

View File

@ -398,9 +398,7 @@ static int16_t cocoa_input_state(
{
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if (
(binds[port][i].key < RETROK_LAST) &&
apple_key_state[rarch_keysym_lut[binds[port][i].key]] & 0x80)
if ((binds[port][i].key < RETROK_LAST) && apple_key_state[rarch_keysym_lut[binds[port][i].key]])
ret |= (1 << i);
}
}

View File

@ -1302,6 +1302,10 @@ MSG_HASH(
MENU_ENUM_LABEL_INPUT_AUTODETECT_ENABLE,
"input_autodetect_enable"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE,
"input_sensors_enable"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_BUTTON_AXIS_THRESHOLD,
"input_axis_threshold"

View File

@ -2010,6 +2010,14 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_AUTODETECT_ENABLE,
"Automatically configures controllers that have a profile, Plug-and-Play style."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SENSORS_ENABLE,
"Auxiliary Sensor Input"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_SENSORS_ENABLE,
"Enables input from accelerometer, gyroscope and illuminance sensors, if supported by the current hardware. May have a performance impact and/or increase power drain on some platforms."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_BUTTON_AXIS_THRESHOLD,
"Input Button Axis Threshold"

View File

@ -487,6 +487,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_savestate_file_compression, MENU_
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_autosave_interval, MENU_ENUM_SUBLABEL_AUTOSAVE_INTERVAL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_remap_binds_enable, MENU_ENUM_SUBLABEL_INPUT_REMAP_BINDS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_autodetect_enable, MENU_ENUM_SUBLABEL_INPUT_AUTODETECT_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_sensors_enable, MENU_ENUM_SUBLABEL_INPUT_SENSORS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_swap_ok_cancel, MENU_ENUM_SUBLABEL_MENU_INPUT_SWAP_OK_CANCEL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_pause_libretro, MENU_ENUM_SUBLABEL_PAUSE_LIBRETRO)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_menu_savestate_resume, MENU_ENUM_SUBLABEL_MENU_SAVESTATE_RESUME)
@ -2818,6 +2819,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_INPUT_AUTODETECT_ENABLE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_autodetect_enable);
break;
case MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_sensors_enable);
break;
case MENU_ENUM_LABEL_INPUT_REMAP_BINDS_ENABLE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_remap_binds_enable);
break;

View File

@ -6585,7 +6585,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
if (!mui)
return;
gfx_display_set_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, true, false);
/* Clear text */
materialui_font_bind(&mui->font_data.title);
@ -6796,7 +6796,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
materialui_font_unbind(&mui->font_data.list);
materialui_font_unbind(&mui->font_data.hint);
gfx_display_unset_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, false, true);
}
/* Determines current list view type, based on

View File

@ -2697,7 +2697,7 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
last_use_preferred_system_color_theme = use_preferred_system_color_theme;
}
gfx_display_set_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, true, false);
/* Clear text */
ozone_font_bind(&ozone->fonts.footer);
@ -2915,7 +2915,7 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
ozone_font_unbind(&ozone->fonts.entries_sublabel);
ozone_font_unbind(&ozone->fonts.sidebar);
gfx_display_unset_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, false, true);
}
static void ozone_set_header(ozone_handle_t *ozone)

View File

@ -3082,7 +3082,7 @@ static void stripes_frame(void *data, video_frame_info_t *video_info)
video_height);
}
gfx_display_unset_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, false, true);
}
static void stripes_layout_ps3(stripes_handle_t *stripes, int width, int height)

View File

@ -4025,7 +4025,7 @@ static void xmb_draw_bg(
draw.pipeline_active = xmb_shader_pipeline_active(menu_shader_pipeline);
gfx_display_blend_begin(userdata);
gfx_display_set_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, true, false);
#ifdef HAVE_SHADERPIPELINE
if (menu_shader_pipeline > XMB_SHADER_PIPELINE_WALLPAPER
@ -5231,7 +5231,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
video_height);
}
gfx_display_unset_viewport(video_width, video_height);
video_driver_set_viewport(video_width, video_height, false, true);
}
static void xmb_layout_ps3(xmb_handle_t *xmb, int width)

View File

@ -5986,6 +5986,10 @@ unsigned menu_displaylist_build_list(
MENU_ENUM_LABEL_INPUT_BIND_MODE,
PARSE_ONLY_UINT, false) == 0)
count++;
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE,
PARSE_ONLY_BOOL, false) == 0)
count++;
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_INPUT_HAPTIC_FEEDBACK_SETTINGS,
PARSE_ACTION, false) == 0)

View File

@ -7296,6 +7296,26 @@ static void general_write_handler(rarch_setting_t *setting)
audio_driver_load_system_sounds();
#endif
break;
case MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE:
/* When toggling sensor input off, ensure
* that all sensors are actually disabled */
if (!*setting->value.target.boolean)
{
size_t i;
for (i = 0; i < DEFAULT_MAX_PADS; i++)
{
/* Event rate does not matter when disabling
* sensors - set to zero */
input_sensor_set_state(i,
RETRO_SENSOR_ACCELEROMETER_DISABLE, 0);
input_sensor_set_state(i,
RETRO_SENSOR_GYROSCOPE_DISABLE, 0);
input_sensor_set_state(i,
RETRO_SENSOR_ILLUMINANCE_DISABLE, 0);
}
}
break;
default:
break;
}
@ -11714,6 +11734,22 @@ static bool setting_append_list(
SD_FLAG_ADVANCED
);
CONFIG_BOOL(
list, list_info,
&settings->bools.input_sensors_enable,
MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE,
MENU_ENUM_LABEL_VALUE_INPUT_SENSORS_ENABLE,
DEFAULT_INPUT_SENSORS_ENABLE,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE
);
#if 0
CONFIG_BOOL(
list, list_info,

View File

@ -909,6 +909,7 @@ enum msg_hash_enums
MENU_LABEL(INPUT_USER_BINDS),
MENU_LABEL(INPUT_DUTY_CYCLE),
MENU_LABEL(INPUT_AUTODETECT_ENABLE),
MENU_LABEL(INPUT_SENSORS_ENABLE),
MENU_LABEL(INPUT_DESCRIPTOR_LABEL_SHOW),
MENU_LABEL(INPUT_DESCRIPTOR_HIDE_UNBOUND),
MENU_LABEL(INPUT_BUTTON_AXIS_THRESHOLD),

View File

@ -19587,10 +19587,15 @@ static bool rarch_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE:
{
struct retro_sensor_interface *iface =
(struct retro_sensor_interface*)data;
settings_t *settings = p_rarch->configuration_settings;
bool input_sensors_enable = settings->bools.input_sensors_enable;
struct retro_sensor_interface *iface = (struct retro_sensor_interface*)data;
RARCH_LOG("[Environ]: GET_SENSOR_INTERFACE.\n");
if (!input_sensors_enable)
return false;
iface->set_sensor_state = input_sensor_set_state;
iface->get_sensor_input = input_sensor_get_input;
break;
@ -23840,6 +23845,17 @@ bool input_sensor_set_state(unsigned port,
enum retro_sensor_action action, unsigned rate)
{
struct rarch_state *p_rarch = &rarch_st;
settings_t *settings = p_rarch->configuration_settings;
bool input_sensors_enable = settings->bools.input_sensors_enable;
/* If sensors are disabled, inhibit any enable
* actions (but always allow disable actions) */
if (!input_sensors_enable &&
((action == RETRO_SENSOR_ACCELEROMETER_ENABLE) ||
(action == RETRO_SENSOR_GYROSCOPE_ENABLE) ||
(action == RETRO_SENSOR_ILLUMINANCE_ENABLE)))
return false;
if (p_rarch->current_input_data &&
p_rarch->current_input->set_sensor_state)
return p_rarch->current_input->set_sensor_state(p_rarch->current_input_data,
@ -23850,8 +23866,12 @@ bool input_sensor_set_state(unsigned port,
float input_sensor_get_input(unsigned port, unsigned id)
{
struct rarch_state *p_rarch = &rarch_st;
if (p_rarch->current_input_data &&
p_rarch->current_input->get_sensor_input)
settings_t *settings = p_rarch->configuration_settings;
bool input_sensors_enable = settings->bools.input_sensors_enable;
if (input_sensors_enable &&
p_rarch->current_input_data &&
p_rarch->current_input->get_sensor_input)
return p_rarch->current_input->get_sensor_input(p_rarch->current_input_data,
port, id);
return 0.0f;
@ -32008,16 +32028,14 @@ error:
return false;
}
bool video_driver_set_viewport(unsigned width, unsigned height,
void video_driver_set_viewport(unsigned width, unsigned height,
bool force_fullscreen, bool allow_rotate)
{
struct rarch_state *p_rarch = &rarch_st;
if (!p_rarch->current_video || !p_rarch->current_video->set_viewport)
return false;
p_rarch->current_video->set_viewport(
p_rarch->video_driver_data, width, height,
force_fullscreen, allow_rotate);
return true;
if (p_rarch->current_video && p_rarch->current_video->set_viewport)
p_rarch->current_video->set_viewport(
p_rarch->video_driver_data, width, height,
force_fullscreen, allow_rotate);
}
bool video_driver_set_rotation(unsigned rotation)

View File

@ -1610,7 +1610,7 @@ void video_driver_set_filtering(unsigned index, bool smooth, bool ctx_scaling);
const char *video_driver_get_ident(void);
bool video_driver_set_viewport(unsigned width, unsigned height,
void video_driver_set_viewport(unsigned width, unsigned height,
bool force_fullscreen, bool allow_rotate);
void video_driver_get_size(unsigned *width, unsigned *height);

View File

@ -19,11 +19,15 @@
#include <stdlib.h>
#include <string.h>
#include <objc/objc-runtime.h>
#include <objc/objc.h>
#include <objc/message.h>
#include <objc/NSObjCRuntime.h>
#include "cocoa_defines.h"
#include "cocoa_common.h"
#include "../../ui_companion_driver.h"
extern id NSApp;
extern id const NSDefaultRunLoopMode;
static void* ui_application_cocoa_initialize(void)
{
return NULL;
@ -31,18 +35,22 @@ static void* ui_application_cocoa_initialize(void)
static void ui_application_cocoa_process_events(void)
{
SEL sel_nextEventMatchingMask_untilDate_inMode_dequeue =
sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:");
Class class_NSDate = objc_getClass("NSDate");
SEL sel_distantPast = sel_registerName("distantPast");
SEL sel_sendEvent = sel_registerName("sendEvent:");
id distant_past = ((id (*)(Class, SEL))objc_msgSend)(class_NSDate, sel_distantPast);
for (;;)
{
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (!event)
id event = ((id (*)(id, SEL, NSUInteger, id, id, BOOL))objc_msgSend)(NSApp, sel_nextEventMatchingMask_untilDate_inMode_dequeue,
NSUIntegerMax,
distant_past,
NSDefaultRunLoopMode,
YES);
if (event == nil)
break;
#ifndef HAVE_COCOA_METAL
[event retain];
#endif
[NSApp sendEvent: event];
#ifndef HAVE_COCOA_METAL
[event retain];
#endif
((id (*)(id, SEL, id))objc_msgSend)(NSApp, sel_sendEvent, event);
}
}

View File

@ -60,45 +60,42 @@ static void app_terminate(void)
- (void)sendEvent:(NSEvent *)event {
[super sendEvent:event];
cocoa_input_data_t *apple = NULL;
NSEventType event_type = event.type;
[super sendEvent:event];
switch ((int32_t)event_type)
{
case NSEventTypeKeyDown:
case NSEventTypeKeyUp:
{
NSString* ch = event.characters;
uint32_t character = 0;
uint32_t mod = 0;
uint32_t i;
NSString* ch = event.characters;
uint32_t mod = 0;
const char *inputTextUTF8 = ch.UTF8String;
uint32_t character = inputTextUTF8[0];
NSEventModifierFlags mods = event.modifierFlags;
uint16_t keycode = event.keyCode;
if (ch && ch.length != 0)
{
uint32_t i;
character = [ch characterAtIndex:0];
if (event.modifierFlags & NSEventModifierFlagCapsLock)
if (mods & NSEventModifierFlagCapsLock)
mod |= RETROKMOD_CAPSLOCK;
if (event.modifierFlags & NSEventModifierFlagShift)
if (mods & NSEventModifierFlagShift)
mod |= RETROKMOD_SHIFT;
if (event.modifierFlags & NSEventModifierFlagControl)
if (mods & NSEventModifierFlagControl)
mod |= RETROKMOD_CTRL;
if (event.modifierFlags & NSEventModifierFlagOption)
if (mods & NSEventModifierFlagOption)
mod |= RETROKMOD_ALT;
if (event.modifierFlags & NSEventModifierFlagCommand)
if (mods & NSEventModifierFlagCommand)
mod |= RETROKMOD_META;
if (event.modifierFlags & NSEventModifierFlagNumericPad)
if (mods & NSEventModifierFlagNumericPad)
mod |= RETROKMOD_NUMLOCK;
for (i = 1; i < ch.length; i++)
apple_input_keyboard_event(event_type == NSEventTypeKeyDown,
0, [ch characterAtIndex:i], mod, RETRO_DEVICE_KEYBOARD);
}
0, inputTextUTF8[i], mod, RETRO_DEVICE_KEYBOARD);
apple_input_keyboard_event(event_type == NSEventTypeKeyDown,
event.keyCode, character, mod, RETRO_DEVICE_KEYBOARD);
keycode, character, mod, RETRO_DEVICE_KEYBOARD);
}
break;
#if defined(HAVE_COCOA_METAL)
@ -107,14 +104,15 @@ static void app_terminate(void)
case NSFlagsChanged:
#endif
{
static uint32_t old_flags = 0;
uint32_t new_flags = event.modifierFlags;
bool down = (new_flags & old_flags) == old_flags;
static NSEventModifierFlags old_flags = 0;
NSEventModifierFlags new_flags = event.modifierFlags;
bool down = (new_flags & old_flags) == old_flags;
uint16_t keycode = event.keyCode;
old_flags = new_flags;
old_flags = new_flags;
apple_input_keyboard_event(down, event.keyCode,
0, event.modifierFlags, RETRO_DEVICE_KEYBOARD);
apple_input_keyboard_event(down, keycode,
0, new_flags, RETRO_DEVICE_KEYBOARD);
}
break;
case NSEventTypeMouseMoved:
@ -122,37 +120,29 @@ static void app_terminate(void)
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged:
{
NSPoint pos;
apple = (cocoa_input_data_t*)input_driver_get_data();
CGFloat delta_x = event.deltaX;
CGFloat delta_y = event.deltaY;
#if defined(HAVE_COCOA_METAL)
CGPoint pos = [apple_platform.renderView
convertPoint:[event locationInWindow] fromView:nil];
#elif defined(HAVE_COCOA)
CGPoint pos = [[CocoaView get]
convertPoint:[event locationInWindow] fromView:nil];
#endif
cocoa_input_data_t
*apple = (cocoa_input_data_t*)
input_driver_get_data();
if (!apple)
return;
pos.x = 0;
pos.y = 0;
#if defined(HAVE_COCOA_METAL)
pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil];
#elif defined(HAVE_COCOA)
pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
#endif
/* FIXME: Disable clipping until graphical offset issues
* are fixed */
#if 0
NSInteger window_number = [[[NSApplication sharedApplication] keyWindow] windowNumber];
if ([NSWindow windowNumberAtPoint:pos belowWindowWithWindowNumber:0] != window_number)
return;
#endif
/* Relative */
apple->mouse_rel_x += (int16_t)event.deltaX;
apple->mouse_rel_y += (int16_t)event.deltaY;
apple->mouse_rel_x += (int16_t)delta_x;
apple->mouse_rel_y += (int16_t)delta_y;
/* Absolute */
apple->touches[0].screen_x = (int16_t)pos.x;
apple->touches[0].screen_y = (int16_t)pos.y;
apple->window_pos_x = (int16_t)pos.x;
apple->window_pos_y = (int16_t)pos.y;
apple->touches[0].screen_x = (int16_t)pos.x;
apple->touches[0].screen_y = (int16_t)pos.y;
apple->window_pos_x = (int16_t)pos.x;
apple->window_pos_y = (int16_t)pos.y;
}
break;
#if defined(HAVE_COCOA_METAL)
@ -166,32 +156,38 @@ static void app_terminate(void)
case NSEventTypeRightMouseDown:
case NSEventTypeOtherMouseDown:
{
NSInteger number = event.buttonNumber;
#ifdef HAVE_COCOA_METAL
NSPoint pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil];
CGPoint pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil];
#else
NSPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
CGPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
#endif
apple = (cocoa_input_data_t*)input_driver_get_data();
cocoa_input_data_t
*apple = (cocoa_input_data_t*)
input_driver_get_data();
if (!apple || pos.y < 0)
return;
apple->mouse_buttons |= (1 << event.buttonNumber);
apple->touch_count = 1;
apple->mouse_buttons |= (1 << number);
apple->touch_count = 1;
}
break;
case NSEventTypeLeftMouseUp:
case NSEventTypeRightMouseUp:
case NSEventTypeOtherMouseUp:
{
NSInteger number = event.buttonNumber;
#ifdef HAVE_COCOA_METAL
NSPoint pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil];
CGPoint pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil];
#else
NSPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
CGPoint pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
#endif
apple = (cocoa_input_data_t*)input_driver_get_data();
cocoa_input_data_t
*apple = (cocoa_input_data_t*)
input_driver_get_data();
if (!apple || pos.y < 0)
return;
apple->mouse_buttons &= ~(1 << event.buttonNumber);
apple->touch_count = 0;
apple->mouse_buttons &= ~(1 << number);
apple->touch_count = 0;
}
break;
default:
@ -283,37 +279,34 @@ static char **waiting_argv;
if (vt == _vt)
return;
RARCH_LOG("[Cocoa]: change view type: %d ? %d\n", _vt, vt);
_vt = vt;
if (_renderView != nil)
{
_renderView.wantsLayer = NO;
_renderView.layer = nil;
_renderView.wantsLayer = NO;
_renderView.layer = nil;
[_renderView removeFromSuperview];
self.window.contentView = nil;
_renderView = nil;
_renderView = nil;
}
switch (vt) {
switch (vt)
{
case APPLE_VIEW_TYPE_VULKAN:
case APPLE_VIEW_TYPE_METAL:
{
MetalView *v = [MetalView new];
v.paused = YES;
v.enableSetNeedsDisplay = NO;
_renderView = v;
}
break;
case APPLE_VIEW_TYPE_METAL:
{
MetalView *v = [MetalView new];
v.paused = YES;
v.enableSetNeedsDisplay = NO;
_renderView = v;
}
break;
case APPLE_VIEW_TYPE_OPENGL:
{
case APPLE_VIEW_TYPE_OPENGL:
_renderView = [CocoaView get];
break;
}
case APPLE_VIEW_TYPE_NONE:
default:
case APPLE_VIEW_TYPE_NONE:
default:
return;
}

View File

@ -328,8 +328,6 @@ enum
if (vt == _vt)
return;
RARCH_LOG("[Cocoa]: change view type: %d ? %d\n", _vt, vt);
_vt = vt;
if (_renderView != nil)
{
@ -337,29 +335,28 @@ enum
_renderView = nil;
}
switch (vt) {
switch (vt)
{
#ifdef HAVE_COCOA_METAL
case APPLE_VIEW_TYPE_VULKAN:
case APPLE_VIEW_TYPE_METAL:
{
MetalView *v = [MetalView new];
v.paused = YES;
v.enableSetNeedsDisplay = NO;
case APPLE_VIEW_TYPE_METAL:
{
MetalView *v = [MetalView new];
v.paused = YES;
v.enableSetNeedsDisplay = NO;
#if TARGET_OS_IOS
v.multipleTouchEnabled = YES;
v.multipleTouchEnabled = YES;
#endif
_renderView = v;
}
break;
_renderView = v;
}
break;
#endif
case APPLE_VIEW_TYPE_OPENGL_ES:
{
case APPLE_VIEW_TYPE_OPENGL_ES:
_renderView = (BRIDGE GLKView*)glkitview_init();
break;
}
case APPLE_VIEW_TYPE_NONE:
default:
case APPLE_VIEW_TYPE_NONE:
default:
return;
}
@ -418,6 +415,7 @@ enum
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSError *error;
char arguments[] = "retroarch";
char *argv[] = {arguments, NULL};
int argc = 1;
@ -429,7 +427,6 @@ enum
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
NSError *error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
if (error) {
NSLog(@"Could not set audio session category: %@",error.localizedDescription);