2015-04-12 14:50:39 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-04-12 14:50:39 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-06 17:39:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-02 09:14:47 +00:00
|
|
|
#if TARGET_OS_IPHONE
|
|
|
|
#include <CoreGraphics/CoreGraphics.h>
|
|
|
|
#else
|
2015-06-02 07:00:27 +00:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
2015-06-02 09:14:47 +00:00
|
|
|
#endif
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-12 14:55:50 +00:00
|
|
|
#include <OpenGL/CGLTypes.h>
|
|
|
|
#include <OpenGL/OpenGL.h>
|
2015-04-12 14:50:39 +00:00
|
|
|
#include <AppKit/NSScreen.h>
|
|
|
|
#include <AppKit/NSOpenGL.h>
|
2015-04-19 22:38:55 +00:00
|
|
|
#elif defined(HAVE_COCOATOUCH)
|
2015-04-12 14:55:50 +00:00
|
|
|
#include <GLKit/GLKit.h>
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-01-16 17:57:00 +00:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2015-04-12 14:50:39 +00:00
|
|
|
#endif
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-09-01 10:02:04 +00:00
|
|
|
|
|
|
|
#include <retro_assert.h>
|
2016-09-14 12:10:39 +00:00
|
|
|
#include <compat/apple_compat.h>
|
2015-09-01 10:02:04 +00:00
|
|
|
|
2015-04-20 10:56:05 +00:00
|
|
|
#import "../../ui/drivers/cocoa/cocoa_common.h"
|
2017-05-08 23:25:59 +00:00
|
|
|
#include "../video_driver.h"
|
2015-04-12 14:50:39 +00:00
|
|
|
#include "../../configuration.h"
|
2015-11-23 11:07:00 +00:00
|
|
|
#include "../../verbosity.h"
|
2015-04-12 14:50:39 +00:00
|
|
|
|
2017-04-15 17:21:10 +00:00
|
|
|
#if __has_feature(objc_arc)
|
|
|
|
#define BRIDGE __bridge
|
|
|
|
#else
|
|
|
|
#define BRIDGE
|
|
|
|
#endif
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-12 14:50:39 +00:00
|
|
|
#define GLContextClass EAGLContext
|
|
|
|
#define GLFrameworkID CFSTR("com.apple.opengles")
|
|
|
|
#define RAScreen UIScreen
|
|
|
|
|
2016-01-15 13:08:38 +00:00
|
|
|
#ifndef UIUserInterfaceIdiomTV
|
|
|
|
#define UIUserInterfaceIdiomTV 2
|
|
|
|
#endif
|
|
|
|
|
2016-05-01 23:55:02 +00:00
|
|
|
#ifndef UIUserInterfaceIdiomCarPlay
|
|
|
|
#define UIUserInterfaceIdiomCarPlay 3
|
|
|
|
#endif
|
|
|
|
|
2015-04-12 14:50:39 +00:00
|
|
|
@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
|
|
|
|
|
2017-06-27 04:11:08 +00:00
|
|
|
typedef struct cocoa_ctx_data
|
|
|
|
{
|
|
|
|
bool core_hw_context_enable;
|
|
|
|
} cocoa_ctx_data_t;
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2016-06-04 06:09:55 +00:00
|
|
|
|
2015-04-12 14:50:39 +00:00
|
|
|
static GLKView *g_view;
|
2016-01-18 21:13:35 +00:00
|
|
|
UIView *g_pause_indicator_view;
|
2015-04-12 14:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static GLContextClass* g_hw_ctx;
|
|
|
|
static GLContextClass* g_context;
|
|
|
|
|
|
|
|
static int g_fast_forward_skips;
|
|
|
|
static bool g_is_syncing = true;
|
2017-06-18 17:35:34 +00:00
|
|
|
static bool g_use_hw_ctx = false;
|
2015-04-12 14:50:39 +00:00
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2016-06-07 14:47:48 +00:00
|
|
|
#include "../../ui/drivers/ui_cocoa.h"
|
2015-04-12 14:50:39 +00:00
|
|
|
static NSOpenGLPixelFormat* g_format;
|
|
|
|
|
2016-02-26 12:39:01 +00:00
|
|
|
void *glcontext_get_ptr(void)
|
2016-02-26 12:36:12 +00:00
|
|
|
{
|
2016-02-26 13:25:57 +00:00
|
|
|
return g_context;
|
2016-02-26 12:36:12 +00:00
|
|
|
}
|
2016-02-26 13:25:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned g_minor = 0;
|
|
|
|
static unsigned g_major = 0;
|
2016-02-26 12:36:12 +00:00
|
|
|
|
2015-04-12 14:50:39 +00:00
|
|
|
/* forward declaration */
|
|
|
|
void *nsview_get_ptr(void);
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-12 14:50:39 +00:00
|
|
|
static void glkitview_init_xibs(void)
|
|
|
|
{
|
|
|
|
/* iOS Pause menu and lifecycle. */
|
|
|
|
UINib *xib = (UINib*)[UINib nibWithNibName:BOXSTRING("PauseIndicatorView") bundle:nil];
|
|
|
|
g_pause_indicator_view = [[xib instantiateWithOwner:[RetroArch_iOS get] options:nil] lastObject];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void *glkitview_init(void)
|
|
|
|
{
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-12 14:50:39 +00:00
|
|
|
glkitview_init_xibs();
|
|
|
|
|
|
|
|
g_view = [GLKView new];
|
|
|
|
g_view.multipleTouchEnabled = YES;
|
|
|
|
g_view.enableSetNeedsDisplay = NO;
|
|
|
|
[g_view addSubview:g_pause_indicator_view];
|
|
|
|
|
2017-04-15 17:28:10 +00:00
|
|
|
return (BRIDGE void *)((GLKView*)g_view);
|
2015-04-12 14:50:39 +00:00
|
|
|
#else
|
|
|
|
return nsview_get_ptr();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-19 15:40:10 +00:00
|
|
|
void cocoagl_bind_game_view_fbo(void)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2016-01-16 21:02:49 +00:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
|
|
|
/* Implicitly initializes your audio session */
|
2016-01-18 12:19:28 +00:00
|
|
|
AVAudioSession *audio_session = [AVAudioSession sharedInstance];
|
|
|
|
[audio_session setCategory:AVAudioSessionCategoryAmbient error:nil];
|
|
|
|
[audio_session setActive:YES error:nil];
|
2016-01-16 21:02:49 +00:00
|
|
|
#endif
|
2015-04-12 14:50:39 +00:00
|
|
|
if (g_context)
|
|
|
|
[g_view bindDrawable];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-16 10:58:36 +00:00
|
|
|
static float get_from_selector(Class obj_class, id obj_id, SEL selector, CGFloat *ret)
|
2016-01-16 10:40:48 +00:00
|
|
|
{
|
|
|
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
|
2016-01-16 10:49:10 +00:00
|
|
|
[obj_class instanceMethodSignatureForSelector:selector]];
|
2016-01-16 10:40:48 +00:00
|
|
|
[invocation setSelector:selector];
|
2016-01-16 10:49:10 +00:00
|
|
|
[invocation setTarget:obj_id];
|
2016-01-16 10:40:48 +00:00
|
|
|
[invocation invoke];
|
|
|
|
[invocation getReturnValue:ret];
|
2017-04-15 18:20:08 +00:00
|
|
|
#if __has_feature(objc_arc)
|
|
|
|
#else
|
2017-04-15 17:13:21 +00:00
|
|
|
[invocation release];
|
2017-04-15 18:20:08 +00:00
|
|
|
#endif
|
2016-01-16 10:40:48 +00:00
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
2015-11-14 21:25:48 +00:00
|
|
|
void *get_chosen_screen(void)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
2016-01-15 12:58:16 +00:00
|
|
|
NSArray *screens = [RAScreen screens];
|
2016-01-15 14:38:21 +00:00
|
|
|
if (!screens || !settings)
|
2016-01-15 12:58:16 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-04-28 19:03:04 +00:00
|
|
|
if (settings->uints.video_monitor_index >= screens.count)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2016-06-08 05:41:59 +00:00
|
|
|
RARCH_WARN("video_monitor_index is greater than the number of connected monitors; using main screen instead.");
|
2017-04-15 17:20:42 +00:00
|
|
|
return (BRIDGE void*)screens;
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 19:03:04 +00:00
|
|
|
return ((BRIDGE void*)[screens objectAtIndex:settings->uints.video_monitor_index]);
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 17:20:42 +00:00
|
|
|
|
2016-01-15 21:15:23 +00:00
|
|
|
float get_backing_scale_factor(void)
|
|
|
|
{
|
2017-04-15 17:27:09 +00:00
|
|
|
static float
|
|
|
|
backing_scale_def = 0.0f;
|
|
|
|
RAScreen *screen = NULL;
|
|
|
|
|
2017-04-15 18:20:47 +00:00
|
|
|
(void)screen;
|
|
|
|
|
2017-04-15 17:27:09 +00:00
|
|
|
if (backing_scale_def != 0.0f)
|
|
|
|
return backing_scale_def;
|
|
|
|
|
|
|
|
backing_scale_def = 1.0f;
|
2016-01-16 10:58:36 +00:00
|
|
|
#ifdef HAVE_COCOA
|
2017-04-15 17:27:09 +00:00
|
|
|
screen = (BRIDGE RAScreen*)get_chosen_screen();
|
|
|
|
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
SEL selector = NSSelectorFromString(BOXSTRING("backingScaleFactor"));
|
|
|
|
if ([screen respondsToSelector:selector])
|
|
|
|
{
|
|
|
|
CGFloat ret;
|
|
|
|
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
|
|
|
backing_scale_def = (float)get_from_selector
|
|
|
|
([[g_view window] class], [g_view window], selector, &ret);
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 21:15:23 +00:00
|
|
|
#endif
|
2017-04-15 17:27:09 +00:00
|
|
|
|
|
|
|
return backing_scale_def;
|
2016-01-15 21:15:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
void cocoagl_gfx_ctx_update(void)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-25 22:50:58 +00:00
|
|
|
#if MAC_OS_X_VERSION_10_7
|
2017-06-18 17:35:34 +00:00
|
|
|
CGLUpdateContext(g_hw_ctx.CGLContextObj);
|
2015-04-25 22:50:58 +00:00
|
|
|
CGLUpdateContext(g_context.CGLContextObj);
|
|
|
|
#else
|
2017-06-18 17:35:34 +00:00
|
|
|
[g_hw_ctx update];
|
2015-04-12 14:50:39 +00:00
|
|
|
[g_context update];
|
|
|
|
#endif
|
2015-04-25 22:50:58 +00:00
|
|
|
#endif
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 17:29:22 +00:00
|
|
|
static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-06-27 04:11:08 +00:00
|
|
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
|
|
|
calloc(1, sizeof(cocoa_ctx_data_t));
|
|
|
|
|
|
|
|
if (!cocoa_ctx)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return cocoa_ctx;
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static void cocoagl_gfx_ctx_destroy(void *data)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-10-01 07:33:53 +00:00
|
|
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
|
|
|
|
|
|
|
if (!cocoa_ctx)
|
|
|
|
return;
|
2015-04-12 14:50:39 +00:00
|
|
|
|
|
|
|
[GLContextClass clearCurrentContext];
|
|
|
|
|
2015-11-16 03:22:54 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-12 14:50:39 +00:00
|
|
|
[g_context clearDrawable];
|
|
|
|
if (g_context)
|
|
|
|
[g_context release];
|
|
|
|
g_context = nil;
|
|
|
|
if (g_format)
|
|
|
|
[g_format release];
|
|
|
|
g_format = nil;
|
|
|
|
if (g_hw_ctx)
|
2017-06-18 17:35:34 +00:00
|
|
|
{
|
|
|
|
[g_hw_ctx clearDrawable];
|
2015-04-12 14:50:39 +00:00
|
|
|
[g_hw_ctx release];
|
2017-06-18 17:35:34 +00:00
|
|
|
}
|
2015-04-12 14:50:39 +00:00
|
|
|
g_hw_ctx = nil;
|
|
|
|
#endif
|
|
|
|
[GLContextClass clearCurrentContext];
|
|
|
|
g_context = nil;
|
2017-10-01 07:33:53 +00:00
|
|
|
|
|
|
|
free(cocoa_ctx);
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static bool cocoagl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-12 14:50:39 +00:00
|
|
|
if (api != GFX_CTX_OPENGL_ES_API)
|
|
|
|
return false;
|
2015-04-19 22:38:55 +00:00
|
|
|
#elif defined(HAVE_COCOA)
|
2015-04-12 14:50:39 +00:00
|
|
|
if (api != GFX_CTX_OPENGL_API)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_minor = minor;
|
|
|
|
g_major = major;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static void cocoagl_gfx_ctx_swap_interval(void *data, unsigned interval)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH) // < No way to disable Vsync on iOS?
|
2015-04-12 14:50:39 +00:00
|
|
|
// Just skip presents so fast forward still works.
|
|
|
|
g_is_syncing = interval ? true : false;
|
|
|
|
g_fast_forward_skips = interval ? 0 : 3;
|
2015-04-19 22:38:55 +00:00
|
|
|
#elif defined(HAVE_COCOA)
|
2015-04-12 14:50:39 +00:00
|
|
|
GLint value = interval ? 1 : 0;
|
|
|
|
[g_context setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-26 00:53:50 +00:00
|
|
|
static void cocoagl_gfx_ctx_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
#ifdef HAVE_COCOA
|
|
|
|
if (state)
|
|
|
|
[NSCursor unhide];
|
|
|
|
else
|
|
|
|
[NSCursor hide];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-26 01:01:15 +00:00
|
|
|
static bool cocoagl_gfx_ctx_set_video_mode(void *data,
|
2017-01-18 16:41:27 +00:00
|
|
|
video_frame_info_t *video_info,
|
2017-01-11 05:35:50 +00:00
|
|
|
unsigned width, unsigned height, bool fullscreen)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-06-18 17:35:34 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
|
|
|
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
|
|
|
if ([g_view respondsToSelector: @selector(setWantsBestResolutionOpenGLSurface:)])
|
|
|
|
[g_view setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
|
|
|
|
NSOpenGLPixelFormatAttribute attributes [] = {
|
2017-06-26 05:16:41 +00:00
|
|
|
NSOpenGLPFAColorSize,
|
|
|
|
24,
|
2017-06-18 17:35:34 +00:00
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFAAllowOfflineRenderers,
|
|
|
|
NSOpenGLPFADepthSize,
|
|
|
|
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
|
2017-06-26 05:16:41 +00:00
|
|
|
0, /* profile */
|
|
|
|
0, /* profile enum */
|
2017-06-18 17:35:34 +00:00
|
|
|
(NSOpenGLPixelFormatAttribute)0
|
|
|
|
};
|
2017-06-26 05:16:41 +00:00
|
|
|
|
2017-06-26 05:23:04 +00:00
|
|
|
#if MAC_OS_X_VERSION_10_7
|
2017-06-26 05:16:41 +00:00
|
|
|
if (g_major == 3 && (g_minor >= 1 && g_minor <= 3))
|
|
|
|
{
|
|
|
|
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
|
|
|
attributes[7] = NSOpenGLProfileVersion3_2Core;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-26 05:23:04 +00:00
|
|
|
#if MAC_OS_X_VERSION_10_10
|
2017-06-26 05:16:41 +00:00
|
|
|
if (g_major == 4 && g_minor == 1)
|
|
|
|
{
|
|
|
|
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
|
|
|
attributes[7] = NSOpenGLProfileVersion4_1Core;
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-18 17:35:34 +00:00
|
|
|
|
|
|
|
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
|
|
|
|
if (g_format == nil)
|
|
|
|
{
|
|
|
|
/* NSOpenGLFPAAllowOfflineRenderers is
|
|
|
|
not supported on this OS version. */
|
|
|
|
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
|
|
|
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_use_hw_ctx)
|
|
|
|
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
|
|
|
|
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(g_use_hw_ctx) ? g_hw_ctx : nil];
|
|
|
|
[g_context setView:g_view];
|
|
|
|
#else
|
|
|
|
if (g_use_hw_ctx)
|
2017-06-18 17:43:55 +00:00
|
|
|
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
2017-06-18 17:35:34 +00:00
|
|
|
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
|
|
|
g_view.context = g_context;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
[g_context makeCurrentContext];
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-26 00:57:53 +00:00
|
|
|
static bool has_went_fullscreen = false;
|
2015-04-12 14:50:39 +00:00
|
|
|
/* TODO: Screen mode support. */
|
2017-01-11 05:35:50 +00:00
|
|
|
|
2015-04-26 01:01:15 +00:00
|
|
|
if (fullscreen)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-01-11 05:35:50 +00:00
|
|
|
if (!has_went_fullscreen)
|
|
|
|
{
|
|
|
|
[g_view enterFullScreenMode:get_chosen_screen() withOptions:nil];
|
|
|
|
cocoagl_gfx_ctx_show_mouse(data, false);
|
|
|
|
}
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
2015-04-26 01:01:15 +00:00
|
|
|
else
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2015-04-26 01:01:15 +00:00
|
|
|
if (has_went_fullscreen)
|
|
|
|
{
|
2017-01-11 05:35:50 +00:00
|
|
|
[g_view exitFullScreenModeWithOptions:nil];
|
|
|
|
[[g_view window] makeFirstResponder:g_view];
|
|
|
|
cocoagl_gfx_ctx_show_mouse(data, true);
|
2015-04-26 01:01:15 +00:00
|
|
|
}
|
2017-01-11 05:35:50 +00:00
|
|
|
|
|
|
|
[[g_view window] setContentSize:NSMakeSize(width, height)];
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
2017-01-11 05:35:50 +00:00
|
|
|
|
2015-04-26 00:57:53 +00:00
|
|
|
has_went_fullscreen = fullscreen;
|
2015-04-12 14:50:39 +00:00
|
|
|
#endif
|
2017-01-11 05:35:50 +00:00
|
|
|
|
2015-04-12 14:50:39 +00:00
|
|
|
(void)data;
|
|
|
|
|
2017-01-11 05:35:50 +00:00
|
|
|
/* TODO: Maybe iOS users should be able to show/hide the status bar here? */
|
2015-04-12 14:50:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
float cocoagl_gfx_ctx_get_native_scale(void)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-04-15 17:20:42 +00:00
|
|
|
static CGFloat ret = 0.0f;
|
|
|
|
SEL selector = NSSelectorFromString(BOXSTRING("nativeScale"));
|
|
|
|
RAScreen *screen = (BRIDGE RAScreen*)get_chosen_screen();
|
|
|
|
|
|
|
|
if (ret != 0.0f)
|
|
|
|
return ret;
|
|
|
|
if (!screen)
|
|
|
|
return 0.0f;
|
|
|
|
|
2015-04-12 14:50:39 +00:00
|
|
|
if ([screen respondsToSelector:selector])
|
2017-04-15 17:20:42 +00:00
|
|
|
return (float)get_from_selector([screen class], screen, selector, &ret);
|
|
|
|
|
2016-01-16 10:51:24 +00:00
|
|
|
ret = 1.0f;
|
2016-01-16 10:50:44 +00:00
|
|
|
selector = NSSelectorFromString(BOXSTRING("scale"));
|
|
|
|
if ([screen respondsToSelector:selector])
|
2016-01-16 10:51:24 +00:00
|
|
|
ret = screen.scale;
|
2015-04-12 14:50:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static void cocoagl_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2016-01-16 12:29:33 +00:00
|
|
|
float screenscale = cocoagl_gfx_ctx_get_native_scale();
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2016-01-16 15:21:39 +00:00
|
|
|
CGRect size;
|
2016-01-16 15:20:19 +00:00
|
|
|
GLsizei backingPixelWidth, backingPixelHeight;
|
2016-01-16 12:29:33 +00:00
|
|
|
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
2016-01-16 15:14:25 +00:00
|
|
|
CGRect cgrect = NSRectToCGRect([g_view frame]);
|
2016-01-16 15:46:20 +00:00
|
|
|
#if MAC_OS_X_VERSION_10_7
|
2016-01-16 15:20:19 +00:00
|
|
|
SEL selector = NSSelectorFromString(BOXSTRING("convertRectToBacking:"));
|
|
|
|
if ([g_view respondsToSelector:selector])
|
|
|
|
cgrect = NSRectToCGRect([g_view convertRectToBacking:[g_view bounds]]);
|
2016-01-16 15:46:20 +00:00
|
|
|
#endif
|
2016-01-16 15:20:19 +00:00
|
|
|
backingPixelWidth = CGRectGetWidth(cgrect);
|
|
|
|
backingPixelHeight = CGRectGetHeight(cgrect);
|
|
|
|
size = CGRectMake(0, 0, backingPixelWidth, backingPixelHeight);
|
2016-01-16 12:29:33 +00:00
|
|
|
#else
|
2016-01-16 12:30:38 +00:00
|
|
|
CGRect size = g_view.bounds;
|
2016-01-16 12:29:33 +00:00
|
|
|
#endif
|
|
|
|
*width = CGRectGetWidth(size) * screenscale;
|
|
|
|
*height = CGRectGetHeight(size) * screenscale;
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 00:58:44 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2017-05-19 01:34:53 +00:00
|
|
|
static void cocoagl_gfx_ctx_update_title(void *data, void *data2)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2016-06-22 15:42:32 +00:00
|
|
|
ui_window_cocoa_t view;
|
2017-05-19 01:34:53 +00:00
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
2017-01-18 16:41:27 +00:00
|
|
|
|
2016-06-04 06:20:39 +00:00
|
|
|
view.data = (CocoaView*)nsview_get_ptr();
|
2016-06-04 06:09:55 +00:00
|
|
|
|
2017-01-19 18:08:39 +00:00
|
|
|
if (window)
|
2017-01-19 05:33:52 +00:00
|
|
|
{
|
|
|
|
char title[128];
|
|
|
|
|
|
|
|
title[0] = '\0';
|
|
|
|
|
|
|
|
video_driver_get_window_title(title, sizeof(title));
|
|
|
|
|
|
|
|
if (title[0])
|
|
|
|
window->set_title(&view, title);
|
|
|
|
}
|
2015-04-12 14:50:39 +00:00
|
|
|
}
|
2017-01-19 00:58:44 +00:00
|
|
|
#endif
|
2015-04-12 14:50:39 +00:00
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static bool cocoagl_gfx_ctx_get_metrics(void *data, enum display_metric_types type,
|
2015-04-12 14:50:39 +00:00
|
|
|
float *value)
|
|
|
|
{
|
2017-04-15 17:20:42 +00:00
|
|
|
RAScreen *screen = (BRIDGE RAScreen*)get_chosen_screen();
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-12 14:50:39 +00:00
|
|
|
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;
|
2016-01-15 21:15:23 +00:00
|
|
|
float scale = get_backing_scale_factor();
|
2015-06-12 18:12:43 +00:00
|
|
|
float dpi = (display_width/ physical_width) * 25.4f * scale;
|
2015-04-19 22:38:55 +00:00
|
|
|
#elif defined(HAVE_COCOATOUCH)
|
2015-04-19 15:40:10 +00:00
|
|
|
float scale = cocoagl_gfx_ctx_get_native_scale();
|
2015-11-05 21:17:02 +00:00
|
|
|
CGRect screen_rect = [screen bounds];
|
2015-04-12 14:50:39 +00:00
|
|
|
float display_height = screen_rect.size.height;
|
|
|
|
float physical_width = screen_rect.size.width * scale;
|
|
|
|
float physical_height = screen_rect.size.height * scale;
|
2016-01-15 13:03:56 +00:00
|
|
|
float dpi = 160 * scale;
|
2016-05-02 12:53:23 +00:00
|
|
|
unsigned idiom_type = UI_USER_INTERFACE_IDIOM();
|
2016-01-15 13:03:56 +00:00
|
|
|
|
2016-05-02 12:53:23 +00:00
|
|
|
switch (idiom_type)
|
2016-01-15 13:03:56 +00:00
|
|
|
{
|
2016-03-02 16:25:13 +00:00
|
|
|
case -1: /* UIUserInterfaceIdiomUnspecified */
|
2016-01-15 13:08:38 +00:00
|
|
|
/* TODO */
|
|
|
|
break;
|
2016-01-15 13:03:56 +00:00
|
|
|
case UIUserInterfaceIdiomPad:
|
|
|
|
dpi = 132 * scale;
|
|
|
|
break;
|
|
|
|
case UIUserInterfaceIdiomPhone:
|
|
|
|
dpi = 163 * scale;
|
|
|
|
break;
|
2016-01-15 13:08:38 +00:00
|
|
|
case UIUserInterfaceIdiomTV:
|
2016-05-01 23:55:02 +00:00
|
|
|
case UIUserInterfaceIdiomCarPlay:
|
2016-01-15 13:08:38 +00:00
|
|
|
/* TODO */
|
|
|
|
break;
|
2015-04-21 11:58:19 +00:00
|
|
|
}
|
2015-04-12 14:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
(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:
|
2015-04-21 11:58:19 +00:00
|
|
|
*value = dpi;
|
2015-04-12 14:50:39 +00:00
|
|
|
break;
|
|
|
|
case DISPLAY_METRIC_NONE:
|
|
|
|
default:
|
|
|
|
*value = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static bool cocoagl_gfx_ctx_has_focus(void *data)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
2015-04-12 14:50:39 +00:00
|
|
|
return ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive);
|
|
|
|
#else
|
|
|
|
return [NSApp isActive];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static bool cocoagl_gfx_ctx_suppress_screensaver(void *data, bool enable)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 01:50:56 +00:00
|
|
|
#if !defined(HAVE_COCOATOUCH)
|
2015-04-19 15:40:10 +00:00
|
|
|
static bool cocoagl_gfx_ctx_has_windowed(void *data)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-19 01:50:56 +00:00
|
|
|
#endif
|
2015-04-12 14:50:39 +00:00
|
|
|
|
2017-05-19 01:34:53 +00:00
|
|
|
static void cocoagl_gfx_ctx_swap_buffers(void *data, void *data2)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
if (!(--g_fast_forward_skips < 0))
|
|
|
|
return;
|
|
|
|
|
2015-04-19 22:38:55 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2015-04-12 14:50:39 +00:00
|
|
|
[g_context flushBuffer];
|
2017-06-18 17:35:34 +00:00
|
|
|
[g_hw_ctx flushBuffer];
|
2015-04-19 22:38:55 +00:00
|
|
|
#elif defined(HAVE_COCOATOUCH)
|
2015-04-15 05:34:22 +00:00
|
|
|
if (g_view)
|
|
|
|
[g_view display];
|
2015-04-12 14:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
g_fast_forward_skips = g_is_syncing ? 0 : 3;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static gfx_ctx_proc_t cocoagl_gfx_ctx_get_proc_address(const char *symbol_name)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID),
|
2017-04-15 17:20:42 +00:00
|
|
|
(BRIDGE CFStringRef)BOXSTRING(symbol_name)
|
2015-04-12 14:50:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static void cocoagl_gfx_ctx_check_window(void *data, bool *quit,
|
2017-01-23 00:02:33 +00:00
|
|
|
bool *resize, unsigned *width, unsigned *height, bool is_shutdown)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
unsigned new_width, new_height;
|
|
|
|
|
|
|
|
*quit = false;
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height);
|
2015-04-12 14:50:39 +00:00
|
|
|
if (new_width != *width || new_height != *height)
|
|
|
|
{
|
|
|
|
*width = new_width;
|
|
|
|
*height = new_height;
|
|
|
|
*resize = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 23:13:57 +00:00
|
|
|
static void cocoagl_gfx_ctx_input_driver(void *data,
|
|
|
|
const char *name,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
2017-01-15 23:13:57 +00:00
|
|
|
*input = NULL;
|
2015-04-12 14:50:39 +00:00
|
|
|
*input_data = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
static void cocoagl_gfx_ctx_bind_hw_render(void *data, bool enable)
|
2015-04-12 14:50:39 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
g_use_hw_ctx = enable;
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
[g_hw_ctx makeCurrentContext];
|
|
|
|
else
|
|
|
|
[g_context makeCurrentContext];
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:35:35 +00:00
|
|
|
static uint32_t cocoagl_gfx_ctx_get_flags(void *data)
|
|
|
|
{
|
2017-06-27 04:14:13 +00:00
|
|
|
uint32_t flags = 0;
|
|
|
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
2017-06-27 04:11:08 +00:00
|
|
|
|
2016-05-05 15:35:28 +00:00
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
|
2017-06-27 04:11:08 +00:00
|
|
|
|
|
|
|
if (cocoa_ctx->core_hw_context_enable)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
|
|
|
|
|
2016-05-05 15:35:28 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cocoagl_gfx_ctx_set_flags(void *data, uint32_t flags)
|
|
|
|
{
|
|
|
|
(void)flags;
|
2017-06-27 04:11:08 +00:00
|
|
|
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
|
|
|
|
|
|
|
if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT))
|
|
|
|
cocoa_ctx->core_hw_context_enable = true;
|
2016-05-05 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:40:10 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_cocoagl = {
|
|
|
|
cocoagl_gfx_ctx_init,
|
|
|
|
cocoagl_gfx_ctx_destroy,
|
|
|
|
cocoagl_gfx_ctx_bind_api,
|
|
|
|
cocoagl_gfx_ctx_swap_interval,
|
|
|
|
cocoagl_gfx_ctx_set_video_mode,
|
|
|
|
cocoagl_gfx_ctx_get_video_size,
|
2015-04-12 14:50:39 +00:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_get_metrics,
|
2015-04-12 14:50:39 +00:00
|
|
|
NULL,
|
2017-01-19 00:58:44 +00:00
|
|
|
#if defined(HAVE_COCOA)
|
2017-01-18 16:42:11 +00:00
|
|
|
cocoagl_gfx_ctx_update_title,
|
2017-01-19 00:58:44 +00:00
|
|
|
#else
|
|
|
|
NULL, /* update_title */
|
|
|
|
#endif
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_check_window,
|
2017-01-19 13:31:57 +00:00
|
|
|
NULL, /* set_resize */
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_has_focus,
|
|
|
|
cocoagl_gfx_ctx_suppress_screensaver,
|
2017-01-19 01:50:56 +00:00
|
|
|
#if defined(HAVE_COCOATOUCH)
|
|
|
|
NULL,
|
|
|
|
#else
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_has_windowed,
|
2017-01-19 01:50:56 +00:00
|
|
|
#endif
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_swap_buffers,
|
|
|
|
cocoagl_gfx_ctx_input_driver,
|
|
|
|
cocoagl_gfx_ctx_get_proc_address,
|
2015-04-12 14:50:39 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-04-19 15:40:10 +00:00
|
|
|
"cocoagl",
|
2016-05-05 03:35:35 +00:00
|
|
|
cocoagl_gfx_ctx_get_flags,
|
2016-05-05 15:35:28 +00:00
|
|
|
cocoagl_gfx_ctx_set_flags,
|
2015-04-19 15:40:10 +00:00
|
|
|
cocoagl_gfx_ctx_bind_hw_render,
|
2016-08-31 13:02:07 +00:00
|
|
|
NULL,
|
|
|
|
NULL
|
2015-04-12 14:50:39 +00:00
|
|
|
};
|