diff --git a/docs/graphics-kext/design.md b/docs/graphics-kext/design.md index 125dba719..6a21271ab 100644 --- a/docs/graphics-kext/design.md +++ b/docs/graphics-kext/design.md @@ -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 diff --git a/guest/kext/src/ReimsGraphics.hpp b/guest/kext/src/ReimsGraphics.hpp index b7663a23e..ae6c1bde0 100644 --- a/guest/kext/src/ReimsGraphics.hpp +++ b/guest/kext/src/ReimsGraphics.hpp @@ -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 diff --git a/guest/kext/src/ReimsGraphicsMobile.cpp b/guest/kext/src/ReimsGraphicsMobile.cpp index 6ac5960fa..9385981b5 100644 --- a/guest/kext/src/ReimsGraphicsMobile.cpp +++ b/guest/kext/src/ReimsGraphicsMobile.cpp @@ -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__ diff --git a/guest/kext/src/RgfxMobileModes.hpp b/guest/kext/src/RgfxMobileModes.hpp index 301942863..0d448aba0 100644 --- a/guest/kext/src/RgfxMobileModes.hpp +++ b/guest/kext/src/RgfxMobileModes.hpp @@ -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(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. diff --git a/guest/kext/tests/mobile_modes_test.cpp b/guest/kext/tests/mobile_modes_test.cpp index b49b27b6f..3605ca2a1 100644 --- a/guest/kext/tests/mobile_modes_test.cpp +++ b/guest/kext/tests/mobile_modes_test.cpp @@ -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");