Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: keep the shared panel lit through an opening fold

Jackyf0501888141e
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index c104f21b..9158d5ac 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -5050,3 +5050,41 @@ backboardd or SpringBoard crash reports.
Trap seen while probing: the CA `IOSurface` object in a page is a C++ object,
not an `IOSurfaceRef`; `CFRetain` on it is a PAC failure that crash-loops
backboardd.
+
+## 2026-10-30: the fold's fade to black on one panel
+
+Opening out of closed showed 7 to 13 frames of black (about 0.12 to 0.2 s)
+on the shared panel, measured on sbdisplay-duo (iPhone19,4 27.1, CoreMotion
+relay path) from a ScreenCaptureKit stream of the VM window at 60 fps
+(`screencapture -l` manages about 8 fps, and a screen-region recording misses
+a covered window). The frames show SpringBoard's continuous fold effect: the
+cover blurs, then fades to black, and after the swap the inner display fades
+in from black. On hardware those are two screens. The panel itself never goes
+off: the inner display is lit, then takes the panel, then the cover is turned
+off. It is the same with SpringBoard drawing the inner display itself
+(`com.vphone.folddisplay.inner-pages` state 0), so the pages path is not the
+cause.
+
+The effect is tuned by `SBDeviceContinuousFoldInteractionSettings`
+(SpringBoard.framework, `+[SBDeviceContinuousFoldInteractionDomain
+rootSettings]`): `fadeToBlackEnabled` with `outerFadeToBlackStart/End` and
+`innerFadeToBlackStart/End`, `dimmingEnabled`, cone, cylinder and seam dims,
+blur radii. FoldDisplay turns `fadeToBlackEnabled` off in SpringBoard, so the
+cover dims and blurs but does not go black. The panel also changes hands
+inside SpringBoard's primary-swap callback, with the inner display's layer
+added in the same transaction, instead of two main-queue hops later, when
+SpringBoard had already hidden the cover's content. Opening now shows 0 to 9
+dark frames, usually 2 to 6; closing shows none, as before.
+
+Tried and dropped: handing the panel to the inner display when a fold toward
+it starts (`SBFDisplayContentModeTransitionContext`'s
+`initial/finalContentModeOfDisplayForWindowScene:`), lighting it early: it
+then showed its own fade in from black, 0.2 s; holding the inner layer back
+until backboardd shows a new page: no change.
+
+Two related host-window effects: the window follows a fold it did not ask for
+(DeviceHub, a guest-side request) from `display.orientation`'s `fold_angle`,
+which it now reads four times a second on a foldable guest (once before), so
+the cover drawn in the window's open shape, sideways, lasts about 0.1 s
+instead of about 0.5 s. A fold while the screen sleeps lights it, and the
+panel's first 0.2 s are its last frame from before sleep.
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
index ff44e3f4..2878952e 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
@@ -53,7 +53,10 @@ static void vpApplyPanelStates(id primaryCompletion, id innerCompletion) {
long long inner = innerOwns && vpInnerWantedState ? 1 : 0;
BOOL changed = inner != vpInnerAppliedState;
vpApplyPanelState(vpInnerStateControl, inner, &vpInnerAppliedState, innerCompletion);
- if (changed && vpInnerStateControl) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(inner != 0); });
+ if (changed && vpInnerStateControl) {
+ if (NSThread.isMainThread) vpShowInnerDisplay(inner != 0);
+ else dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(inner != 0); });
+ }
}
// SpringBoard asks for a transition only when it wants a state the panel is
@@ -107,14 +110,16 @@ static void vpSharedScanoutTransition(id self, SEL selector, long long state, id
static IMP vpOriginalPerformContentModeTransition, vpOriginalHandlePrimarySwap;
static int vpInnerOwnedPanel = -1;
+static void vpApplyPanelOwner(void) {
+ BOOL innerOwns = vpInnerOwnsPanel();
+ if (innerOwns == vpInnerOwnedPanel) return;
+ vpInnerOwnedPanel = innerOwns;
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel owned by the %@", innerOwns ? @"inner display" : @"cover"]);
+ vpApplyPanelStates(nil, nil);
+}
+
static void vpFollowPanelOwner(void) {
- dispatch_async(dispatch_get_main_queue(), ^{
- BOOL innerOwns = vpInnerOwnsPanel();
- if (innerOwns == vpInnerOwnedPanel) return;
- vpInnerOwnedPanel = innerOwns;
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel owned by the %@", innerOwns ? @"inner display" : @"cover"]);
- vpApplyPanelStates(nil, nil);
- });
+ dispatch_async(dispatch_get_main_queue(), ^{ vpApplyPanelOwner(); });
}
static void vpFollowContentModeTransition(id self, SEL selector, id transitionCoordinator) {
@@ -122,9 +127,11 @@ static void vpFollowContentModeTransition(id self, SEL selector, id transitionCo
vpFollowPanelOwner();
}
+// At once, in SpringBoard's own transaction: it hides the content leaving
+// the panel here, and a later hop showed the panel empty in between.
static void vpFollowPrimarySwap(id self, SEL selector, id coordinator, id from, id to, id lockProvider) {
((void (*)(id, SEL, id, id, id, id))vpOriginalHandlePrimarySwap)(self, selector, coordinator, from, to, lockProvider);
- vpFollowPanelOwner();
+ vpApplyPanelOwner();
}
static void vpInstallContentModeOwnership(void) {
@@ -157,6 +164,14 @@ void vpInstallSharedPanel(void) {
vpOriginalTransitionDisplayState = method_setImplementation(transition, (IMP)vpSharedScanoutTransition);
vpInstallContentModeOwnership();
vpFollowInnerPages();
+ // SpringBoard's fold effect fades the panel being folded away to black and
+ // the arriving one in from black: two screens on hardware, about 0.12 s of
+ // black on this one panel each time it opens. Without the fade the cover
+ // dims and blurs and the inner display takes over at the swap.
+ id settings =((id (*)(id, SEL))objc_msgSend)(objc_getClass("SBDeviceContinuousFoldInteractionDomain"), sel_registerName("rootSettings"));
+ SEL setFade = sel_registerName("setFadeToBlackEnabled:");
+ if ([settings respondsToSelector:setFade]) ((void (*)(id, SEL, BOOL))objc_msgSend)(settings, setFade, NO);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: fold fade to black off=%d", [settings respondsToSelector:setFade]]);
vpFoldDisplayLog(@"inner display: shared scanout installed");
}