Skip to content

fix(display): correct Windows DPI scale step mapping - #1182

Merged
qiin2333 merged 1 commit into
masterfrom
codex/fix-display-scale-steps
Oct 25, 2026
Merged

qiin2333 merged 1 commit into
masterfrom
codex/fix-display-scale-steps

Conversation

@qiin2333

@qiin2333 qiin2333 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

改了啥呀

  • 将 Windows GET/SET_DPI_SCALE 的相对索引表恢复为实际的 12 个桌面缩放档位,移除误混入的 120/140/160/180。
  • 提取仅依赖标准库的转换 helper,真实 GET/SET 路径复用它;异常相对值使用宽整数计算,避免溢出。
  • 新增独立测试目标 display_scale_steps_unit_tests,直接断言 Windows 相对值与百分比的对应关系。

为啥要改

原来的 16 档表会错读当前/推荐缩放,也会向 Windows 写入错误的相对档位。例如请求 150% 实际可能设置成 200%,再读回来却仍显示 150%。杂鱼错位读写互相掩护,普通 round-trip 测试抓不住。

正确表和索引语义可参照 Windows DPI scaling sample。

客户端联动:qiin2333/moonlight-vplus#757。

验证

  • macOS 使用 clang++ -std=c++23 -Wall -Wextra -Werror -fsanitize=address,undefined -fno-omit-frame-pointer,直接编译生产 helper、GoogleTest 和新增测试并运行:4/4 通过。
  • 测试使用独立字面预期,例如原生相对值 (-3,-1,8) 必须得到推荐 175%、当前 150%、上限 500%;写入 150% 相对推荐 175% 必须为 -1。
  • Mutation 验证:仅将 helper 临时替回原 16 档表后,同一组 4 个测试全部失败,确认能捕获原始错误。
  • git diff --check origin/master...HEAD 通过。
  • Windows CI 完整 host 编译通过;ctest --test-dir build --output-on-failure 的 34/34 个测试目标全部通过,包含本次内含 4 项回归用例的 display_scale_steps_unit_tests。
  • CodeRabbit 和 Copilot review 均无待处理问题。
  • 尚未进行真实 Windows 显示器的 DPI 生效验收;CI 编译和测试通过不代表已验证 Windows API 对实际显示器的生效结果。

@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 d2b831c.

Files selected for processing: 4
  • src/platform/windows/display_device/display_scale_steps.h
  • src/platform/windows/display_device/windows_utils.cpp
  • tests/CMakeLists.txt
  • tests/unit/test_display_scale_steps.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
Context from checks skipped due to timeout: 2
  • GitHub Check: Setup Release
  • GitHub Check: VDD helper smoke tests
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/display_scale_steps.h
Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

CodeRabbit configuration file

Files:

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

CodeRabbit configuration file

Files:

  • tests/CMakeLists.txt
  • tests/unit/test_display_scale_steps.cpp
Cppcheck (2.22.0)
tests/unit/test_display_scale_steps.cpp

[error] 9-9: syntax error

(syntaxError)

Additional comments: 1
src/platform/windows/display_device/display_scale_steps.h: 1

27-29: 🎯 Functional Correctness

需要先确认 Windows 是否会返回超出范围的当前值。本次检查没有取得这一证据,因此无法判定该评论。

评论称 decode_range 在 current_index 超出报告范围时返回空值。源码中该逻辑已确认存在。但评论还称 Windows 可能返回此类值,并称参考样例会先将当前值钳制到范围内。这两个前提需要实际 API 行为或参考样例代码支持,当前上下文中没有相关证据。

Summary by CodeRabbit

  • 改进
    • 改进 Windows 显示缩放选项的识别与设置,支持正确显示当前、推荐及可用的缩放比例。
    • 对无效或不受支持的缩放范围进行处理,避免应用不适用的缩放设置。
  • 测试
    • 增加缩放比例解析与设置相关的测试,涵盖有效范围、无效范围及边界输入。

Walkthrough

新增 Windows DPI 缩放步进工具,用于解码缩放范围和计算相对推荐值。Windows 缩放读取和设置逻辑改为使用该工具。新增单元测试及独立测试目标。

Changes

Windows DPI 缩放

Layer / File(s) Summary
步进转换与单元测试
src/platform/windows/display_device/display_scale_steps.h, tests/unit/test_display_scale_steps.cpp, tests/CMakeLists.txt
新增 12 项缩放百分比表、范围索引结构,以及相对值解码和百分比编码函数。新增测试,覆盖有效输入、无效输入和 int32_t 极值,并注册独立测试目标。
Windows 缩放读取与设置
src/platform/windows/display_device/windows_utils.cpp
缩放详情读取改用 decode_range,并从百分比表填充当前、推荐和支持的缩放值。设置逻辑改用 relative_from_percent 计算相对推荐值;转换失败或目标百分比不受该显示器支持时返回不支持缩放错误。

