feat(libSceNKWebKit): implement the cairo GraphicsContext core #24980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24980"
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 momgaroganuchi-crypto on 2026-11-21T14:07:29Z.
What
Implements 33
libSceNKWebKitexports that throw onmaintoday: the cairo immediate-modeWebCore::GraphicsContextcore and theWebCore::GraphicsContextStatelifecycle.GraphicsContext(PlatformContextCairo*)wraps the cairo context atPlatformContextCairo+0. Implemented operations are construction and destruction,save,restore,translate,scale,applyDeviceScaleFactor,clip,fillRect(state color and explicit color),clearRect,fillPath,strokePath,strokeRect,drawNativeImage, the fill/stroke color and stroke thickness setters,setShouldAntialias,setShouldSmoothFonts,setImageInterpolationQuality,setShadow,clearShadow,drawLineForText,hasPlatformContext,platformContextandgetCTM, plusGraphicsContextStateconstruction and destruction.fillPath/strokePathread thePathcairo context at +0, so they work with the Path implementation from #24965 without depending on it.drawNativeImagescales the source rectangle onto the destination with the cairo CTM andcairo_set_source_surface; it supports every blend mode, the default orientation and default interpolation quality, and throws for other orientations and interpolation qualities. Its per-drawImagePaintingOptionsblend mode maps to the cairo operator, withPlusDarkerandPlusLighterfalling back toOVERas WebKit's cairo backend does, and theCompositeOperatorvalues map from WebCore to cairo:DestinationOverthroughDestinationAtopshift by one because cairo reserves operator 6 forDEST,XORmaps to 11,PlusDarkertoDARKEN,PlusLightertoADDandDifferencetoDIFFERENCE. The context-levelcompositeOperatorandblendModeare stored in the state but not applied to fills and strokes, becausesetCompositeOperationis unimplemented here; globalalphamultiplies the source alpha offillRect,fillPath,strokePath,strokeRectand thedrawLineForTextunderlines.Layouts:
GraphicsContextStateis the 96-byte 2020 source layout andGraphicsContextis 144 bytes; both are asserted insrc/GraphicsContextAbi.hpp.GraphicsContextkeeps a host state stack in its private object and mirrors the cairo save/restore stack.The 33 exports are declared once in
include/GraphicsContextExports.hpp; the duplicate placeholders are removed frominclude/LegacyExports.hpp,include/InventoryExports.hppandsrc/GraphicsContextAbi.hpp. Cairo calls go through the internal_nid_no_patchhelpers inlibcairo/include/Bridge.hppandlibcairo/Bridge.cpp, the same mechanism as the existingCairoSurfaceDestroy_nid_no_patch, because the NID patcher rewrites libcairo exports but leaves non-SCE imports of a system library unchanged.Known gaps, recorded in the debt fragment:
setShadowrecords the offset, blur and color but cairo drawing does not paint or blur a shadow;setShouldSmoothFontsandsetImageInterpolationQualityonly record their value;drawNativeImagerejects non-default orientation and interpolation values; the context-level composite operator and blend mode are not applied becausesetCompositeOperationis unimplemented; gradient and pattern pointers are not reference counted becauseGradientandPatternare unimplemented; theGraphicsContextImplfactory constructor remains throwing.New files:
include/GraphicsContextExports.hpp,src/GraphicsContextAbi.hpp,src/GraphicsContext.cpp,tests/GraphicsContext.cpp,libcairo/include/Bridge.hpp,libcairo/Bridge.cpp. The debt fragment adds the Functional entry and removes the four inventory rows.Overlap: the libcairo
_nid_no_patchbridge files are also added by the independent #24965; both copies are identical, so whichever merges first, the other rebases without a semantic conflict.Tested
Windows 11, MinGW-w64 GCC 16.2, Release:
nkwebkit_graphicscontextpasses. It draws into a cairo image surface and checks pixels forfillRect, explicit-color fills,clearRect, save/restore with translation and scaling, clipping,fillPath,strokePath,strokeRect,drawNativeImagewith the default andDestinationOver/XORoperators,drawNativeImagewithMultiplyand a rejected unknown blend mode, single and double text underlines, 50% global alpha on bothfillRectoverloads compared against a direct cairo fill of the same alpha, a half-transparent underline,getCTM, the platform-context queries, a null platform context, shadow state and the defaultGraphicsContextStatevalues.public_headers, all 65public_headers_compile_*tests andpatched_librariespass.tools/check_conventions.py --base origin/mainpasses.tools/debt_fold.py --checkpasses for this fragment; the repository's unrelatedfeat-libwebrtc-rnn-vad.mdfragment fails on its own, so it was moved aside for the check.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 PrivacyOnion on 2026-11-21T15:01:08Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
34560c3411:tools/check_conventions.pypassed.nkwebkit_graphicscontext_testsbuilt cleanly.nkwebkit_graphicscontext):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/src/GraphicsContext.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T16:33:23Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
173385b1d7:tools/check_conventions.pypassed.nkwebkit_graphicscontext_testsbuilt cleanly.nkwebkit_graphicscontext):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp,core/libs/prx/libcairo/Bridge.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T22:55:33Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: apply the stored composite operator, blend mode, and global alpha to ordinary drawing operations, or explicitly limit the implementation claims and exports to behavior that is actually supported.
What I ran
f53dda487ffae92aae0933839b7adfe20a1ad406using the prepared diff andrepo_read.pysource reads.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp:360: normalfillRectcallsApplyOperator, but that helper readscontext.state.compositeOperatorandblendModewhile there is no implementation of the exportedsetCompositeOperationin the changed source; the new export remains a throwing placeholder inExport.cpp.fillRectalso sets the source from the raw color without applyingcontext.state.alpha. As a result, callers cannot set the advertised composite state, and global alpha has no effect on ordinary drawing. Implement the setter and apply global alpha consistently to fills, strokes, and text drawing (or remove those claimed capabilities until implemented).Non-blocking
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded from the review folder; their changed hunks were visible in the prepared diff, but the full files were not read.To get this to a good state
Implement and test composite-operation state updates and global-alpha rendering on a new head; rerun the GraphicsContext test and relevant NKWebKit checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T09:39:28Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the noted limitations are documented and optional.
What I ran
Reviewed head
ac668988a854e1bf570191f4731e4da3242697bc. Read the prepared description, commit list, manifest, diff, and relevant changed source, ABI, test, and Cairo bridge files usingrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded from the prepared files as too large; their relevant hunks appear in the diff, but their full files were not read. Runtime behavior, build results, test results, and console compatibility were not independently verified. The PR description reports Windows tests and says the change was not compared with a console module.Files read:
core/libs/prx/libSceNKWebKit/CMakeLists.txt,Export.cppdiff hunks,include/GraphicsContextExports.hpp,include/LegacyExports.hpp,libSceNKWebKit.hpp,src/GraphicsContext.cpp,src/GraphicsContextAbi.hpp,tests/GraphicsContext.cpp,core/libs/prx/libcairo/Bridge.cpp,core/libs/prx/libcairo/CMakeLists.txtdiff hunk,core/libs/prx/libcairo/include/Bridge.hpp, and the debt fragment. Excluded from full-file review:Export.cpp,include/InventoryExports.hpp.To get this to a good state
Nothing is required. The PR description documents the known limitations, including shadows not being rendered and context-level composite settings not being applied.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:48:03Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
67bf855a6f56e688530d33068c450d59527dfc46using the prepared diff andrepo_read.py. No tests were run in this review; test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
getCTMignores theIncludeDeviceScaleargument and always returns the raw Cairo matrix (core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp:507). If callers request device scale, the result will not reflect that request.drawNativeImageaccepts the image size parameter but does not use it when mapping the source rectangle (core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp:416). Confirm that the intended contract is to rely solely on the supplied source rectangle, or use the size to validate or constrain the source region.Not verified
No tests or console behavior were run or independently confirmed.
Export.cppwas read only at its changed tail additions. Full contents were read for the other changed source files and declarations excepttests/GraphicsContext.cpp, of which only lines 1–110 were read. Excluded by the review bundle:Export.cppfull text (too large); the diff also omits lockfiles, minified files,dist/,build/, and.svgfiles by preparation rule. Author-reported test results were not independently verified.To get this to a good state
Nothing is required. Optional: honor
IncludeDeviceScaleingetCTMand clarify or use thedrawNativeImageimage size parameter.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:48:57Z.
Review: COMMENTED
drawNativeImagecallsCairoSavebefore mapping the composite operator and blend mode.CairoOperatorcan throw for unsupported values, which skips the matching restore. A caller that catches the exception inherits an extra Cairo state frame, and the next publicrestorecan pop that frame while popping the preceding WebCore state. Please validate the operator before saving or scope the Cairo restore to the operation.Source review at
67bf855a6f. A trial merge onto484e8e6b77conflicts inExport.cppandLegacyExports.hpp.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.