From c0c22c8ff1ebe95e8848d206a8ffc4619597afa0 Mon Sep 17 00:00:00 2001 From: Aleksi Juvani <3168386+aleksijuvani@users.noreply.github.com> Date: Tue, 6 Aug 2019 23:47:00 +0300 Subject: [PATCH] Disable overscan compensation for external displays on iOS (#1088) --- CHANGELOG.md | 2 ++ src/platform_impl/ios/ffi.rs | 17 +++++++++++++++++ src/platform_impl/ios/window.rs | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d68f064d..e3f35ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ - On iOS, fix a crash that occurred while acquiring a monitor's name. - On iOS, fix armv7-apple-ios compile target. - Removed the `T: Clone` requirement from the `Clone` impl of `EventLoopProxy`. +- On iOS, disable overscan compensation for external displays (removes black + bars surrounding the image). # 0.20.0 Alpha 2 (2019-07-09) diff --git a/src/platform_impl/ios/ffi.rs b/src/platform_impl/ios/ffi.rs index 4782cf1a..1536c7b2 100644 --- a/src/platform_impl/ios/ffi.rs +++ b/src/platform_impl/ios/ffi.rs @@ -201,6 +201,23 @@ impl Into for UIRectEdge { } } +#[repr(transparent)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct UIScreenOverscanCompensation(NSInteger); + +unsafe impl Encode for UIScreenOverscanCompensation { + fn encode() -> Encoding { + NSInteger::encode() + } +} + +#[allow(dead_code)] +impl UIScreenOverscanCompensation { + pub const Scale: UIScreenOverscanCompensation = UIScreenOverscanCompensation(0); + pub const InsetBounds: UIScreenOverscanCompensation = UIScreenOverscanCompensation(1); + pub const None: UIScreenOverscanCompensation = UIScreenOverscanCompensation(2); +} + #[link(name = "UIKit", kind = "framework")] #[link(name = "CoreFoundation", kind = "framework")] extern "C" { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 9e15aa9a..7c8b9501 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -16,7 +16,7 @@ use crate::{ event_loop, ffi::{ id, CGFloat, CGPoint, CGRect, CGSize, UIEdgeInsets, UIInterfaceOrientationMask, - UIRectEdge, + UIRectEdge, UIScreenOverscanCompensation, }, monitor, view, EventLoopWindowTarget, MonitorHandle, }, @@ -175,14 +175,22 @@ impl Inner { } }; - let current: id = msg_send![self.window, screen]; - let bounds: CGRect = msg_send![uiscreen, bounds]; - // this is pretty slow on iOS, so avoid doing it if we can + let current: id = msg_send![self.window, screen]; if uiscreen != current { let () = msg_send![self.window, setScreen: uiscreen]; } + + let bounds: CGRect = msg_send![uiscreen, bounds]; let () = msg_send![self.window, setFrame: bounds]; + + // For external displays, we must disable overscan compensation or + // the displayed image will have giant black bars surrounding it on + // each side + let () = msg_send![ + uiscreen, + setOverscanCompensation: UIScreenOverscanCompensation::None + ]; } }