feat(libcairo): implement cairo_arc and cairo_arc_negative #28015

Open
Ducengarth wants to merge 2 commits from upstream-pr/28015 into main
Ducengarth commented 2026-11-28 04:31:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-28T04:31:20Z.


What

Implements cairo_arc (NID R0TePTSHd2k) and cairo_arc_negative (NID 2w5H3b3yPqw) in libcairo.

  • Both forward to the bundled Cairo 1.18.0 (aps5_cairo_arc, aps5_cairo_arc_negative), like cairo_move_to, cairo_line_to and cairo_curve_to in Context.cpp. cmake/Cairo.cmake already generates the aps5_ names for every cairo.h function, and cairo-arc.c is already part of cairo_backend.
  • In Cairo 1.18.0 (cairo.c, cairo-default-context.c), cairo_arc raises angle2 by whole turns until it is not below angle1, and cairo_arc_negative lowers it until it is not above. A radius of 0 or less adds two line_to calls to the center. Otherwise the arc first lines to its start point, which becomes a move_to when there is no current point. A context already in error is left unchanged.
  • Path.hpp declares both next to the other path operations. The stubs and their inventory declarations are removed, and a debt fragment removes the two rows from the callable exports table. The path operations have no entry of their own: the existing Context.cpp entries already cover running Cairo 1.18.0 without Sony's patches, none of which touches arcs, and the unmeasured console behaviour.

Tested

