feat(libcairo): implement path geometry and operator state #18381

Merged
bipinkrish merged 5 commits from upstream-pr/18381 into main 2026-11-12 09:15:47 +00:00
bipinkrish commented 2026-11-11 13:03:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bipinkrish on 2026-11-11T13:03:25Z.


What

Bring the missing Cairo path geometry from #15430 and #15675 onto current main. cairo_rectangle adds a closed path in quantized device coordinates, and cairo_path_extents bounds line segments and cubic extrema in user coordinates. It writes each requested coordinate independently. cairo_set_operator and cairo_get_operator preserve the operator across nested save and restore.

#15324 already supplies the path storage and is merged. This PR preserves the five original commits from hyvvs and Dean Galvin, including the rectangle closure, cubic rounding, closed-point and nullable-output corrections. It updates the debt file for the four exports. PS5 firmware behavior remains unmeasured.

Tested

Ubuntu 24.04.4, x86-64, GCC 13.3, Release. Tested head 4d309832c35f385a79fe2e33b2f14bb4362ebdc5.

  • Built the Cairo module and its test targets from source using the pinned submodules. ctest --test-dir build -R '^(guest_cairo_.*|public_headers)$' --output-on-failure passed 11 of 11 tests.
  • Compared the raw and NID-patched exports with native Cairo 1.18.0. The copied paths and extents matched for 1,500 deterministic mixed paths and 500 rectangles with positive, negative and zero dimensions. Each nullable output position and all 29 operators through nested save and restore also matched. The path cases used non-unit device scales, rotations and translations.
  • Rebuilt the original Cairo sources and ran both new test executables against that module. Each failed on its expected throwing export, cairo_get_operator and cairo_path_extents.
  • git diff --check and tools/check_conventions.py --base upstream/main passed. The required origin/main check reported the same four pre-existing commit-subject errors as the unmodified upstream baseline because the fork's main is behind.
  • Ran tools/pr_overlap.py --branch codex/cairo-path-geometry against 1,982 open PRs on upstream main 1e8dfd69d55. The branch merged cleanly with that base. The checker flagged shared debt edits in #15208, #16895 and #16954 and a CMake test registration in #16954. It returned 2 because #14212 already conflicts with main, so I reviewed its Cairo debt diff directly. Its only shared edit removes the stale callable count. I reviewed all four branch diffs and found no shared export implementation.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5259966872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18381). Originally posted by [bipinkrish](https://github.com/bipinkrish) on 2026-11-11T13:03:25Z. --- ### What Bring the missing Cairo path geometry from #15430 and #15675 onto current main. `cairo_rectangle` adds a closed path in quantized device coordinates, and `cairo_path_extents` bounds line segments and cubic extrema in user coordinates. It writes each requested coordinate independently. `cairo_set_operator` and `cairo_get_operator` preserve the operator across nested save and restore. #15324 already supplies the path storage and is merged. This PR preserves the five original commits from hyvvs and Dean Galvin, including the rectangle closure, cubic rounding, closed-point and nullable-output corrections. It updates the debt file for the four exports. PS5 firmware behavior remains unmeasured. ### 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. --> Ubuntu 24.04.4, x86-64, GCC 13.3, Release. Tested head `4d309832c35f385a79fe2e33b2f14bb4362ebdc5`. - Built the Cairo module and its test targets from source using the pinned submodules. `ctest --test-dir build -R '^(guest_cairo_.*|public_headers)$' --output-on-failure` passed 11 of 11 tests. - Compared the raw and NID-patched exports with native Cairo 1.18.0. The copied paths and extents matched for 1,500 deterministic mixed paths and 500 rectangles with positive, negative and zero dimensions. Each nullable output position and all 29 operators through nested save and restore also matched. The path cases used non-unit device scales, rotations and translations. - Rebuilt the original Cairo sources and ran both new test executables against that module. Each failed on its expected throwing export, `cairo_get_operator` and `cairo_path_extents`. - `git diff --check` and `tools/check_conventions.py --base upstream/main` passed. The required `origin/main` check reported the same four pre-existing commit-subject errors as the unmodified upstream baseline because the fork's main is behind. - Ran `tools/pr_overlap.py --branch codex/cairo-path-geometry` against 1,982 open PRs on upstream main `1e8dfd69d55`. The branch merged cleanly with that base. The checker flagged shared debt edits in #15208, #16895 and #16954 and a CMake test registration in #16954. It returned 2 because #14212 already conflicts with main, so I reviewed its Cairo debt diff directly. Its only shared edit removes the stale callable count. I reviewed all four branch diffs and found no shared export implementation. ### 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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-11 16:08:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T16:08:44Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4d309832c3:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_cairo_geometry_tests, guest_cairo_path_extents_tests built cleanly.
  • CTest (guest_cairo_geometry, guest_cairo_path_extents):
    1/2 Test #4219: guest_cairo_path_extents .........   Passed    0.01 sec
    2/2 Test #4218: guest_cairo_geometry .............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libcairo/Context.cpp, core/libs/prx/libcairo/Export.cpp, core/libs/prx/libcairo/include/Context.hpp, core/libs/prx/libcairo/include/InventoryExports.hpp, core/libs/prx/libcairo/include/Path.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libcairo/Context.cpp that cairo_set_operator and cairo_get_operator correctly initialize compositionOperator to 2 (CAIRO_OPERATOR_OVER), preserve operator state across cairo_save and cairo_restore through SavedState, and return fallback 2 when context is null or invalid.
    • Verified in core/libs/prx/libcairo/Context.cpp that cairo_rectangle correctly computes device distance and target device scale via Fixed(), generates closed subpaths matching native Cairo canonicalization for positive, negative, and zero dimensions, and handles allocation failure cleanly.
    • Verified in core/libs/prx/libcairo/Context.cpp that cairo_path_extents independently checks each output pointer (x1, y1, x2, y2) for nullptr prior to writing, safely returns (0, 0, 0, 0) for null/invalid contexts and degenerate/move-only paths, and correctly maps device bounding ranges through cairo_matrix_invert and UserPoint.
    • Verified in core/libs/prx/libcairo/Context.cpp that AddCubicRange accurately solves cubic Bézier first-derivative roots for both linear (a == 0, b != 0) and quadratic cases, discards negative discriminants, evaluates only interior parametric values t ∈ (0, 1), and quantizes extrema through Fixed().
    • Verified in core/libs/prx/libcairo/Context.cpp that cairo_close_path checks hasCurrent, removes redundant collinear line-to segments before recording type 3 close commands, and appends a restart move-to point.
    • Verified that all modified source, header, and test files (Context.cpp, Export.cpp, Context.hpp, Path.hpp, InventoryExports.hpp, GuestCairoGeometry.cpp, GuestCairoPathExtents.cpp) adhere strictly to AGENTS.md rules with zero inline comments, no stubbed success returns, and accurate debt tracking in docs/dev/debt/libcairo.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5861723969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18381#pullrequestreview-5861723969). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T16:08:44Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4d309832c3`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_cairo_geometry_tests`, `guest_cairo_path_extents_tests` built cleanly. - **CTest** (`guest_cairo_geometry`, `guest_cairo_path_extents`): ``` 1/2 Test #4219: guest_cairo_path_extents ......... Passed 0.01 sec 2/2 Test #4218: guest_cairo_geometry ............. Passed 0.01 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libcairo/Context.cpp`, `core/libs/prx/libcairo/Export.cpp`, `core/libs/prx/libcairo/include/Context.hpp`, `core/libs/prx/libcairo/include/InventoryExports.hpp`, `core/libs/prx/libcairo/include/Path.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified in core/libs/prx/libcairo/Context.cpp that cairo_set_operator and cairo_get_operator correctly initialize compositionOperator to 2 (CAIRO_OPERATOR_OVER), preserve operator state across cairo_save and cairo_restore through SavedState, and return fallback 2 when context is null or invalid. - Verified in core/libs/prx/libcairo/Context.cpp that cairo_rectangle correctly computes device distance and target device scale via Fixed(), generates closed subpaths matching native Cairo canonicalization for positive, negative, and zero dimensions, and handles allocation failure cleanly. - Verified in core/libs/prx/libcairo/Context.cpp that cairo_path_extents independently checks each output pointer (x1, y1, x2, y2) for nullptr prior to writing, safely returns (0, 0, 0, 0) for null/invalid contexts and degenerate/move-only paths, and correctly maps device bounding ranges through cairo_matrix_invert and UserPoint. - Verified in core/libs/prx/libcairo/Context.cpp that AddCubicRange accurately solves cubic Bézier first-derivative roots for both linear (a == 0, b != 0) and quadratic cases, discards negative discriminants, evaluates only interior parametric values t ∈ (0, 1), and quantizes extrema through Fixed(). - Verified in core/libs/prx/libcairo/Context.cpp that cairo_close_path checks hasCurrent, removes redundant collinear line-to segments before recording type 3 close commands, and appends a restart move-to point. - Verified that all modified source, header, and test files (Context.cpp, Export.cpp, Context.hpp, Path.hpp, InventoryExports.hpp, GuestCairoGeometry.cpp, GuestCairoPathExtents.cpp) adhere strictly to AGENTS.md rules with zero inline comments, no stubbed success returns, and accurate debt tracking in docs/dev/debt/libcairo.md. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!18381
No description provided.