Repository navigation
feat(libSceNKWebKit): implement the cairo GraphicsContext core - #24980
momgaroganuchi-crypto wants to merge 8 commits into
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 34560c3411:
- Conventions:
tools/check_conventions.pypassed. - Build:
nkwebkit_graphicscontext_testsbuilt cleanly. - CTest (
nkwebkit_graphicscontext):1/1 Test #4818: nkwebkit_graphicscontext ......... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
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.1/1 Test #4818: nkwebkit_graphicscontext .........***Failed 0.02 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- core/libs/prx/libSceNKWebKit/src/GraphicsContextAbi.hpp: verified standard-layout assertions, alignments, member offsets, and size constraints (State: 96 bytes, Context: 144 bytes, PlatformContext: 8 bytes, ImagePaintingOptions: 12 bytes) against WebKit 2020 layout.
- core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp: checked null-pointer validations on self, platform, rect, color, scale, and path parameters across all exported functions, ensuring std::invalid_argument is thrown where required.
- core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp: verified color unpacking, OutOfLineFlag handling, and RGBA conversion math in SetSource for fillRect, fillPath, strokePath, and strokeRect.
- core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp: verified cairo_save/cairo_restore nesting and stack state mirroring across GraphicsContext lifecycle, save(), restore(), clearRect(), and drawNativeImage().
- core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp: verified getCTM affine transform extraction from cairo_matrix_t (xx, yx, xy, yy, x0, y0) into WebCore::AffineTransform.
- Concerns:
- core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp:137: CairoOperator directly returns compositeOperator for values <= 10. In WebCore, WebCore::CompositeOperator values 6 through 10 correspond to DestinationOver (6), DestinationIn (7), DestinationOut (8), DestinationAtop (9), and XOR (10). In libcairo, value 6 is CAIRO_OPERATOR_DEST (which retains destination and discards the source surface), while CAIRO_OPERATOR_DEST_OVER is 7, CAIRO_OPERATOR_DEST_IN is 8, CAIRO_OPERATOR_DEST_OUT is 9, CAIRO_OPERATOR_DEST_ATOP is 10, and CAIRO_OPERATOR_XOR is 11. When drawNativeImage is invoked with ImagePaintingOptions::compositeOperator = 6 (CompositeOperator::DestinationOver), cairo_set_operator receives CAIRO_OPERATOR_DEST (6), discarding the native image instead of compositing it under the destination. Additionally, all operators 6-10 are off-by-one and CAIRO_OPERATOR_XOR (11) is unreachable.
Requesting changes for the points above.
Progress report (03a67f5 → ac66898)📈 System libraries: 45.95% (+0.08%, +33 implemented functions) ✅ 33 implemented
Changed libraries (implemented exports)
|
|
Fixed in 173385b. CairoOperator now maps WebCore DestinationOver..DestinationAtop to cairo 7..10, XOR to 11, PlusDarker to DARKEN, PlusLighter to ADD and Difference to DIFFERENCE; Also fixed the windows checks: the 32 exports are declared once in include/GraphicsContextExports.hpp, with the duplicates removed from LegacyExports.hpp, InventoryExports.hpp and GraphicsContextAbi.hpp, and cairo calls go through the stable nid_no_patch bridge in libcairo so patched_libraries resolves them after NID patching. Re-ran |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 173385b1d7:
- Conventions:
tools/check_conventions.pypassed. - Build:
nkwebkit_graphicscontext_testsbuilt cleanly. - CTest (
nkwebkit_graphicscontext):1/1 Test #4821: nkwebkit_graphicscontext ......... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
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.1/1 Test #4821: nkwebkit_graphicscontext .........***Failed 0.02 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified CairoOperator mapping in core/libs/prx/libSceNKWebKit/src/GraphicsContext.cpp correctly remaps WebCore::CompositeOperator 6-10 to libcairo CAIRO_OPERATOR_DEST_OVER (7) through CAIRO_OPERATOR_XOR (11), fixing the previous off-by-one destination operator defect.
- Verified ABI layout, size (State 96 bytes, Context 144 bytes, ImagePaintingOptions 12 bytes), and member offsets in core/libs/prx/libSceNKWebKit/src/GraphicsContextAbi.hpp against WebKit 2020 specifications via static assertions.
- Verified null pointer validations in Checked() and drawing entry points (Checked, SetSource, AppendPath, setShadow) throwing std::invalid_argument on null context, path, offset, or color pointers.
- Verified color bit unpacking, OutOfLineFlag detection, and normalized RGBA channel mapping in SetSource without integer overflow or signedness issues.
- Verified cairo_save and cairo_restore stack mirroring in GraphicsContextPrivate correctly tracks GraphicsContextState lifecycle and cleans up host state on destruction.
Looks Good To Me
173385b to
ee8648b
Compare
|
Added a follow-up commit |
|
Added |
|
Added |
|
I removed |
MarcZX10
left a comment
There was a problem hiding this comment.
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
- Reviewed head
f53dda487ffae92aae0933839b7adfe20a1ad406using the prepared diff andrepo_read.pysource reads. - No commands or tests were run by me; test results in the description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | GraphicsContext implementation and tests inspected |
| Programmatic checks | not run | Description reports Windows and convention checks |
| Console comparison | not run | Description says no console module comparison |
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
- None.
Not verified
- The full texts of
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. - No tests, build, precheck, or PS5 console validation were run by me. Author-reported results were not independently confirmed.
- No files were excluded by rule beyond the oversized files noted above; minified, build, distribution, lockfile, and SVG exclusions were not otherwise enumerated in the review bundle.
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.
Immediate-mode GraphicsContext over a PlatformContextCairo cairo_t: state, save/restore, transforms, clipping, rectangle and path fill/stroke, colors, antialias and shadow state. The impl-factory constructor, gradients, smoothing and shadow rendering remain unimplemented.
Extends the cairo GraphicsContext core with drawNativeImage and strokeRect, and the ImagePaintingOptions layout.
Moves the GraphicsContext declarations into GraphicsContextExports.hpp and drops the duplicates from LegacyExports.hpp, InventoryExports.hpp and GraphicsContextAbi.hpp. Maps WebCore DestinationOver through Difference to the cairo operator values, and routes cairo calls through stable _nid_no_patch helpers in libcairo so the patched module resolves them. Adds DestinationOver and XOR coverage.
Adds GraphicsContext::setCompositeOperation, beginTransparencyLayer and endTransparencyLayer over cairo, and applies the state composite operator to rectangle and path fills and strokes. Non-Normal blend modes throw. Tests cover DestinationOver, XOR, the rejected blend mode and a 50% transparency layer.
Implements GraphicsContext::drawLineForText over cairo, including single and double underlines, device-pixel rounding, the small-scale alpha shade and the current composite operator. Tests cover one and two lines at integer coordinates.
Maps every WebCore BlendMode to the cairo operator used by setCompositeOperation, the state applied before fills and strokes, and drawNativeImage. PlusDarker and PlusLighter use OVER as WebKit's cairo backend does. Tests cover Multiply, Screen and an unknown blend mode.
setCompositeOperation, beginTransparencyLayer and endTransparencyLayer are already implemented in open PRs 23755/23757/23758/23999/24000/24009, so this PR keeps only drawLineForText and the drawNativeImage blend-mode mapping. The three stubs are restored and the overlap is removed.
f53dda4 to
9d01e4a
Compare
Fills, strokes and text underlines now multiply their source alpha by GraphicsContextState::alpha. The context-level composite operator and blend mode are no longer applied to them: setCompositeOperation is still a throwing stub, so claiming that state changed the cairo operator was wrong. drawNativeImage keeps mapping its own per-draw ImagePaintingOptions.
9d01e4a to
ac66898
Compare
|
Fixed in
Local (Windows 11, MinGW-w64 GCC 16.2, Release): full build 7434/7434; |
MarcZX10
left a comment
There was a problem hiding this comment.
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 using repo_read.py. No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Core implementation and bridge inspected |
| Tests | not run | Runs reported in PR description only |
| Full changed-file review | not run | Two changed files excluded from prepared folder |
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
Export.cpp and include/InventoryExports.hpp were 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.cpp diff 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.txt diff 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.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
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)