feat(libcairo): implement rectangle paths and operator state #15430

Closed
hyvvs wants to merge 2 commits from upstream-pr/15430 into main
hyvvs commented 2026-11-03 08:26:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hyvvs on 2026-11-03T08:26:19Z.


What

Implement three additional, previously throwing Cairo exports atop the tested Cairo path-data stack #15324: cairo_rectangle, cairo_set_operator and cairo_get_operator. This is +3 genuinely callable exports over the parent branch, not a claim of +3 upstream merged exports.

cairo_rectangle constructs a closeable rectangular path in Cairo 24.8 device coordinates, applying the existing CTM and device scale while quantizing displacement separately from the starting point. Zero-width/height rectangles and negative dimensions follow Cairo 1.18's actual path stream. The operator defaults to OVER (2), is preserved across nested cairo_save/cairo_restore, and has a typed System V guest ABI. Operator storage does not yet render; paint, clip, stroke and fill remain intentionally unimplemented. No silent fake drawing successes or new third-party dependencies.

Tested

  • Windows 11 MinGW GCC 15.2, -O2 -DNDEBUG -Wall -Wextra -Werror -pedantic: source-linked GuestCairoGeometry.cpp with real Context.cpp, Surface.cpp and Matrix.cpp compiled and passed. Assertions forced active under NDEBUG; ABI pointer types asserted.
  • Linux Ubuntu WSL GCC + ASan/UBSan -O1 -g -DNDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer, leak detection and halt-on-error enabled: source-linked tests passed.
  • Native differential: linked the same test source directly to system Cairo 1.18.0 libcairo.so.2 and compared the entire output byte-for-byte to the MinGW guest implementation and Linux ASan build: 1,035 exact matching rectangle path streams, including 1,024 deterministic random inputs, zero-sized dimensions, negative sizes and transformed CTM cases. This found and fixed initial mismatch in zero-size path segments and separately quantized rectangle displacements. Operators checked for all 29 valid enum values, nested save/restore, default OVER.
  • python tools/progress.py --module libcairo: 75/161 on this branch, compared with 72/161 on its direct parent #15324; 3 new exports. python core/libs/tests/test_public_headers.py --audit-only: 405-library public-header audit passed.
  • git diff --check, strict tools/check_conventions.py and hosted Windows CTest: consult PR checks for latest status; local integrated CMake/CTest was not run.

