feat(libcairo): implement cairo_pattern_reference #27995

Open
sammybourke42666-debug wants to merge 1 commit from upstream-pr/27995 into main
sammybourke42666-debug commented 2026-11-28 02:07:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sammybourke42666-debug on 2026-11-28T02:07:57Z.


What

Forward the guest cairo_pattern_reference export to the pinned Cairo backend. It returns the same pointer and increments the reference count of live patterns, including allocated error patterns. Null and static error patterns pass through unchanged. The prototype and implementation match src/cairo.h and src/cairo-pattern.c in Sony’s published Cairo source for PS5 system software 9.00 and later. Sony Cairo source

The progress scanner reports libcairo increasing from 108/161 to 109/161, with cairo_pattern_reference as the only newly implemented export.

Tested

Windows 11 x64 (build 26200), WinLibs GCC 15.2.0, Release, at a4ebd9084c plus this change.

  • ctest --test-dir ../b -R '^guest_cairo_surface_pattern_' --output-on-failure passed all three tests, including native reference ownership and static and allocated error patterns.
  • A native probe linked to the pinned Cairo backend passed reference-count, surface-lifetime, null and error-pattern checks.
  • ctest --test-dir ../b -R '^public_headers$' --output-on-failure passed.
  • The before/after tools/progress.py --compare report lists one newly implemented export and the same declared total.

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

