feat(libSceNKWebKit): implement DefaultFilterOperation construction and InvertLightnessFilterOperation color exports #23080

Merged
FinleyLaempe merged 3 commits from upstream-pr/23080 into main 2026-11-20 12:44:11 +00:00
FinleyLaempe commented 2026-11-18 17:43:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by FinleyLaempe on 2026-11-18T17:43:50Z.


What

Implements WebCore::DefaultFilterOperation::create(WebCore::FilterOperation::OperationType), both WebCore::DefaultFilterOperation(OperationType) constructors and WebCore::InvertLightnessFilterOperation::blend(const WebCore::FilterOperation*, double, bool), WebCore::InvertLightnessFilterOperation::transformColor(WebCore::SRGBA<float>&) const and WebCore::InvertLightnessFilterOperation::inverseTransformColor(WebCore::SRGBA<float>&) const in libSceNKWebKit, which were throwing stubs in Export.cpp.

  • Behaviour follows pinned FilterOperation.cpp for blend and the hueRotate/toDarkMode/toLightMode colour transforms, and FilterOperation.h for create. The new src/FilterOperation.cpp carries the Apple upstream notice, as AGENTS.md asks for adapted code.
  • Per the debt fragment, the console names differ from the pinned source: OperationType is a 32-bit enum (pinned Type is uint8_t), and blend takes (const FilterOperation*, double, bool) instead of the pinned BlendingContext&, ignoring progress and blendToPassthrough as the pinned code ignores BlendingContext&.
  • Objects are the existing 16/24-byte WebCore::FilterOperation, WebCore::DefaultFilterOperation and WebCore::InvertLightnessFilterOperation guest records from RegionExports.hpp, zero-filled with a refcount of 1 and a 12-slot library vtable; base slots (isIdentity, outsets, affectsOpacity, movesPixels, shouldBeRestrictedBySecurityOrigin, colour transforms on DefaultFilterOperation) return neutral defaults.
  • Allocation goes through the module's WTF::fastMalloc export declared in WtfExports.hpp; create returns a non-trivially-destructible 8-byte WTF::Ref through WTF::adoptRef (RegionExports.hpp), blend a WTF::RefPtr<WebCore::FilterOperation>.
  • clone and operator== of both classes stay NotImplemented_nid_no_patch in Export.cpp (declared in InventoryExports.hpp); the vtable clone and equals slots point at those exports, so dispatching through them throws, as the tests assert.
  • Constructors and all InvertLightnessFilterOperation methods throw std::invalid_argument on a null this. Colour transforms treat NaN components as 0 and clamp the result to [0, 1], mirroring the pinned resolved() plus makeFromComponentsClamping; blend returns this when from has a different type, otherwise a fresh InvertLightnessFilterOperation.
  • RegionExports.hpp (main): FilterOperation::deref now frees through NKWebKit::Deallocate instead of std::free, because main's Allocate puts an AllocationHeader in front of the pointer (src/Bmalloc.cpp), so std::free on it was a bug. The file also gains a host-side WTF::RefPtr<T> template mirroring the existing WTF::Ref for blend's return type.
  • src/FilterOperation.cpp pins the base offsets with offsetof asserts but omits one for the non-standard-layout DefaultFilterOperation because MinGW rejects that; sizeof asserts still pin both layouts (16/24 bytes).
  • The six exports move out of Export.cpp and LegacyExports.hpp into the new include/FilterOperationExports.hpp, included from libSceNKWebKit.hpp.
  • The new tests/FilterOperation.cpp covers create for several represented types, both constructors, blend's same-type and different-type paths, the vtable dispatch and the colour transforms against the pinned matrices, including extended-range components, out-of-range alpha and NaN, plus the null-this throws.
  • The new fragment docs/dev/debt/changes/feat-nkwebkit-filter-operations.md changes the existing "[Filter operations]" debt entry, which said the FilterOperation subclasses stay stubs, into one for the new file. It is marked "not compared with a console module", and notes that the console sret convention for the hidden WTF::Ref/RefPtr result pointers is unmeasured. These exports are not rows in the module's NID inventory table, so no rows are removed.
  • Blur, DropShadow, BasicColorMatrix, BasicComponentTransfer and the remaining FilterOperation members stay stubs.

