Modernize iOS screen resize code a little.

This commit is contained in:
Henrik Rydgård
2026-02-13 18:08:28 +01:00
parent 7b84e42218
commit 42970d1118
4 changed files with 33 additions and 14 deletions
+2 -2
View File
@@ -313,8 +313,8 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
INFO_LOG(Log::System, "didBecomeActive begin");
[self updateResolutionWithView:self.view];
[self runGLRenderLoop];
[self updateResolution:[UIScreen mainScreen]];
INFO_LOG(Log::System, "didBecomeActive end");
@@ -383,8 +383,8 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
NSLog(@"Rotation finished");
// Reinitialize graphics context to match new size
[self requestExitGLRenderLoop];
[self updateResolutionWithView:self.view];
[self runGLRenderLoop];
[self updateResolution:[UIScreen mainScreen]];
}];
}
+1 -1
View File
@@ -32,7 +32,7 @@
- (void)uiStateChanged;
- (void)pickPhoto:(NSString *)saveFilename requestId:(int)requestId;
- (void)updateResolution:(UIScreen *)screen;
- (void)updateResolutionWithView:(UIView *)view;
@end
+19 -7
View File
@@ -442,17 +442,28 @@ extern float g_safeInsetBottom;
[self setNeedsStatusBarAppearanceUpdate];
}
- (void)updateResolution:(UIScreen *)screen {
float scale = screen.nativeScale;
CGSize size = screen.bounds.size;
- (void)updateResolutionWithView:(UIView *)view {
// 1. Get the scale from the window scene (safest for Metal)
CGFloat scale = 1.0;
if (view.window.windowScene) {
scale = view.window.windowScene.screen.nativeScale;
} else {
scale = [UITraitCollection currentTraitCollection].displayScale;
}
// 2. Get the ACTUAL bounds of the view (already corrected for orientation)
CGSize size = view.bounds.size;
// Your existing logic
float dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale;
const float dpi_scale_x = 240.0f / dpi;
const float dpi_scale_y = 240.0f / dpi;
g_display.Recalculate(size.width * scale, size.height * scale, dpi_scale_x, dpi_scale_y, UIScaleFactorToMultiplier(g_Config.iUIScaleFactor));
[[sharedViewController getView] setContentScaleFactor:scale];
g_display.Recalculate(size.width * scale, size.height * scale,
dpi_scale_x, dpi_scale_y,
UIScaleFactorToMultiplier(g_Config.iUIScaleFactor));
[view setContentScaleFactor:scale];
// PSP native resize
PSP_CoreParameter().pixelWidth = g_display.pixel_xres;
@@ -460,7 +471,8 @@ extern float g_safeInsetBottom;
NativeResized();
NSLog(@"Updated display resolution: (%d, %d) @%.1fx", g_display.pixel_xres, g_display.pixel_yres, scale);
NSLog(@"Updated display resolution: (%d, %d) @%.1fx",
g_display.pixel_xres, g_display.pixel_yres, (float)scale);
}
@end
+11 -4
View File
@@ -294,8 +294,8 @@ void VulkanRenderLoop(IOSVulkanContext *graphicsContext, CAMetalLayer *metalLaye
// Spin up the emu thread. It will in turn spin up the Vulkan render thread
// on its own.
[self updateResolutionWithView:self.view];
[self runVulkanRenderLoop];
[self updateResolution:[UIScreen mainScreen]];
}
- (void)willResignActive {
@@ -345,7 +345,7 @@ void VulkanRenderLoop(IOSVulkanContext *graphicsContext, CAMetalLayer *metalLaye
graphicsContext = new IOSVulkanContext();
[self updateResolution:[UIScreen mainScreen]];
[self updateResolutionWithView:self.view];
if (!graphicsContext->InitAPI()) {
_assert_msg_(false, "Failed to init Vulkan");
@@ -365,7 +365,14 @@ void VulkanRenderLoop(IOSVulkanContext *graphicsContext, CAMetalLayer *metalLaye
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
INFO_LOG(Log::G3D, "viewWillAppear");
self.view.contentScaleFactor = UIScreen.mainScreen.nativeScale;
// This is to make sure we get 1:1 pixels.
UIWindowScene *scene = self.view.window.windowScene;
if (scene) {
self.view.contentScaleFactor = scene.screen.nativeScale;
}
if (@available(iOS 16.0, *)) {
[self setNeedsUpdateOfSupportedInterfaceOrientations];
}
}
- (void)viewWillDisappear:(BOOL)animated {
@@ -407,8 +414,8 @@ void VulkanRenderLoop(IOSVulkanContext *graphicsContext, CAMetalLayer *metalLaye
NSLog(@"Rotation finished");
// Reinitialize graphics context to match new size
[self requestExitVulkanRenderLoop];
[self updateResolutionWithView:self.view];
[self runVulkanRenderLoop];
[self updateResolution:[UIScreen mainScreen]];
}];
}