feat(libSceNKWebKit): implement refIfNotNull and derefIfNotNull for cairo #19105

Closed
KernelPanicNT wants to merge 4 commits from upstream-pr/19105 into main
KernelPanicNT commented 2026-11-12 19:43:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-11-12T19:43:23Z.


What

Implements the four cairo specializations of WTF::refIfNotNull and WTF::derefIfNotNull in libSceNKWebKit. They threw through NotImplemented_nid_no_patch among the older callable exports.

Export NID Calls
WTF::refIfNotNull<_cairo>(_cairo*) HHnnPwUh7oM cairo_reference
WTF::derefIfNotNull<_cairo>(_cairo*) arCP3jQ+Jbo cairo_destroy
WTF::refIfNotNull<_cairo_surface>(_cairo_surface*) bZYKXT+p6Rw cairo_surface_reference
WTF::derefIfNotNull<_cairo_surface>(_cairo_surface*) 2kDZb3V0F5g cairo_surface_destroy
  • New src/RefPtrCairo.cpp and include/RefPtrCairoExports.hpp. Each function returns at once for a null pointer and otherwise forwards to the tree's libcairo implementation of that call, as WebKit's RefPtrCairo.cpp does.
  • core/libs/prx/libSceNKWebKit/CMakeLists.txt adds libcairo to libSceNKWebKit's private link libraries. This is the same prx-to-prx link that libSceFreeTypeOptOl -> libSceFreeType, libSceFontGs -> libSceFont and libSceNKWebKit's own libSceJsc/libSceIcu links use. No symbol is defined in both libraries. A cairo_t or cairo_surface_t that a title gets from libcairo therefore keeps a single reference count when WebKit code refs or derefs it here. The only test that calls cairo directly (nkwebkit_refptrcairo) also links libcairo, following the existing wtf -> libkernel case in the same loop.
  • Debt: the four names leave include/LegacyExports.hpp and Export.cpp. The older-export counts are left as they are (the debt file keeps historical inventory counts). A new entry records that the result is not compared with a console module and that the objects must come from the tree's libcairo.

Source of the behaviour

  • WebKit c55364d53f97 RefPtrCairo.cpp#L28-L50: if (LIKELY(ptr)) cairo_reference(ptr);, cairo_destroy, cairo_surface_reference, cairo_surface_destroy. This is the only source; the reference counting itself is the existing libcairo code (Context.cpp, Surface.cpp).

Tested

Linux x86-64 (Ubuntu 24.04, GCC 14), on main 09ab49de9649. The new nkwebkit_refptrcairo test tracks each object's lifetime with a cairo_surface_set_user_data destroy callback:

  • An image surface that gets one refIfNotNull survives cairo_surface_destroy and is released by the matching derefIfNotNull.
  • A context from cairo_create keeps its target alive through refIfNotNull and cairo_destroy, and derefIfNotNull releases it and its target.
  • Null pointers are ignored.

Results:

  • ctest -R '^(nkwebkit_(refptrcairo|noops)|guest_nkwebkit_dates)$' passed in 2 of 2 runs.
  • Negative control: with the four bodies replaced by NotImplemented_nid_no_patch, nkwebkit_refptrcairo aborts and the other two still pass.
  • tools/progress.py --compare: +4 implemented.
  • tools/check_conventions.py --base origin/main passes.