Not tested: actual PS5 console/firmware, full Cairo rendering, macOS. Branch is stacked: dependency order #14258 (merged) → #14327 → #14328 → #14329 / other concurrent Cairo owner branches → #15315 → #15317 → #15324 → this PR. The new exports do not overlap #15208's eight pattern exports.

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 (no new third-party code)
  • Generic behaviour, not specific to one title
  • Depends on: #15324
  • Fixes: none
  • Unblocks: further Cairo path geometry and fill/clip work
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5134120553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15430). Originally posted by [hyvvs](https://github.com/hyvvs) on 2026-11-03T08:26:19Z. --- ### What Implement **three additional, previously throwing Cairo exports** atop the tested Cairo path-data stack [#15324](https://github.com/boykopovar/AnyPS5/pull/15324): `cairo_rectangle`, `cairo_set_operator` and `cairo_get_operator`. This is +3 genuinely callable exports over the parent branch, not a claim of +3 upstream merged exports. `cairo_rectangle` constructs a closeable rectangular path in Cairo 24.8 device coordinates, applying the existing CTM and device scale while quantizing displacement separately from the starting point. Zero-width/height rectangles and negative dimensions follow Cairo 1.18's actual path stream. The operator defaults to OVER (2), is preserved across nested `cairo_save`/`cairo_restore`, and has a typed System V guest ABI. Operator storage does not yet render; paint, clip, stroke and fill remain intentionally unimplemented. No silent fake drawing successes or new third-party dependencies. ### Tested - Windows 11 MinGW GCC 15.2, `-O2 -DNDEBUG -Wall -Wextra -Werror -pedantic`: source-linked `GuestCairoGeometry.cpp` with real `Context.cpp`, `Surface.cpp` and `Matrix.cpp` compiled and passed. Assertions forced active under `NDEBUG`; ABI pointer types asserted. - Linux Ubuntu WSL GCC + ASan/UBSan `-O1 -g -DNDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer`, leak detection and halt-on-error enabled: source-linked tests passed. - Native differential: linked the same test source directly to system Cairo 1.18.0 `libcairo.so.2` and compared the **entire output byte-for-byte** to the MinGW guest implementation and Linux ASan build: **1,035 exact matching rectangle path streams**, including 1,024 deterministic random inputs, zero-sized dimensions, negative sizes and transformed CTM cases. This found and fixed initial mismatch in zero-size path segments and separately quantized rectangle displacements. Operators checked for all 29 valid enum values, nested save/restore, default OVER. - `python tools/progress.py --module libcairo`: 75/161 on this branch, compared with 72/161 on its direct parent #15324; 3 new exports. `python core/libs/tests/test_public_headers.py --audit-only`: 405-library public-header audit passed. - `git diff --check`, strict `tools/check_conventions.py` and hosted Windows CTest: consult PR checks for latest status; local integrated CMake/CTest was not run. Not tested: actual PS5 console/firmware, full Cairo rendering, macOS. Branch is **stacked**: dependency order #14258 (merged) → #14327 → #14328 → #14329 / other concurrent Cairo owner branches → #15315 → #15317 → #15324 → this PR. The new exports do not overlap #15208's eight pattern exports. ### Checklist - [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 (no new third-party code) - [x] Generic behaviour, not specific to one title - [x] Depends on: #15324 - [x] Fixes: none - [x] Unblocks: further Cairo path geometry and fill/clip work - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-03 08:38:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T08:38:39Z.

Review: DISMISSED


Reviewed — changes requested

cairo_get_target reports NO_MEMORY for an errored context regardless of its actual sticky status, and the new null-context test currently asserts that incorrect result.

What I ran

Reviewed all 15 changed files at head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 against base 4f41f4c375f5abb487dbd184fbc150f31994d762. The current-base merge previews are clean; the declared #15324 head is included in this branch. Environment: Debian 12, Linux x86_64, Python 3.11.2, Git 2.39.5. No compiler was used.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15430 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --json
python3 tools/pr_stack_check.py 15430 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current/stack
gh pr checks 15430 --repo boykopovar/AnyPS5

I also read all changed files across three review portions. The source review and the static checks do not include a build or execution of the C++ tests.

Results

Check Result Note
Diff and conventions passed Whitespace and repository convention checks passed.
ABI audit passed 151 symbols checked; no lexical findings.
Dependency and merge preview passed Clean previews; #15324 is included.
Test registration passed All five new Cairo tests are registered in CMake.
Rectangle assertion quality failed The geometry test prints path data but does not compare it with expected output.
Hosted checks not run All six checks were pending at the final refresh.
Build and CTest not run No local build was run.
Precheck table, raw helper diagnostics and hosted status

The complete precheck table is reproduced below. Its overall “checks failed” conclusion is due to helper scripts missing from the isolated PR snapshot; I reran the ABI audit in the workspace, and manually checked CMake test registration.

| Check | Status | Command / reason |
|---|---|---|
| build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` |
| diff_check | passed | `git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7` |
| conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --title feat(libcairo): implement rectangle paths and operator state --body /tmp/anyps5-pr-precheck/15430-20261103T-current/pr-body.md` |
| changed_export_abi_audit | failed | `/usr/bin/python3 tools/pr_abi_audit.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --json` |
| python_syntax | not_applicable | `No changed Python implementation files.` |
| related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` |
| python_test_registration | not_applicable | `No changed test_*.py files.` |
| live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15430 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current/stack` |
| build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` |
| test_quality_heuristics | failed | `/usr/bin/python3 /tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38 --json core/libs/prx/libcairo/CMakeLists.txt core/libs/prx/libcairo/Context.cpp core/libs/prx/libcairo/Export.cpp core/libs/prx/libcairo/Surface.cpp core/libs/prx/libcairo/include/Context.hpp core/libs/prx/libcairo/include/InventoryExports.hpp core/libs/prx/libcairo/include/Path.hpp core/libs/prx/libcairo/include/Surface.hpp core/libs/prx/libcairo/libcairo.hpp core/libs/tests/GuestCairoContext.cpp core/libs/tests/GuestCairoGeometry.cpp core/libs/tests/GuestCairoGraphicsState.cpp core/libs/tests/GuestCairoPath.cpp core/libs/tests/GuestCairoSurface.cpp docs/dev/debt/libcairo.md` |
| negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` |

Exact missing-helper diagnostics:

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_test_quality.py': [Errno 2] No such file or directory

Direct ABI audit output:

{"status": "passed", "symbol_count": 151, "finding_count": 0}

The test-quality helper also warned that the five new C++ tests might be unregistered. I checked the exact-head core/libs/prx/libcairo/CMakeLists.txt; each has an add_test_executable and add_test registration, so that heuristic warning is a false positive. The remaining geometry assertion gap is visible in the test body: it prints path entries and checks finiteness/bounds but does not assert expected rectangle coordinates or command sequence.

Hosted checks at final refresh:

conventions pending
eligibility pending
intake pending
labels pending
library-portability pending
report pending

Negative control

Not run. I did not alter the source or run a failure-injection test.

Findings

Blocking

  • The context error status is lost by cairo_get_target. cairo_create(nullptr) returns the kNullPointer context, but its singleton target is initialized as CairoSurfaceError(kNoMemory). For other contexts that enter an error later, cairo_get_target also unconditionally returns a kNoMemory surface. Thus callers see status 1 instead of the context’s actual error (for example, status 7 for a null target), and the test currently codifies that wrong result. Cairo 1.18 returns an error surface carrying cr->status. Please preserve the actual context status when returning an error surface, initialize the null-pointer target with kNullPointer, and update/add a test that checks the reported status.

    The null-target initializer can be corrected along these lines:

                                         CairoSurfaceError(kNullPointer));
    

