chore(cocoa): Cleanup unnecessary conditionals in Metal source files

This commit is contained in:
Stuart Carnie 2018-11-05 06:53:35 -07:00
parent 98e6adcfca
commit 68760b36f2
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
7 changed files with 28 additions and 146 deletions

View File

@ -14,8 +14,8 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COCOA_COMMON_H
#define __COCOA_COMMON_H
#ifndef __COCOA_COMMON_METAL_H
#define __COCOA_COMMON_METAL_H
#include <Foundation/Foundation.h>

View File

@ -43,7 +43,6 @@
#include "../../../location/location_driver.h"
#include "../../../camera/camera_driver.h"
#ifdef HAVE_METAL
@implementation MetalView
- (void)keyDown:(NSEvent*)theEvent
@ -61,7 +60,6 @@
return YES;
}
@end
#endif
static CocoaView* g_instance;
@ -102,7 +100,7 @@ void *glkitview_init(void);
#if defined(HAVE_COCOA_METAL)
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes:@[NSColorPboardType, NSFilenamesPboardType]];
#elif defined(HAVE_COCOATOUCH)
self.view = (__bridge GLKView*)glkitview_init();

View File

@ -23,10 +23,6 @@
#include "cocoa_common_metal.h"
#include "../../ui_companion_driver.h"
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSEventMaskAny NSAnyEventMask
#endif
static void* ui_application_cocoa_initialize(void)
{
return NULL;
@ -47,14 +43,7 @@ static void ui_application_cocoa_process_events(void)
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (!event)
break;
#if __has_feature(objc_arc)
[NSApp sendEvent: event];
#else
[event retain];
[NSApp sendEvent: event];
[event release];
#endif
}
}

View File

@ -27,31 +27,25 @@
static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state)
{
NSOpenPanel* panel = (NSOpenPanel*)[NSOpenPanel openPanel];
NSArray *filetypes = NULL;
if (!string_is_empty(state->filters))
filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil];
[panel setAllowedFileTypes:filetypes];
#if defined(MAC_OS_X_VERSION_10_6)
[panel setMessage:BOXSTRING(state->title)];
if ([panel runModalForDirectory:BOXSTRING(state->startdir) file:nil] != 1)
return false;
#else
[panel setTitle:NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"))];
[panel setDirectory:BOXSTRING(state->startdir)];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:NO];
[panel setTreatsFilePackagesAsDirectories:NO];
NSInteger result = [panel runModal];
if (result != 1)
return false;
#endif
NSURL *url = (NSURL*)panel.URL;
const char *res_path = [url.path UTF8String];
state->result = strdup(res_path);
NSOpenPanel *panel = [NSOpenPanel openPanel];
if (!string_is_empty(state->filters))
{
[panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]];
}
panel.title = NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"));
panel.directoryURL = [NSURL fileURLWithPath:BOXSTRING(state->startdir)];
panel.canChooseDirectories = NO;
panel.canChooseFiles = YES;
panel.allowsMultipleSelection = NO;
panel.treatsFilePackagesAsDirectories = NO;
NSModalResponse result = [panel runModal];
if (result != NSModalResponseOK)
return false;
const char *res_path = [panel.URL.path UTF8String];
state->result = strdup(res_path);
return true;
}

View File

