Skip to content

fix(macos): HDR improvements and prevent separate mpv window#1394

Open
Emanuel5014 wants to merge 2 commits into
edde746:mainfrom
Emanuel5014:main
Open

fix(macos): HDR improvements and prevent separate mpv window#1394
Emanuel5014 wants to merge 2 commits into
edde746:mainfrom
Emanuel5014:main

Conversation

@Emanuel5014

Copy link
Copy Markdown

Changes

HDR Fixes (macOS)

  • Added target-peak to match display EDR headroom
  • Added target-prim, target-trc, tone-mapping, gamut-mapping-mode toggles in setHDREnabled()
  • Set tone-mapping=auto, hdr-compute-peak=auto, target-colorspace-hint=auto, target-prim=auto, target-trc=auto as defaults before init
  • Changed target-colorspace-hint from "auto" to "yes" when HDR is enabled at runtime
  • EDR mode is now handled entirely by mpv/gpu-next via target-colorspace-hint — no manual wantsExtendedDynamicRangeContent toggle needed

Window Embedding Fix (macOS)

  • Set layer.device = MTLCreateSystemDefaultDevice() on the MpvMetalLayer before passing it as wid, ensuring the Metal layer has a valid device for Vulkan surface creation

Code Cleanup

  • Simplified layer management in MpvPlayerCore.swift: removed attachMetalLayer, updateDrawableSize, setMetalLayerHidden, restoreMetalLayerAfterOcclusion helpers
  • Added updateEDRMode(sigPeak:) call on MPV_EVENT_PLAYBACK_RESTART
  • Restored configureMoltenVKPlacementHeaps() for MoltenVK compatibility

Copilot AI review requested due to automatic review settings June 21, 2026 14:35

Copilot AI 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.

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 device prior to passing the layer as wid, 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)
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.

2 participants