fix(macos): HDR improvements and prevent separate mpv window#1394
Open
Emanuel5014 wants to merge 2 commits into
Open
fix(macos): HDR improvements and prevent separate mpv window#1394Emanuel5014 wants to merge 2 commits into
Emanuel5014 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the macOS mpv integration to improve HDR behavior (via mpv gpu-next HDR/tone-mapping options and display headroom tuning) and to better embed the mpv renderer into the app window by ensuring the backing CAMetalLayer is correctly configured for MoltenVK/Vulkan surface creation.
Changes:
- Configure additional mpv HDR-related defaults (e.g.,
tone-mapping,hdr-compute-peak,target-prim,target-trc) and update runtime HDR toggling behavior. - Improve macOS window embedding by setting the Metal layer’s
deviceprior to passing the layer aswid, and simplify Metal layer management. - Refresh EDR mode handling flow (shifted to mpv/gpu-next via
target-colorspace-hint) and trigger EDR refresh on playback restart.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| shared/apple/MpvPlayer/MpvPlayerCoreBase.swift | Adds mpv HDR defaults/toggles and refreshes EDR update behavior on playback restart. |
| macos/Runner/MpvPlayer/MpvPlayerCore.swift | Sets up the Metal layer with a Metal device for embedding, simplifies layer attach/visibility logic, and computes target-peak from EDR headroom. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+26
to
29
| // Create and configure Metal layer for mpv rendering | ||
| let layer = MpvMetalLayer() | ||
| layer.device = MTLCreateSystemDefaultDevice() | ||
| layer.frame = contentView.bounds |
Comment on lines
98
to
+103
| contentView.wantsLayer = true | ||
| if let contentLayer = contentView.layer { | ||
| attachMetalLayer(to: contentLayer, frame: contentView.bounds) | ||
| if let superlayer = contentView.layer, metalLayer.superlayer !== superlayer { | ||
| withoutLayerAnimations { | ||
| superlayer.backgroundColor = NSColor.black.cgColor | ||
| superlayer.isOpaque = true | ||
| superlayer.insertSublayer(metalLayer, at: 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
HDR Fixes (macOS)
target-peakto match display EDR headroomtarget-prim,target-trc,tone-mapping,gamut-mapping-modetoggles insetHDREnabled()tone-mapping=auto,hdr-compute-peak=auto,target-colorspace-hint=auto,target-prim=auto,target-trc=autoas defaults before inittarget-colorspace-hintfrom"auto"to"yes"when HDR is enabled at runtimetarget-colorspace-hint— no manualwantsExtendedDynamicRangeContenttoggle neededWindow Embedding Fix (macOS)
layer.device = MTLCreateSystemDefaultDevice()on theMpvMetalLayerbefore passing it aswid, ensuring the Metal layer has a valid device for Vulkan surface creationCode Cleanup
MpvPlayerCore.swift: removedattachMetalLayer,updateDrawableSize,setMetalLayerHidden,restoreMetalLayerAfterOcclusionhelpersupdateEDRMode(sigPeak:)call onMPV_EVENT_PLAYBACK_RESTARTconfigureMoltenVKPlacementHeaps()for MoltenVK compatibility