Not tested on Windows, on a device or with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5284072476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19105). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-12T19:43:23Z. --- ### What Implements the four cairo specializations of `WTF::refIfNotNull` and `WTF::derefIfNotNull` in `libSceNKWebKit`. They threw through `NotImplemented_nid_no_patch` among the older callable exports. | Export | NID | Calls | |---|---|---| | `WTF::refIfNotNull<_cairo>(_cairo*)` | `HHnnPwUh7oM` | `cairo_reference` | | `WTF::derefIfNotNull<_cairo>(_cairo*)` | `arCP3jQ+Jbo` | `cairo_destroy` | | `WTF::refIfNotNull<_cairo_surface>(_cairo_surface*)` | `bZYKXT+p6Rw` | `cairo_surface_reference` | | `WTF::derefIfNotNull<_cairo_surface>(_cairo_surface*)` | `2kDZb3V0F5g` | `cairo_surface_destroy` | - New `src/RefPtrCairo.cpp` and `include/RefPtrCairoExports.hpp`. Each function returns at once for a null pointer and otherwise forwards to the tree's `libcairo` implementation of that call, as WebKit's `RefPtrCairo.cpp` does. - `core/libs/prx/libSceNKWebKit/CMakeLists.txt` adds `libcairo` to libSceNKWebKit's private link libraries. This is the same prx-to-prx link that `libSceFreeTypeOptOl` -> `libSceFreeType`, `libSceFontGs` -> `libSceFont` and libSceNKWebKit's own `libSceJsc`/`libSceIcu` links use. No symbol is defined in both libraries. A `cairo_t` or `cairo_surface_t` that a title gets from `libcairo` therefore keeps a single reference count when WebKit code refs or derefs it here. The only test that calls cairo directly (`nkwebkit_refptrcairo`) also links `libcairo`, following the existing `wtf` -> `libkernel` case in the same loop. - Debt: the four names leave `include/LegacyExports.hpp` and `Export.cpp`. The older-export counts are left as they are (the debt file keeps historical inventory counts). A new entry records that the result is not compared with a console module and that the objects must come from the tree's `libcairo`. **Source of the behaviour** - WebKit `c55364d53f97` [RefPtrCairo.cpp#L28-L50](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp#L28-L50): `if (LIKELY(ptr)) cairo_reference(ptr);`, `cairo_destroy`, `cairo_surface_reference`, `cairo_surface_destroy`. This is the only source; the reference counting itself is the existing `libcairo` code (`Context.cpp`, `Surface.cpp`). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux x86-64 (Ubuntu 24.04, GCC 14), on `main` `09ab49de9649`. The new `nkwebkit_refptrcairo` test tracks each object's lifetime with a `cairo_surface_set_user_data` destroy callback: - An image surface that gets one `refIfNotNull` survives `cairo_surface_destroy` and is released by the matching `derefIfNotNull`. - A context from `cairo_create` keeps its target alive through `refIfNotNull` and `cairo_destroy`, and `derefIfNotNull` releases it and its target. - Null pointers are ignored. Results: - `ctest -R '^(nkwebkit_(refptrcairo|noops)|guest_nkwebkit_dates)$'` passed in 2 of 2 runs. - Negative control: with the four bodies replaced by `NotImplemented_nid_no_patch`, `nkwebkit_refptrcairo` aborts and the other two still pass. - `tools/progress.py --compare`: +4 implemented. - `tools/check_conventions.py --base origin/main` passes. Not tested on Windows, on a device or with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-17 10:31:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T10:31:04Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional. Head ea997d6894dc, base main.

What I ran

  • Read the description, commits, manifest and the diff of the head.
  • Checked the cairo calls in the new code against the libcairo headers in the tree (include/Context.hpp, include/Surface.hpp).
  • Searched the tree for every remaining use of the four removed names.
  • Checked the test loop in CMakeLists.txt.
  • No build and no test run in this review.

Results

Check Result Note
Diff read against the description passed All hunks read
cairo API used by the new code passed Signatures match the libcairo headers
Leftover references to the removed names passed Only the new files and the new test
Test registration in CMake passed refptrcairo links libcairo
Build and ctest not run No build in this review
Author-reported tests and tools not run ctest, negative control, progress.py, check_conventions.py are the author's results

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Full text of Export.cpp, include/LegacyExports.hpp and docs/dev/debt/libSceNKWebKit.md was not read. Only their changed hunks were read, plus a search for the removed names. Those hunks are removals and one added debt entry.
  • Runtime behaviour of cairo_reference, cairo_destroy and the surface reference counts in libcairo. The test that checks it was not run here.
  • The NIDs in the description and the export table they feed were not checked against a console module. The debt entry says this too.
  • The author's ctest runs, the negative control and the tools/progress.py and tools/check_conventions.py results are author-reported and were not run here.

To get this to a good state

Nothing is required.

Optional:

  • Read the full text of the three large files above before any formal approval.
  • Note in the debt entry which libcairo build the reference counts were checked against.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5936812589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19105#pullrequestreview-5936812589). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T10:31:04Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. Head `ea997d6894dc`, base `main`. ## What I ran - Read the description, commits, manifest and the diff of the head. - Checked the cairo calls in the new code against the libcairo headers in the tree (`include/Context.hpp`, `include/Surface.hpp`). - Searched the tree for every remaining use of the four removed names. - Checked the test loop in `CMakeLists.txt`. - No build and no test run in this review. ## Results | Check | Result | Note | |---|---|---| | Diff read against the description | passed | All hunks read | | cairo API used by the new code | passed | Signatures match the libcairo headers | | Leftover references to the removed names | passed | Only the new files and the new test | | Test registration in CMake | passed | `refptrcairo` links `libcairo` | | Build and `ctest` | not run | No build in this review | | Author-reported tests and tools | not run | `ctest`, negative control, `progress.py`, `check_conventions.py` are the author's results | ## Findings **Blocking** None. **Non-blocking** None. ## Not verified - Full text of `Export.cpp`, `include/LegacyExports.hpp` and `docs/dev/debt/libSceNKWebKit.md` was not read. Only their changed hunks were read, plus a search for the removed names. Those hunks are removals and one added debt entry. - Runtime behaviour of `cairo_reference`, `cairo_destroy` and the surface reference counts in libcairo. The test that checks it was not run here. - The NIDs in the description and the export table they feed were not checked against a console module. The debt entry says this too. - The author's `ctest` runs, the negative control and the `tools/progress.py` and `tools/check_conventions.py` results are author-reported and were not run here. ## To get this to a good state Nothing is required. Optional: - Read the full text of the three large files above before any formal approval. - Note in the debt entry which libcairo build the reference counts were checked against.

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