From ccfbc5fcd090590e0278db1aa93d9bfe80d09641 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Sun, 9 Jun 2019 22:15:39 +0800 Subject: [PATCH 01/11] Show root view controller on external display --- ios/AppDelegate.h | 1 + ios/AppDelegate.mm | 30 +++++++++++++++++++++--------- ios/ViewController.mm | 17 ++++++++++------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/ios/AppDelegate.h b/ios/AppDelegate.h index 263e85d369..feb65efbf4 100644 --- a/ios/AppDelegate.h +++ b/ios/AppDelegate.h @@ -7,6 +7,7 @@ @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; +@property (strong, nonatomic) UIScreen *screen; @property (strong, nonatomic) ViewController *viewController; diff --git a/ios/AppDelegate.mm b/ios/AppDelegate.mm index 5ae6e18003..34b90b2bbe 100644 --- a/ios/AppDelegate.mm +++ b/ios/AppDelegate.mm @@ -72,15 +72,27 @@ } -(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.viewController = [[ViewController alloc] init]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMediaServicesWereReset:) name:AVAudioSessionMediaServicesWereResetNotification object:nil]; - - self.window.rootViewController = self.viewController; - [self.window makeKeyAndVisible]; + + [[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { + UIScreen* screen = (UIScreen*)notification.object; + self.screen = screen; + + NSLog(@"Display connected: %@", screen.debugDescription); + UIScreenMode* mode = screen.availableModes[screen.availableModes.count - 1]; + [screen setCurrentMode:mode]; + [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; + + self.window = [[UIWindow alloc] initWithFrame:[screen bounds]]; + [self.window setScreen:screen]; + self.viewController = [[ViewController alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMediaServicesWereReset:) name:AVAudioSessionMediaServicesWereResetNotification object:nil]; + + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + }]; return YES; } diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 5eba171e2b..8ebae24cdc 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -5,6 +5,7 @@ // Modified by xSacha // +#import "AppDelegate.h" #import "ViewController.h" #import "SubtleVolume.h" #import @@ -144,7 +145,8 @@ static GraphicsContext *graphicsContext; - (void)viewDidLoad { [super viewDidLoad]; - self.view.frame = [[UIScreen mainScreen] bounds]; + UIScreen* screen = [(AppDelegate*)[UIApplication sharedApplication].delegate screen]; + self.view.frame = [screen bounds]; self.view.multipleTouchEnabled = YES; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; @@ -159,12 +161,13 @@ static GraphicsContext *graphicsContext; self.preferredFramesPerSecond = 60; // Might be useful for a speed boot, sacrificing resolution: - // view.contentScaleFactor = 1.0; + view.contentScaleFactor = screen.scale; - float scale = [UIScreen mainScreen].scale; + float scale = screen.scale; + - if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) { - scale = [UIScreen mainScreen].nativeScale; + if ([screen respondsToSelector:@selector(nativeScale)]) { + scale = screen.nativeScale; } CGSize size = [[UIApplication sharedApplication].delegate window].frame.size; @@ -176,8 +179,8 @@ static GraphicsContext *graphicsContext; } g_dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; - g_dpi_scale_x = 240.0f / g_dpi; - g_dpi_scale_y = 240.0f / g_dpi; + g_dpi_scale_x = 1;//240.0f / g_dpi; + g_dpi_scale_y = 1;//240.0f / g_dpi; g_dpi_scale_real_x = g_dpi_scale_x; g_dpi_scale_real_y = g_dpi_scale_y; pixel_xres = size.width * scale; From 259f0ce22e41b8feab64333c2e26bd02e3e2ed7d Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 01:24:58 +0800 Subject: [PATCH 02/11] Auto switch between internal and external display --- CMakeLists.txt | 2 + ios/AppDelegate.mm | 31 +++------- ios/DisplayManager.h | 24 ++++++++ ios/DisplayManager.mm | 139 ++++++++++++++++++++++++++++++++++++++++++ ios/ViewController.mm | 31 +--------- 5 files changed, 178 insertions(+), 49 deletions(-) create mode 100644 ios/DisplayManager.h create mode 100644 ios/DisplayManager.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index 89ec8303c5..3735f82025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -735,6 +735,8 @@ elseif(IOS) ios/main.mm ios/AppDelegate.mm ios/AppDelegate.h + ios/DisplayManager.h + ios/DisplayManager.mm ios/ViewController.mm ios/ViewController.h ios/iOSCoreAudio.mm diff --git a/ios/AppDelegate.mm b/ios/AppDelegate.mm index 34b90b2bbe..4cbd2ae1fb 100644 --- a/ios/AppDelegate.mm +++ b/ios/AppDelegate.mm @@ -1,4 +1,5 @@ #import "AppDelegate.h" +#import "DisplayManager.h" #import "ViewController.h" #import "base/NativeApp.h" #import "Core/System.h" @@ -72,27 +73,15 @@ } -(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - - [[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { - UIScreen* screen = (UIScreen*)notification.object; - self.screen = screen; - - NSLog(@"Display connected: %@", screen.debugDescription); - UIScreenMode* mode = screen.availableModes[screen.availableModes.count - 1]; - [screen setCurrentMode:mode]; - [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; - - self.window = [[UIWindow alloc] initWithFrame:[screen bounds]]; - [self.window setScreen:screen]; - self.viewController = [[ViewController alloc] init]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMediaServicesWereReset:) name:AVAudioSessionMediaServicesWereResetNotification object:nil]; - - self.window.rootViewController = self.viewController; - [self.window makeKeyAndVisible]; - }]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.viewController = [[ViewController alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMediaServicesWereReset:) name:AVAudioSessionMediaServicesWereResetNotification object:nil]; + + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; return YES; } diff --git a/ios/DisplayManager.h b/ios/DisplayManager.h new file mode 100644 index 0000000000..fb46707a19 --- /dev/null +++ b/ios/DisplayManager.h @@ -0,0 +1,24 @@ +// +// DisplayManager.h +// native +// +// Created by xieyi on 2019/6/9. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface DisplayManager : NSObject + +- (void)setupDisplayListener; +- (void)updateResolution:(UIScreen *)screen; + +@property (nonatomic, strong) UIScreen *mainScreen; + +@property (class, readonly, strong) DisplayManager *shared; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm new file mode 100644 index 0000000000..5b20d8a252 --- /dev/null +++ b/ios/DisplayManager.mm @@ -0,0 +1,139 @@ +// +// DisplayManager.m +// native +// +// Created by xieyi on 2019/6/9. +// + +#import "DisplayManager.h" +#import "ViewController.h" +#import "AppDelegate.h" +#include "base/display.h" +#include "base/NativeApp.h" +#include "Core/System.h" + +#define IS_IPAD() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) + +@interface DisplayManager () + +@property BOOL listenerActive; +@property (atomic, retain) NSMutableArray *extDisplays; + +- (void)updateScreen:(UIScreen *)screen; + +@end + +@implementation DisplayManager + +- (instancetype)init +{ + self = [super init]; + if (self) { + [self setListenerActive:NO]; + [self setExtDisplays:[[NSMutableArray alloc] init]]; + } + return self; +} + ++ (DisplayManager *)shared { + static DisplayManager *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[DisplayManager alloc] init]; + }); + return sharedInstance; +} + +- (void)setupDisplayListener { + if ([self listenerActive]) { + NSLog(@"setupDisplayListener already called"); + return; + } + NSLog(@"Setting up display manager"); + [self setMainScreen:[UIScreen mainScreen]]; + // Display connected + [[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { + UIScreen *screen = (UIScreen *) notification.object; + NSLog(@"New display connected: %@", [screen debugDescription]); + [[self extDisplays] addObject:screen]; + // Do not switch to second connected display + if ([self mainScreen] != [UIScreen mainScreen]) { + return; + } + [self updateScreen:screen]; + }]; + // Display disconnected + [[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidDisconnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { + UIScreen *screen = (UIScreen *) notification.object; + NSLog(@"Display disconnected: %@", [screen debugDescription]); + if ([[self extDisplays] containsObject:screen]) { + [[self extDisplays] removeObject:screen]; + } + if ([[self extDisplays] count] > 0) { + UIScreen *newScreen = [[self extDisplays] lastObject]; + [self updateScreen:newScreen]; + } else { + [self updateScreen:[UIScreen mainScreen]]; + } + }]; + [self setListenerActive:YES]; +} + +- (void)updateScreen:(UIScreen *)screen { + [self setMainScreen:screen]; + UIWindow *gameWindow = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window]; + [gameWindow setScreen:screen]; + // Set optimal resolution + // Dispatch later to prevent "no window is preset" error + dispatch_async(dispatch_get_main_queue(), ^{ + if (screen != [UIScreen mainScreen]) { + NSUInteger count = [[screen availableModes] count]; + UIScreenMode* mode = [screen availableModes][count - 1]; + [screen setCurrentMode:mode]; + [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; + } + [self updateResolution:screen]; + }); +} + +- (void)updateResolution:(UIScreen *)screen { + float scale = screen.scale; + + if ([screen respondsToSelector:@selector(nativeScale)]) { + scale = screen.nativeScale; + } + + CGSize size = screen.applicationFrame.size; + + if (size.height > size.width) { + float h = size.height; + size.height = size.width; + size.width = h; + } + + g_dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; + g_dpi_scale_x = 240.0f / g_dpi; + g_dpi_scale_y = 240.0f / g_dpi; + g_dpi_scale_real_x = g_dpi_scale_x; + g_dpi_scale_real_y = g_dpi_scale_y; + pixel_xres = size.width * scale; + pixel_yres = size.height * scale; + + dp_xres = pixel_xres * g_dpi_scale_x; + dp_yres = pixel_yres * g_dpi_scale_y; + + pixel_in_dps_x = (float)pixel_xres / (float)dp_xres; + pixel_in_dps_y = (float)pixel_yres / (float)dp_yres; + + [[sharedViewController view] setContentScaleFactor:scale]; + + // PSP native resize + PSP_CoreParameter().pixelWidth = pixel_xres; + PSP_CoreParameter().pixelHeight = pixel_yres; + + NativeResized(); + + NSLog(@"Updated display resolution: (%d, %d) @%.1fx", pixel_xres, pixel_yres, scale); +} + +@end diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 8ebae24cdc..457e331a74 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -7,6 +7,7 @@ #import "AppDelegate.h" #import "ViewController.h" +#import "DisplayManager.h" #import "SubtleVolume.h" #import #include @@ -144,6 +145,7 @@ static GraphicsContext *graphicsContext; - (void)viewDidLoad { [super viewDidLoad]; + [[DisplayManager shared] setupDisplayListener]; UIScreen* screen = [(AppDelegate*)[UIApplication sharedApplication].delegate screen]; self.view.frame = [screen bounds]; @@ -163,34 +165,7 @@ static GraphicsContext *graphicsContext; // Might be useful for a speed boot, sacrificing resolution: view.contentScaleFactor = screen.scale; - float scale = screen.scale; - - - if ([screen respondsToSelector:@selector(nativeScale)]) { - scale = screen.nativeScale; - } - - CGSize size = [[UIApplication sharedApplication].delegate window].frame.size; - - if (size.height > size.width) { - float h = size.height; - size.height = size.width; - size.width = h; - } - - g_dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; - g_dpi_scale_x = 1;//240.0f / g_dpi; - g_dpi_scale_y = 1;//240.0f / g_dpi; - g_dpi_scale_real_x = g_dpi_scale_x; - g_dpi_scale_real_y = g_dpi_scale_y; - pixel_xres = size.width * scale; - pixel_yres = size.height * scale; - - dp_xres = pixel_xres * g_dpi_scale_x; - dp_yres = pixel_yres * g_dpi_scale_y; - - pixel_in_dps_x = (float)pixel_xres / (float)dp_xres; - pixel_in_dps_y = (float)pixel_yres / (float)dp_yres; + [[DisplayManager shared] updateResolution:[UIScreen mainScreen]]; graphicsContext = new IOSGraphicsContext(); From bed47ea30a192be07b88f4e646744b453cc66582 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 02:30:19 +0800 Subject: [PATCH 03/11] =?UTF-8?q?Fix=20iPhone=20won=E2=80=99t=20switch=20t?= =?UTF-8?q?o=20external=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/DisplayManager.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index 5b20d8a252..eeff3f1069 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -82,6 +82,8 @@ - (void)updateScreen:(UIScreen *)screen { [self setMainScreen:screen]; UIWindow *gameWindow = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window]; + // Hide before moving window to external display, otherwise iPhone won't switch to it + [gameWindow setHidden:YES]; [gameWindow setScreen:screen]; // Set optimal resolution // Dispatch later to prevent "no window is preset" error @@ -93,6 +95,7 @@ [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; } [self updateResolution:screen]; + [gameWindow setHidden:NO]; }); } From d5d76b086fc193a057f9ea821bcfa260ff0d1056 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 02:48:18 +0800 Subject: [PATCH 04/11] Do some clean up --- ios/AppDelegate.mm | 1 - ios/ViewController.mm | 3 --- 2 files changed, 4 deletions(-) diff --git a/ios/AppDelegate.mm b/ios/AppDelegate.mm index 4cbd2ae1fb..5ae6e18003 100644 --- a/ios/AppDelegate.mm +++ b/ios/AppDelegate.mm @@ -1,5 +1,4 @@ #import "AppDelegate.h" -#import "DisplayManager.h" #import "ViewController.h" #import "base/NativeApp.h" #import "Core/System.h" diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 457e331a74..bdcf92e7d5 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -162,9 +162,6 @@ static GraphicsContext *graphicsContext; [EAGLContext setCurrentContext:self.context]; self.preferredFramesPerSecond = 60; - // Might be useful for a speed boot, sacrificing resolution: - view.contentScaleFactor = screen.scale; - [[DisplayManager shared] updateResolution:[UIScreen mainScreen]]; graphicsContext = new IOSGraphicsContext(); From a68c982b85c9aeea3d38e3df7775bc4486d1eaba Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 05:44:58 +0800 Subject: [PATCH 05/11] Fix overscan compensation (Hack) --- ios/DisplayManager.mm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index eeff3f1069..bdaafd48bd 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -18,6 +18,9 @@ @property BOOL listenerActive; @property (atomic, retain) NSMutableArray *extDisplays; +@property CGRect originalFrame; +@property CGRect originalBounds; +@property CGAffineTransform originalTransform; - (void)updateScreen:(UIScreen *)screen; @@ -51,6 +54,10 @@ } NSLog(@"Setting up display manager"); [self setMainScreen:[UIScreen mainScreen]]; + UIWindow *gameWindow = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window]; + [self setOriginalFrame: [gameWindow frame]]; + [self setOriginalBounds:[gameWindow bounds]]; + [self setOriginalTransform:[gameWindow transform]]; // Display connected [[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { UIScreen *screen = (UIScreen *) notification.object; @@ -92,9 +99,23 @@ NSUInteger count = [[screen availableModes] count]; UIScreenMode* mode = [screen availableModes][count - 1]; [screen setCurrentMode:mode]; + // Fix overscan + // TODO: Hacky solution. Screen is still scaled even if UIScreenOverscanCompensationNone is set. [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; + CGSize fullSize = mode.size; + UIEdgeInsets insets = [screen overscanCompensationInsets]; + fullSize.width -= insets.left + insets.right; + fullSize.height -= insets.top + insets.bottom; + [gameWindow setFrame:CGRectMake(insets.left, insets.top, fullSize.width, fullSize.height)]; + [gameWindow setBounds:CGRectMake(0, 0, fullSize.width, fullSize.height)]; + [self updateResolution:screen]; + [gameWindow setTransform:CGAffineTransformMakeScale(mode.size.width / fullSize.width, mode.size.height / fullSize.height)]; + } else { + [gameWindow setTransform:[self originalTransform]]; + [gameWindow setFrame:[self originalFrame]]; + [gameWindow setBounds:[self originalBounds]]; + [self updateResolution:screen]; } - [self updateResolution:screen]; [gameWindow setHidden:NO]; }); } From 364b447ee4c70eb5de934937d4da8e68afc5678b Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 14:04:18 +0800 Subject: [PATCH 06/11] Simple dpi scaling --- ios/DisplayManager.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index bdaafd48bd..94a7a69bad 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -135,7 +135,12 @@ size.width = h; } - g_dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; + if (screen == [UIScreen mainScreen]) { + g_dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; + } else { + float diagonal = sqrt(size.height * size.height + size.width * size.width); + g_dpi = diagonal * scale * 0.1f; + } g_dpi_scale_x = 240.0f / g_dpi; g_dpi_scale_y = 240.0f / g_dpi; g_dpi_scale_real_x = g_dpi_scale_x; From 1affe0bff3c62fbdc6235e061d40d82eecf71785 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 14:44:06 +0800 Subject: [PATCH 07/11] Fix shutdown because of Discord deinitializer https://github.com/hrydgard/ppsspp/blob/f94beb518504eebadb94dfdc009cf9f4461bc6a4/UI/DiscordIntegration.cpp#L40 Calling exit(0) without NativeShutdown() breaks the assertion. --- ios/ViewController.mm | 3 ++- ios/main.mm | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ios/ViewController.mm b/ios/ViewController.mm index bdcf92e7d5..ad334f0d8d 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -213,7 +213,6 @@ static GraphicsContext *graphicsContext; time_update(); } - threadStopped = true; ILOG("Emulation thread shutting down\n"); NativeShutdownGraphics(); @@ -221,6 +220,8 @@ static GraphicsContext *graphicsContext; // Also ask the main thread to stop, so it doesn't hang waiting for a new frame. ILOG("Emulation thread stopping\n"); graphicsContext->StopThread(); + + threadStopped = true; }); } diff --git a/ios/main.mm b/ios/main.mm index ce1803e023..e52f3f8bf9 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -61,7 +61,10 @@ bool System_GetPropertyBool(SystemProperty prop) { void System_SendMessage(const char *command, const char *parameter) { if (!strcmp(command, "finish")) { - exit(0); + dispatch_async(dispatch_get_main_queue(), ^{ + [sharedViewController shutdown]; + exit(0); + }); } } From 4a7e9d47e3e62810f748cf0db7be509c76cb3092 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Tue, 11 Jun 2019 15:09:42 +0800 Subject: [PATCH 08/11] Ignore mute switch when connected to external display --- ios/DisplayManager.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index 94a7a69bad..5aca0161c9 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -11,6 +11,7 @@ #include "base/display.h" #include "base/NativeApp.h" #include "Core/System.h" +#import #define IS_IPAD() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) @@ -67,6 +68,9 @@ if ([self mainScreen] != [UIScreen mainScreen]) { return; } + // Ignore mute switch when connected to external display + NSError *error = nil; + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; [self updateScreen:screen]; }]; // Display disconnected @@ -80,6 +84,8 @@ UIScreen *newScreen = [[self extDisplays] lastObject]; [self updateScreen:newScreen]; } else { + NSError *error = nil; + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error]; [self updateScreen:[UIScreen mainScreen]]; } }]; From c0a1404308ceb19ccf49af304128d85329b8a97e Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Thu, 13 Jun 2019 22:57:19 +0800 Subject: [PATCH 09/11] Fix invalid mode on iPad Pro 2018 When connected to 4K display via C2HDMI cable, the last item in availableModes is 5K. --- ios/DisplayManager.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index 5aca0161c9..1bd04aa1a1 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -105,6 +105,7 @@ NSUInteger count = [[screen availableModes] count]; UIScreenMode* mode = [screen availableModes][count - 1]; [screen setCurrentMode:mode]; + mode = [screen currentMode]; // Fix overscan // TODO: Hacky solution. Screen is still scaled even if UIScreenOverscanCompensationNone is set. [screen setOverscanCompensation:UIScreenOverscanCompensationNone]; From 0e7c85d89e6635005dc35f52a3d095e904abdea9 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Wed, 19 Jun 2019 17:47:14 +0800 Subject: [PATCH 10/11] Disable external display by default Configuration is in system settings --- CMakeLists.txt | 2 ++ ios/DisplayManager.mm | 4 ++++ ios/Settings.bundle/Root.plist | 21 +++++++++++++++++++++ ios/Settings.bundle/en.lproj/Root.strings | Bin 0 -> 480 bytes 4 files changed, 27 insertions(+) create mode 100644 ios/Settings.bundle/Root.plist create mode 100644 ios/Settings.bundle/en.lproj/Root.strings diff --git a/CMakeLists.txt b/CMakeLists.txt index 3735f82025..547d322307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1988,6 +1988,7 @@ if(TargetBin) endif() if(IOS) + list(APPEND NativeAssets ios/Settings.bundle) add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Launch Screen.storyboard") else() add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource}) @@ -2044,6 +2045,7 @@ if(IOS) set_target_properties(${TargetBin} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/ios/PPSSPP-Info.plist" RESOURCE "ios/Launch Screen.storyboard" + RESOURCE "ios/Settings.bundle" XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "iPhone/iPad" XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index 1bd04aa1a1..495353a6df 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -49,6 +49,10 @@ } - (void)setupDisplayListener { + // Disable external display by default + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enable_external_display"] == NO) { + return; + } if ([self listenerActive]) { NSLog(@"setupDisplayListener already called"); return; diff --git a/ios/Settings.bundle/Root.plist b/ios/Settings.bundle/Root.plist new file mode 100644 index 0000000000..627d9c50de --- /dev/null +++ b/ios/Settings.bundle/Root.plist @@ -0,0 +1,21 @@ + + + + + StringsTable + Root + PreferenceSpecifiers + + + Type + PSToggleSwitchSpecifier + Title + enable_external_display + Key + enable_external_display + DefaultValue + + + + + diff --git a/ios/Settings.bundle/en.lproj/Root.strings b/ios/Settings.bundle/en.lproj/Root.strings new file mode 100644 index 0000000000000000000000000000000000000000..cc9f6b61f9b3065f4b63eb8a342290f9c0a47a41 GIT binary patch literal 480 zcmaiwL2kk@6hvpuDXc6JDhH@oAe9?*k3!;TN71-**WNf>WFKA z(bH*I-aFWF)K+*$?N#at-fOPx`F9%6vscoI88u2LvO^$K!nb5^^$Fq}6<7zuGl$Gg z{A(Cay@P$Zp}#&ydd}%LNO_O&oHI~2{QtX`Z!*-r&0 Yfp)PX;f?n=!QRtazKXlMnP5=M^ literal 0 HcmV?d00001 From b37553fba25c0ca543127067141be65db4c5b879 Mon Sep 17 00:00:00 2001 From: Xie Yi Date: Mon, 24 Jun 2019 08:49:47 +0800 Subject: [PATCH 11/11] fix indent --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 547d322307..558fa7b90c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1988,7 +1988,7 @@ if(TargetBin) endif() if(IOS) - list(APPEND NativeAssets ios/Settings.bundle) + list(APPEND NativeAssets ios/Settings.bundle) add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Launch Screen.storyboard") else() add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource})