Skip to content

Commit 65fb1a5

Browse files
authored
Merge pull request #19224 from hrydgard/more-ios-fixes
More iOS fixes
2 parents e1b760f + 8e12189 commit 65fb1a5

File tree

9 files changed

+65
-39
lines changed

9 files changed

+65
-39
lines changed

Common/Render/Text/draw_text_cocoa.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,15 @@ void Destroy() {
167167
return false;
168168
}
169169

170-
std::string printable = ReplaceAll(str, "&&", "&");
171-
NSString* string = [[NSString alloc] initWithBytes:printable.data() length:printable.length() encoding: NSUTF8StringEncoding];
172-
173170
auto iter = fontMap_.find(fontHash_);
174171
if (iter == fontMap_.end()) {
175172
return false;
176173
}
174+
175+
// INFO_LOG(SYSTEM, "Rasterizing %.*s", (int)str.length(), str.data());
176+
177+
NSString* string = [[NSString alloc] initWithBytes:str.data() length:str.length() encoding: NSUTF8StringEncoding];
178+
177179
NSDictionary* attributes = iter->second->attributes;
178180
NSAttributedString* as = [[NSAttributedString alloc] initWithString:string attributes:attributes];
179181

SDL/CocoaBarItems.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,11 @@ -(void)openRecentItem: (NSMenuItem *)item {
645645

646646
-(void)openSystemFileBrowser {
647647
int g = 0;
648-
DarwinDirectoryPanelCallback callback = [g] (bool succ, Path thePathChosen) {
648+
DarwinDirectoryPanelCallback panelCallback = [g] (bool succ, Path thePathChosen) {
649649
if (succ)
650650
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, thePathChosen.c_str());
651651
};
652-
653-
DarwinFileSystemServices services;
654-
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true);
652+
DarwinFileSystemServices::presentDirectoryPanel(panelCallback, /* allowFiles = */ true, /* allowDirectorites = */ true);
655653
}
656654

657655
-(void)openMemstickFolder {

SDL/SDLMain.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
273273
g_requestManager.PostSystemFailure(requestId);
274274
}
275275
};
276-
DarwinFileSystemServices services;
277276
BrowseFileType fileType = (BrowseFileType)param3;
278-
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false, fileType);
277+
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false, fileType);
279278
return true;
280279
}
281280
case SystemRequestType::BROWSE_FOR_FOLDER:
@@ -287,8 +286,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
287286
g_requestManager.PostSystemFailure(requestId);
288287
}
289288
};
290-
DarwinFileSystemServices services;
291-
services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
289+
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
292290
return true;
293291
}
294292
#endif

UI/DarwinFileSystemServices.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ typedef std::function<void (bool, Path)> DarwinDirectoryPanelCallback;
2020
class DarwinFileSystemServices {
2121
public:
2222
/// Present a panel to choose a file or directory.
23-
void presentDirectoryPanel(
24-
DarwinDirectoryPanelCallback,
23+
static void presentDirectoryPanel(
24+
DarwinDirectoryPanelCallback panelCallback,
2525
bool allowFiles = false,
2626
bool allowDirectories = true,
2727
BrowseFileType fileType = BrowseFileType::ANY);
2828

2929
static Path appropriateMemoryStickDirectoryToUse();
3030
static void setUserPreferredMemoryStickDirectory(Path);
31+
32+
static void ClearDelegate();
3133
private:
3234
static Path __defaultMemoryStickPath();
3335
#if PPSSPP_PLATFORM(IOS)
3436
// iOS only, needed for UIDocumentPickerViewController
35-
void *__pickerDelegate = NULL;
37+
static void *__pickerDelegate;
3638
#endif // PPSSPP_PLATFORM(IOS)
3739
};
3840

UI/DarwinFileSystemServices.mm

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,38 @@
2121
#include <UIKit/UIKit.h>
2222

2323
@interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>
24-
@property DarwinDirectoryPanelCallback callback;
24+
@property DarwinDirectoryPanelCallback panelCallback;
2525
@end
2626

27+
void *DarwinFileSystemServices::__pickerDelegate = nullptr;
28+
29+
void DarwinFileSystemServices::ClearDelegate() {
30+
// TODO: Figure out how to free the delegate.
31+
// CFRelease((__bridge DocumentPickerDelegate *)__pickerDelegate);
32+
__pickerDelegate = NULL;
33+
}
34+
2735
@implementation DocumentPickerDelegate
28-
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)callback {
36+
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)panelCallback {
2937
if (self = [super init]) {
30-
self.callback = callback;
38+
self.panelCallback = panelCallback;
3139
}
3240
return self;
3341
}
3442

35-
- (void)didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
43+
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
3644
if (urls.count >= 1)
37-
self.callback(true, Path(urls[0].path.UTF8String));
45+
self.panelCallback(true, Path(urls[0].path.UTF8String));
3846
else
39-
self.callback(false, Path());
47+
self.panelCallback(false, Path());
4048

4149
INFO_LOG(SYSTEM, "Callback processed, pre-emptively hide keyboard");
4250
[sharedViewController hideKeyboard];
51+
DarwinFileSystemServices::ClearDelegate();
4352
}
4453

4554
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
46-
self.callback(false, Path());
55+
self.panelCallback(false, Path());
4756

4857
INFO_LOG(SYSTEM, "Picker cancelled, pre-emptively hide keyboard");
4958
[sharedViewController hideKeyboard];
@@ -56,7 +65,7 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
5665
#endif // __has_include(<UIKit/UIKit.h>)
5766