Non-blocking

  • GuestCairoGeometry.cpp prints rectangle path data but does not compare the coordinates or path structure with expected values. The PR reports a separate byte-for-byte comparison against native Cairo, but that comparison is not part of the checked-in CTest, so a future rectangle regression could still pass CI. Adding representative expected-output assertions would make the regression coverage durable.

Sources

Not verified

I did not build or run C++ tests, reproduce the author-reported Windows/ASan runs or native Cairo differential, test another OS, or test console behavior. The six hosted checks were pending at the final refresh.

To get this to a good state

Preserve the actual context status in the returned error surface and update the null-context regression expectation; consider adding durable rectangle-output assertions. Please rerun the no-build precheck and hosted checks on the new head. I will inspect the updated diff and rerun the same no-build commands before reconsidering the review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5749185788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15430#pullrequestreview-5749185788). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T08:38:39Z. **Review:** DISMISSED --- # Reviewed — changes requested `cairo_get_target` reports `NO_MEMORY` for an errored context regardless of its actual sticky status, and the new null-context test currently asserts that incorrect result. ## What I ran Reviewed all 15 changed files at head `88b15f0f3d6897bca2d3add5341413cbe050dfe7` against base `4f41f4c375f5abb487dbd184fbc150f31994d762`. The current-base merge previews are clean; the declared #15324 head is included in this branch. Environment: Debian 12, Linux x86_64, Python 3.11.2, Git 2.39.5. No compiler was used. ```sh git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7 python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15430 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --json python3 tools/pr_stack_check.py 15430 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current/stack gh pr checks 15430 --repo boykopovar/AnyPS5 ``` I also read all changed files across three review portions. The source review and the static checks do not include a build or execution of the C++ tests. ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | Whitespace and repository convention checks passed. | | ABI audit | passed | 151 symbols checked; no lexical findings. | | Dependency and merge preview | passed | Clean previews; #15324 is included. | | Test registration | passed | All five new Cairo tests are registered in CMake. | | Rectangle assertion quality | failed | The geometry test prints path data but does not compare it with expected output. | | Hosted checks | not run | All six checks were pending at the final refresh. | | Build and CTest | not run | No local build was run. | <details> <summary>Precheck table, raw helper diagnostics and hosted status</summary> The complete precheck table is reproduced below. Its overall “checks failed” conclusion is due to helper scripts missing from the isolated PR snapshot; I reran the ABI audit in the workspace, and manually checked CMake test registration. ```text | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` | | diff_check | passed | `git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7` | | conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --title feat(libcairo): implement rectangle paths and operator state --body /tmp/anyps5-pr-precheck/15430-20261103T-current/pr-body.md` | | changed_export_abi_audit | failed | `/usr/bin/python3 tools/pr_abi_audit.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 --json` | | python_syntax | not_applicable | `No changed Python implementation files.` | | related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` | | python_test_registration | not_applicable | `No changed test_*.py files.` | | live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15430 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15430-20261103T-current/stack` | | build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` | | test_quality_heuristics | failed | `/usr/bin/python3 /tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38 --json core/libs/prx/libcairo/CMakeLists.txt core/libs/prx/libcairo/Context.cpp core/libs/prx/libcairo/Export.cpp core/libs/prx/libcairo/Surface.cpp core/libs/prx/libcairo/include/Context.hpp core/libs/prx/libcairo/include/InventoryExports.hpp core/libs/prx/libcairo/include/Path.hpp core/libs/prx/libcairo/include/Surface.hpp core/libs/prx/libcairo/libcairo.hpp core/libs/tests/GuestCairoContext.cpp core/libs/tests/GuestCairoGeometry.cpp core/libs/tests/GuestCairoGraphicsState.cpp core/libs/tests/GuestCairoPath.cpp core/libs/tests/GuestCairoSurface.cpp docs/dev/debt/libcairo.md` | | negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` | ``` Exact missing-helper diagnostics: ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15430-20261103T-current/head-88b15f0f3d68-da273e38/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` Direct ABI audit output: ```json {"status": "passed", "symbol_count": 151, "finding_count": 0} ``` The test-quality helper also warned that the five new C++ tests might be unregistered. I checked the exact-head `core/libs/prx/libcairo/CMakeLists.txt`; each has an `add_test_executable` and `add_test` registration, so that heuristic warning is a false positive. The remaining geometry assertion gap is visible in the test body: it prints path entries and checks finiteness/bounds but does not assert expected rectangle coordinates or command sequence. Hosted checks at final refresh: ```text conventions pending eligibility pending intake pending labels pending library-portability pending report pending ``` </details> ## Negative control Not run. I did not alter the source or run a failure-injection test. ## Findings ### Blocking - **The context error status is lost by `cairo_get_target`.** `cairo_create(nullptr)` returns the `kNullPointer` context, but its singleton target is initialized as `CairoSurfaceError(kNoMemory)`. For other contexts that enter an error later, `cairo_get_target` also unconditionally returns a `kNoMemory` surface. Thus callers see status 1 instead of the context’s actual error (for example, status 7 for a null target), and the test currently codifies that wrong result. Cairo 1.18 returns an error surface carrying `cr->status`. Please preserve the actual context status when returning an error surface, initialize the null-pointer target with `kNullPointer`, and update/add a test that checks the reported status. The null-target initializer can be corrected along these lines: ```suggestion CairoSurfaceError(kNullPointer)); ``` ### Non-blocking - `GuestCairoGeometry.cpp` prints rectangle path data but does not compare the coordinates or path structure with expected values. The PR reports a separate byte-for-byte comparison against native Cairo, but that comparison is not part of the checked-in CTest, so a future rectangle regression could still pass CI. Adding representative expected-output assertions would make the regression coverage durable. ## Sources - [Null-pointer context construction and error singleton at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L74-L85) - [`cairo_get_target` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L274-L279) - [Null-target test currently expecting `NO_MEMORY`](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/tests/GuestCairoContext.cpp#L38-L42) - [Rectangle test output without expected-value assertions](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/tests/GuestCairoGeometry.cpp#L42-L59) - [Cairo 1.18 `cairo_get_target` preserves `cr->status`](https://gitlab.freedesktop.org/cairo/cairo/-/blob/3909090108bb2db55330e3eb148aebe664735363/src/cairo.c#L4188-L4194) ## Not verified I did not build or run C++ tests, reproduce the author-reported Windows/ASan runs or native Cairo differential, test another OS, or test console behavior. The six hosted checks were pending at the final refresh. ## To get this to a good state Preserve the actual context status in the returned error surface and update the null-context regression expectation; consider adding durable rectangle-output assertions. Please rerun the no-build precheck and hosted checks on the new head. I will inspect the updated diff and rerun the same no-build commands before reconsidering the review.
XairRrR commented 2026-11-03 10:15:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T10:15:01Z.

Review: DISMISSED


Reviewed — changes requested

The merged tree builds and the libcairo tests pass. However, guest_cairo_geometry never compares the rectangle output with expected values: a deliberately wrong fourth corner still passes. Separately, cairo_rectangle decides which edges to emit from the user-space width and height, not from the quantized device displacements, so its path stream for near-zero sizes differs from the one it gives for exact zero.

What I ran

Head 88b15f0f3d6897bca2d3add5341413cbe050dfe7 merged with --no-ff into main 4f41f4c375f5abb487dbd184fbc150f31994d762 (merged tree 9915e2c985d9937ed1b4049a184a2ce9150a17f7). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -j8 --test-load 32 -R guest_cairo --output-on-failure
ctest --test-dir build -R public_headers --output-on-failure
# mutation: Context.cpp:525 -> AppendLine(state, x + 2 * hx, y + hy + 1)
ninja -C build -j32 -l32 guest_cairo_geometry_tests libcairo
ctest --test-dir build -R guest_cairo_geometry --output-on-failure
# probe: one GuestCairoGeometry.cpp case {5, 8, 9, 0} -> {5, 8, 9, 0.001}
ninja -C build -j32 -l32 guest_cairo_geometry_tests libcairo
build/tests/guest_cairo_geometry_tests
# restored both files from the merged tree, rebuilt, ran the test again
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py passed
Configure / build / libs (script) ok
Script test run (2464 tests) no new failures, no timeouts; 4 failures that also fail on main (guest_interfaces, guest_socket_options_multicast, unwrap_self_…, vector_constant_factor_tininess) are not this PR's. guest_net_ctl was skipped, which also happens on main.
public_headers + 64 public_headers_compile_* 65/65 passed
guest_cairo_matrix/surface/context/graphics_state/path/geometry 6/6 passed, each under 0.05 s
Mutation of the rectangle's fourth corner guest_cairo_geometry still passed
Worktree after restore git status --porcelain empty
Vulkan validation not applicable (no AGC/shader/VideoOut files)
Probe output: exact-zero vs 0.001 height
rect 4.00000 2.00000 0.00000 7.00000 : 7 | 0 2 4.00000 2.00000 | 1 2 4.00000 9.00000 | 3 1 | 0 2 4.00000 2.00000
rect 5.00000 8.00000 9.00000 0.00100 : 9 | 0 2 5.00000 8.00000 | 1 2 14.00000 8.00000 | 1 2 5.00000 8.00000 | 3 1 | 0 2 5.00000 8.00000

