Skip to content

macOS Apple Silicon: detect built-in Retina display (#3404) - #3436

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-retina-3404
Jul 8, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-retina-3404

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Detect the Apple Silicon built-in Retina panel (which has no EDID EPROM) by enumerating IOMobileFramebuffer nodes and synthesizing a DisplayInfo from CoreGraphics and NSScreen properties
  • External monitors are explicitly skipped via the external boolean property since they are already enumerated with their real EDID via IOPortTransportStateDisplayPort, preserving backward-compatible output
  • Intel IODisplayConnect path is unchanged

The synthesized DisplayInfo (flagged isEdidSynthetic()) includes:

  • Native pixel resolution from the framebuffer node (DisplayWidth/DisplayHeight)
  • Physical dimensions from CGDisplayScreenSize
  • Product ID from CGDisplayModelNumber
  • Serial from CGDisplaySerialNumber
  • Display name from NSScreen.localizedName (via ObjC runtime bridge)

JNA (oshi-core) and FFM (oshi-core-ffm) parity, sharing the native-agnostic EdidUtil in oshi-common.

Closes #3404

New bindings

  • CoreGraphicsExt (JNA): CGDisplayScreenSize
  • CoreGraphicsFunctions (FFM): CGGetActiveDisplayList, CGDisplayIsBuiltin, CGDisplayModelNumber, CGDisplaySerialNumber, CGDisplayScreenSize
  • ObjCRuntime (JNA): objc_getClass, sel_registerName, objc_msgSend
  • ObjC runtime (FFM): inline MethodHandle bindings for NSScreen dispatch

Test plan

  • Validated live on M2 Max (both JNA and FFM)
  • External monitor EDID output matches master
  • NativeComparisonTest.displays() passes (JNA/FFM parity)
  • New unit tests for MacDisplayUtil and DisplayInfoImpl edge cases
  • CI (macOS runner is Apple Silicon) and local tests on both M2 and M3

Summary by CodeRabbit

  • New Features

    • Improved Mac display detection to recognize Apple Silicon built-in Retina panels and show richer display details.
    • Added broader support for display metadata, including manufacturer decoding, serial handling, resolution, size, and model naming.
  • Bug Fixes

    • Prevented failures when display serials or preferred resolutions are missing or malformed.
    • Made display info generation more resilient, falling back gracefully when some details can’t be read.
  • Tests

    • Added coverage for Apple display synthesis, serial fallback behavior, and null-handling edge cases.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds Apple Silicon built-in Retina display detection by synthesizing DisplayInfo from IOMobileFramebuffer registry attributes when no EDID exists. It introduces EdidUtil manufacturer decoding/synthesis helpers, safe EDID serial writing, new JNA/FFM CoreGraphics and Objective-C bindings, and platform-specific display discovery in MacDisplayJNA/MacDisplayFFM.

Changes

Apple Silicon display synthesis

Layer / File(s) Summary
Safe EDID serial writing and preferred-resolution guard
oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java, oshi-common/src/main/java/oshi/util/EdidUtil.java (null guard), oshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.java
DisplayInfoImpl adds setSerialNoSafe to fall back to numeric hex-parsed serial when the string form fails; EdidUtil.setPreferredResolution short-circuits on null; tests updated to expect non-throwing behavior with new fallback/null-resolution coverage.
EdidUtil manufacturer decoding and synthesis helper
oshi-common/src/main/java/oshi/util/EdidUtil.java, oshi-common/src/test/java/oshi/util/EdidUtilTest.java
Adds decodeManufacturerId and synthesizeDisplayInfo to build a synthetic DisplayInfo from manufacturer/model/serial/resolution/size attributes with fallback naming, plus extensive new unit tests.
Native CoreGraphics and Objective-C bindings
oshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.java, oshi-core/src/main/java/oshi/jna/platform/mac/ObjCRuntime.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.java
New JNA CoreGraphicsExt (screen size) and ObjCRuntime (Objective-C message dispatch) interfaces; FFM CoreGraphicsFunctions gains downcalls for active display list, built-in check, model/serial number, and screen size.
MacDisplayJNA built-in display discovery
oshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.java
Adds a synthetic-display constructor and getAppleSiliconBuiltInDisplay() path that discovers IOMobileFramebuffer nodes, reads DisplayAttributes, synthesizes DisplayInfo, and enriches it via CoreGraphics/NSScreen lookups with CoreFoundation helper accessors.
MacDisplayFFM built-in display discovery
oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
Mirrors the JNA implementation using Java FFM APIs for framebuffer discovery, attribute reading, synthesis, CoreGraphics enrichment, localized-name lookup, and CFDictionary helpers.
Changelog
CHANGELOG.md
Adds a new-feature bullet describing Apple Silicon built-in Retina display detection.

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MacDisplayJNA
  participant IOKit
  participant EdidUtil
  participant CoreGraphicsExt
  participant ObjCRuntime

  MacDisplayJNA->>IOKit: locate IOMobileFramebuffer nodes
  IOKit-->>MacDisplayJNA: DisplayAttributes / ProductAttributes
  MacDisplayJNA->>EdidUtil: synthesizeDisplayInfo(manufacturer, model, resolution, size)
  EdidUtil-->>MacDisplayJNA: synthetic DisplayInfo
  MacDisplayJNA->>CoreGraphicsExt: findBuiltInDisplayId / model / serial / screen size
  CoreGraphicsExt-->>MacDisplayJNA: enrichment data
  MacDisplayJNA->>ObjCRuntime: NSScreen.localizedName lookup
  ObjCRuntime-->>MacDisplayJNA: localized display name
  MacDisplayJNA-->>MacDisplayJNA: enriched Display added to list
Loading

Possibly related PRs

  • oshi/oshi#3415: Extends the DisplayInfo/EDID encoding foundation by updating the same DisplayInfoImpl and EdidUtil synthesis/serial handling code paths.
  • oshi/oshi#3416: Also modifies EdidUtil.setPreferredResolution(...) guard logic and EDID serial encoding/setting paths.

Poem

A hop, a peek behind the screen so bright,
Silicon panels found without their EDID light. 🐰
Through IOKit burrows and ObjC calls,
I synthesize names, sizes, serials — all!
Now every built-in Mac display shows true,
A rabbit's work, delivered fresh and new. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy #3404 by adding Apple Silicon built-in display discovery, synthesized display info, and preserving external display detection.
Out of Scope Changes check ✅ Passed The extra bindings, helpers, and tests all support the display-detection feature and do not appear unrelated to the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: detecting the Apple Silicon built-in Retina display on macOS.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 260 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.36%. Comparing base (f19cf50) to head (4dbe92b).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...java/oshi/hardware/platform/mac/MacDisplayJNA.java 12.33% 132 Missing and 3 partials ⚠️
...java/oshi/hardware/platform/mac/MacDisplayFFM.java 24.84% 121 Missing and 3 partials ⚠️
oshi-common/src/main/java/oshi/util/EdidUtil.java 97.05% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3436      +/-   ##
============================================
- Coverage     75.19%   74.36%   -0.83%     
  Complexity       76       76              
============================================
  Files           580      580              
  Lines         21609    21972     +363     
  Branches       3588     3670      +82     
============================================
+ Hits          16249    16340      +91     
- Misses         3332     3592     +260     
- Partials       2028     2040      +12     
Flag Coverage Δ
freebsd 26.71% <12.08%> (-0.25%) ⬇️
linux 31.23% <12.08%> (-0.33%) ⬇️
macos 31.72% <28.57%> (-0.10%) ⬇️
openbsd 26.20% <12.08%> (-0.24%) ⬇️
solaris 28.21% <12.08%> (-0.28%) ⬇️
windows 39.52% <12.08%> (-0.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.java`:
- Around line 90-100: The CGDisplayScreenSize FFM binding is missing the
required SegmentAllocator for its struct return, so the current downcall setup
and invokeExact call will fail at runtime. Update the
CoreGraphicsFunctions.CGDisplayScreenSize method handle and wrapper to accept a
SegmentAllocator argument and pass it through when invoking the native function,
using the CG_SIZE_LAYOUT return struct. Then adjust the MacDisplayFFM call site
to supply an allocator so widthMm and heightMm can be populated correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4d1a1146-3b38-4e5e-a9a1-4ca778a299a3

📥 Commits

Reviewing files that changed from the base of the PR and between d22319e and e451850.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.java
  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacDisplayUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/ObjCRuntime.java
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/ObjCRuntime.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.java
  • oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.java
🔇 Additional comments (17)
CHANGELOG.md (1)

6-6: LGTM!

oshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.java (1)

187-226: LGTM!

oshi-common/src/main/java/oshi/util/EdidUtil.java (1)

483-485: LGTM!

oshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.java (1)

83-121: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.java (2)

33-44: LGTM!


68-104: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacDisplayUtilTest.java (1)

17-124: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java (4)

184-196: 🎯 Functional Correctness | ⚡ Quick win

Downstream of the CGDisplayScreenSize struct-return bug.

CGDisplayScreenSize(builtInId) here will throw WrongMethodTypeException (missing SegmentAllocator) and get swallowed by the catch (Throwable), leaving widthMm/heightMm null on FFM. This is addressed by the root-cause fix in CoreGraphicsFunctions.CGDisplayScreenSize; update this call site to pass an Arena/allocator as part of that fix.


107-159: LGTM!


229-315: LGTM!


320-339: LGTM!

oshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.java (1)

16-37: LGTM!

oshi-core/src/main/java/oshi/jna/platform/mac/ObjCRuntime.java (1)

18-29: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.java (1)

54-88: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.java (3)

145-209: LGTM!


273-322: LGTM!


237-270: 🎯 Functional Correctness

No action needed com.sun.jna.platform.mac.CoreGraphics already declares CGDisplayModelNumber, CGDisplaySerialNumber, CGDisplayIsBuiltin, and CGGetActiveDisplayList; CoreGraphicsExt only adds CGDisplayScreenSize.

			> Likely an incorrect or invalid review comment.

…3404)

Detect the Apple Silicon built-in Retina panel by enumerating the stable
IOMobileFramebuffer base class and synthesizing a DisplayInfo from
DisplayAttributes/ProductAttributes (flagged via isEdidSynthetic). External
monitors are explicitly skipped (via the "external" boolean property on the
framebuffer node) since they are already enumerated with their real EDID via
the IOPortTransportStateDisplayPort path, preserving backward-compatible
EDID output. The Intel IODisplayConnect path is unchanged. JNA (oshi-core)
and FFM (oshi-core-ffm) parity, sharing the new native-agnostic oshi-common
MacDisplayUtil for the field mapping.

The synthesized DisplayInfo includes:
- Native pixel resolution (DisplayWidth/DisplayHeight from the fb node)
- Physical dimensions in cm from CGDisplayScreenSize (mm, rounded)
- Product ID from CGDisplayModelNumber (proper 16-bit EDID model code)
- Serial from CGDisplaySerialNumber (EDID bytes 12-15 via numeric path)
- Display name from NSScreen.localizedName via ObjC runtime bridge
- IONameMatched as last-resort fallback name

Also fixes DisplayInfoImpl.synthesizeEdid to gracefully handle serial
numbers that don't round-trip through EdidUtil.setSerialNo(String) by
falling back to the numeric setSerialNo(long) overload.

New native bindings added:
- CoreGraphicsExt (JNA): CGDisplayScreenSize
- CoreGraphicsFunctions (FFM): CGGetActiveDisplayList, CGDisplayIsBuiltin,
  CGDisplayModelNumber, CGDisplaySerialNumber, CGDisplayScreenSize
- ObjCRuntime (JNA): objc_getClass, sel_registerName, objc_msgSend
- ObjC runtime (FFM): inline MethodHandle bindings for NSScreen dispatch

Validated live on an M2 Max: both JNA and FFM getDisplays() now return the
built-in panel (mfg=APP, model=a050, serial=FD626D62, name="Built-in Retina
Display", synthetic=true) where they returned 0 displays before, and
external monitors produce the same EDID as master.
@dbwiddis

dbwiddis commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Coverage: CI vs Local (with built-in display)

CI reports 28.57% patch coverage because the macOS runner is a VM with no built-in display — the entire IOMobileFramebuffer / CoreGraphics / ObjC runtime path is unreachable there. Local testing on an M3 Pro with the built-in Retina display active shows the real coverage:

File Local Line Coverage Local Branch Coverage
oshi-common/EdidUtil.java 213/215 (99%) 134/137 (98%)
oshi-common/DisplayInfoImpl.java 92/92 (100%) 44/44 (100%)
oshi-core/MacDisplayJNA.java 162/186 (87%) 56/108 (52%)
oshi-core-ffm/MacDisplayFFM.java 170/194 (88%) 46/78 (59%)

The remaining uncovered lines/branches in the JNA/FFM files are:

  • Null-guard early-returns (headless environment paths — nsScreenClass == null, screensArray == null, etc.)
  • The IODisplayConnect Intel path (no Intel Mac available)
  • Exception catch blocks (defensive, never triggered in normal operation)

The NativeComparisonTest (JNA == FFM parity) passes locally, confirming both implementations produce identical output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal Retina display is not listed on MacDisplayJNA

1 participant