feat(libcairo): implement six region exports #14329

Merged
hyvvs merged 18 commits from upstream-pr/14329 into main 2026-11-08 12:40:37 +00:00
hyvvs commented 2026-11-01 09:31:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hyvvs on 2026-11-01T09:31:35Z.


What

Implement six previously throwing libcairo region exports with typed guest SysV ABI: cairo_region_create, cairo_region_reference, cairo_region_destroy, cairo_region_union_rectangle, cairo_region_get_rectangle, and cairo_region_num_rectangles.

Regions are refcounted; rectangle union uses Cairo/Pixman's canonical representation of nonoverlapping sorted horizontal bands, merging touching and overlapping x intervals and vertically coalescing matching bands. Integer endpoint/span guards return a persistent CAIRO_STATUS_INVALID_SIZE where conversion to Pixman signed coordinates would be nonportable. Zero/negative extent rectangles contribute no area. Invalid rectangle indices produce an empty rectangle (native Cairo leaves those indices unspecified). The behavior follows the public Cairo region implementation and Pixman region algorithm, with divergence described in the libcairo debt file.

Measured progress: 0/161 -> 6/161 (3.73%) callable libcairo exports. The 155 remaining exports still throw. No third-party dependency added.

Open PRs #14258 (matrix), #14327 (image/surface) and #14308 (general unimplemented-return fixes) touch shared Export.cpp, headers or libcairo CMake integration. Their implemented exports are disjoint. The CMake additions and stub deletions may need routine conflict resolution if those PRs merge first.

Coordinated landing order: #14258 (matrix) -> #14327 (image surfaces) -> #14328 (font options) -> #14329 (regions). Symbol implementations are disjoint but the PRs share Cairo export inventory, CMake, and technical-debt files. Each later PR will integrate earlier merged changes before landing; standalone branches are not yet a single integrated Cairo build.

