Skip to content

test(compositor): share the D3D11 render-test harness - #933

Open
quotentiroler wants to merge 1 commit into
getopenscreen:mainfrom
quotentiroler:test/compositor-shared-render-harness
Open

quotentiroler wants to merge 1 commit into
getopenscreen:mainfrom
quotentiroler:test/compositor-shared-render-harness

Conversation

@quotentiroler

@quotentiroler quotentiroler commented Sep 30, 2026 •

Copy link
Copy Markdown

Summary

Five Windows render tests in crates/compositor/tests/ each carried their own copy of the same setup: an identical gpu() probe, and a synthetic NV12 source frame (FakeFrame, MockFrame, GridFrame, Source). In each frame type, texture creation, map/unmap and the AVFrame wrapping were the same ~40 lines around a different pixel fill. Four tests also carried the same write_ppm.

tests/common/ now holds them once:

  • gpu(), unchanged.
  • Nv12Frame::new(gpu, size, luma, chroma): luma(col, row) fills the Y plane and chroma(bx, by) returns [Cb, Cr] for each 2×2 block. Each test keeps its own fill as a small builder next to its existing doc comment (fake_frame, mock_frame, grid_frame, source).
  • write_ppm, unchanged, with the doc comment it had in output_geometry_golden.rs.

The D3D pieces sit behind #[cfg(windows)], so output_geometry_golden.rs, which also runs on macOS, only pulls in write_ppm.

Net: 11 files, 479 lines removed and 264 added. No test logic, assertion or threshold changes.

Related issue

None. Found while auditing the crate for duplicated code.

Type of change

  • Bug fix
  • Feature
  • Enhancement
  • Documentation
  • Refactor / maintenance
  • Performance
  • Security

Release impact

  • Patch
  • Minor
  • Major / breaking change
  • No release note needed

Desktop impact

  • Windows
  • macOS
  • Linux
  • Installer / packaging
  • Not platform-specific

Test code only. Nothing under src/ changes.

Screenshots / video

Not applicable.

Testing

The render tests were not run locally. The machine I made this on has no MSVC toolchain, and in CI rust-windows-compositor-check runs cargo check --all-targets, which compiles these tests but doesn't execute them. What was checked instead:

  • CI on the fork: all three Rust jobs pass (Windows cargo check --all-targets, Linux and macOS cargo test): https://github.com/quotentiroler/openscreen/actions/runs/36782635810
  • Same textures: the new Nv12Frame fill writes byte-for-byte what each old loop wrote. I checked this with a simulation of the old and new loops, for every fill in the five tests, at several sizes and with a padded row pitch. One point worth stating: the old constant-chroma loops wrote every column of the UV plane, alternating U/V, and the new code writes once per 2×2 block. Those are equal because every source size these tests use is even. NV12 requires even dimensions, and the aspect-ratio cases already round with & !1.
  • Unchanged helpers: gpu() and write_ppm are moved without changes.

If you can run cargo test -p openscreen-compositor --tests on a Windows machine with a GPU, that exercises the moved code for real.

Summary by CodeRabbit

  • Tests
    • Standardized image-output and video-frame setup across compositor rendering tests. Existing rendering scenarios, benchmark cases, image exports, and assertions remain unchanged.
    • Expanded shared test support for Windows-based GPU and NV12 frame setup. This does not change the compositor’s end-user features or rendering behavior.

Five Windows render tests each carried their own copy of the same setup:
an identical `gpu()` probe, and a synthetic NV12 source frame (FakeFrame,
MockFrame, GridFrame, Source) whose texture creation, map/unmap and
AVFrame wrapping were the same ~40 lines around a different pixel fill.
Four tests also carried the same `write_ppm`.

tests/common/ now holds them once:

- `gpu()`, unchanged.
- `Nv12Frame::new(gpu, size, luma, chroma)`: `luma(col, row)` fills the
  Y plane, `chroma(bx, by)` returns `[Cb, Cr]` for each 2x2 block. Each
  test keeps its own fill as a small builder next to its existing doc
  comment (`fake_frame`, `mock_frame`, `grid_frame`, `source`).
- `write_ppm`, unchanged, with the doc comment it had in
  output_geometry_golden.

The D3D pieces sit behind `#[cfg(windows)]`, so output_geometry_golden,
which also runs on macOS, only pulls in `write_ppm`.

The textures are byte-for-byte what the old loops wrote. The old
constant-chroma loops wrote every column of the UV plane alternating
U/V, which equals one write per 2x2 block because every source size
these tests use is even (NV12 requires it, and the aspect-ratio cases
already round with `& !1`).

No test logic, assertion or threshold changes.
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 0502ef07-535c-4179-b9db-cf7747a0bdbb

📥 Commits

Reviewing files that changed from the base of the PR and between 409cf4d and df7a3ab.

📒 Files selected for processing (11)
  • crates/compositor/tests/animated_background.rs
  • crates/compositor/tests/common/mod.rs
  • crates/compositor/tests/common/nv12.rs
  • crates/compositor/tests/cursor_model_render.rs
  • crates/compositor/tests/cursor_tap_render.rs
  • crates/compositor/tests/device_frame_render.rs
  • crates/compositor/tests/follow_camera_render.rs
  • crates/compositor/tests/output_geometry_golden.rs
  • crates/compositor/tests/privacy_blur_under_zoom.rs
  • crates/compositor/tests/screen_trail_render.rs
  • crates/compositor/tests/window_frame_render.rs

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


📝 Walkthrough

Walkthrough

Compositor tests now use shared helpers for GPU setup, synthetic NV12 frame creation, and PPM image writing. The render test scenarios and assertions remain unchanged.

Changes

Compositor test utilities

Layer / File(s) Summary
Shared GPU, NV12, and PPM helpers
crates/compositor/tests/common/*
The common test module adds shared NV12 frame creation and PPM writing helpers, plus Windows-only exports for GPU and frame utilities.
NV12 render-test setup
crates/compositor/tests/cursor_model_render.rs, crates/compositor/tests/cursor_tap_render.rs, crates/compositor/tests/device_frame_render.rs, crates/compositor/tests/follow_camera_render.rs, crates/compositor/tests/screen_trail_render.rs
These tests replace local GPU and NV12 frame setup with the shared helpers. Their test scenarios and assertions remain unchanged.
PPM writer reuse
crates/compositor/tests/animated_background.rs, crates/compositor/tests/output_geometry_golden.rs, crates/compositor/tests/privacy_blur_under_zoom.rs, crates/compositor/tests/window_frame_render.rs
These tests import the common PPM writer and remove their local implementations.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to df7a3

This test-only refactor consolidates fixture setup and image writing without an identified behavior change. It is mergeable after normal checks; Windows render tests have not been executed locally.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: sharing the D3D11 render-test harness across compositor tests.
Description check ✅ Passed The description covers the refactor scope, issue status, change type, release and platform impact, screenshots, and testing. It also documents that Windows render tests were not executed and identifie…
Docstring Coverage ✅ Passed Docstring coverage is 84.75% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 11 files.
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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.98.1)

Clippy execution failed


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.

This branch has not been deployed

No deployments
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