(Metal) Refactor

This commit is contained in:
twinaphex 2019-09-22 10:28:51 +02:00
parent 6a9feb7978
commit ad1fb29092
4 changed files with 79 additions and 66 deletions

View File

@ -1,9 +1,18 @@
//
// metal_common.h
// RetroArch_Metal
//
// Created by Stuart Carnie on 5/14/18.
//
/* RetroArch - A frontend for libretro.
* Copyright (C) 2018-2019 - Stuart Carnie
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* 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/>.
*/
#ifndef METAL_COMMON_H__
#define METAL_COMMON_H__
@ -26,6 +35,38 @@ extern MTLPixelFormat SelectOptimalPixelFormat(MTLPixelFormat fmt);
#pragma mark - Classes
#import <MetalKit/MetalKit.h>
@interface MetalView : MTKView
@end
#ifdef HAVE_COCOA_METAL
@protocol ApplePlatform
/*! @brief renderView returns the current render view based on the viewType */
@property (readonly) id renderView;
/*! @brief isActive returns true if the application has focus */
@property (readonly) bool hasFocus;
@property (readwrite) apple_view_type_t viewType;
/*! @brief setVideoMode adjusts the video display to the specified mode */
- (void)setVideoMode:(gfx_ctx_mode_t)mode;
/*! @brief setCursorVisible specifies whether the cursor is visible */
- (void)setCursorVisible:(bool)v;
/*! @brief controls whether the screen saver should be disabled and
* the displays should not sleep.
*/
- (bool)setDisableDisplaySleep:(bool)disable;
@end
extern id<ApplePlatform> apple_platform;
#endif
@interface FrameView : NSObject
@property (nonatomic, readonly) RPixelFormat format;

View File

@ -1,8 +1,17 @@
/*
* metal_common.m
* RetroArch_Metal
/* RetroArch - A frontend for libretro.
* Copyright (C) 2018-2019 - Stuart Carnie
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* Created by Stuart Carnie on 5/14/18.
* 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/>.
*/
#import <Foundation/Foundation.h>
@ -39,6 +48,24 @@
x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y); \
}
@implementation MetalView
- (void)keyDown:(NSEvent*)theEvent
{
}
/* Stop the annoying sound when pressing a key. */
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)isFlipped
{
return YES;
}
@end
#pragma mark - private categories
@interface FrameView()

View File

@ -50,40 +50,6 @@ typedef enum apple_view_type {
APPLE_VIEW_TYPE_METAL,
} apple_view_type_t;
#ifdef HAVE_METAL
#import <MetalKit/MetalKit.h>
@interface MetalView : MTKView
@end
#ifdef HAVE_COCOA_METAL
@protocol ApplePlatform
/*! @brief renderView returns the current render view based on the viewType */
@property (readonly) id renderView;
/*! @brief isActive returns true if the application has focus */
@property (readonly) bool hasFocus;
@property (readwrite) apple_view_type_t viewType;
/*! @brief setVideoMode adjusts the video display to the specified mode */
- (void)setVideoMode:(gfx_ctx_mode_t)mode;
/*! @brief setCursorVisible specifies whether the cursor is visible */
- (void)setCursorVisible:(bool)v;
/*! @brief controls whether the screen saver should be disabled and
* the displays should not sleep.
*/
- (bool)setDisableDisplaySleep:(bool)disable;
@end
extern id<ApplePlatform> apple_platform;
#endif
#endif
#if defined(HAVE_COCOATOUCH)
#include <UIKit/UIKit.h>

View File

@ -29,27 +29,6 @@
#ifdef HAVE_COCOATOUCH
#import "GCDWebUploader.h"
#import "WebServer.h"
#endif
#ifdef HAVE_METAL
@implementation MetalView
- (void)keyDown:(NSEvent*)theEvent
{
}
/* Stop the annoying sound when pressing a key. */
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)isFlipped
{
return YES;
}
@end
#endif
static CocoaView* g_instance;
@ -354,6 +333,6 @@ void *glkitview_init(void);
}];
#endif
}
#endif // end HAVE_COCOATOUCH
#endif
@end