5867
void DarwinFileSystemServices::presentDirectoryPanel(
59-
DarwinDirectoryPanelCallback callback,
68+
DarwinDirectoryPanelCallback panelCallback,
6069
bool allowFiles, bool allowDirectories,
6170
BrowseFileType fileType) {
6271
dispatch_async(dispatch_get_main_queue(), ^{
@@ -86,14 +95,17 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
8695
}
8796
// if (!allowFiles && allowDirectories)
8897
// panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder];
89-
90-
NSModalResponse modalResponse = [panel runModal];
91-
INFO_LOG(SYSTEM, "Mac: Received response from modal");
92-
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
93-
callback(true, Path(panel.URLs.firstObject.path.UTF8String));
94-
} else if (modalResponse == NSModalResponseCancel) {
95-
callback(false, Path());
96-
}
98+
NSModalResponse modalResponse = [panel runModal];
99+
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
100+
INFO_LOG(SYSTEM, "Mac: Received OK response from modal");
101+
panelCallback(true, Path(panel.URLs.firstObject.path.UTF8String));
102+
} else if (modalResponse == NSModalResponseCancel) {
103+
INFO_LOG(SYSTEM, "Mac: Received Cancel response from modal");
104+
panelCallback(false, Path());
105+
} else {
106+
WARN_LOG(SYSTEM, "Mac: Received unknown responsde from modal");
107+
panelCallback(false, Path());
108+
}
97109
#elif PPSSPP_PLATFORM(IOS)
98110
UIViewController *rootViewController = UIApplication.sharedApplication
99111
.keyWindow
@@ -116,7 +128,7 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
116128
UIDocumentPickerViewController *pickerVC = [[UIDocumentPickerViewController alloc] initWithDocumentTypes: types inMode: pickerMode];
117129
// What if you wanted to go to heaven, but then God showed you the next few lines?
118130
// serious note: have to do this, because __pickerDelegate has to stay retained as a class property
119-
__pickerDelegate = (void *)CFBridgingRetain([[DocumentPickerDelegate alloc] initWithCallback:callback]);
131+
__pickerDelegate = (void *)CFBridgingRetain([[DocumentPickerDelegate alloc] initWithCallback:panelCallback]);
120132
pickerVC.delegate = (__bridge DocumentPickerDelegate *)__pickerDelegate;
121133
[rootViewController presentViewController:pickerVC animated:true completion:nil];
122134
#endif

UI/MiscScreens.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
978978
"",
979979
"",
980980
cr->T("tools", "Free tools used:"),
981-
#ifdef __ANDROID__
981+
#if PPSSPP_PLATFORM(ANDROID)
982982
"Android SDK + NDK",
983983
#endif
984984
#if defined(USING_QT_UI)
@@ -990,6 +990,17 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
990990
"CMake",
991991
"freetype2",
992992
"zlib",
993+
"rcheevos",
994+
"SPIRV-Cross",
995+
"armips",
996+
"Basis Universal",
997+
"cityhash",
998+
"zstd",
999+
"glew",
1000+
"libchdr",
1001+
"minimp3",
1002+
"xxhash",
1003+
"naett-http",
9931004
"PSP SDK",
9941005
"",
9951006
"",
@@ -1011,7 +1022,6 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
10111022
cr->T("info5", "PSP is a trademark by Sony, Inc."),
10121023
};
10131024

1014-
10151025
// TODO: This is kinda ugly, done on every frame...
10161026
char temp[256];
10171027
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {

ios/ViewController.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#include "Core/HLE/sceUsbCam.h"
4141
#include "Core/HLE/sceUsbGps.h"
4242

43+
#if !__has_feature(objc_arc)
44+
#error Must be built with ARC, please revise the flags for ViewController.mm to include -fobjc-arc.
45+
#endif
46+
4347
class IOSGLESContext : public GraphicsContext {
4448
public:
4549
IOSGLESContext() {
@@ -424,6 +428,7 @@ -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
424428
- (void)uiStateChanged
425429
{
426430
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
431+
[self hideKeyboard];
427432
}
428433

429434
- (UIView *)getView {

ios/ViewControllerMetal.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ - (void)loadView {
387387

388388
- (void)viewDidLoad {
389389
[super viewDidLoad];
390+
[self hideKeyboard];
391+
390392
[[DisplayManager shared] setupDisplayListener];
391393

392394
INFO_LOG(SYSTEM, "Metal viewDidLoad");
@@ -414,8 +416,6 @@ - (void)viewDidLoad {
414416
locationHelper = [[LocationHelper alloc] init];
415417
[locationHelper setDelegate:self];
416418

417-
[self hideKeyboard];
418-
419419
UIScreenEdgePanGestureRecognizer *mBackGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:) ];
420420
[mBackGestureRecognizer setEdges:UIRectEdgeLeft];
421421
[[self view] addGestureRecognizer:mBackGestureRecognizer];
@@ -500,6 +500,7 @@ -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
500500
- (void)uiStateChanged
501501
{
502502
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
503+
[self hideKeyboard];
503504
}
504505

505506
- (void)bindDefaultFBO

ios/main.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
430430
g_requestManager.PostSystemFailure(requestId);
431431
}
432432
};
433-
DarwinFileSystemServices services;
434-
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
433+
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
435434
return true;
436435
}
437436
case SystemRequestType::BROWSE_FOR_FOLDER:
@@ -443,8 +442,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
443442
g_requestManager.PostSystemFailure(requestId);
444443
}
445444
};
446-
DarwinFileSystemServices services;
447-
services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
445+
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
448446
return true;
449447
}
450448
case SystemRequestType::CAMERA_COMMAND:

0 commit comments

Comments
 (0)