Tested

  • Passed: Windows 64-bit MinGW GCC C++20 linked guest-SysV ABI region geometry/lifecycle tests (-Wall -Wextra -Werror).
  • Passed: Ubuntu WSL GCC C++20 region tests with ASan, UBSan and leak detection (-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror).
  • Passed: Differential comparison against native Cairo 1.18/Pixman: the exact rectangle count, order and coordinates matched after 8,192 successive randomized unions.
  • Passed: Standalone Export.cpp compilation under Windows MinGW and Ubuntu GCC.
  • Passed: python tools/tests/test_progress.py (57 tests); python core/libs/tests/test_public_headers.py --audit-only (398 libraries, 26,175 exports); python tools/progress.py --module libcairo (6/161); python tools/check_conventions.py --base upstream/main; git diff --check; python tools/pr_overlap.py --branch feat/libcairo-regions (shared-file overlaps documented above).
  • Baseline issue: required python tools/check_conventions.py --base origin/main reports unrelated inherited unknown-NID/commit-subject errors because fork origin/main (df9cf83c41) is behind current upstream/main (26fa1212b8). Against current upstream/main, conventions pass.
  • Complete CMake/CTest runtime build and real PS5 hardware not tested; third-party submodules are not initialized in this isolated worktree.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: #14328 (merge-order coordination only; implemented export families are disjoint)
  • Fixes: none
  • Unblocks: none identified
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5106121668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14329). Originally posted by [hyvvs](https://github.com/hyvvs) on 2026-11-01T09:31:35Z. --- ### What Implement six previously throwing `libcairo` region exports with typed guest SysV ABI: `cairo_region_create`, `cairo_region_reference`, `cairo_region_destroy`, `cairo_region_union_rectangle`, `cairo_region_get_rectangle`, and `cairo_region_num_rectangles`. Regions are refcounted; rectangle union uses Cairo/Pixman's canonical representation of nonoverlapping sorted horizontal bands, merging touching and overlapping x intervals and vertically coalescing matching bands. Integer endpoint/span guards return a persistent `CAIRO_STATUS_INVALID_SIZE` where conversion to Pixman signed coordinates would be nonportable. Zero/negative extent rectangles contribute no area. Invalid rectangle indices produce an empty rectangle (native Cairo leaves those indices unspecified). The behavior follows the public [Cairo region implementation](https://chromium.googlesource.com/chromiumos/third_party/cairo/+/master/src/cairo-region.c) and [Pixman region algorithm](https://sources.debian.org/src/pixman/0.42.2-1/pixman/pixman-region.c/), with divergence described in the libcairo debt file. **Measured progress:** 0/161 -> **6/161 (3.73%)** callable libcairo exports. The 155 remaining exports still throw. No third-party dependency added. Open PRs [#14258](https://github.com/boykopovar/AnyPS5/pull/14258) (matrix), [#14327](https://github.com/boykopovar/AnyPS5/pull/14327) (image/surface) and [#14308](https://github.com/boykopovar/AnyPS5/pull/14308) (general unimplemented-return fixes) touch shared `Export.cpp`, headers or libcairo CMake integration. Their implemented exports are disjoint. The CMake additions and stub deletions may need routine conflict resolution if those PRs merge first. **Coordinated landing order:** #14258 (matrix) -> #14327 (image surfaces) -> #14328 (font options) -> #14329 (regions). Symbol implementations are disjoint but the PRs share Cairo export inventory, CMake, and technical-debt files. Each later PR will integrate earlier merged changes before landing; standalone branches are not yet a single integrated Cairo build. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - **Passed:** Windows 64-bit MinGW GCC C++20 linked guest-SysV ABI region geometry/lifecycle tests (`-Wall -Wextra -Werror`). - **Passed:** Ubuntu WSL GCC C++20 region tests with ASan, UBSan and leak detection (`-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror`). - **Passed:** Differential comparison against native Cairo 1.18/Pixman: the exact rectangle count, order and coordinates matched after **8,192 successive randomized unions**. - **Passed:** Standalone `Export.cpp` compilation under Windows MinGW and Ubuntu GCC. - **Passed:** `python tools/tests/test_progress.py` (57 tests); `python core/libs/tests/test_public_headers.py --audit-only` (398 libraries, 26,175 exports); `python tools/progress.py --module libcairo` (6/161); `python tools/check_conventions.py --base upstream/main`; `git diff --check`; `python tools/pr_overlap.py --branch feat/libcairo-regions` (shared-file overlaps documented above). - **Baseline issue:** required `python tools/check_conventions.py --base origin/main` reports unrelated inherited unknown-NID/commit-subject errors because fork `origin/main` (`df9cf83c41`) is behind current upstream/main (`26fa1212b8`). Against current upstream/main, conventions pass. - Complete CMake/CTest runtime build and real PS5 hardware not tested; third-party submodules are not initialized in this isolated worktree. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: #14328 (merge-order coordination only; implemented export families are disjoint) - [x] Fixes: none - [x] Unblocks: none identified - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 06:16:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T06:16:30Z.

Review: COMMENTED


Reviewed — no blocking findings

This implements six libcairo region exports (cairo_region_create, reference, destroy, union_rectangle, get_rectangle and num_rectangles) in a new Region.cpp, with the stubs removed from Export.cpp. The union keeps the region as canonical bands, and a model-based test checks it: 250 random unions against a coverage grid, with the band invariants checked on every step. The Windows CTest run passed guest_cairo_regions.

What I ran

  • Head 65dd172d0d341cfe59d34e7feb94b7f8b7a8343f; base 26fa1212b82f76dd49cf12d65e445d6ff3e0844c. 6 files, +413/-37: libcairo/Region.cpp (new, 201 lines), libcairo/CMakeLists.txt (new, registers guest_cairo_regions), libcairo/Export.cpp (six stubs removed), libcairo/include/InventoryExports.hpp (six declarations with parameters), core/libs/tests/GuestCairoRegions.cpp (new, 179 lines), and docs/dev/debt/libcairo.md.
  • Read Region.cpp in full: the band merge (AppendBand), the union over band boundaries (UnionRectangle), the overflow and size checks (UnionSafely and the bounds in cairo_region_union_rectangle), and the accessors.
  • Read the test's Verify helper and TestRandomUnions in full. The random test checks the banding invariants and compares every cell with a coverage grid.
  • Checked the six declarations against the definitions: all six match, and the six removed stubs are the same names.
  • Hosted: the Windows CTest run passed guest_cairo_regions (Test #2724, 0.04 s). The run reports 2595 cases, all passing.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. ABI audit passed: 161 symbols, no findings.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout; an earlier run was cancelled and the later run succeeded
Mergeability and dependencies passed stack check passed
ABI audit (main-checkout tool) passed 161 symbols, no findings
Declarations match definitions; removed stubs match passed six declarations, six stubs removed
Band merge and coalescing (read) passed by reading touching intervals in a band are merged; identical adjacent bands are coalesced
Overflow and size limits (read) passed by reading x2 and y2 above INT32_MAX, and box widths or heights above INT_MAX, return the error status
Random-union model test (read and hosted) passed TestRandomUnions checks banding and coverage after each of 250 unions
guest_cairo_regions (hosted, Windows) passed Test #2724, 0.04 s
cairo_region_reference on the error region returns null not verified cairo's own behaviour was not compared
Linux build and runtime tests not run Linux is skipped on pull requests
Negative controls not run no local build
Hosted CI passed windows passed (2595 cases); report, conventions and library-portability succeeded; linux, relinkers and write-watch skipped
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed (161 symbols). Stack check: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a local build, and code from this head is not run here.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

  • The error-state behaviour of cairo_region_reference and the other accessors against cairo's own source.
  • Linux behaviour.
  • The debt entry's wording (not read in full).

To get this to a good state

  • Nothing to change.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732730707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14329#pullrequestreview-5732730707). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T06:16:30Z. **Review:** COMMENTED --- # Reviewed — no blocking findings This implements six libcairo region exports (`cairo_region_create`, `reference`, `destroy`, `union_rectangle`, `get_rectangle` and `num_rectangles`) in a new `Region.cpp`, with the stubs removed from `Export.cpp`. The union keeps the region as canonical bands, and a model-based test checks it: 250 random unions against a coverage grid, with the band invariants checked on every step. The Windows CTest run passed `guest_cairo_regions`. ## What I ran - Head `65dd172d0d341cfe59d34e7feb94b7f8b7a8343f`; base `26fa1212b82f76dd49cf12d65e445d6ff3e0844c`. 6 files, +413/-37: `libcairo/Region.cpp` (new, 201 lines), `libcairo/CMakeLists.txt` (new, registers `guest_cairo_regions`), `libcairo/Export.cpp` (six stubs removed), `libcairo/include/InventoryExports.hpp` (six declarations with parameters), `core/libs/tests/GuestCairoRegions.cpp` (new, 179 lines), and `docs/dev/debt/libcairo.md`. - Read `Region.cpp` in full: the band merge (`AppendBand`), the union over band boundaries (`UnionRectangle`), the overflow and size checks (`UnionSafely` and the bounds in `cairo_region_union_rectangle`), and the accessors. - Read the test's `Verify` helper and `TestRandomUnions` in full. The random test checks the banding invariants and compares every cell with a coverage grid. - Checked the six declarations against the definitions: all six match, and the six removed stubs are the same names. - Hosted: the Windows CTest run passed `guest_cairo_regions` (`Test #2724`, 0.04 s). The run reports 2595 cases, all passing. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. ABI audit passed: 161 symbols, no findings. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout; an earlier run was cancelled and the later run succeeded | | Mergeability and dependencies | passed | stack check passed | | ABI audit (main-checkout tool) | passed | 161 symbols, no findings | | Declarations match definitions; removed stubs match | passed | six declarations, six stubs removed | | Band merge and coalescing (read) | passed by reading | touching intervals in a band are merged; identical adjacent bands are coalesced | | Overflow and size limits (read) | passed by reading | `x2` and `y2` above INT32_MAX, and box widths or heights above INT_MAX, return the error status | | Random-union model test (read and hosted) | passed | `TestRandomUnions` checks banding and coverage after each of 250 unions | | `guest_cairo_regions` (hosted, Windows) | passed | `Test #2724`, 0.04 s | | `cairo_region_reference` on the error region returns null | not verified | cairo's own behaviour was not compared | | Linux build and runtime tests | not run | Linux is skipped on pull requests | | Negative controls | not run | no local build | | Hosted CI | passed | windows passed (2595 cases); report, conventions and library-portability succeeded; linux, relinkers and write-watch skipped | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed (161 symbols). Stack check: passed. Hosted: `gh api repos/boykopovar/AnyPS5/commits/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/check-runs`, and the Windows job log. </details> ## Negative control Not run here. A negative control needs a local build, and code from this head is not run here. ## Findings **Blocking** None. **Non-blocking** None. ## Sources - Implementation: https://github.com/boykopovar/AnyPS5/blob/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/core/libs/prx/libcairo/Region.cpp - Test: https://github.com/boykopovar/AnyPS5/blob/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/core/libs/tests/GuestCairoRegions.cpp - Declarations: https://github.com/boykopovar/AnyPS5/blob/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/core/libs/prx/libcairo/include/InventoryExports.hpp - CMake: https://github.com/boykopovar/AnyPS5/blob/65dd172d0d341cfe59d34e7feb94b7f8b7a8343f/core/libs/prx/libcairo/CMakeLists.txt - Windows job log: check-run `windows` on 65dd172d0d341cfe59d34e7feb94b7f8b7a8343f ## Not verified - The error-state behaviour of `cairo_region_reference` and the other accessors against cairo's own source. - Linux behaviour. - The debt entry's wording (not read in full). ## To get this to a good state - Nothing to change.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14329
No description provided.