Revert code in hopes iOS works again

This commit is contained in:
twinaphex 2019-11-20 06:25:40 +01:00
parent d2d240ecf5
commit 861379d8e3
3 changed files with 108 additions and 45 deletions

View File

@ -48,8 +48,6 @@
#include "../common/metal_common.h"
#endif
#include "../../ui/drivers/cocoa/apple_platform.h"
typedef struct cocoa_ctx_data
{
bool core_hw_context_enable;
@ -63,6 +61,10 @@ typedef struct cocoa_ctx_data
static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE;
#if defined(HAVE_COCOATOUCH)
static GLKView *g_view;
#endif
static GLContextClass* g_hw_ctx;
static GLContextClass* g_context;
@ -91,6 +93,27 @@ static unsigned g_major = 0;
@end
#endif
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);
#elif defined(HAVE_COCOA_METAL)
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;
}
void nsview_set_ptr(CocoaView *p)
{
g_instance = p;
}
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
static NSOpenGLPixelFormat* g_format;
@ -151,6 +174,21 @@ static void cocoagl_gfx_ctx_set_flags(void *data, uint32_t flags)
cocoa_ctx->core_hw_context_enable = true;
}
void *glkitview_init(void)
{
#if defined(HAVE_COCOATOUCH)
g_view = [GLKView new];
#if TARGET_OS_IOS
g_view.multipleTouchEnabled = YES;
#endif
g_view.enableSetNeedsDisplay = NO;
return (BRIDGE void *)((GLKView*)g_view);
#else
return nsview_get_ptr();
#endif
}
#if defined(HAVE_COCOATOUCH)
void cocoagl_bind_game_view_fbo(void)
{
@ -211,7 +249,7 @@ float get_backing_scale_factor(void)
#if defined(HAVE_COCOA_METAL)
NSView *g_view = apple_platform.renderView;
#elif defined(HAVE_COCOA)
CocoaView *g_view = [CocoaView get];
CocoaView *g_view = g_instance;
#endif
backing_scale_def = (float)get_from_selector
([[g_view window] class], [g_view window], selector, &ret);
@ -332,7 +370,7 @@ float cocoagl_gfx_ctx_get_native_scale(void)
static void cocoagl_gfx_ctx_update_title(void *data, void *data2)
{
const ui_window_t *window = ui_companion_driver_get_window_ptr();
if (window)
{
char title[128];
@ -447,15 +485,15 @@ static void cocoagl_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned
#if defined(HAVE_COCOA_METAL)
NSView *g_view = apple_platform.renderView;
#elif defined(HAVE_COCOA)
CocoaView *g_view = [CocoaView get];
CocoaView *g_view = g_instance;
#endif
NSRect rect = [g_view frame];
#if MAC_OS_X_VERSION_10_7
SEL selector = NSSelectorFromString(BOXSTRING("convertRectToBacking:"));
if ([g_view respondsToSelector:selector])
rect = [g_view convertRectToBacking:[g_view bounds]];
cgrect = NSRectToCGRect([g_view convertRectToBacking:[g_view bounds]]);
else
#endif
cgrect = NSRectToCGRect(rect);
cgrect = NSRectToCGRect([g_view frame]);
backingPixelWidth = CGRectGetWidth(cgrect);
backingPixelHeight = CGRectGetHeight(cgrect);
size = CGRectMake(0, 0, backingPixelWidth, backingPixelHeight);
@ -655,7 +693,7 @@ static bool cocoagl_gfx_ctx_set_video_mode(void *data,
#if defined(HAVE_COCOA_METAL)
NSView *g_view = apple_platform.renderView;
#elif defined(HAVE_COCOA)
CocoaView *g_view = [CocoaView get];
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
#endif
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
@ -818,6 +856,7 @@ static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_dr
return cocoa_ctx;
}
#ifdef HAVE_COCOA_METAL
static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
{
#ifdef HAVE_VULKAN
@ -857,6 +896,7 @@ static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned heig
return true;
}
#endif
const gfx_ctx_driver_t gfx_ctx_cocoagl = {
cocoagl_gfx_ctx_init,
@ -878,7 +918,11 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = {
NULL, /* update_title */
#endif
cocoagl_gfx_ctx_check_window,
#if defined(HAVE_COCOA_METAL)
cocoagl_gfx_ctx_set_resize,
#else
NULL, /* set_resize */
#endif
cocoagl_gfx_ctx_has_focus,
cocoagl_gfx_ctx_suppress_screensaver,
#if defined(HAVE_COCOATOUCH)

View File

@ -35,39 +35,11 @@
/* forward declarations */
void cocoagl_gfx_ctx_update(void);
void *glkitview_init(void);
static CocoaView* g_instance;
static 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);
#elif defined(HAVE_COCOA_METAL)
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;
}
#if defined(HAVE_COCOATOUCH)
static GLKView *g_view;
static void *glkitview_init(void)
{
g_view = [GLKView new];
#if TARGET_OS_IOS
g_view.multipleTouchEnabled = YES;
#endif
g_view.enableSetNeedsDisplay = NO;
return (BRIDGE void *)((GLKView*)g_view);
}
#ifdef HAVE_COCOATOUCH
@interface CocoaView()<GCDWebUploaderDelegate> {
}
@end
#endif
@ -92,8 +64,8 @@ static void *glkitview_init(void)
CocoaView *view = (BRIDGE CocoaView*)nsview_get_ptr();
if (!view)
{
view = [CocoaView new];
g_instance = view;
view = [CocoaView new];
nsview_set_ptr(view);
}
return view;
}

View File

@ -40,7 +40,54 @@
#include "../../tasks/tasks_internal.h"
#include ".././verbosity.h"
#include "cocoa/apple_platform.h"
#if defined(HAVE_COCOA_METAL)
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
@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)
id<ApplePlatform> apple_platform;
@interface RetroArch_OSX : NSObject <ApplePlatform, NSApplicationDelegate>
{
NSWindow* _window;
apple_view_type_t _vt;
NSView* _renderView;
id _sleepActivity;
WindowListener *_listener;
}
#elif defined(HAVE_COCOA)
id apple_platform;
#if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
@interface RetroArch_OSX : NSObject
#else
@interface RetroArch_OSX : NSObject <NSApplicationDelegate>
#endif
{
NSWindow* _window;
}
#endif
@property (nonatomic, retain) NSWindow IBOutlet* window;
@end
static void app_terminate(void)
{
@ -128,7 +175,7 @@ static void app_terminate(void)
apple = (cocoa_input_data_t*)input_driver_get_data();
if (!apple)
return;
pos.x = 0;
pos.y = 0;
@ -280,7 +327,7 @@ static char** waiting_argv;
return;
}
RARCH_LOG("[Cocoa]: change view type: %d %d\n", _vt, vt);
RARCH_LOG("[Cocoa]: change view type: %d ? %d\n", _vt, vt);
_vt = vt;
if (_renderView != nil)