For the unmodified case {5, 8, 9, 0} the PR emits M(5,8) L(14,8) Z M(5,8), which is 7 elements.

Negative control

Restoring the production files from main would remove Context.cpp and Surface.cpp. The new tests would then fail to link, which proves nothing about the rectangle. So I used a targeted mutation instead: I changed the fourth rectangle corner in Context.cpp:525 to x + 2 * hx, y + hy + 1 and rebuilt. guest_cairo_geometry still passed. The test would also pass if cairo_rectangle emitted nothing. I restored the merged file, rebuilt, and confirmed the worktree is clean.

Findings

Blocking

  1. guest_cairo_geometry does not test cairo_rectangle. core/libs/tests/GuestCairoGeometry.cpp L42–L61 prints each path. It only asserts that the status is 0, the headers are well formed and the coordinates are finite. MarcZX10 raised this as non-blocking. I'm adding new evidence and treating it as blocking: the mutation above shows that a wrong rectangle passes CI, and cairo_rectangle is the main export this PR adds. The 1,035-case comparison with native Cairo described in the PR is not in the repository. Suggested fix: check expected element streams (types and points) for the fixed cases: positive, negative, zero and near-zero sizes, and the transformed CTM. The expected values could come from the native comparison the author already ran, or the printed native output could be checked in as a table.

  2. cairo_rectangle gives different paths for inputs with identical device displacements. core/libs/prx/libcairo/Context.cpp L507–L527 decides with width != 0 and height != 0 on the user-space values. A height of 0.001 quantizes to a device displacement of 0, exactly like 0. Yet the PR emits M L(14,8) L(5,8) Z for the first and M L(14,8) Z for the second (probe above). Cairo builds a rectangle as move, three relative lines and close on 24.8 fixed values, so both inputs must produce the same stream. This contradicts the description's claim that zero-size rectangles "follow Cairo 1.18's actual path stream": that is only true when the size is exactly zero. The root cause seems to be in cairo_close_path L585–L592. As I read Cairo's _cairo_path_fixed_close_path, it first adds a line_to back to the last move point and then drops the final LINE_TO before adding CLOSE_PATH. This PR's close does neither, and the rectangle code works around that with the user-space zero checks. My reading of the Cairo source is from memory: I had no network or native Cairo here. The inconsistency between the two inputs, though, is shown by the PR's own output. Suggested fix: implement that close-path step, emit the three lines from the quantized wx/wy/hx/hy without user-space conditions, and add the near-zero case to the test from finding 1.