Priority: Normal

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

Change: Bug fix

Suggested reviewers: yundi339

Merge Risk: Minimal · up to d2b83

No identified issue blocks merging this DPI scale mapping change.

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 8 functions across 3 files. (1 skipped: 1 … 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 DPI 缩放步进映射,简洁且具体。
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.
Description check Passed PR 描述明确说明了 Windows DPI 缩放步进表修正、转换 helper、生产路径复用和新增测试。内容与变更文件及 PR 目标直接相关。
Full details: Docstring Coverage

Explanation

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 8 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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.

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.

🟢 Approval recommended

The focused mapping correction has direct regression coverage and no identified blocking issues, though Windows host compilation and live display validation remain unverified.

No open issues 🎉

What changed in this PR

Corrects Windows desktop DPI scaling so reported percentages and requested scale changes use the proper native step mapping.

Changes:

  • Replaces the incorrect 16-entry mapping with the 12 supported desktop scaling steps.
  • Shares bounds-checked, overflow-safe conversion helpers between the Windows GET and SET paths.
  • Adds a standalone regression test target with explicit percentage expectations and invalid-range checks.
File Description
tests/​unit/​test_display_scale_steps.cpp Tests native offsets, expected percentages, unsupported values, and overflow boundaries.
tests/​CMakeLists.txt Registers the standalone test target and excludes its source from the shared test suite.
src/​platform/​windows/​display_device/​windows_utils.cpp Uses the shared helpers for reading and setting display scale.
src/​platform/​windows/​display_device/​display_scale_steps.h Defines the corrected scale table and validated conversion helpers.

Review effort: Balanced

@qiin2333
qiin2333 merged commit f52bc47 into master Oct 25, 2026
5 checks passed
@qiin2333
qiin2333 deleted the codex/fix-display-scale-steps branch October 25, 2026 07:41
qiin2333 added a commit to qiin2333/moonlight-vplus that referenced this pull request Oct 25, 2026
## 改了啥呀

- 波形触觉卡片接入显隐、长按编辑、配置同步与备份恢复;旧配置沿用原来的显示行为。
-
码率只显示一个目标读数,请求中显示小型进度提示;读数固定在标题行,切换时不再推动整个菜单。手动请求串行并合并最新目标,关闭重开菜单共用连接内队列,旧回调不会覆盖新预览,失败响应不参与同值去重;请求总时限
15 秒。
- 显示缩放压成一行,使用主机提供的离散百分比并标出推荐值;仍在松手后提交,应用中忽略重复输入。
- 串流屏幕组合只提供主屏/副屏/仅此屏,摘要继续显示当前策略;完整设置页保留全部策略。
-
分辨率列表明确区分已保存项与当前未保存项,删除后不再伪装成保存成功的条目;显式空列表保持为空。低带宽开关合并进列表,旧开关与旧备份迁移为实际的
360p/480p 条目。
- 补齐中英俄繁体说明,DPI
触摸与手柄共用回调;清除旧开关、重复注入、冗余状态/转发方法、临时截图代码;分辨率备份场景并入既有测试,删除独立测试文件、重复断言和多余夹具。

## 为啥要改


快速切码率会因读数增减一行推动整个菜单,迟到的请求也可能覆盖新选择;这些杂鱼状态现在有了明确的收敛顺序。删除分辨率只管理候选列表,保留当前串流参数,避免暗中改分辨率或重算手动码率。

主机 Windows DPI 映射另有索引错误,修复在
AlkaidLab/foundation-sunshine#1182
。客户端继续以主机返回的能力为准;真实 Windows 显示器上的缩放生效尚未验收。

## 验证

- `:app:testNonRootDebugUnitTest`:1,037 项通过,覆盖码率请求交错、超时后返回旧值、慢速正文与 HTTPS
端口发现超时。
- 本地 Debug APK 与 instrumentation APK 构建通过;[最新 Android
CI](https://github.com/qiin2333/moonlight-vplus/actions/runs/40176780082)
验证中。
- Android 15 模拟器 34 项本轮相关回归通过,包含显示卡片交互、手柄焦点导航、分辨率删除和备份恢复;另验收暗色主题、俄语、横屏及
300dp/130% 字体下的紧凑布局与单一码率读数。
- 主题色生成校验和 release 脚本测试通过。
- `git diff --check` 通过。
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