feat(libcairo): implement rectangle paths and operator state #15430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15430"
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-03T08:26:19Z.
What
Implement three additional, previously throwing Cairo exports atop the tested Cairo path-data stack #15324:
cairo_rectangle,cairo_set_operatorandcairo_get_operator. This is +3 genuinely callable exports over the parent branch, not a claim of +3 upstream merged exports.cairo_rectangleconstructs a closeable rectangular path in Cairo 24.8 device coordinates, applying the existing CTM and device scale while quantizing displacement separately from the starting point. Zero-width/height rectangles and negative dimensions follow Cairo 1.18's actual path stream. The operator defaults to OVER (2), is preserved across nestedcairo_save/cairo_restore, and has a typed System V guest ABI. Operator storage does not yet render; paint, clip, stroke and fill remain intentionally unimplemented. No silent fake drawing successes or new third-party dependencies.Tested
-O2 -DNDEBUG -Wall -Wextra -Werror -pedantic: source-linkedGuestCairoGeometry.cppwith realContext.cpp,Surface.cppandMatrix.cppcompiled and passed. Assertions forced active underNDEBUG; ABI pointer types asserted.-O1 -g -DNDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer, leak detection and halt-on-error enabled: source-linked tests passed.libcairo.so.2and compared the entire output byte-for-byte to the MinGW guest implementation and Linux ASan build: 1,035 exact matching rectangle path streams, including 1,024 deterministic random inputs, zero-sized dimensions, negative sizes and transformed CTM cases. This found and fixed initial mismatch in zero-size path segments and separately quantized rectangle displacements. Operators checked for all 29 valid enum values, nested save/restore, default OVER.python tools/progress.py --module libcairo: 75/161 on this branch, compared with 72/161 on its direct parent #15324; 3 new exports.python core/libs/tests/test_public_headers.py --audit-only: 405-library public-header audit passed.git diff --check, stricttools/check_conventions.pyand hosted Windows CTest: consult PR checks for latest status; local integrated CMake/CTest was not run.Not tested: actual PS5 console/firmware, full Cairo rendering, macOS. Branch is stacked: dependency order #14258 (merged) → #14327 → #14328 → #14329 / other concurrent Cairo owner branches → #15315 → #15317 → #15324 → this PR. The new exports do not overlap #15208's eight pattern exports.
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T08:38:39Z.
Review: DISMISSED
Reviewed — changes requested
cairo_get_targetreportsNO_MEMORYfor an errored context regardless of its actual sticky status, and the new null-context test currently asserts that incorrect result.What I ran
Reviewed all 15 changed files at head
88b15f0f3d6897bca2d3add5341413cbe050dfe7against base4f41f4c375f5abb487dbd184fbc150f31994d762. The current-base merge previews are clean; the declared #15324 head is included in this branch. Environment: Debian 12, Linux x86_64, Python 3.11.2, Git 2.39.5. No compiler was used.I also read all changed files across three review portions. The source review and the static checks do not include a build or execution of the C++ tests.
Results
Precheck table, raw helper diagnostics and hosted status
The complete precheck table is reproduced below. Its overall “checks failed” conclusion is due to helper scripts missing from the isolated PR snapshot; I reran the ABI audit in the workspace, and manually checked CMake test registration.
Exact missing-helper diagnostics:
Direct ABI audit output:
The test-quality helper also warned that the five new C++ tests might be unregistered. I checked the exact-head
core/libs/prx/libcairo/CMakeLists.txt; each has anadd_test_executableandadd_testregistration, so that heuristic warning is a false positive. The remaining geometry assertion gap is visible in the test body: it prints path entries and checks finiteness/bounds but does not assert expected rectangle coordinates or command sequence.Hosted checks at final refresh:
Negative control
Not run. I did not alter the source or run a failure-injection test.
Findings
Blocking
The context error status is lost by
cairo_get_target.cairo_create(nullptr)returns thekNullPointercontext, but its singleton target is initialized asCairoSurfaceError(kNoMemory). For other contexts that enter an error later,cairo_get_targetalso unconditionally returns akNoMemorysurface. Thus callers see status 1 instead of the context’s actual error (for example, status 7 for a null target), and the test currently codifies that wrong result. Cairo 1.18 returns an error surface carryingcr->status. Please preserve the actual context status when returning an error surface, initialize the null-pointer target withkNullPointer, and update/add a test that checks the reported status.The null-target initializer can be corrected along these lines:
Non-blocking
GuestCairoGeometry.cppprints rectangle path data but does not compare the coordinates or path structure with expected values. The PR reports a separate byte-for-byte comparison against native Cairo, but that comparison is not part of the checked-in CTest, so a future rectangle regression could still pass CI. Adding representative expected-output assertions would make the regression coverage durable.Sources
cairo_get_targetat the reviewed headNO_MEMORYcairo_get_targetpreservescr->statusNot verified
I did not build or run C++ tests, reproduce the author-reported Windows/ASan runs or native Cairo differential, test another OS, or test console behavior. The six hosted checks were pending at the final refresh.
To get this to a good state
Preserve the actual context status in the returned error surface and update the null-context regression expectation; consider adding durable rectangle-output assertions. Please rerun the no-build precheck and hosted checks on the new head. I will inspect the updated diff and rerun the same no-build commands before reconsidering the review.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T10:15:01Z.
Review: DISMISSED
Reviewed — changes requested
The merged tree builds and the libcairo tests pass. However,
guest_cairo_geometrynever compares the rectangle output with expected values: a deliberately wrong fourth corner still passes. Separately,cairo_rectangledecides which edges to emit from the user-space width and height, not from the quantized device displacements, so its path stream for near-zero sizes differs from the one it gives for exact zero.What I ran
Head
88b15f0f3d6897bca2d3add5341413cbe050dfe7merged with--no-ffintomain4f41f4c375f5abb487dbd184fbc150f31994d762(merged tree9915e2c985d9937ed1b4049a184a2ce9150a17f7). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pylibs(script)main(guest_interfaces,guest_socket_options_multicast,unwrap_self_…,vector_constant_factor_tininess) are not this PR's.guest_net_ctlwas skipped, which also happens onmain.public_headers+ 64public_headers_compile_*guest_cairo_matrix/surface/context/graphics_state/path/geometryguest_cairo_geometrystill passedgit status --porcelainemptyProbe output: exact-zero vs 0.001 height
For the unmodified case
{5, 8, 9, 0}the PR emitsM(5,8) L(14,8) Z M(5,8), which is 7 elements.Negative control
Restoring the production files from
mainwould removeContext.cppandSurface.cpp. The new tests would then fail to link, which proves nothing about the rectangle. So I used a targeted mutation instead: I changed the fourth rectangle corner inContext.cpp:525tox + 2 * hx, y + hy + 1and rebuilt.guest_cairo_geometrystill passed. The test would also pass ifcairo_rectangleemitted nothing. I restored the merged file, rebuilt, and confirmed the worktree is clean.Findings
Blocking
guest_cairo_geometrydoes not testcairo_rectangle.core/libs/tests/GuestCairoGeometry.cppL42–L61 prints each path. It only asserts that the status is 0, the headers are well formed and the coordinates are finite. MarcZX10 raised this as non-blocking. I'm adding new evidence and treating it as blocking: the mutation above shows that a wrong rectangle passes CI, andcairo_rectangleis the main export this PR adds. The 1,035-case comparison with native Cairo described in the PR is not in the repository. Suggested fix: check expected element streams (types and points) for the fixed cases: positive, negative, zero and near-zero sizes, and the transformed CTM. The expected values could come from the native comparison the author already ran, or the printed native output could be checked in as a table.cairo_rectanglegives different paths for inputs with identical device displacements.core/libs/prx/libcairo/Context.cppL507–L527 decides withwidth != 0andheight != 0on the user-space values. A height of0.001quantizes to a device displacement of 0, exactly like0. Yet the PR emitsM L(14,8) L(5,8) Zfor the first andM L(14,8) Zfor the second (probe above). Cairo builds a rectangle as move, three relative lines and close on 24.8 fixed values, so both inputs must produce the same stream. This contradicts the description's claim that zero-size rectangles "follow Cairo 1.18's actual path stream": that is only true when the size is exactly zero. The root cause seems to be incairo_close_pathL585–L592. As I read Cairo's_cairo_path_fixed_close_path, it first adds aline_toback to the last move point and then drops the finalLINE_TObefore addingCLOSE_PATH. This PR's close does neither, and the rectangle code works around that with the user-space zero checks. My reading of the Cairo source is from memory: I had no network or native Cairo here. The inconsistency between the two inputs, though, is shown by the PR's own output. Suggested fix: implement that close-path step, emit the three lines from the quantizedwx/wy/hx/hywithout user-space conditions, and add the near-zero case to the test from finding 1.Non-blocking
Broken source link in the debt file.
docs/dev/debt/libcairo.md:23changes the gist revision of the "selected export metadata" link froma3838ac54ebcc0bbfeb3cc46002a9a2dcce4dbdctoa3838ac54ebcc46002a9a2dcce4dbdc. Nine characters are gone, so the citation no longer points at that revision. Restore the original 40-character hash.Debt headings and entry style.
docs/dev/debt/libcairo.md:7and:11add### Functional image and surface exportsand### Functional context and coordinate transforms. Neither is a section of theTechnicalDebt.mdindex (Build, Silent stubs, Unknown function info, Functional), and no other debt file uses them. CONTRIBUTING asks for entries under the index sections, stating the gap first. The new entries mostly describe implemented behaviour and test runs ("Windows and Linux sanitizer tests … passed"). Move them under### Functionaland reduce them to what is still open: no rasterizer, an unused operator, native behaviour not measured, and so on.The NID table no longer matches its text. The text says "86 remaining callable NIDs", which matches the 86 throwing exports in
Export.cpp. The table still has 129 rows: the surface, operator and rectangle rows were removed, but the 43 rows for context, state and path exports implemented in this branch (cairo_create,cairo_move_to,cairo_set_dash, …) remain. Remove those rows too, or keep the full map and drop the word "remaining".On the existing review
MarcZX10's blocking point is that
cairo_get_targetshould return an error surface that carriescr->status, for example 7 forcairo_create(NULL). I don't think it holds. As I recall Cairo 1.18's_cairo_surface_create_in_error, the context-only statuses (INVALID_RESTORE,INVALID_MATRIX,NULL_POINTER,INVALID_DASH, …) fall through to theNO_MEMORYnil surface. Only the surface-level statuses get their own nil surfaces. That matches what the PR does (L74–L79, L274–L280) and what the test expects. I could not confirm this against native Cairo here; the author's native comparison would settle it.Not verified
maincontains the whole declared stack (#15324 and its parents, +65 implemented functions, per the progress report), not only the three exports in the title. I reviewed all of it, but focused on the rectangle and operator code.To get this to a good state
guest_cairo_geometryassert expected rectangle path streams, so that the mutation above fails.Pull request closed