Repository navigation
macOS Apple Silicon: detect built-in Retina display (#3404) - #3436
Conversation
📝 WalkthroughWalkthroughThis PR adds Apple Silicon built-in Retina display detection by synthesizing ChangesApple Silicon display synthesis
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
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (11)
CHANGELOG.mdoshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.javaoshi-common/src/main/java/oshi/util/EdidUtil.javaoshi-common/src/test/java/oshi/hardware/DisplayInfoImplTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacDisplayUtilTest.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.javaoshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.javaoshi-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.javaoshi-core/src/main/java/oshi/jna/platform/mac/ObjCRuntime.javaoshi-core/src/main/java/oshi/jna/platform/mac/CoreGraphicsExt.javaoshi-common/src/main/java/oshi/hardware/DisplayInfoImpl.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacDisplayUtil.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/mac/CoreGraphicsFunctions.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacDisplayJNA.javaoshi-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 winDownstream of the
CGDisplayScreenSizestruct-return bug.
CGDisplayScreenSize(builtInId)here will throwWrongMethodTypeException(missingSegmentAllocator) and get swallowed by thecatch (Throwable), leavingwidthMm/heightMmnull on FFM. This is addressed by the root-cause fix inCoreGraphicsFunctions.CGDisplayScreenSize; update this call site to pass anArena/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 CorrectnessNo action needed
com.sun.jna.platform.mac.CoreGraphicsalready declaresCGDisplayModelNumber,CGDisplaySerialNumber,CGDisplayIsBuiltin, andCGGetActiveDisplayList;CoreGraphicsExtonly addsCGDisplayScreenSize.> 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.
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
The remaining uncovered lines/branches in the JNA/FFM files are:
The |
Summary
IOMobileFramebuffernodes and synthesizing aDisplayInfofrom CoreGraphics and NSScreen propertiesexternalboolean property since they are already enumerated with their real EDID viaIOPortTransportStateDisplayPort, preserving backward-compatible outputIODisplayConnectpath is unchangedThe synthesized
DisplayInfo(flaggedisEdidSynthetic()) includes:DisplayWidth/DisplayHeight)CGDisplayScreenSizeCGDisplayModelNumberCGDisplaySerialNumberNSScreen.localizedName(via ObjC runtime bridge)JNA (
oshi-core) and FFM (oshi-core-ffm) parity, sharing the native-agnosticEdidUtilinoshi-common.Closes #3404
New bindings
CoreGraphicsExt(JNA):CGDisplayScreenSizeCoreGraphicsFunctions(FFM):CGGetActiveDisplayList,CGDisplayIsBuiltin,CGDisplayModelNumber,CGDisplaySerialNumber,CGDisplayScreenSizeObjCRuntime(JNA):objc_getClass,sel_registerName,objc_msgSendMethodHandlebindings forNSScreendispatchTest plan
NativeComparisonTest.displays()passes (JNA/FFM parity)MacDisplayUtilandDisplayInfoImpledge casesSummary by CodeRabbit
New Features
Bug Fixes
Tests