Skip to content

fix(stream): use measured viewport for pip sizing#50

Open
qiin2333 wants to merge 2 commits into
masterfrom
codex/fix-pip-viewport-sizing
Open

fix(stream): use measured viewport for pip sizing#50
qiin2333 wants to merge 2 commits into
masterfrom
codex/fix-pip-viewport-sizing

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 在串流视频根容器上记录 ArkUI 实际布局尺寸,画中画/浮窗场景优先用这个尺寸重新计算 XComponent。
  • 保留原来的全屏和窗口尺寸兜底逻辑,没有把 ArkUI layout 状态塞进 service,职责更清爽一点。
  • 画面尺寸变化后同步更新 displayInfo 和 PanZoom 父容器尺寸,避免缩放触控坐标继续被旧尺寸带偏。裁切小问题,别再装大尾巴狼了。

为啥要改

用户反馈画中画里“画面居中了但是裁切,没有缩放”。之前修复主要依赖 window/drawableRect,在 PiP 这种系统容器里可能仍然拿到偏大的窗口尺寸。ArkUI 的 onAreaChange 才是当前页面真实可绘制区域,用它做 XComponent 等比适配更贴近实际布局。

验证

  • git diff --check -- entry/src/main/ets/pages/StreamPage.ets
  • 尝试运行:NODE_PATH=/Users/mac/Program/moonlight-harmony/node_modules DEVECO_SDK_HOME=/Users/mac/ohos-sdk-cache/6.1-Release-mac/sdk-ci-shape node /Applications/DevEco-Studio.app/Contents/tools/hvigor/hvigor/bin/hvigor.js --no-daemon --mode module -p module=entry assembleHap
    • 当前本机阻塞在 :nativelib:default@BuildNativeWithCmake,缓存 SDK 的 clang++ 链接阶段走到 macOS ld64.lld,不识别 OHOS linker 参数(如 --build-id=sha1--no-undefined-z)。

需要测试和回归

  • 画中画/PiP:横屏串流进入画中画后,画面应完整等比缩小,不再居中裁切。
  • 普通浮窗:拖拽/调整窗口大小后,XComponent 应继续按窗口内容区等比适配。
  • 全屏串流:首次进入、横竖屏切换、服务端分辨率变化后不应出现额外黑边或拉伸。
  • 缩放模式:双指缩放开启后,触控坐标不应相对画面偏移。
  • stretchVideo 开启时:仍应按设置填满容器,不被本次 measured viewport 逻辑破坏。

Summary by CodeRabbit

优化与修复

  • Bug Fixes

    • 改进视频视口尺寸测量与缓存机制,减少抖动与重复计算
    • 在全屏及窗口模式下优先使用已测量的视口尺寸,缺失时自动回退
    • 容器/视口区域变化时,能更准确同步调整视频显示与映射
  • Performance

    • 对视口变化更新进行阈值去抖,降低频繁重算带来的卡顿

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7f21dff4-2473-4525-9aa8-8b7732f5891a

📥 Commits

Reviewing files that changed from the base of the PR and between c6205c5 and 4fed200.

📒 Files selected for processing (1)
  • entry/src/main/ets/pages/StreamPage.ets
🚧 Files skipped from review as they are similar to previous changes (1)
  • entry/src/main/ets/pages/StreamPage.ets

📝 Walkthrough

Walkthrough

StreamPage 新增 videoViewportWidthVp/HeightVp 状态字段及对应的 getMeasuredVideoViewportSize()handleVideoViewportAreaChange() 方法,后者带阈值去抖。recalculateXComponentSize()configureStreamWindow() 均改为优先使用测量视口尺寸计算 XComponent 大小,同时引入 DisplaySize 类型。

Changes

视频视口尺寸缓存与 XComponent 计算优先策略

Layer / File(s) Summary
视口状态字段、缓存方法与去抖处理
entry/src/main/ets/pages/StreamPage.ets
引入 DisplaySize 类型;新增 videoViewportWidthVp/HeightVp 状态字段;新增 handleVideoViewportAreaChange(阈值去抖 + 缓存更新 + 触发重算)与 getMeasuredVideoViewportSize(返回 DisplaySize | null);onAreaChange 改为调用 handleVideoViewportAreaChange
recalculateXComponentSize 中的测量视口优先逻辑
entry/src/main/ets/pages/StreamPage.ets
全屏分支:measuredViewport 存在时跳过 updateScreenSize();非全屏分支:优先使用 measuredViewport,无测量值时才异步获取当前窗口视口尺寸。
configureStreamWindow 中的测量视口优先策略
entry/src/main/ets/pages/StreamPage.ets
getMeasuredVideoViewportSize() 更新 displayInfo.screenWidth/Height,并根据测量视口是否存在在 calculateXComponentSizeForViewportcalculateXComponentSize 之间切换。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • AlkaidLab/moonlight-harmony#47:同样修改 StreamPage.ets 中 XComponent 尺寸计算逻辑,引入 StreamWindowManager.getCurrentWindowViewportSize()calculateXComponentSizeForViewport(),是本次测量视口优先策略的直接前置变更。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 标题准确概括了主要改动:在 PiP 尺寸计算中使用测量的视口尺寸,清晰指出了问题域(stream)和解决方案(measured viewport)。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-pip-viewport-sizing

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.

@coderabbitai coderabbitai Bot 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.

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 `@entry/src/main/ets/pages/StreamPage.ets`:
- Around line 1253-1256: The code updates displayInfo.screenWidth and
screenHeight when viewportSize is available, but fails to synchronize the
panZoomHandler parent container size, which causes touch coordinate offset
issues during scaling interactions. After updating the displayInfo dimensions in
the if block (where viewportSize is checked), also call
panZoomHandler.setParentSize() with the same width and height values. Apply this
same synchronization fix to all locations where displayInfo screen dimensions
are updated, including the section referenced at lines 1259-1265.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aed9c4ce-4aad-4e4a-867f-751af505006d

📥 Commits

Reviewing files that changed from the base of the PR and between 77a07ae and c6205c5.

📒 Files selected for processing (1)
  • entry/src/main/ets/pages/StreamPage.ets

Comment thread entry/src/main/ets/pages/StreamPage.ets
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.

1 participant