feat(libcairo): implement cairo_in_fill #19529

Open
maxperso wants to merge 3 commits from upstream-pr/19529 into main
maxperso commented 2026-11-13 13:38:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maxperso on 2026-11-13T13:38:16Z.


What

Implements cairo_in_fill in libcairo: whether a point is inside the current path under the context's fill rule.

  • InFill.cpp ports the winding test of Cairo 1.18.0 (src/cairo-path-in-fill.c), its curve flattening (_cairo_spline_decompose in src/cairo-spline.c) and its unclamped 24.8 conversion (_cairo_fixed_from_double in src/cairo-fixed-private.h), with the Cairo licence header as the other derived files carry it.
  • cairo_in_fill in Context.cpp feeds it the stored path elements. It returns 0 for a null or failed context and for a path whose fill is empty (no curve and no line that moves), transforms the query with the current matrix and the target's device scale, ignores a pending cairo_move_to as Cairo does, closes the last subpath, and answers 1 on an edge before reading the fill rule.
  • Two inputs throw through NotImplemented_nid_no_patch and are recorded in docs/dev/debt/libcairo.md: a query whose device coordinates are not finite (Cairo skips the transform while it tracks its matrices as identity, a flag this context does not keep) and, off the edges, a fill rule other than winding and even-odd (Cairo reaches ASSERT_NOT_REACHED).
  • #19098 is moving libcairo onto Cairo built from source, and #19141 has not reached contexts and paths yet. Until it does this keeps the hand-written context answering; guest_cairo_in_fill only uses public exports, so it can stay as a regression test for that port.
  • Followed from the Cairo source even where it looks wrong: a curve whose control points coincide with its ends is dropped without moving the current point when the query is not above, below or left of its bounding box (_cairo_in_fill_curve_to returns when _cairo_spline_init fails), and the query wraps every 16777216 device units.

Tested

macOS 26.6.2 on an Apple M3 Pro, full build for x86-64 run under Rosetta 2 (Apple clang 21.0.0, Release), at main 174899a5cc:

  • ctest -R guest_cairo: 13 of 13 pass, including the new guest_cairo_in_fill. It checks hand-derived cases (edges, corners, ties of the 1/256 rounding, both fill rules, implicit closing, pending moves, lone points, the matrix and the device scale, curve apexes, the dropped curves, the two throwing inputs), 36000 probes on random polygons against an independent winding-number count (2285 inside, 21744 outside, 11971 on an edge) and 5293 probes on random curves against a 512-step flattening, skipping probes within 0.75 of the curve.
  • public_headers, export_gap and progress_report pass.
  • Outside the repository: the functions of InFill.cpp returned the same edge flag and winding as a Python transliteration of the Cairo sources on 300000 random queries (coordinates up to the 32-bit limits, so integer wrap-around included) and the same fixed-point value on 75175 doubles. The same 12000 queries ran clean under AddressSanitizer and UndefinedBehaviorSanitizer.
  • Each of 15 deliberate faults in the new code (rounding, edge test, final close, pending move, empty fill, fill rule, matrix, device scale, tolerance, dropped curve) makes guest_cairo_in_fill fail.

Not tested on Linux or Windows. Not compared with a native Cairo build or a console.