Non-blocking

  1. Broken source link in the debt file. docs/dev/debt/libcairo.md:23 changes the gist revision of the "selected export metadata" link from a3838ac54ebcc0bbfeb3cc46002a9a2dcce4dbdc to a3838ac54ebcc46002a9a2dcce4dbdc. Nine characters are gone, so the citation no longer points at that revision. Restore the original 40-character hash.

  2. Debt headings and entry style. docs/dev/debt/libcairo.md:7 and :11 add ### Functional image and surface exports and ### Functional context and coordinate transforms. Neither is a section of the TechnicalDebt.md index (Build, Silent stubs, Unknown function info, Functional), and no other debt file uses them. CONTRIBUTING asks for entries under the index sections, stating the gap first. The new entries mostly describe implemented behaviour and test runs ("Windows and Linux sanitizer tests … passed"). Move them under ### Functional and reduce them to what is still open: no rasterizer, an unused operator, native behaviour not measured, and so on.

  3. The NID table no longer matches its text. The text says "86 remaining callable NIDs", which matches the 86 throwing exports in Export.cpp. The table still has 129 rows: the surface, operator and rectangle rows were removed, but the 43 rows for context, state and path exports implemented in this branch (cairo_create, cairo_move_to, cairo_set_dash, …) remain. Remove those rows too, or keep the full map and drop the word "remaining".

On the existing review

MarcZX10's blocking point is that cairo_get_target should return an error surface that carries cr->status, for example 7 for cairo_create(NULL). I don't think it holds. As I recall Cairo 1.18's _cairo_surface_create_in_error, the context-only statuses (INVALID_RESTORE, INVALID_MATRIX, NULL_POINTER, INVALID_DASH, …) fall through to the NO_MEMORY nil surface. Only the surface-level statuses get their own nil surfaces. That matches what the PR does (L74–L79, L274–L280) and what the test expects. I could not confirm this against native Cairo here; the author's native comparison would settle it.

