Run a virtual iPhone on an Apple Silicon Mac.
Swift
Duo: fill the cover-sized panel with the inner display
Jacky737591ff8901
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.mdindex e408a261..a7a35440 100644--- a/Research/Guest/iphone_duo_bringup.md+++ b/Research/Guest/iphone_duo_bringup.md@@ -4771,18 +4771,18 @@ the two-display path that reason is gone: the inner display is its ownvphone-vm now boots the machine's own screen, 1398×2034 at 3x: the cover is466×678 points with its native layout (the right-side Dock and status column-are the Duo's outer-display design). Open, the compositor fits the inner-display onto the panel turned upright and shrunk to 0.697, which leaves 23 px-bars along the panel's long sides. backboardd computes the same rectangle when-it adds the inner display (`vpLocateInnerPanelImage`, from the LCD's and the-inner display's pixel sizes) and maps each touch through it before turning it-by the mount; a touch in a bar lands on the inner display's edge.+are the Duo's outer-display design). Open, the compositor turns the inner+display upright and fills the panel with it: 0.697 across and 0.713 along,+about 2% tighter across than along. A first version kept the proportions and+left 23 px black bars along the long sides, which the user did not want; with+the fill, the digitizer (which spans the panel) maps onto the whole inner+display, so backboardd's touch turn needs no rectangle of its own.Measured on the test VM (bundle built from this change):- Taps logged in SpringBoard land at the expected points: inner, panel pixel- (X, Y) of the landscape screenshot at ((X - 23.3) / 2.09, Y / 2.09) points- for the centre and four corners; cover, at (X / 3, Y / 3).+ (X, Y) of the landscape screenshot at (X × 951 / 2034, Y × 669 / 1398) points+ for the centre and four corners (no bars); cover, at (X / 3, Y / 3).- Guest screenshots match the VM window at offset (0, 0) in all four inner andthree cover orientations (cover tested with Safari, which rotates on iPhone).- Three launch-sequence captures: no black frames, 2-5 transient tiles.diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.mindex d5153a6d..28519db9 100644--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m@@ -5,12 +5,6 @@static id vpInnerRenderDisplay;-// Where the inner display's image lies on the panel, in the panel's normalized-// portrait frame. The panel is the cover's; SpringBoard's compositor-// (FoldDisplayPanel.m) fits the inner display onto it upright, centered and-// shrunk to fit, so touches on the panel are mapped through this rectangle.-static CGRect vpInnerPanelImage = {{0, 0}, {1, 1}};-// MARK: - the render display@protocol VPhoneInnerDisplayInitialization@@ -41,29 +35,6 @@ static void vpTagUnknownDisplay(id display) {vpFoldDisplayLog([NSString stringWithFormat:@"inner display: tag %@ (%lu)", describe(unknown), (unsigned long)unknown]);}-static CGSize vpDisplayPixels(id display) {- CGRect bounds = CGRectZero;- id value = [display valueForKey:@"bounds"];- if ([value isKindOfClass:NSValue.class] && strcmp([value objCType], @encode(CGRect)) == 0) [value getValue:&bounds];- return bounds.size;-}--static void vpLocateInnerPanelImage(id server, id inner) {- CGSize panel = CGSizeZero, pixels = vpDisplayPixels(inner);- for (id display in [server valueForKey:@"displays"])- if ([[display valueForKey:@"name"] isEqual:@"LCD"]) panel = vpDisplayPixels(display);- if (panel.width < 1 || pixels.width < 1) {- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel size unknown ({%.0f, %.0f}), touches unfitted", panel.width, panel.height]);- return;- }- CGSize upright = pixels.width > pixels.height ? CGSizeMake(pixels.height, pixels.width) : pixels;- CGFloat scale = MIN(1, MIN(panel.width / upright.width, panel.height / upright.height));- CGSize image = CGSizeMake(upright.width * scale / panel.width, upright.height * scale / panel.height);- vpInnerPanelImage = CGRectMake((1 - image.width) / 2, (1 - image.height) / 2, image.width, image.height);- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: on the {%.0f, %.0f} panel at {%.4f, %.4f, %.4f, %.4f}",- panel.width, panel.height, vpInnerPanelImage.origin.x, vpInnerPanelImage.origin.y, image.width, image.height]);-}-// Adds the inner panel's render display to a render server, once. It is// never removed: FrontBoard keeps identities for the life of the monitor.static BOOL vpAddInnerRenderDisplayToServer(id server) {@@ -88,7 +59,6 @@ static BOOL vpAddInnerRenderDisplayToServer(id server) {((void (*)(id, SEL, BOOL))objc_msgSend)(display, setEnabled, YES);vpTagUnknownDisplay(display);vpInnerRenderDisplay = display;- vpLocateInnerPanelImage(server, display);vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display added %@ uniqueId=%@", display,[display respondsToSelector:sel_registerName("uniqueId")] ? [display valueForKey:@"uniqueId"] : @"-"]);return YES;@@ -190,7 +160,6 @@ static id vpInnerDigitizerState(id self, SEL selector, id service) {// reports positions on the portrait cover panel, which backboardd would// stretch onto the inner display's landscape space unturned; while the// inner display has the digitizer, each finger's normalized position is-// taken into the inner display's image on the panel (vpInnerPanelImage) and// turned by the mount first.typedef struct __IOHIDEvent *VPHIDEventRef;static IMP vpOriginalHandleDirectTouch;@@ -202,11 +171,9 @@ static void (*vpHIDEventSetFloat)(VPHIDEventRef, uint32_t, double);static void vpTurnDigitizerPosition(VPHIDEventRef event) {static const uint32_t digitizer = 11, x = 11 << 16, y = (11 << 16) | 1;if (vpHIDEventType(event) == digitizer) {- CGRect image = vpInnerPanelImage;- double u = MIN(1, MAX(0, (vpHIDEventGetFloat(event, x) - image.origin.x) / image.size.width));- double v = MIN(1, MAX(0, (vpHIDEventGetFloat(event, y) - image.origin.y) / image.size.height));- vpHIDEventSetFloat(event, x, 1 - v);- vpHIDEventSetFloat(event, y, u);+ double nx = vpHIDEventGetFloat(event, x), ny = vpHIDEventGetFloat(event, y);+ vpHIDEventSetFloat(event, x, 1 - ny);+ vpHIDEventSetFloat(event, y, nx);}CFArrayRef children = vpHIDEventChildren(event);for (CFIndex index = 0; children && index < CFArrayGetCount(children); index++)diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.mindex 76fa57b0..00f06878 100644--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m@@ -262,18 +262,21 @@ static void vpShowInnerDisplay(BOOL shown) {}}if (!vpInnerPanelQueue) vpInnerPanelQueue = dispatch_queue_create("com.vphone.folddisplay.inner-panel", DISPATCH_QUEUE_SERIAL);- // The inner display's points fill the panel's, turned a quarter (-90- // degrees) when they read landscape on the portrait panel, centered,- // shrunk only if they do not fit.+ // The inner display fills the panel, turned a quarter (-90 degrees)+ // when it reads landscape on the portrait panel. The panel is the+ // cover's, a little narrower than the inner display (1398x2034+ // against 2007x2853), so the fill is about 2% tighter across than+ // along; it leaves no bars, and the digitizer, which spans the panel,+ // maps onto the whole inner display as it is.id rootLayer = vpReadObject(rootWindow, "layer");CGRect panel = ((CGRect (*)(id, SEL))objc_msgSend)(rootLayer, sel_registerName("bounds"));CGFloat pointScale = ((double (*)(id, SEL))objc_msgSend)(vpReadObject(rootWindow, "screen"), sel_registerName("scale"));CGSize inner = CGSizeMake(pixels.width / pointScale, pixels.height / pointScale);BOOL turned = inner.width > inner.height;CGSize upright = turned ? CGSizeMake(inner.height, inner.width) : inner;- CGFloat scale = MIN(1, MIN(panel.size.width / upright.width, panel.size.height / upright.height));- CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);- if (turned) transform = CGAffineTransformRotate(transform, -M_PI_2);+ CGAffineTransform transform = CGAffineTransformConcat(+ turned ? CGAffineTransformMakeRotation(-M_PI_2) : CGAffineTransformIdentity,+ CGAffineTransformMakeScale(panel.size.width / upright.width, panel.size.height / upright.height));id root = [objc_getClass("CALayer") new];((void (*)(id, SEL, CGRect))objc_msgSend)(root, sel_registerName("setFrame:"), panel);((void (*)(id, SEL, CGColorRef))objc_msgSend)(root, sel_registerName("setBackgroundColor:"),@@ -291,8 +294,9 @@ static void vpShowInnerDisplay(BOOL shown) {sel_registerName("displayLinkWithTarget:selector:"), [VPhoneInnerPanelRefresh new], @selector(refresh:));((void (*)(id, SEL, id, id))objc_msgSend)(vpInnerPanelRefresh, sel_registerName("addToRunLoop:forMode:"),NSRunLoop.mainRunLoop, NSRunLoopCommonModes);- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shown=1 panel={%.0f, %.0f} inner={%.0f, %.0f} turned=%d scale=%.3f",- panel.size.width, panel.size.height, inner.width, inner.height, turned, scale]);+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shown=1 panel={%.0f, %.0f} inner={%.0f, %.0f} turned=%d scale={%.3f, %.3f}",+ panel.size.width, panel.size.height, inner.width, inner.height, turned,+ panel.size.width / upright.width, panel.size.height / upright.height]);} @catch (NSException *exception) {vpFoldDisplayLog([NSString stringWithFormat:@"inner display: show exception %@", exception.reason]);}