Skip to content

fix(windows): 避免自动颜色管理开启时串流误启 HDR - #1183

Merged
qiin2333 merged 1 commit into
AlkaidLab:masterfrom
JahsehXL:codex/fix-windows-acm-hdr-state
Oct 25, 2026
Merged

qiin2333 merged 1 commit into
AlkaidLab:masterfrom
JahsehXL:codex/fix-windows-acm-hdr-state

Conversation

@JahsehXL

Copy link
Copy Markdown
Contributor

开启 Windows 自动颜色管理(ACM)但关闭 HDR 时,开始或结束串流可能把原有显示器的 HDR 打开。修复后按实际 HDR 用户开关保存、设置和恢复状态,ACM 可以继续开启。

原因与修改

旧 DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO::advancedColorEnabled 表示某种高级颜色模式已开启,不能区分 SDR 的 WCG/ACM 与 HDR。Windows 11 26200 实机上,HDR 关闭且 ACM 开启时,旧接口仍报告 enabled;随后旧 setter 会真正开启 HDR。

  • 优先运行时探测 GET_ADVANCED_COLOR_INFO_2,读取 highDynamicRangeSupported 和 highDynamicRangeUserEnabled。保存用户开关,避免系统策略暂时抑制 HDR 时错误覆盖其意图。
  • 使用专门的 SET_HDR_STATE,不写 WCG 开关。新接口已可用时,HDR 写入失败不会回退到旧的高级颜色 setter。
  • 仅在新查询返回 ERROR_INVALID_PARAMETER / ERROR_NOT_SUPPORTED 时使用原有接口,保留旧系统兼容;其他失败正常上报。
  • 使用私有 ABI 结构及大小断言,兼容缺少新类型声明的 SDK。保留原有 VDD 重应用策略和 Windows 头文件引入顺序。

Related: #13(历史讨论中已有关闭 ACM 的绕过办法)。

验证

  • 用仓库固定的 GoogleTest 子模块、本机 MSVC 19.44 / Windows SDK 10.0.26100.0 独立编译新增测试;不额外定义 NOMINMAX:7 个测试全部通过。
  • 覆盖 ACM 开/HDR 关、HDR 与 ACM 同开、用户 HDR 开但暂未激活、WCG-only 显示器、旧查询回退、查询失败及 HDR 写入失败不得回退等场景。
  • Windows 11 26200 上通过真实 DisplayConfig 接口检查当前 4 个显示目标,并对已经关闭 HDR 的目标执行同状态 HDR-off 请求:HDR 保持关闭,ACM、10bpc 和当前颜色模式保持不变。主屏 ACM 为开启状态。
  • 私有结构的大小及关键字段偏移与本机微软 SDK 原生定义一致。
  • 新文件通过仓库 .clang-format 检查;git diff --check 通过。独立代码审查已完成。
  • 新测试位于现有 aggregate GoogleTest 的自动发现目录,不需要改 CMake 注册。

验证边界

本机未配置仓库要求的完整 MSYS2/UCRT64 主机构建依赖,未完成整个 Sunshine 主机的构建,也未用补丁二进制完成 Moonlight 连接/退出循环。旧 Windows 的回退路径已模拟测试,尚未旧系统实机验证。

旧版本已持久化的 original_hdr_states=enabled 无法区分真实 HDR 与误存的 ACM,不会盲目迁移;遇到旧快照时,应在非串流状态重置 Sunshine 显示设备记忆,再确认 Windows HDR 设置。

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0219abe and 181e637.

Files selected for processing: 3
  • src/platform/windows/display_device/hdr_state_api.h
  • src/platform/windows/display_device/windows_utils.cpp
  • tests/unit/platform/windows/test_hdr_state_api.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details
Additional context used
Path-based instructions: 3
平台抽象层代码(Windows/Linux/macOS)。确保各平台实现一致, 注意 Windows API 调用的错误处理和资源释放。

CodeRabbit configuration file

Files:

  • src/platform/windows/display_device/windows_utils.cpp
  • src/platform/windows/display_device/hdr_state_api.h
Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

CodeRabbit configuration file

Files:

  • src/platform/windows/display_device/windows_utils.cpp
  • src/platform/windows/display_device/hdr_state_api.h
测试文件。验证测试覆盖率、边界情况和断言正确性。

CodeRabbit configuration file

Files:

  • tests/unit/platform/windows/test_hdr_state_api.cpp
Cppcheck (2.22.0)
tests/unit/platform/windows/test_hdr_state_api.cpp

[error] 80-80: syntax error

(syntaxError)

Summary by CodeRabbit

  • 修复
    • 改进 Windows HDR 状态的查询与设置:更准确地区分 HDR 支持状态和用户开关状态,即使 HDR 暂未激活,也能保留开关状态。
    • 在系统不支持专用 HDR 接口时,兼容使用旧版显示设置接口;其他查询或写入失败时不再尝试另一接口。

Walkthrough

新增 Windows HDR 状态 API。该 API 查询并设置目标显示器的 HDR 状态,仅在指定错误时回退到旧版高级颜色 API。Windows 显示设备状态处理已改用该 API,并新增相关单元测试。

Changes

Windows HDR 状态处理

Layer / File(s) Summary
HDR 状态 API 与行为测试
src/platform/windows/display_device/hdr_state_api.h, tests/unit/platform/windows/test_hdr_state_api.cpp
新增 HDR 状态查询与设置逻辑。现代查询仅在返回 ERROR_INVALID_PARAMETER 或 ERROR_NOT_SUPPORTED 时使用旧版 API;其他错误直接返回。测试覆盖 HDR 与 ACM/WCG 状态区分、旧版回退及写入错误处理。
Windows 显示设备集成
src/platform/windows/display_device/windows_utils.cpp
HDR 状态查询和设置改为调用新 API。查询失败时记录错误并返回 unknown;设置失败时记录错误并返回 false。

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: qiin2333

Merge Risk: Minimal · up to 181e6

The reported legacy-system behavior predates this change. No identified PR regression remains to block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed 标题准确概括了主要修复内容:避免 Windows 自动颜色管理开启时,在串流过程中错误启用 HDR。标题简洁、明确,并与变更内容一致。
Description check Passed 描述详细说明了问题原因、API 修改、兼容策略、测试覆盖范围和验证边界,内容与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Copy link
Copy Markdown
Collaborator

nice work

@qiin2333
qiin2333 merged commit b052a5f into AlkaidLab:master Oct 25, 2026
4 checks passed
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