@ -25,20 +25,10 @@
#include "../../ui_companion_driver.h"
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSAlertStyleCritical NSCriticalAlertStyle
#define NSAlertStyleWarning NSWarningAlertStyle
#define NSAlertStyleInformational NSInformationalAlertStyle
#endif
static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type)
{
NSInteger response;
#if __has_feature(objc_arc)
NSModalResponse response;
NSAlert *alert = [NSAlert new];
#else
NSAlert* alert = [[NSAlert new] autorelease];
#endif
if (!string_is_empty(state->title))
[alert setMessageText:BOXSTRING(state->title)];
@ -80,19 +70,11 @@ static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_stat
break;
}
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
[alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window()
completionHandler:^(NSModalResponse returnCode) {
[[NSApplication sharedApplication] stopModalWithCode:returnCode];
}];
response = [alert runModal];
#else
[alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window()
modalDelegate:apple_platform
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
response = [[NSApplication sharedApplication] runModalForWindow:[alert window]];
#endif
switch (state->buttons)
{

View File

@ -32,12 +32,6 @@ static void* ui_window_cocoa_init(void)
static void ui_window_cocoa_destroy(void *data)
{
#if !__has_feature(objc_arc)
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (CocoaView*)cocoa->data;
// TODO(sgc): incorrect behavior
[[cocoa_view window] release];
#endif
}
static void ui_window_cocoa_set_focused(void *data)
@ -73,7 +67,7 @@ static void ui_window_cocoa_set_droppable(void *data, bool droppable)
if (droppable)
{
[[cocoa_view window] registerForDraggedTypes:[NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil]];
[[cocoa_view window] registerForDraggedTypes:@[NSPasteboardTypeColor, NSPasteboardTypeFileURL]];
}
else
{
@ -85,9 +79,7 @@ static bool ui_window_cocoa_focused(void *data)
{
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data;
if ([[cocoa_view window] isMainWindow] == YES)
return true;
return false;
return cocoa_view.window.isMainWindow;
}
ui_window_t ui_window_cocoa = {

View File

@ -38,12 +38,9 @@
#include "../../tasks/tasks_internal.h"
#include ".././verbosity.h"
#ifdef HAVE_METAL
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
#endif
#if !((defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__))))
@interface WindowListener : NSResponder<NSWindowDelegate>
@end
@ -61,23 +58,16 @@
{}
@end
#endif
id<ApplePlatform> apple_platform;
#if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
@interface RetroArch_OSX : NSObject <ApplePlatform>
#else
@interface RetroArch_OSX : NSObject <ApplePlatform, NSApplicationDelegate>
#endif
{
NSWindow* _window;
apple_view_type_t _vt;
NSView* _renderView;
id _sleepActivity;
#if !(defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
WindowListener *_listener;
#endif
}
@property (nonatomic, retain) NSWindow IBOutlet* window;
@ -88,42 +78,10 @@ static void app_terminate(void)
{
[[NSApplication sharedApplication] terminate:nil];
}
#ifdef HAVE_METAL
@interface RAWindow : NSWindow
@end
@implementation RAWindow
#else
@interface RApplication : NSApplication
@end
@implementation RApplication
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSEventTypeKeyDown NSKeyDown
#define NSEventTypeKeyUp NSKeyUp
#define NSEventTypeFlagsChanged NSFlagsChanged
#define NSEventTypeMouseMoved NSMouseMoved
#define NSEventTypeLeftMouseDragged NSLeftMouseDragged
#define NSEventTypeRightMouseDragged NSRightMouseDragged
#define NSEventTypeOtherMouseDragged NSOtherMouseDragged
#define NSEventTypeLeftMouseDown NSLeftMouseDown
#define NSEventTypeRightMouseDown NSRightMouseDown
#define NSEventTypeOtherMouseDown NSOtherMouseDown
#define NSEventTypeLeftMouseUp NSLeftMouseUp
#define NSEventTypeRightMouseUp NSRightMouseUp
#define NSEventTypeOtherMouseUp NSOtherMouseUp
#define NSEventTypeScrollWheel NSScrollWheel
// modifier flags
#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
#define NSEventModifierFlagShift NSShiftKeyMask
#define NSEventModifierFlagControl NSControlKeyMask
#define NSEventModifierFlagOption NSAlternateKeyMask
#define NSEventModifierFlagCommand NSCommandKeyMask
#define NSEventModifierFlagNumericPad NSNumericPadKeyMask
#endif
- (void)sendEvent:(NSEvent *)event {
[super sendEvent:event];
@ -246,39 +204,19 @@ static char** waiting_argv;
@synthesize window = _window;
#if !__has_feature(objc_arc)
- (void)dealloc
{
[_window release];
[super dealloc];
}
#endif
#define NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY (1 << 17)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
unsigned i;
apple_platform = self;
SEL selector = NSSelectorFromString(BOXSTRING("setCollectionBehavior:"));
SEL fsselector = NSSelectorFromString(BOXSTRING("toggleFullScreen:"));
if ([self.window respondsToSelector:selector])
{
if ([self.window respondsToSelector:fsselector])
[self.window setCollectionBehavior:NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY];
}
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
#if !(defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
_listener = [WindowListener new];
#endif
[self.window setAcceptsMouseMovedEvents: YES];
#if !(defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
[self.window setNextResponder:_listener];
self.window.delegate = _listener;
#endif
[[self.window contentView] setAutoresizesSubviews:YES];
@ -324,14 +262,12 @@ static char** waiting_argv;
switch (vt) {
case APPLE_VIEW_TYPE_VULKAN:
case APPLE_VIEW_TYPE_METAL:
#if defined(HAVE_METAL) || defined(HAVE_VULKAN)
{
MetalView *v = [MetalView new];
v.paused = YES;
v.enableSetNeedsDisplay = NO;
_renderView = v;
}
#endif
break;
case APPLE_VIEW_TYPE_OPENGL:
@ -349,9 +285,7 @@ static char** waiting_argv;
[_renderView setFrame: [[self.window contentView] bounds]];
self.window.contentView = _renderView;
#if !(defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
[self.window.contentView setNextResponder:_listener];
#endif
self.window.contentView.nextResponder = _listener;
}
- (apple_view_type_t)viewType {
@ -367,8 +301,7 @@ static char** waiting_argv;
}
- (void)setVideoMode:(gfx_ctx_mode_t)mode {
#ifdef HAVE_METAL
BOOL isFullScreen = (self.window.styleMask & NSFullScreenWindowMask) == NSFullScreenWindowMask;
BOOL isFullScreen = (self.window.styleMask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;
if (mode.fullscreen && !isFullScreen)
{
[self.window toggleFullScreen:self];
@ -386,7 +319,6 @@ static char** waiting_argv;
[self.window setContentSize:NSMakeSize(mode.width-1, mode.height)];
}
[self.window setContentSize:NSMakeSize(mode.width, mode.height)];
#endif
}
- (void)setCursorVisible:(bool)v {
@ -398,7 +330,6 @@ static char** waiting_argv;
- (bool)setDisableDisplaySleep:(bool)disable
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
if (disable && _sleepActivity == nil)
{
_sleepActivity = [NSProcessInfo.processInfo beginActivityWithOptions:NSActivityIdleDisplaySleepDisabled reason:@"disable screen saver"];
@ -409,10 +340,6 @@ static char** waiting_argv;
_sleepActivity = nil;
}
return YES;
#else
return NO;
#endif
}