Windows 11 Pro, WinLibs GCC 15.2.0 UCRT, Release, BUILD_TESTING=ON, on 8b2baa04b84 (current main plus this commit):

  • guest_cairo_arc (new), guest_cairo_path, guest_cairo_path_extents and guest_cairo_context pass, 3 of 3 runs.
  • guest_cairo_arc compares the copied path, path status, cairo_has_current_point and the current point exactly with direct calls to the bundled Cairo on a separate native context. It covers both functions, three starting states (no path, after move_to, after line_to), three transforms (identity, translate plus scale, singular scale that puts the context in error) and ten arcs:
    • a quarter turn;
    • a wrapped quarter turn;
    • a full turn;
    • three and a half turns;
    • a large negative wrap;
    • equal angles;
    • zero, negative and 1e-9 radii;
    • a far-off center.
  • It also checks results that do not depend on the native call:
    • the start point (move_to to the arc start with no current point, line_to to it after one);
    • the end point and current point;
    • that cairo_arc adds only curves after the start;
    • the fill extents of positive and negative quarter arcs (a quarter circle against three quarters), and of wrapped half arcs (the upper half against the lower half);
    • that radii of 0 and -2 leave only move_to/line_to elements at the center.
  • Three mutations each fail the test at the native comparison, and the restored code passes:
    • cairo_arc forwarding to aps5_cairo_arc_negative;
    • cairo_arc swapping the angles;
    • cairo_arc_negative forwarding to aps5_cairo_arc.
  • python3 tools/check_conventions.py passes, as do core/libs/tests/test_public_headers.py --audit-only and tools/debt_fold.py --check.
  • python3 tools/pr_overlap.py --branch reports no shared exports.
    • #27995 (cairo_pattern_reference) removes the neighbouring line in include/InventoryExports.hpp, so whichever merges second needs a one-line rebase.
    • #19529 (cairo_in_fill) shares Context.cpp, Path.hpp and the CMake file. git merge-tree shows that its conflicts with this branch are the same four files it already conflicts in against main.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for drawing positive and negative arcs in Cairo paths, with controls for the arc’s center, radius, and angles.
  • Bug Fixes
    • Arc path behavior now matches native Cairo across varied angles, transforms, and path states, including wrapped angles and nonpositive radii.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5536670495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015). Originally posted by [Ducengarth](https://github.com/Ducengarth) on 2026-11-28T04:31:20Z. --- ### What Implements `cairo_arc` (NID `R0TePTSHd2k`) and `cairo_arc_negative` (NID `2w5H3b3yPqw`) in libcairo. - Both forward to the bundled Cairo 1.18.0 (`aps5_cairo_arc`, `aps5_cairo_arc_negative`), like `cairo_move_to`, `cairo_line_to` and `cairo_curve_to` in `Context.cpp`. `cmake/Cairo.cmake` already generates the `aps5_` names for every `cairo.h` function, and `cairo-arc.c` is already part of `cairo_backend`. - In Cairo 1.18.0 ([cairo.c](https://gitlab.freedesktop.org/cairo/cairo/-/blob/1.18.0/src/cairo.c#L1853-L1920), [cairo-default-context.c](https://gitlab.freedesktop.org/cairo/cairo/-/blob/1.18.0/src/cairo-default-context.c#L774-L813)), `cairo_arc` raises `angle2` by whole turns until it is not below `angle1`, and `cairo_arc_negative` lowers it until it is not above. A radius of 0 or less adds two `line_to` calls to the center. Otherwise the arc first lines to its start point, which becomes a `move_to` when there is no current point. A context already in error is left unchanged. - `Path.hpp` declares both next to the other path operations. The stubs and their inventory declarations are removed, and a debt fragment removes the two rows from the callable exports table. The path operations have no entry of their own: the existing `Context.cpp` entries already cover running Cairo 1.18.0 without Sony's patches, none of which touches arcs, and the unmeasured console behaviour. ### Tested Windows 11 Pro, WinLibs GCC 15.2.0 UCRT, Release, `BUILD_TESTING=ON`, on `8b2baa04b84` (current `main` plus this commit): - `guest_cairo_arc` (new), `guest_cairo_path`, `guest_cairo_path_extents` and `guest_cairo_context` pass, 3 of 3 runs. - `guest_cairo_arc` compares the copied path, path status, `cairo_has_current_point` and the current point exactly with direct calls to the bundled Cairo on a separate native context. It covers both functions, three starting states (no path, after `move_to`, after `line_to`), three transforms (identity, translate plus scale, singular scale that puts the context in error) and ten arcs: - a quarter turn; - a wrapped quarter turn; - a full turn; - three and a half turns; - a large negative wrap; - equal angles; - zero, negative and 1e-9 radii; - a far-off center. - It also checks results that do not depend on the native call: - the start point (`move_to` to the arc start with no current point, `line_to` to it after one); - the end point and current point; - that `cairo_arc` adds only curves after the start; - the fill extents of positive and negative quarter arcs (a quarter circle against three quarters), and of wrapped half arcs (the upper half against the lower half); - that radii of 0 and -2 leave only `move_to`/`line_to` elements at the center. - Three mutations each fail the test at the native comparison, and the restored code passes: - `cairo_arc` forwarding to `aps5_cairo_arc_negative`; - `cairo_arc` swapping the angles; - `cairo_arc_negative` forwarding to `aps5_cairo_arc`. - `python3 tools/check_conventions.py` passes, as do `core/libs/tests/test_public_headers.py --audit-only` and `tools/debt_fold.py --check`. - `python3 tools/pr_overlap.py --branch` reports no shared exports. - #27995 (`cairo_pattern_reference`) removes the neighbouring line in `include/InventoryExports.hpp`, so whichever merges second needs a one-line rebase. - #19529 (`cairo_in_fill`) shares `Context.cpp`, `Path.hpp` and the CMake file. `git merge-tree` shows that its conflicts with this branch are the same four files it already conflicts in against `main`. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for drawing positive and negative arcs in Cairo paths, with controls for the arc’s center, radius, and angles. * **Bug Fixes** * Arc path behavior now matches native Cairo across varied angles, transforms, and path states, including wrapped angles and nonpositive radii. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-28 04:34:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T04:34:09Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8b2baa04b8:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_cairo_arc_tests built cleanly.
  • CTest (guest_cairo_arc):
    1/1 Test #6334: guest_cairo_arc ..................   Passed    0.08 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libcairo/Context.cpp, core/libs/prx/libcairo/Export.cpp, 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:
    • core/libs/prx/libcairo/Context.cpp: verified cairo_arc and cairo_arc_negative signature, calling convention APS5_VABI, and backend forwarding match aps5_cairo_arc / aps5_cairo_arc_negative without pointer dereferencing on context (handled downstream by cairo)
    • core/libs/prx/libcairo/include/Path.hpp: verified prototype declarations for cairo_arc and cairo_arc_negative match Cairo C API standards and upstream declarations
    • core/libs/prx/libcairo/Export.cpp and InventoryExports.hpp: verified removal of old stub implementations and unneeded declarations
    • docs/dev/debt/changes/feat-libcairo-arc.md: confirmed technical debt fragment properly registers removal of cairo_arc and cairo_arc_negative from debt inventory
    • core/libs/tests/GuestCairoArc.cpp: verified exhaustive test suite covering comparisons against native Cairo backend, quadrant arcs, angle wrapping, lines before arcs, and non-positive radii

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6095826680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015#pullrequestreview-6095826680). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-28T04:34:09Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `8b2baa04b8`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_cairo_arc_tests` built cleanly. - **CTest** (`guest_cairo_arc`): ``` 1/1 Test #6334: guest_cairo_arc .................. Passed 0.08 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libcairo/Context.cpp`, `core/libs/prx/libcairo/Export.cpp`, `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**: - core/libs/prx/libcairo/Context.cpp: verified cairo_arc and cairo_arc_negative signature, calling convention APS5_VABI, and backend forwarding match aps5_cairo_arc / aps5_cairo_arc_negative without pointer dereferencing on context (handled downstream by cairo) - core/libs/prx/libcairo/include/Path.hpp: verified prototype declarations for cairo_arc and cairo_arc_negative match Cairo C API standards and upstream declarations - core/libs/prx/libcairo/Export.cpp and InventoryExports.hpp: verified removal of old stub implementations and unneeded declarations - docs/dev/debt/changes/feat-libcairo-arc.md: confirmed technical debt fragment properly registers removal of cairo_arc and cairo_arc_negative from debt inventory - core/libs/tests/GuestCairoArc.cpp: verified exhaustive test suite covering comparisons against native Cairo backend, quadrant arcs, angle wrapping, lines before arcs, and non-positive radii Looks Good To Me
MarcZX10 commented 2026-11-28 08:13:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T08:13:06Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code forwards both arc functions to the bundled Cairo backend and includes focused behavioral tests.

What I ran

Reviewed head 8b2baa04b844469062fc9cba0d58f9c7d5ee0d96. I used repo_read.py to inspect the prepared diff and the relevant code at that head. No build or tests were run during this review; the Windows test results in the PR description are author-reported.

Results

Check Result Note
Diff and changed files passed All seven changed files read
Targeted callers and declarations passed Arc forwarding and test registration inspected
Build and tests not run Only author-reported results available

Findings

Blocking

None.

Non-blocking

None.

Not verified

No runtime behavior, build, or tests were independently verified. The author reports the new arc test and related checks pass on Windows 11 with GCC 15.2.0. No changed files were excluded from review.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096700856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015#pullrequestreview-6096700856). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T08:13:06Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code forwards both arc functions to the bundled Cairo backend and includes focused behavioral tests. ## What I ran Reviewed head `8b2baa04b844469062fc9cba0d58f9c7d5ee0d96`. I used `repo_read.py` to inspect the prepared diff and the relevant code at that head. No build or tests were run during this review; the Windows test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All seven changed files read | | Targeted callers and declarations | passed | Arc forwarding and test registration inspected | | Build and tests | not run | Only author-reported results available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No runtime behavior, build, or tests were independently verified. The author reports the new arc test and related checks pass on Windows 11 with GCC 15.2.0. No changed files were excluded from review. ## To get this to a good state Nothing is required.
Plyxen commented 2026-11-28 11:11:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T11:11:33Z.

Review: APPROVED


Checked head 8b2baa04b8 on Windows 11 with WinLibs GCC 15.2 (Release), on main c6331cc61b.

  • tools/check_conventions.py --head and tools/debt_fold.py --check pass, and the full build succeeds.
  • All 24 focused tests pass, including guest_cairo_arc and guest_cairo_scaled_font.
  • Full CPU suite (5,145 tests): the only failures are windows_read_trap_unknown, which fails on main too (fixed in #28028), and the frame_capture_minimize load timeout.

From reading the code: both exports forward to the bundled cairo, and CheckMatchesNative compares the copied path, its status and the current point with native cairo. It covers both directions, three path prefixes, a singular matrix, zero and negative radii, and angle spans past 2π. The prototypes match the cairo_arc signature through the static_asserts.

#27995 removes the neighbouring cairo_pattern_reference line in include/InventoryExports.hpp, so the two don't apply together. Whichever merges second needs a one-line rebase.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6097408925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015#pullrequestreview-6097408925). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T11:11:33Z. **Review:** APPROVED --- Checked head `8b2baa04b8` on Windows 11 with WinLibs GCC 15.2 (Release), on `main` `c6331cc61b`. - `tools/check_conventions.py --head` and `tools/debt_fold.py --check` pass, and the full build succeeds. - All 24 focused tests pass, including `guest_cairo_arc` and `guest_cairo_scaled_font`. - Full CPU suite (5,145 tests): the only failures are `windows_read_trap_unknown`, which fails on `main` too (fixed in #28028), and the `frame_capture_minimize` load timeout. From reading the code: both exports forward to the bundled cairo, and `CheckMatchesNative` compares the copied path, its status and the current point with native cairo. It covers both directions, three path prefixes, a singular matrix, zero and negative radii, and angle spans past 2π. The prototypes match the `cairo_arc` signature through the `static_assert`s. #27995 removes the neighbouring `cairo_pattern_reference` line in `include/InventoryExports.hpp`, so the two don't apply together. Whichever merges second needs a one-line rebase. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 08:17:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:17:58Z.

Review: COMMENTED


The Linux arc fixture passed. It checks clockwise and counterclockwise arcs, current-point updates, and transformed and singular inputs against the pinned Cairo backend.

I compiled the changed translation unit together with the fixture and linked the existing Linux guest libraries.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165968116 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015#pullrequestreview-6165968116). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T08:17:58Z. **Review:** COMMENTED --- The Linux arc fixture passed. It checks clockwise and counterclockwise arcs, current-point updates, and transformed and singular inputs against the pinned Cairo backend. I compiled the changed translation unit together with the fixture and linked the existing Linux guest libraries. AI-assisted: yes.
MarcZX10 commented 2026-12-04 14:19:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T14:19:57Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at 46f95bc26e1bfc3570ac1cb4880ac602e1a03ec8 forwards both arc functions to the bundled Cairo backend, and I found no blocking defects in the changed code.

What I ran

Static review only; no build or tests were run. The prepared diff and file snapshots were inspected, and the pinned reader search found the two forwarding calls.

python3 repo_read.py search aps5_cairo_arc

All seven files listed under reviewed in files.json were read; files.json lists no excluded files. The reader’s additional cat request could not run because its logging attempted to write to the read-only review folder.

Results

Check Result Note
Changed code review passed All seven changed files reviewed
Tests and build not run No local execution
Author-reported checks not run Reported in the PR description only

Negative control

The PR description reports three forwarding and angle mutations failed the new test, with restored code passing. I did not run those mutations.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

I did not independently run the test suite or verify behavior on a physical console. The PR’s test and convention-check results are author-reported.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6190564488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28015#pullrequestreview-6190564488). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T14:19:57Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `46f95bc26e1bfc3570ac1cb4880ac602e1a03ec8` forwards both arc functions to the bundled Cairo backend, and I found no blocking defects in the changed code. ## What I ran Static review only; no build or tests were run. The prepared diff and file snapshots were inspected, and the pinned reader search found the two forwarding calls. ```text python3 repo_read.py search aps5_cairo_arc ``` All seven files listed under `reviewed` in `files.json` were read; `files.json` lists no excluded files. The reader’s additional `cat` request could not run because its logging attempted to write to the read-only review folder. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All seven changed files reviewed | | Tests and build | not run | No local execution | | Author-reported checks | not run | Reported in the PR description only | ## Negative control The PR description reports three forwarding and angle mutations failed the new test, with restored code passing. I did not run those mutations. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Arc forwarding in Context.cpp](https://github.com/boykopovar/AnyPS5/blob/46f95bc26e1bfc3570ac1cb4880ac602e1a03ec8/core/libs/prx/libcairo/Context.cpp#L311-L320) - [Arc declarations in Path.hpp](https://github.com/boykopovar/AnyPS5/blob/46f95bc26e1bfc3570ac1cb4880ac602e1a03ec8/core/libs/prx/libcairo/include/Path.hpp#L35-L38) - [Arc behavior coverage in GuestCairoArc.cpp](https://github.com/boykopovar/AnyPS5/blob/46f95bc26e1bfc3570ac1cb4880ac602e1a03ec8/core/libs/tests/GuestCairoArc.cpp) ## Not verified I did not independently run the test suite or verify behavior on a physical console. The PR’s test and convention-check results are author-reported. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28015:upstream-pr/28015'
git switch 'upstream-pr/28015'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28015'
git switch 'upstream-pr/28015'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28015'
git switch 'upstream-pr/28015'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28015'
git switch 'main'
git merge --squash 'upstream-pr/28015'
git switch 'main'
git merge --ff-only 'upstream-pr/28015'
git switch 'main'
git merge 'upstream-pr/28015'
git push origin 'main'
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!28015
No description provided.