feat(libcairo): implement seventeen context and CTM exports #15315
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15315"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hyvvs on 2026-11-02T23:29:08Z.
What
Implement 17 Cairo context and CTM exports, owned surface references, save/restore, and affine coordinate conversion. Merge sequence: #14327 -> #14328 -> #14329 -> #15315 -> #15317 -> #15324.
Tested
Windows MinGW C++20 -DNDEBUG DLL-linked guest PASS (8,192 lifetimes); Ubuntu WSL -DNDEBUG ASan+UBSan/leak check PASS; native Cairo1.18 4,096 CTM differential PASS; headers, progress and conventions PASS. Full integrated CMake/CTest and PS5 console not tested.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Detailed implementation and verification notes
Summary
Implement 17 formerly throwing libcairo exports: context create/reference/destroy, nested save/restore, borrowed target lookup, 11 user/device coordinate and CTM transformations.
The implementation owns a reference to the CairoSurface provided by #14327, tracks context refcounts and sticky error states, and uses the ten affine matrix primitives already merged via #14258. Save/restore manages the currently implemented CTM state, and inverse transforms use validated matrix inversion.
Validation
Dependencies and scope
This PR is stacked on #14327 (19 image/surface exports) because cairo_create and cairo_destroy must retain/release those real surface objects. It currently includes the parent branch history; land #14327 first, then refresh this PR's base before merging. #14258 matrix primitives have already merged into main.
These exports are functional for context lifetimes and coordinate state, NOT full Cairo rendering. Path construction, clipping, pixels, rendering, other graphics-state fields, and PS5 firmware-specific behavior are not claimed. No console differential is available. Newly implemented exports are not counted as upstream coverage until merged.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T23:41:00Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new tests lose their runtime assertions in the repository’s Release configuration, and this head also fails the required PR-template and source-comment rules.
What I ran
Reviewed all 11 changed files at head
4563a8c6fbb9de7d88753dfcd3dc958abae31ea4against PR base5cb015caaaaf83f8ee431414ee6a457b5b307d49. The head contains the open #14327 head as an ancestor and merges cleanly with currentmain. Pairwise previews against open #14328 and #14329 report conflicts in shared Cairo integration files. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. I did not configure or build AnyPS5.Results
assertexpands to a no-op under-DNDEBUG.Precheck table and raw output
The precheck deliberately does not configure, build, or compile AnyPS5.git diff --check 5cb015caaaaf83f8ee431414ee6a457b5b307d49...4563a8c6fbb9de7d88753dfcd3dc958abae31ea4/usr/bin/python3 tools/check_conventions.py --base 5cb015caaaaf83f8ee431414ee6a457b5b307d49 --head 4563a8c6fbb9de7d88753dfcd3dc958abae31ea4 --title feat(libcairo): implement seventeen context and CTM exports --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15315-4563a8c6fbb9/pr-body.md/usr/bin/python3 tools/pr_abi_audit.py --base 5cb015caaaaf83f8ee431414ee6a457b5b307d49 --head 4563a8c6fbb9de7d88753dfcd3dc958abae31ea4 --jsonNo changed Python implementation files.No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.No changed test_*.py files./usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15315 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15315-4563a8c6fbb9/stackNot run: C++ tests need exact-head binaries, which require a build; the precheck does not build./usr/bin/python3 /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15315-4563a8c6fbb9/head-4563a8c6fbb9-cdd473f1/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15315-4563a8c6fbb9/head-4563a8c6fbb9-cdd473f1 --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/Surface.hpp core/libs/prx/libcairo/libcairo.hpp core/libs/tests/GuestCairoContext.cpp core/libs/tests/GuestCairoSurface.cpp docs/dev/debt/libcairo.mdNo changed Python test module in tools/ can be run as a no-build base-source control.The isolated PR snapshot does not contain these reviewer-only scripts. The ABI audit was run from the workspace and passed; the test-quality helper was unavailable, so I inspected the test and CMake registration directly.
Negative control
assert, which is removed by the ReleaseNDEBUGconfiguration.Findings
Blocking
Both new C++ test files use
<cassert>for runtime checks, but the repository build workflow configuresCMAKE_BUILD_TYPE=Release, and the test target helper does not undefineNDEBUG. In that configuration, the assertions compile away; the CTest targets can therefore pass without checking the results they claim to cover. Keep checks active in both test files, for example with an always-on test helper or by undefiningNDEBUGbefore including<cassert>, and make sure the Release CTest path actually exercises them.The PR description replaces the required template with
## Summary,## Validationand## Dependencies and scope. The conventions precheck fails because### What,### Testedand### Checklistare absent. Restore the full template, tick every applicable box, and complete the requiredDepends on,Unblocks,GPUs testedandAI-assistedfields.GuestCairoContext.cppadds an inline code comment, contrary to the repository rule that code comments are prohibited except namespace ends and#endif.Non-blocking
CMakeLists.txt,Export.cpp,InventoryExports.hppanddocs/dev/debt/libcairo.md. Those PRs describe the landing order #14327 → #14328 → #14329, while this PR says it is stacked on #14327. Please coordinate and record where this PR fits in the sequence before integration; the conflicts do not prevent this head from merging with currentmainby itself.Sources
NDEBUGoverrideassertin Releaseassertin ReleaseNot verified
To get this to a good state
Restore the PR template, keep test assertions active in Release, remove the inline code comment, and record the coordinated order for #14327, #14328, #14329 and this PR. On the updated head, rerun
git diff --check,python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15315, the ABI audit, and the pairwise merge previews after the dependency order is agreed; I will inspect the new head and the same results.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T00:01:07Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The new head still has a mismatched Cairo error-surface status, Release-disabled test assertions, and an incomplete required PR template.
What I ran
Rechecked the prior full diff and the four-file update at head
2ffc401e8e8aa51f413709a652ca0433d45d21bd, against base5cb015caaaaf83f8ee431414ee6a457b5b307d49; the head merges cleanly with the base. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. No AnyPS5 build or C++ tests were run.Results
assert(false)preprocesses to a no-op with-DNDEBUG.Check output
The same four files conflicted in the preview against each sibling PR. The context came from the exact live sibling heads recorded in their Sources links.
The precheck’s isolated snapshot lacked the reviewer-only ABI and test-quality scripts; I ran the ABI audit directly in the workspace. The stack check reported a clean preview against current
main. The exact-head PR body reports test runs, but I did not reproduce them.Negative control
No source mutation or exact-head C++ negative control was run because no test binary was built. The separate preprocessor probe confirms that an
assertexpression becomes a no-op under-DNDEBUG; it does not execute the PR tests.Findings
Blocking
cairo_get_targetreturns the wrong status surface for an error context.cairo_create(nullptr)creates akNullPointercontext, but its static target is initialized withCairoSurfaceError(kNoMemory), andcairo_get_targetreturns that stored target without checking the context status. The added test consequently expects status1. Cairo’scairo_create(NULL)returns aNULL_POINTERcontext, andcairo_get_targetreturns an error surface carrying the context’s status. Return an error surface matching the context status and assertkNullPointerfor this case. The same getter also returns the ordinary target after a valid context later enters an error state.The new test assertions are disabled by the repository’s Release configuration. The workflow configures
CMAKE_BUILD_TYPE=Release, the shared test-target helper adds no-UNDEBUG, and the preprocessor probe showsassert(false)becomes a no-op under-DNDEBUG. Thus the new context test can pass without checking its claims. Keep these assertions active in Release, for example with an always-on test assertion helper, and ensure the CI CTest target uses it.The PR description omits required template fields. The conventions checker reports missing
### What,### Testedand### Checklist; required checklist entries includingDepends on,Unblocks,GPUs testedandAI-assistedare also absent. Restore the complete template and fill every item.Non-blocking
CMakeLists.txt,Export.cpp,InventoryExports.hppand the libcairo debt file. Agree and record where #15315 lands relative to the #14327 → #14328 → #14329 sequence, then refresh the PR base when those changes land.docs/dev/debt/libcairo.md, and the repository convention allows code comments when a debt file is changed.Sources
cairo_get_targetat this head and the getter implementation.cairo_create(NULL),cairo_get_target.Not verified
No AnyPS5 build, CTest, Windows run, Linux runtime test, PS5 console test or behavioral negative control was performed. The MinGW, sanitizer and native-Cairo differential results in the description are author-reported, not independently reproduced. Hosted checks were queued at final refresh.
To get this to a good state
Make
cairo_get_targetreturn an error surface with the matching context status, correct the null-pointer expectation, keep test assertions active in Release, and restore the full PR template. Coordinate the landing order with #14328 and #14329. On the new head, I will rerun the diff check, precheck, ABI audit, stack previews, assertion probe and applicable hosted checks, then inspect the updated changes and tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T07:54:28Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The current implementation reports incorrect Cairo error statuses from
cairo_get_targetand returns the image type for rectangle subsurfaces.What I ran
Reviewed all 11 changed files at head
efbf7f24b950791cda5afe2718877acfa4287563against the PR base5cb015caaaaf83f8ee431414ee6a457b5b307d49. The currentmaintip isd1ae628bc2f62459cce1e9872ba5632c938c71f2; the stack checker reports clean individual merge previews against that tip. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. No local build or CTest was run.Results
Check output
git diff --checkexited successfully with no output. The ABI audit printedABI audit: passedandfindings: []. The precheck recorded the optional test-quality helper as unavailable becausetools/pr_test_quality.pyis absent from the isolated head snapshot.gh pr checksreportedwindows,conventions,eligibility,labels,library-portabilityandreportas passed; the Linux and specialized jobs were skipped.Negative control
Not run: the added C++ tests require a build, and no negative-control binary was available.
Findings
Blocking
cairo_get_targetreturns the wrong surface status after context errors. Aftercairo_scale(context, 0, 1)the context status iskInvalidMatrix(5), and after an unmatchedcairo_restoreit iskInvalidRestore(2), but this function returnsCairoSurfaceError(kNoMemory)(1). The null-pointer error context also stores a no-memory target despite its context status beingkNullPointer(7). Callers therefore observe a different error throughcairo_surface_status(cairo_get_target(context))than throughcairo_status(context). Return an error surface carrying the context's actual status, and initialize the null-pointer error target with the null-pointer status; update the tests to assert those statuses.Rectangle subsurfaces report the image surface type.
cairo_surface_create_for_rectanglecreates a non-image surface, butcairo_surface_get_typeunconditionally returnskImageSurfaceType, and the test currently asserts that value. Cairo assigns rectangle subsurfaces the distinctCAIRO_SURFACE_TYPE_SUBSURFACEtype. Store/return the corresponding ABI type for this surface and assert it in the test.Non-blocking
None found in the reviewed files beyond the two blockers above.
Sources
cairo_get_targetimplementation and its error-status test and test.cairo_get_targetimplementation returns an error surface withcr->status.Not verified
I did not build or run the C++ tests, test other operating systems, or run console behavior. The hosted Linux and specialized jobs were skipped. The lexical ABI audit does not prove calling-convention or runtime ABI compatibility.
To get this to a good state
Correct both error-status and surface-type behaviors, update the assertions to check Cairo's reported values, then I will rerun the precheck and inspect the new exact head.