Not verified

  • Native Cairo 1.18 behaviour: no Cairo library or source on this machine and no network. The Cairo semantics cited above come from my reading of the source, not from a run.
  • The author's Windows/MinGW, ASan/UBSan and 1,035-case native comparison runs.
  • Console or firmware behaviour.
  • The diff against main contains the whole declared stack (#15324 and its parents, +65 implemented functions, per the progress report), not only the three exports in the title. I reviewed all of it, but focused on the rectangle and operator code.

To get this to a good state

  • Make guest_cairo_geometry assert expected rectangle path streams, so that the mutation above fails.
  • Make the rectangle and close-path code depend only on the quantized device values, and add a near-zero-size case.
  • Optionally fix the gist hash, the debt headings and the NID table.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750398360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15430#pullrequestreview-5750398360). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T10:15:01Z. **Review:** DISMISSED --- # Reviewed — changes requested The merged tree builds and the libcairo tests pass. However, `guest_cairo_geometry` never compares the rectangle output with expected values: a deliberately wrong fourth corner still passes. Separately, `cairo_rectangle` decides which edges to emit from the user-space width and height, not from the quantized device displacements, so its path stream for near-zero sizes differs from the one it gives for exact zero. ## What I ran Head `88b15f0f3d6897bca2d3add5341413cbe050dfe7` merged with `--no-ff` into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` (merged tree `9915e2c985d9937ed1b4049a184a2ce9150a17f7`). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, `BUILD_TESTING=ON`. ```sh git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...88b15f0f3d6897bca2d3add5341413cbe050dfe7 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -j8 --test-load 32 -R guest_cairo --output-on-failure ctest --test-dir build -R public_headers --output-on-failure # mutation: Context.cpp:525 -> AppendLine(state, x + 2 * hx, y + hy + 1) ninja -C build -j32 -l32 guest_cairo_geometry_tests libcairo ctest --test-dir build -R guest_cairo_geometry --output-on-failure # probe: one GuestCairoGeometry.cpp case {5, 8, 9, 0} -> {5, 8, 9, 0.001} ninja -C build -j32 -l32 guest_cairo_geometry_tests libcairo build/tests/guest_cairo_geometry_tests # restored both files from the merged tree, rebuilt, ran the test again git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | passed | | Configure / build / `libs` (script) | ok | | Script test run (2464 tests) | no new failures, no timeouts; 4 failures that also fail on `main` (`guest_interfaces`, `guest_socket_options_multicast`, `unwrap_self_…`, `vector_constant_factor_tininess`) are not this PR's. `guest_net_ctl` was skipped, which also happens on `main`. | | `public_headers` + 64 `public_headers_compile_*` | 65/65 passed | | `guest_cairo_matrix/surface/context/graphics_state/path/geometry` | 6/6 passed, each under 0.05 s | | Mutation of the rectangle's fourth corner | `guest_cairo_geometry` **still passed** | | Worktree after restore | `git status --porcelain` empty | | Vulkan validation | not applicable (no AGC/shader/VideoOut files) | <details><summary>Probe output: exact-zero vs 0.001 height</summary> ``` rect 4.00000 2.00000 0.00000 7.00000 : 7 | 0 2 4.00000 2.00000 | 1 2 4.00000 9.00000 | 3 1 | 0 2 4.00000 2.00000 rect 5.00000 8.00000 9.00000 0.00100 : 9 | 0 2 5.00000 8.00000 | 1 2 14.00000 8.00000 | 1 2 5.00000 8.00000 | 3 1 | 0 2 5.00000 8.00000 ``` For the unmodified case `{5, 8, 9, 0}` the PR emits `M(5,8) L(14,8) Z M(5,8)`, which is 7 elements. </details> ## Negative control Restoring the production files from `main` would remove `Context.cpp` and `Surface.cpp`. The new tests would then fail to link, which proves nothing about the rectangle. So I used a targeted mutation instead: I changed the fourth rectangle corner in `Context.cpp:525` to `x + 2 * hx, y + hy + 1` and rebuilt. **`guest_cairo_geometry` still passed.** The test would also pass if `cairo_rectangle` emitted nothing. I restored the merged file, rebuilt, and confirmed the worktree is clean. ## Findings ### Blocking 1. **`guest_cairo_geometry` does not test `cairo_rectangle`.** [`core/libs/tests/GuestCairoGeometry.cpp` L42–L61](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/tests/GuestCairoGeometry.cpp#L42-L61) prints each path. It only asserts that the status is 0, the headers are well formed and the coordinates are finite. MarcZX10 raised this as non-blocking. I'm adding new evidence and treating it as blocking: the mutation above shows that a wrong rectangle passes CI, and `cairo_rectangle` is the main export this PR adds. The 1,035-case comparison with native Cairo described in the PR is not in the repository. Suggested fix: check expected element streams (types and points) for the fixed cases: positive, negative, zero and near-zero sizes, and the transformed CTM. The expected values could come from the native comparison the author already ran, or the printed native output could be checked in as a table. 2. **`cairo_rectangle` gives different paths for inputs with identical device displacements.** [`core/libs/prx/libcairo/Context.cpp` L507–L527](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L507-L527) decides with `width != 0` and `height != 0` on the user-space values. A height of `0.001` quantizes to a device displacement of 0, exactly like `0`. Yet the PR emits `M L(14,8) L(5,8) Z` for the first and `M L(14,8) Z` for the second (probe above). Cairo builds a rectangle as move, three relative lines and close on 24.8 fixed values, so both inputs must produce the same stream. This contradicts the description's claim that zero-size rectangles "follow Cairo 1.18's actual path stream": that is only true when the size is exactly zero. The root cause seems to be in [`cairo_close_path` L585–L592](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L585-L592). As I read Cairo's `_cairo_path_fixed_close_path`, it first adds a `line_to` back to the last move point and then drops the final `LINE_TO` before adding `CLOSE_PATH`. This PR's close does neither, and the rectangle code works around that with the user-space zero checks. My reading of the Cairo source is from memory: I had no network or native Cairo here. The inconsistency between the two inputs, though, is shown by the PR's own output. Suggested fix: implement that close-path step, emit the three lines from the quantized `wx/wy/hx/hy` without user-space conditions, and add the near-zero case to the test from finding 1. ### Non-blocking 3. **Broken source link in the debt file.** `docs/dev/debt/libcairo.md:23` changes the gist revision of the "selected export metadata" link from `a3838ac54ebcc0bbfeb3cc46002a9a2dcce4dbdc` to `a3838ac54ebcc46002a9a2dcce4dbdc`. Nine characters are gone, so the citation no longer points at that revision. Restore the original 40-character hash. 4. **Debt headings and entry style.** `docs/dev/debt/libcairo.md:7` and `:11` add `### Functional image and surface exports` and `### Functional context and coordinate transforms`. Neither is a section of the `TechnicalDebt.md` index (Build, Silent stubs, Unknown function info, Functional), and no other debt file uses them. CONTRIBUTING asks for entries under the index sections, stating the gap first. The new entries mostly describe implemented behaviour and test runs ("Windows and Linux sanitizer tests … passed"). Move them under `### Functional` and reduce them to what is still open: no rasterizer, an unused operator, native behaviour not measured, and so on. 5. **The NID table no longer matches its text.** The text says "86 remaining callable NIDs", which matches the 86 throwing exports in `Export.cpp`. The table still has 129 rows: the surface, operator and rectangle rows were removed, but the 43 rows for context, state and path exports implemented in this branch (`cairo_create`, `cairo_move_to`, `cairo_set_dash`, …) remain. Remove those rows too, or keep the full map and drop the word "remaining". ### On the existing review MarcZX10's blocking point is that `cairo_get_target` should return an error surface that carries `cr->status`, for example 7 for `cairo_create(NULL)`. I don't think it holds. As I recall Cairo 1.18's `_cairo_surface_create_in_error`, the context-only statuses (`INVALID_RESTORE`, `INVALID_MATRIX`, `NULL_POINTER`, `INVALID_DASH`, …) fall through to the `NO_MEMORY` nil surface. Only the surface-level statuses get their own nil surfaces. That matches what the PR does ([L74–L79](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L74-L79), [L274–L280](https://github.com/boykopovar/AnyPS5/blob/88b15f0f3d6897bca2d3add5341413cbe050dfe7/core/libs/prx/libcairo/Context.cpp#L274-L280)) and what the test expects. I could not confirm this against native Cairo here; the author's native comparison would settle it. ## Not verified - Native Cairo 1.18 behaviour: no Cairo library or source on this machine and no network. The Cairo semantics cited above come from my reading of the source, not from a run. - The author's Windows/MinGW, ASan/UBSan and 1,035-case native comparison runs. - Console or firmware behaviour. - The diff against `main` contains the whole declared stack (#15324 and its parents, +65 implemented functions, per the progress report), not only the three exports in the title. I reviewed all of it, but focused on the rectangle and operator code. ## To get this to a good state - Make `guest_cairo_geometry` assert expected rectangle path streams, so that the mutation above fails. - Make the rectangle and close-path code depend only on the quantized device values, and add a near-zero-size case. - Optionally fix the gist hash, the debt headings and the NID table. <!-- anyps5-bots job=3215 head=88b15f0f3d6897bca2d3add5341413cbe050dfe7 -->

Pull request closed

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!15430
No description provided.