🐛 Start the arm64 display in its preferred mode

WindowServer never called set_digital_out_mode on any of the four releases
(Ambrosia m3-max-12149: no "N timing modes" line, current mode 16383 x 16383,
every SkyLight size 0 x 0, IOSurface creation failing with e00002c2).
QuartzCore's IOMFBDisplay::update_framebuffer_locked reads an internal
display's TimingElements and ColorElements only when there are more than one
colour mode or at least two timings (read from 14.6.1's and 27.0.1's
QuartzCore). The paravirtual display publishes three colour modes. Ours
publishes one 8-bit colour mode, which is the only format the device scans
out, and the device lists one mode. With one of each, WindowServer adds its
placeholder mode, sets no mode, and takes the display's size from
get_display_size and get_display_area. Both answer from the class's display
size fields, which held 0 x 0 until a mode was set.

So start_hardware now sets the preferred timing, the first one
publishMobileModes lists, the same way set_digital_out_mode does: SET_SCANOUT
first, then the class's size fields in its gate, then DisplayWidth,
DisplayHeight and DPTimingModeId. The class's start calls start_hardware
last, so the size is there before WindowServer opens the framebuffer. When
WindowServer does pick a mode, set_digital_out_mode still sets it.
rgfxMobileStartTimingId picks the timing, and mobile_modes_test covers it.

This is arm64e code only, so the x86-64 kexts are unchanged.
This commit is contained in:
Anees Iqbal committed 2026-11-09 10:30:40 -08:00
1 parent 5a699bbc90
commit 7a97cd15d5
5 files changed
+67 -7

No files matched your search