Summary by CodeRabbit

  • New Features
    • Added support for referencing Cairo patterns.
  • Tests
    • Added coverage for valid, null, and error patterns, including reference counts and error status.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5535671277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995). Originally posted by [sammybourke42666-debug](https://github.com/sammybourke42666-debug) on 2026-11-28T02:07:57Z. --- ### What Forward the guest `cairo_pattern_reference` export to the pinned Cairo backend. It returns the same pointer and increments the reference count of live patterns, including allocated error patterns. Null and static error patterns pass through unchanged. The prototype and implementation match `src/cairo.h` and `src/cairo-pattern.c` in Sony’s published Cairo source for PS5 system software 9.00 and later. [Sony Cairo source](https://www.playstation.com/en-us/oss/ps5/cairo/) The progress scanner reports `libcairo` increasing from 108/161 to 109/161, with `cairo_pattern_reference` as the only newly implemented export. ### Tested Windows 11 x64 (build 26200), WinLibs GCC 15.2.0, Release, at `a4ebd9084c` plus this change. - `ctest --test-dir ../b -R '^guest_cairo_surface_pattern_' --output-on-failure` passed all three tests, including native reference ownership and static and allocated error patterns. - A native probe linked to the pinned Cairo backend passed reference-count, surface-lifetime, null and error-pattern checks. - `ctest --test-dir ../b -R '^public_headers$' --output-on-failure` passed. - The before/after `tools/progress.py --compare` report lists one newly implemented export and the same declared total. <!-- 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. --> ### 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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for referencing Cairo patterns. * **Tests** * Added coverage for valid, null, and error patterns, including reference counts and error status. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-28 02:10:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T02:10:01Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_cairo_surface_pattern_tests built cleanly.
  • CTest (guest_cairo_surface_pattern_patterns, guest_cairo_surface_pattern_source, guest_cairo_surface_pattern_mask):
    1/3 Test #6304: guest_cairo_surface_pattern_source .....   Passed    0.01 sec
    2/3 Test #6303: guest_cairo_surface_pattern_patterns ...   Passed    0.01 sec
    3/3 Test #6305: guest_cairo_surface_pattern_mask .......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libcairo/Export.cpp, core/libs/prx/libcairo/SurfacePattern.cpp, core/libs/prx/libcairo/include/InventoryExports.hpp, core/libs/prx/libcairo/include/SurfacePattern.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libcairo/SurfacePattern.cpp: cairo_pattern_reference forwards correctly to aps5_cairo_pattern_reference with Backend(pattern) and casts return value to CairoPattern* matching Cairo C API semantics.
    • Verified upstream Cairo semantics: cairo_pattern_reference handles nullptr safely (returns nullptr without error), handles static error patterns without crashing, and increments refcount for valid and allocated error patterns.
    • Verified core/libs/prx/libcairo/include/SurfacePattern.hpp and InventoryExports.hpp: prototype updated from int return stub to CairoPattern* APS5_VABI cairo_pattern_reference(CairoPattern* pattern) and stub cleanly removed from Export.cpp and InventoryExports.hpp.
    • Verified AGENTS.md compliance: docs/dev/debt/changes/feat-cairo-pattern-reference.md correctly adds technical debt removal fragment; no prohibited comments added.
    • Verified tests in core/libs/tests/GuestCairoSurfacePattern.cpp: thoroughly tests live pattern refcounting, nullptr input, static error pattern (null pattern), and allocated error pattern refcounting and destruction.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6095131587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6095131587). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-28T02:10:01Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a832030cd3`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_cairo_surface_pattern_tests` built cleanly. - **CTest** (`guest_cairo_surface_pattern_patterns`, `guest_cairo_surface_pattern_source`, `guest_cairo_surface_pattern_mask`): ``` 1/3 Test #6304: guest_cairo_surface_pattern_source ..... Passed 0.01 sec 2/3 Test #6303: guest_cairo_surface_pattern_patterns ... Passed 0.01 sec 3/3 Test #6305: guest_cairo_surface_pattern_mask ....... Passed 0.01 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libcairo/Export.cpp`, `core/libs/prx/libcairo/SurfacePattern.cpp`, `core/libs/prx/libcairo/include/InventoryExports.hpp`, `core/libs/prx/libcairo/include/SurfacePattern.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libcairo/SurfacePattern.cpp: cairo_pattern_reference forwards correctly to aps5_cairo_pattern_reference with Backend(pattern) and casts return value to CairoPattern* matching Cairo C API semantics. - Verified upstream Cairo semantics: cairo_pattern_reference handles nullptr safely (returns nullptr without error), handles static error patterns without crashing, and increments refcount for valid and allocated error patterns. - Verified core/libs/prx/libcairo/include/SurfacePattern.hpp and InventoryExports.hpp: prototype updated from int return stub to CairoPattern* APS5_VABI cairo_pattern_reference(CairoPattern* pattern) and stub cleanly removed from Export.cpp and InventoryExports.hpp. - Verified AGENTS.md compliance: docs/dev/debt/changes/feat-cairo-pattern-reference.md correctly adds technical debt removal fragment; no prohibited comments added. - Verified tests in core/libs/tests/GuestCairoSurfacePattern.cpp: thoroughly tests live pattern refcounting, nullptr input, static error pattern (null pattern), and allocated error pattern refcounting and destruction. Looks Good To Me
Plyxen commented 2026-11-28 11:11:36 +00:00 (Migrated from github.com)

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

Review: APPROVED


Checked head a832030cd3 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 23 focused tests pass, including the three guest_cairo_surface_pattern_* tests.
  • Full CPU suite (5,144 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: cairo_pattern_reference forwards to the bundled cairo, which returns NULL and the static nil patterns unchanged. The test pins both cases, and also the error pattern made from an invalid surface, which cairo allocates, so its count goes to 2.

#28015 removes the neighbouring cairo_arc_negative 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:6097409370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6097409370). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T11:11:36Z. **Review:** APPROVED --- Checked head `a832030cd3` 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 23 focused tests pass, including the three `guest_cairo_surface_pattern_*` tests. - Full CPU suite (5,144 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: `cairo_pattern_reference` forwards to the bundled cairo, which returns `NULL` and the static nil patterns unchanged. The test pins both cases, and also the error pattern made from an invalid surface, which cairo allocates, so its count goes to 2. #28015 removes the neighbouring `cairo_arc_negative` 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)
MarcZX10 commented 2026-11-28 11:27:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T11:27:41Z.

Review: APPROVED


Reviewed — looks good

The implementation forwards the guest pattern reference call to the Cairo backend and adds ownership and error-pattern coverage; the changed code inspected supports merging.

What I ran

Reviewed head a832030cd3ce7548f8d02b10ce78224c730bd70f using the prepared diff and repo_read.py at the pinned head. No commands or tests were run.

Results

Check Result Note
Source review passed All six changed files read
Tests not run Reported test runs were supplied by the author

Findings

Blocking

None.

Non-blocking

None.

Sources

Behavior claims were checked against the prepared diff and the changed source at the pinned head.

Not verified

No tests were run in this review. The author reports native reference ownership, null and error-pattern tests and a public headers check. No files were excluded; all files marked for review in the manifest were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6097481139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6097481139). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T11:27:41Z. **Review:** APPROVED --- # Reviewed — looks good The implementation forwards the guest pattern reference call to the Cairo backend and adds ownership and error-pattern coverage; the changed code inspected supports merging. ## What I ran Reviewed head `a832030cd3ce7548f8d02b10ce78224c730bd70f` using the prepared diff and `repo_read.py` at the pinned head. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All six changed files read | | Tests | not run | Reported test runs were supplied by the author | ## Findings ### Blocking None. ### Non-blocking None. ## Sources Behavior claims were checked against the prepared diff and the changed source at the pinned head. ## Not verified No tests were run in this review. The author reports native reference ownership, null and error-pattern tests and a public headers check. No files were excluded; all files marked for review in the manifest were read. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 08:17:56 +00:00 (Migrated from github.com)

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

Review: COMMENTED


I ran the exact surface-pattern fixture with the changed implementation and the pinned Cairo backend on Linux. All three fixture modes passed, covering pattern reference counting and its use by the source and mask operations.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165967766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6165967766). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T08:17:56Z. **Review:** COMMENTED --- I ran the exact surface-pattern fixture with the changed implementation and the pinned Cairo backend on Linux. All three fixture modes passed, covering pattern reference counting and its use by the source and mask operations. AI-assisted: yes.
MarcZX10 commented 2026-12-04 13:41:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T13:41:55Z.

Review: APPROVED


Reviewed — looks good

The wrapper forwards the guest pattern pointer to Cairo’s reference function and returns the same pointer; the inspected changes show no blocking defect.

What I ran

Reviewed head 833b79cdcc08b3ee7d55ce535f756ade7d45be1d. I read the prepared snapshots of all six changed files and used the pinned repo_read.py reader for source context. I did not run tests or a build.

python3 repo_read.py cat core/libs/prx/libcairo/Pattern.cpp 1 64
python3 repo_read.py cat core/libs/prx/libcairo/Export.cpp 1 80
python3 repo_read.py cat core/libs/prx/libcairo/include/InventoryExports.hpp 1 100
python3 repo_read.py search aps5_cairo_pattern_reference
python3 repo_read.py search cairo_pattern_destroy
python3 repo_read.py search Pattern.hpp core/libs/prx/libcairo
python3 repo_read.py cat core/libs/tests/GuestCairoGradient.cpp 210 235
python3 repo_read.py ls core/libs/prx/libcairo

Results

Check Result Note
Changed-file review passed All six reviewed files read
Tests not run Claims in the PR description were not independently run
Build not run No build invoked

Findings

Blocking

None.

Non-blocking

None.

Sources

The new wrapper converts the guest pointer to the backend pointer, calls Cairo’s reference function, and converts its return value back. The declaration is added to the pattern interface. Pattern.cpp at the reviewed head · Pattern.hpp at the reviewed head

The added tests cover same-pointer return and reference counts for a live surface pattern, null input, and error patterns. GuestCairoSurfacePattern.cpp at the reviewed head

Not verified

No tests or build were run. The reader returned source snippets but then reported a read-only error when attempting to append its audit log. All six files listed under reviewed in files.json were read from their prepared snapshots: core/libs/prx/libcairo/Export.cpp, core/libs/prx/libcairo/Pattern.cpp, core/libs/prx/libcairo/include/InventoryExports.hpp, core/libs/prx/libcairo/include/Pattern.hpp, core/libs/tests/GuestCairoSurfacePattern.cpp, and docs/dev/debt/changes/feat-cairo-pattern-reference.md. files.json lists no excluded files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6190012130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6190012130). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T13:41:55Z. **Review:** APPROVED --- # Reviewed — looks good The wrapper forwards the guest pattern pointer to Cairo’s reference function and returns the same pointer; the inspected changes show no blocking defect. ## What I ran Reviewed head `833b79cdcc08b3ee7d55ce535f756ade7d45be1d`. I read the prepared snapshots of all six changed files and used the pinned `repo_read.py` reader for source context. I did not run tests or a build. ```text python3 repo_read.py cat core/libs/prx/libcairo/Pattern.cpp 1 64 python3 repo_read.py cat core/libs/prx/libcairo/Export.cpp 1 80 python3 repo_read.py cat core/libs/prx/libcairo/include/InventoryExports.hpp 1 100 python3 repo_read.py search aps5_cairo_pattern_reference python3 repo_read.py search cairo_pattern_destroy python3 repo_read.py search Pattern.hpp core/libs/prx/libcairo python3 repo_read.py cat core/libs/tests/GuestCairoGradient.cpp 210 235 python3 repo_read.py ls core/libs/prx/libcairo ``` ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All six reviewed files read | | Tests | not run | Claims in the PR description were not independently run | | Build | not run | No build invoked | ## Findings ### Blocking None. ### Non-blocking None. ## Sources The new wrapper converts the guest pointer to the backend pointer, calls Cairo’s reference function, and converts its return value back. The declaration is added to the pattern interface. [Pattern.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/833b79cdcc08b3ee7d55ce535f756ade7d45be1d/core/libs/prx/libcairo/Pattern.cpp#L56-L58) · [Pattern.hpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/833b79cdcc08b3ee7d55ce535f756ade7d45be1d/core/libs/prx/libcairo/include/Pattern.hpp#L17) The added tests cover same-pointer return and reference counts for a live surface pattern, null input, and error patterns. [GuestCairoSurfacePattern.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/833b79cdcc08b3ee7d55ce535f756ade7d45be1d/core/libs/tests/GuestCairoSurfacePattern.cpp#L61-L86) ## Not verified No tests or build were run. The reader returned source snippets but then reported a read-only error when attempting to append its audit log. All six files listed under `reviewed` in `files.json` were read from their prepared snapshots: `core/libs/prx/libcairo/Export.cpp`, `core/libs/prx/libcairo/Pattern.cpp`, `core/libs/prx/libcairo/include/InventoryExports.hpp`, `core/libs/prx/libcairo/include/Pattern.hpp`, `core/libs/tests/GuestCairoSurfacePattern.cpp`, and `docs/dev/debt/changes/feat-cairo-pattern-reference.md`. `files.json` lists no excluded files. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-04 13:51:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T13:51:15Z.

Review: APPROVED


Verified on Windows 11 (GCC 15.2, Release) on main 484b0368d3. Applied together with #28892, #28891, #28890 and #28817, which touch separate files.

Re-checked after the rebase onto main and the move to Pattern.cpp, at 833b79cdcc.

  • guest_cairo_surface_pattern_patterns, _source and _mask passed in 3 of 3 runs.
  • With the libcairo sources reverted to main, the test no longer compiles, since the declaration is gone. The test built from this change, run against main's libcairo.prx, aborts with "cairo_pattern_reference not implemented". So the export is what the test exercises.
  • The guest pointer now comes from Guest(...) like the other pattern exports in Pattern.cpp. The null, error-pattern and reference-count cases match Cairo's own cairo_pattern_reference.

Not run: Linux and macOS.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6190142943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27995#pullrequestreview-6190142943). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-04T13:51:15Z. **Review:** APPROVED --- Verified on Windows 11 (GCC 15.2, Release) on main 484b0368d3. Applied together with #28892, #28891, #28890 and #28817, which touch separate files. Re-checked after the rebase onto main and the move to `Pattern.cpp`, at 833b79cdcc. - `guest_cairo_surface_pattern_patterns`, `_source` and `_mask` passed in 3 of 3 runs. - With the libcairo sources reverted to main, the test no longer compiles, since the declaration is gone. The test built from this change, run against main's `libcairo.prx`, aborts with "cairo_pattern_reference not implemented". So the export is what the test exercises. - The guest pointer now comes from `Guest(...)` like the other pattern exports in `Pattern.cpp`. The null, error-pattern and reference-count cases match Cairo's own `cairo_pattern_reference`. Not run: Linux and macOS. AI-assisted: yes (Claude Code)
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/27995:upstream-pr/27995'
git switch 'upstream-pr/27995'

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