Tested

Arch Linux x86-64, GCC 16.2.1, Release build with -DBUILD_TESTING=ON: the new nkwebkit_filteroperation test and every other nkwebkit_* test, 143 of 143 passed. python3 tools/check_conventions.py --base upstream/main passes. Not tested on a console or on Windows.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5381095730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23080). Originally posted by [FinleyLaempe](https://github.com/FinleyLaempe) on 2026-11-18T17:43:50Z. --- ### What Implements `WebCore::DefaultFilterOperation::create(WebCore::FilterOperation::OperationType)`, both `WebCore::DefaultFilterOperation(OperationType)` constructors and `WebCore::InvertLightnessFilterOperation::blend(const WebCore::FilterOperation*, double, bool)`, `WebCore::InvertLightnessFilterOperation::transformColor(WebCore::SRGBA<float>&) const` and `WebCore::InvertLightnessFilterOperation::inverseTransformColor(WebCore::SRGBA<float>&) const` in libSceNKWebKit, which were throwing stubs in `Export.cpp`. - Behaviour follows pinned [FilterOperation.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/graphics/filters/FilterOperation.cpp#L294-L400) for `blend` and the hueRotate/toDarkMode/toLightMode colour transforms, and [FilterOperation.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/graphics/filters/FilterOperation.h#L118-L121) for `create`. The new `src/FilterOperation.cpp` carries the Apple upstream notice, as AGENTS.md asks for adapted code. - Per the debt fragment, the console names differ from the pinned source: `OperationType` is a 32-bit enum (pinned `Type` is `uint8_t`), and `blend` takes `(const FilterOperation*, double, bool)` instead of the pinned `BlendingContext&`, ignoring `progress` and `blendToPassthrough` as the pinned code ignores `BlendingContext&`. - Objects are the existing 16/24-byte `WebCore::FilterOperation`, `WebCore::DefaultFilterOperation` and `WebCore::InvertLightnessFilterOperation` guest records from `RegionExports.hpp`, zero-filled with a refcount of 1 and a 12-slot library vtable; base slots (`isIdentity`, `outsets`, `affectsOpacity`, `movesPixels`, `shouldBeRestrictedBySecurityOrigin`, colour transforms on `DefaultFilterOperation`) return neutral defaults. - Allocation goes through the module's `WTF::fastMalloc` export declared in `WtfExports.hpp`; `create` returns a non-trivially-destructible 8-byte `WTF::Ref` through `WTF::adoptRef` (`RegionExports.hpp`), `blend` a `WTF::RefPtr<WebCore::FilterOperation>`. - `clone` and `operator==` of both classes stay `NotImplemented_nid_no_patch` in `Export.cpp` (declared in `InventoryExports.hpp`); the vtable clone and equals slots point at those exports, so dispatching through them throws, as the tests assert. - Constructors and all `InvertLightnessFilterOperation` methods throw `std::invalid_argument` on a null `this`. Colour transforms treat NaN components as 0 and clamp the result to [0, 1], mirroring the pinned `resolved()` plus `makeFromComponentsClamping`; `blend` returns `this` when `from` has a different type, otherwise a fresh `InvertLightnessFilterOperation`. - `RegionExports.hpp` (main): `FilterOperation::deref` now frees through `NKWebKit::Deallocate` instead of `std::free`, because main's `Allocate` puts an `AllocationHeader` in front of the pointer (`src/Bmalloc.cpp`), so `std::free` on it was a bug. The file also gains a host-side `WTF::RefPtr<T>` template mirroring the existing `WTF::Ref` for `blend`'s return type. - `src/FilterOperation.cpp` pins the base offsets with `offsetof` asserts but omits one for the non-standard-layout `DefaultFilterOperation` because MinGW rejects that; `sizeof` asserts still pin both layouts (16/24 bytes). - The six exports move out of `Export.cpp` and `LegacyExports.hpp` into the new `include/FilterOperationExports.hpp`, included from `libSceNKWebKit.hpp`. - The new `tests/FilterOperation.cpp` covers `create` for several represented types, both constructors, blend's same-type and different-type paths, the vtable dispatch and the colour transforms against the pinned matrices, including extended-range components, out-of-range alpha and NaN, plus the null-`this` throws. - The new fragment `docs/dev/debt/changes/feat-nkwebkit-filter-operations.md` changes the existing "[Filter operations]" debt entry, which said the `FilterOperation` subclasses stay stubs, into one for the new file. It is marked "not compared with a console module", and notes that the console sret convention for the hidden `WTF::Ref`/`RefPtr` result pointers is unmeasured. These exports are not rows in the module's NID inventory table, so no rows are removed. - Blur, DropShadow, BasicColorMatrix, BasicComponentTransfer and the remaining `FilterOperation` members stay stubs. ### Tested Arch Linux x86-64, GCC 16.2.1, Release build with `-DBUILD_TESTING=ON`: the new `nkwebkit_filteroperation` test and every other `nkwebkit_*` test, 143 of 143 passed. `python3 tools/check_conventions.py --base upstream/main` passes. Not tested on a console or on Windows. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
copilot-pull-request-reviewer[bot] commented 2026-11-18 17:44:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-18T17:44:04Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5962023199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23080#pullrequestreview-5962023199). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-18T17:44:04Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
PrivacyOnion commented 2026-11-18 17:46:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T17:46:23Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9e5e5cd594:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_filteroperation_tests built cleanly.
  • CTest (nkwebkit_filteroperation):
    1/1 Test #4529: nkwebkit_filteroperation .........   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/include/LegacyExports.hpp, core/libs/prx/libSceNKWebKit/include/RegionExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, core/libs/prx/libSceNKWebKit/src/FilterOperation.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified memory management and ref-counting semantics: WTF::adoptRef and WTF::Ref/WTF::RefPtr correctly manage fastMalloc allocations and NKWebKit::Deallocate on refcount reaching 0 in core/libs/prx/libSceNKWebKit/include/RegionExports.hpp.
    • Verified C ABI signatures and symbols in core/libs/prx/libSceNKWebKit/include/FilterOperationExports.hpp match mangled Itanium C++ names for DefaultFilterOperation and InvertLightnessFilterOperation methods.
    • Audited null pointer handling: Checked(self) guards against null this pointers across constructors, blend, and color transform functions, throwing std::invalid_argument.
    • Verified color transformation math in HueRotate, TransformColorComponents, and ClampedColor in core/libs/prx/libSceNKWebKit/src/FilterOperation.cpp, verifying parity with upstream WebKit logic, NaN handling, and clamp ranges [0.0f, 1.0f].
    • Audited AGENTS.md compliance: copyright headers present, no disallowed inline comments, debt fragment added in docs/dev/debt/changes/feat-nkwebkit-filter-operations.md, and test coverage exercises all added methods and error paths.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5962058290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23080#pullrequestreview-5962058290). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T17:46:23Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `9e5e5cd594`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_filteroperation_tests` built cleanly. - **CTest** (`nkwebkit_filteroperation`): ``` 1/1 Test #4529: nkwebkit_filteroperation ......... 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/include/LegacyExports.hpp`, `core/libs/prx/libSceNKWebKit/include/RegionExports.hpp`, `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp`, `core/libs/prx/libSceNKWebKit/src/FilterOperation.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified memory management and ref-counting semantics: WTF::adoptRef and WTF::Ref/WTF::RefPtr correctly manage fastMalloc allocations and NKWebKit::Deallocate on refcount reaching 0 in core/libs/prx/libSceNKWebKit/include/RegionExports.hpp. - Verified C ABI signatures and symbols in core/libs/prx/libSceNKWebKit/include/FilterOperationExports.hpp match mangled Itanium C++ names for DefaultFilterOperation and InvertLightnessFilterOperation methods. - Audited null pointer handling: Checked(self) guards against null this pointers across constructors, blend, and color transform functions, throwing std::invalid_argument. - Verified color transformation math in HueRotate, TransformColorComponents, and ClampedColor in core/libs/prx/libSceNKWebKit/src/FilterOperation.cpp, verifying parity with upstream WebKit logic, NaN handling, and clamp ranges [0.0f, 1.0f]. - Audited AGENTS.md compliance: copyright headers present, no disallowed inline comments, debt fragment added in docs/dev/debt/changes/feat-nkwebkit-filter-operations.md, and test coverage exercises all added methods and error paths. Looks Good To Me
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!23080
No description provided.