cairo_in_fill stays in the pending count of the progress report because of its two throwing inputs.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5296454978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19529). Originally posted by [maxperso](https://github.com/maxperso) on 2026-11-13T13:38:16Z. --- ### What Implements `cairo_in_fill` in libcairo: whether a point is inside the current path under the context's fill rule. - `InFill.cpp` ports the winding test of Cairo 1.18.0 (`src/cairo-path-in-fill.c`), its curve flattening (`_cairo_spline_decompose` in `src/cairo-spline.c`) and its unclamped 24.8 conversion (`_cairo_fixed_from_double` in `src/cairo-fixed-private.h`), with the Cairo licence header as the other derived files carry it. - `cairo_in_fill` in `Context.cpp` feeds it the stored path elements. It returns 0 for a null or failed context and for a path whose fill is empty (no curve and no line that moves), transforms the query with the current matrix and the target's device scale, ignores a pending `cairo_move_to` as Cairo does, closes the last subpath, and answers 1 on an edge before reading the fill rule. - Two inputs throw through `NotImplemented_nid_no_patch` and are recorded in `docs/dev/debt/libcairo.md`: a query whose device coordinates are not finite (Cairo skips the transform while it tracks its matrices as identity, a flag this context does not keep) and, off the edges, a fill rule other than winding and even-odd (Cairo reaches `ASSERT_NOT_REACHED`). - #19098 is moving libcairo onto Cairo built from source, and #19141 has not reached contexts and paths yet. Until it does this keeps the hand-written context answering; `guest_cairo_in_fill` only uses public exports, so it can stay as a regression test for that port. - Followed from the Cairo source even where it looks wrong: a curve whose control points coincide with its ends is dropped without moving the current point when the query is not above, below or left of its bounding box (`_cairo_in_fill_curve_to` returns when `_cairo_spline_init` fails), and the query wraps every 16777216 device units. ### Tested macOS 26.6.2 on an Apple M3 Pro, full build for x86-64 run under Rosetta 2 (Apple clang 21.0.0, Release), at `main` 174899a5cc: - `ctest -R guest_cairo`: 13 of 13 pass, including the new `guest_cairo_in_fill`. It checks hand-derived cases (edges, corners, ties of the 1/256 rounding, both fill rules, implicit closing, pending moves, lone points, the matrix and the device scale, curve apexes, the dropped curves, the two throwing inputs), 36000 probes on random polygons against an independent winding-number count (2285 inside, 21744 outside, 11971 on an edge) and 5293 probes on random curves against a 512-step flattening, skipping probes within 0.75 of the curve. - `public_headers`, `export_gap` and `progress_report` pass. - Outside the repository: the functions of `InFill.cpp` returned the same edge flag and winding as a Python transliteration of the Cairo sources on 300000 random queries (coordinates up to the 32-bit limits, so integer wrap-around included) and the same fixed-point value on 75175 doubles. The same 12000 queries ran clean under AddressSanitizer and UndefinedBehaviorSanitizer. - Each of 15 deliberate faults in the new code (rounding, edge test, final close, pending move, empty fill, fill rule, matrix, device scale, tolerance, dropped curve) makes `guest_cairo_in_fill` fail. Not tested on Linux or Windows. Not compared with a native Cairo build or a console. `cairo_in_fill` stays in the pending count of the progress report because of its two throwing inputs. ### 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 - [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)
MarcZX10 commented 2026-11-23 05:07:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T05:07:02Z.

Review: APPROVED


Reviewed — looks good

The implementation and its regression test are coherent at the reviewed head; author-reported checks were not run in this review.

What I ran

Reviewed head 8d38a62c4518d905fbb2700eab6a19e816ab23f1. I read the prepared description, commits, manifest, diff, and the full text of changed InFill.cpp, plus relevant Context.hpp and Context.cpp context using repo_read.py. No test or build command was run. The author reports macOS tests and external comparisons in the PR description; these were not independently verified.

Results

Check Result Note
Code review passed Main implementation and test source read
Build and tests not run Results in PR description are author-reported
Linux, Windows, console not run Not tested by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not read the full text of every changed file or run the reported checks. The included changed-file content for Context.cpp was inspected around the implementation, and InFill.cpp was read in full. Other changed files, including GuestCairoInFill.cpp, were inspected through the diff only. The manifest indicates the changed files are included; files.json was not available through the reader. The author reports no Linux or Windows run, native Cairo comparison, or console measurement.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016814179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19529#pullrequestreview-6016814179). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T05:07:02Z. **Review:** APPROVED --- # Reviewed — looks good The implementation and its regression test are coherent at the reviewed head; author-reported checks were not run in this review. ## What I ran Reviewed head `8d38a62c4518d905fbb2700eab6a19e816ab23f1`. I read the prepared description, commits, manifest, diff, and the full text of changed `InFill.cpp`, plus relevant `Context.hpp` and `Context.cpp` context using `repo_read.py`. No test or build command was run. The author reports macOS tests and external comparisons in the PR description; these were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Main implementation and test source read | | Build and tests | not run | Results in PR description are author-reported | | Linux, Windows, console | not run | Not tested by author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not read the full text of every changed file or run the reported checks. The included changed-file content for `Context.cpp` was inspected around the implementation, and `InFill.cpp` was read in full. Other changed files, including `GuestCairoInFill.cpp`, were inspected through the diff only. The manifest indicates the changed files are included; `files.json` was not available through the reader. The author reports no Linux or Windows run, native Cairo comparison, or console measurement. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 15:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:23:21Z.

Review: COMMENTED


This head conflicts with current main in the cairo CMake target, context, export table, and inventory header. The current cairo_in_fill export still uses the stub, so the important integration is to move its binding to the new typed implementation while retaining the other cairo changes on main.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6172781236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19529#pullrequestreview-6172781236). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T15:23:21Z. **Review:** COMMENTED --- This head conflicts with current main in the cairo CMake target, context, export table, and inventory header. The current `cairo_in_fill` export still uses the stub, so the important integration is to move its binding to the new typed implementation while retaining the other cairo changes on main. AI-assisted: yes.
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/19529:upstream-pr/19529'
git switch 'upstream-pr/19529'

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