+4 -1
View File
@@ -319,7 +319,10 @@ Stages:
a timing for each mode the device lists and one 8-bit colour mode.
WindowServer sets one of them by its colour and timing IDs
(set_digital_out_mode), which the device then shows by `SET_SCANOUT`,
as x86-64's setDisplayMode does.
as x86-64's setDisplayMode does. With one colour mode and one timing,
WindowServer sets none and reads the display's size from the class
(QuartzCore's IOMFBDisplay), so the display starts in its preferred
mode (start_hardware).
14. **IOSurfaces follow the discrete model.** IOSurface.kext allocates
surfaces in guest RAM, CAMetalLayer drawables and window backing stores
included. The accelerator gets a per-surface device cache with a sync
+3
View File
@@ -549,6 +549,9 @@ private:
void detachMobileNode();
void publishMobileDisplay();
void publishMobileModes();
// Shows the mode of a published colour and timing ID (set_digital_out_mode), and writes its
// size where the class reads it; kIOReturnUnsupported for a pair it does not publish.
IOReturn setMobileMode(uint32_t colorId, uint32_t timingId, Mode *mode);
static void mobileVblank(OSObject *client, UInt64 count, UInt64 time, UInt64 next);
static void mobilePresented(OSObject *client, UInt64 seqno, UInt32 status, UInt64 time);
// The swaps (ReimsGraphicsMobile.cpp, swap_begin_gated): the next one begun, and the swap
+33 -6
View File
@@ -28,7 +28,9 @@
* Of what the class implements for every subclass, ReimsGraphics overrides what reads the
* class's provider as an AppleARMIODevice unchecked where a process reaches it: get_dot_pitch. And
* as the paravirtual display does, it overrides set_digital_out_mode, which the class answers
* kIOReturnUnsupported, to set the mode WindowServer picks of those it publishes.
* kIOReturnUnsupported, to set the mode WindowServer picks of those it publishes. Unlike the
* paravirtual display, which publishes three colour modes, it publishes one, and the device lists
* one mode, so WindowServer picks none: the display starts in its preferred mode (start_hardware).
*
* A process finds the display as IOMobileFramebuffer.framework counts displays: by a node of the
* device tree (attachMobileNode), then the framebuffer's service and the properties it publishes
@@ -422,7 +424,7 @@ void setElementId(OSObject *element, uint32_t id, uint32_t score)
// publishes its own (RgfxMobileModes.hpp): ColorElements, the one colour mode, and TimingElements,
// a timing for each mode the device lists, with the reduced blanking the x86-64 framebuffer's
// detailed timing gives it (timingFor) at the device's rate, and the colour mode as its ColorModes.
// WindowServer sets one of them with set_digital_out_mode.
// WindowServer sets one of them with set_digital_out_mode where it has two to pick from.
void ReimsGraphics::publishMobileModes()
{
Mode modes[kMaxModes];
@@ -695,6 +697,22 @@ RgfxIOMFBWord ReimsGraphics::start_hardware()
OSSafeReleaseNULL(answer);
}
}
// The display starts in its preferred mode, as a panel does. WindowServer reads an internal
// display's timings only where it publishes two colour modes or two timings: with one of each
// it sets no mode and takes the display's size from get_display_size, which answers the
// class's fields (read from 14.6.1's and 27.0.1's QuartzCore, IOMFBDisplay's
// update_framebuffer_locked and set_physical_and_canvas_sizes). The device lists one mode,
// so the size must be there before WindowServer opens the framebuffer.
IOLockLock(stateLock);
const uint32_t startTiming =
rgfxMobileStartTimingId(modeSet.modes, modeSet.modeCount, modeSet.preferredId);
IOLockUnlock(stateLock);
Mode start{};
const IOReturn shown = startTiming ? setMobileMode(kRgfxColorElementId, startTiming, &start)
: kIOReturnNotReady;
IOLog("ReimsGraphics: display %u starts in timing %u: 0x%x, %ux%u at %u.%03u Hz\n", displayId,
startTiming, shown, start.width, start.height, start.refreshMhz / 1000,
start.refreshMhz % 1000);
if (mobilePipe)
setPipeVblankEnabled(this, true);
if (logged(kStartHardware))
@@ -789,13 +807,25 @@ RgfxIOMFBWord ReimsGraphics::get_dot_pitch(uint32_t *pitch)
// and default framebuffer surface read, and the framebuffer publishes the size and the timing ID:
// DisplayWidth, DisplayHeight and DPTimingModeId. A pair the display does not publish is answered
// kIOReturnUnsupported, as the paravirtual display leaves it to the class, which answers that.
// start_hardware sets the display's first mode the same way (setMobileMode).
RgfxIOMFBWord ReimsGraphics::set_digital_out_mode(uint32_t colorId, uint32_t timingId)
{
Mode mode{};
const IOReturn r = setMobileMode(colorId, timingId, &mode);
if (logged(kSetDigitalOutMode))
IOLog("ReimsGraphics: set_digital_out_mode(%u, %u) = 0x%x: %ux%u at %u.%03u Hz\n", colorId,
timingId, r, mode.width, mode.height, mode.refreshMhz / 1000, mode.refreshMhz % 1000);
return word(r);
}
IOReturn ReimsGraphics::setMobileMode(uint32_t colorId, uint32_t timingId, Mode *shown)
{
IOLockLock(stateLock);
Mode mode{};
const bool published =
rgfxMobileModeFor(colorId, timingId, modeSet.modes, modeSet.modeCount, &mode);
IOLockUnlock(stateLock);
*shown = mode;
IOReturn r = kIOReturnUnsupported;
if (published) {
r = setScanout(mode);
@@ -821,10 +851,7 @@ RgfxIOMFBWord ReimsGraphics::set_digital_out_mode(uint32_t colorId, uint32_t tim
setProperty("DPTimingModeId", timingId, 64);
}
}
if (logged(kSetDigitalOutMode))
IOLog("ReimsGraphics: set_digital_out_mode(%u, %u) = 0x%x: %ux%u at %u.%03u Hz\n", colorId,
timingId, r, mode.width, mode.height, mode.refreshMhz / 1000, mode.refreshMhz % 1000);
return word(r);
return r;
}
#endif // __arm64e__
+17
View File
@@ -107,6 +107,23 @@ inline uint32_t rgfxMobileTimings(const RgfxMode *modes, uint32_t n, int32_t pre
return count;
}
// The timing a display starts in, before WindowServer sets one: the first rgfxMobileTimings lists,
// the preferred mode's, or the first mode's where none is preferred. 0 for a display with no mode.
inline uint32_t rgfxMobileStartTimingId(const RgfxMode *modes, uint32_t n, int32_t preferredId)
{
uint32_t first = 0;
for (uint32_t i = 0; i < n; i++) {
if (modes[i].id <= 0)
continue;
const uint32_t id = kRgfxTimingIdBase + static_cast<uint32_t>(modes[i].id);
if (modes[i].id == preferredId)
return id;
if (!first)
first = id;
}
return first;
}
// The mode of the colour and timing IDs set_digital_out_mode takes, in that order: the mode in
// `modes[0..n)` whose timing has `timingId`, with the display's one colour mode. False for any other
// pair, which the paravirtual display leaves to its parent class to answer.
+10
View File
@@ -162,6 +162,16 @@ void timings()
"with no preferred mode listed, the device's order", "order");
check(rgfxMobileTimings(modes, 0, 7, out) == 0, "no modes, no timings", "order");
// The display starts in the timing listed first.
check(rgfxMobileStartTimingId(modes, 3, 7) == 1007, "the preferred mode's timing", "start");
check(rgfxMobileTimings(modes, 3, 42, out) == 3 &&
rgfxMobileStartTimingId(modes, 3, 42) == out[0].id,
"with none preferred, the first timing listed", "start");
const RgfxMode unnumbered[] = {{0, 640, 480, 60000}, {5, 800, 600, 60000}};
check(rgfxMobileStartTimingId(unnumbered, 2, 0) == 1005, "never mode 0, which has no timing",
"start");
check(rgfxMobileStartTimingId(modes, 0, 7) == 0, "no modes, no timing", "start");
RgfxMode m{};
check(rgfxMobileModeFor(100, 1007, modes, 3, &m) && m.width == 1920 && m.height == 1080,
"the colour and timing IDs set a mode", "set");