feat(libfreetype): implement FT_Bitmap_Blend #16399

Merged
Noxy-HNR merged 5 commits from upstream-pr/16399 into main 2026-11-14 22:28:18 +00:00
Noxy-HNR commented 2026-11-06 16:08:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-06T16:08:17Z.


What

FT_Bitmap_Blend (C3-qsnriefE) in libfreetype currently throws. It now calls the bundled FreeType (3rdparty/freetype) through a thin adapter in src/BitmapBlend.cpp. No FreeType logic is copied into core/.

The adapter takes the guest library handle from libSceFreeType, the source and target FT_Bitmap records, the 26.6 source offset (passed by value), the target offset and the colour. FT_Bitmap has the same layout on the guest and both hosts, and a static_assert checks it. The adapter copies both records, converts the LP64 offsets to host FT_Vector, calls FreeType, then copies the target record and offset back. FreeType allocates, grows and frees the target buffer through the library's allocator, so the guest can release it with libSceFreeType's FT_Bitmap_Done, as on native FreeType.

Before calling FreeType, the adapter opens host writes on the target record, the target offset and the target's existing pixels. If any is refused, it returns FT_Err_Invalid_Argument without calling FreeType. Null arguments return FreeType's own error. Two cases throw through NotImplemented_nid_no_patch:

  • a face's glyph-slot bitmap as the target, because libSceFreeType keeps its host copy in sync, and growing it from another module would leave that copy stale;
  • on Windows, an offset outside the 32-bit host FT_Pos range.

The console signature is not measured, and the debt file records this. No title unblock is claimed.

This branch is built on #16394 (LCD geometry and variation axis flags), which adds the module's CMakeLists.txt, so the diff also shows that commit. This PR's own change is commit aeca597988. It goes right after #16394.

Tested

Current verification (2026-11-07), head fe4b731f2a, merging main eed8517b31: Windows 11 x86-64, WinLibs MinGW GCC 15.2, Ninja, Release, full project configuration with BUILD_TESTING=ON, -j 18. Built guest_legacy_freetype_bitmap_blend_fixture guest_legacy_freetype_library_fixture and ran the focused raw and NID-patched tests matching guest_legacy_freetype_(bitmap_blend|library)(_nid)?: 4/4 passed in each of three runs, none skipped. Test-private patched modules and executable keep validation independent of the global all-library target. Current conventions, whitespace and public-header checks passed. The fixture uses configuration-specific output directories and publishes patched files only after successful patching. No new Linux, macOS, console or title runtime result is claimed.

Manual full-build dispatch for this head returned HTTP 403 (repository admin rights required). Automatic checks are tracked separately; a skipped job is not a pass.

Historical verification follows; results below retain their original heads and do not establish validation of the current head.

New guest_legacy_freetype_bitmap_blend and guest_legacy_freetype_bitmap_blend_nid tests load the raw and NID-patched libfreetype and libSceFreeType modules and run each call side by side with the bundled FreeType on a separate library:

  • Six blend sequences start from an empty target and grow it in every direction. Sources are mono, 2-bit, 4-bit, 8-bit gray, LCD, LCD_V and BGRA, with padded pitches, offsets with fractional bits and negative values, and opaque, translucent and fully transparent colours. After each step, the error, the target record, every target pixel and the target offset match FreeType, and the source is unchanged. Each target is then released with the guest FT_Bitmap_Done.
  • In-place blending into an existing BGRA target that already covers the source.
  • Errors and no-ops, compared with FreeType and checked to leave the target untouched: null library, source, target or offset; a NONE source; zero-width and zero-height sources; mismatched pitch signs; a non-BGRA target; a source wider than 0x7FFF; and offsets whose result exceeds FreeType's 0x10000-pixel limit. Negative pitches on both bitmaps are covered too.
  • On Windows: the target record, the target offset and the target pixels are each placed on a guest page made read-only with sceKernelMprotect (checked with VirtualQuery). Each call is refused without changing any page. A source on a read-only page still blends, and the in-place blend into guest memory matches FreeType once write access is restored.
  • Sabotage check: swapping the red and blue channels, swapping the offset's x and y, not copying the target offset back, and clearing the target on an error each make both tests fail.

Results:

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head aeca597988 on upstream ea3ae18716: ctest -R guest_legacy_freetype 4/4 passed in each of 3 runs.
  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release, aeca597988 merged with upstream 04ab293bc2: ctest -R guest_legacy_freetype 4/4 passed in each of 3 runs, including the read-only page checks.
  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (406 libraries, 30,649 exports): passed.
  • python tools/pr_overlap.py --branch claude/freetype-bitmap-blend (1,883 open PRs): no shared exports. It shares the new core/libs/prx/libfreetype/CMakeLists.txt and neighbouring lines of Export.cpp, LegacyExports.hpp, libfreetype.hpp and the debt file with #15408, #15439, #15442, #15444, #15447 and #15468, which implement other libfreetype exports, so whichever lands later merges main and keeps every source and test. No open PR adds or removes FT_Bitmap_Blend or its NID.

No console or retail-title test.

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
  • 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: #16394
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5190818225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16399). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-06T16:08:17Z. --- ### What `FT_Bitmap_Blend` (`C3-qsnriefE`) in libfreetype currently throws. It now calls the bundled FreeType (`3rdparty/freetype`) through a thin adapter in `src/BitmapBlend.cpp`. No FreeType logic is copied into `core/`. The adapter takes the guest library handle from `libSceFreeType`, the source and target `FT_Bitmap` records, the 26.6 source offset (passed by value), the target offset and the colour. `FT_Bitmap` has the same layout on the guest and both hosts, and a `static_assert` checks it. The adapter copies both records, converts the LP64 offsets to host `FT_Vector`, calls FreeType, then copies the target record and offset back. FreeType allocates, grows and frees the target buffer through the library's allocator, so the guest can release it with `libSceFreeType`'s `FT_Bitmap_Done`, as on native FreeType. Before calling FreeType, the adapter opens host writes on the target record, the target offset and the target's existing pixels. If any is refused, it returns `FT_Err_Invalid_Argument` without calling FreeType. Null arguments return FreeType's own error. Two cases throw through `NotImplemented_nid_no_patch`: - a face's glyph-slot bitmap as the target, because `libSceFreeType` keeps its host copy in sync, and growing it from another module would leave that copy stale; - on Windows, an offset outside the 32-bit host `FT_Pos` range. The console signature is not measured, and the debt file records this. No title unblock is claimed. This branch is built on #16394 (LCD geometry and variation axis flags), which adds the module's `CMakeLists.txt`, so the diff also shows that commit. This PR's own change is commit `aeca597988`. It goes right after #16394. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Current verification (2026-11-07), head `fe4b731f2a`, merging main `eed8517b31`: Windows 11 x86-64, WinLibs MinGW GCC 15.2, Ninja, Release, full project configuration with `BUILD_TESTING=ON`, `-j 18`. Built `guest_legacy_freetype_bitmap_blend_fixture guest_legacy_freetype_library_fixture` and ran the focused raw and NID-patched tests matching `guest_legacy_freetype_(bitmap_blend|library)(_nid)?`: **4/4 passed in each of three runs**, none skipped. Test-private patched modules and executable keep validation independent of the global all-library target. Current conventions, whitespace and public-header checks passed. The fixture uses configuration-specific output directories and publishes patched files only after successful patching. No new Linux, macOS, console or title runtime result is claimed. Manual full-build dispatch for this head returned HTTP 403 (repository admin rights required). Automatic checks are tracked separately; a skipped job is not a pass. Historical verification follows; results below retain their original heads and do not establish validation of the current head. New `guest_legacy_freetype_bitmap_blend` and `guest_legacy_freetype_bitmap_blend_nid` tests load the raw and NID-patched `libfreetype` and `libSceFreeType` modules and run each call side by side with the bundled FreeType on a separate library: - Six blend sequences start from an empty target and grow it in every direction. Sources are mono, 2-bit, 4-bit, 8-bit gray, LCD, LCD_V and BGRA, with padded pitches, offsets with fractional bits and negative values, and opaque, translucent and fully transparent colours. After each step, the error, the target record, every target pixel and the target offset match FreeType, and the source is unchanged. Each target is then released with the guest `FT_Bitmap_Done`. - In-place blending into an existing BGRA target that already covers the source. - Errors and no-ops, compared with FreeType and checked to leave the target untouched: null library, source, target or offset; a `NONE` source; zero-width and zero-height sources; mismatched pitch signs; a non-BGRA target; a source wider than 0x7FFF; and offsets whose result exceeds FreeType's 0x10000-pixel limit. Negative pitches on both bitmaps are covered too. - On Windows: the target record, the target offset and the target pixels are each placed on a guest page made read-only with `sceKernelMprotect` (checked with `VirtualQuery`). Each call is refused without changing any page. A source on a read-only page still blends, and the in-place blend into guest memory matches FreeType once write access is restored. - Sabotage check: swapping the red and blue channels, swapping the offset's x and y, not copying the target offset back, and clearing the target on an error each make both tests fail. Results: - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head `aeca597988` on upstream `ea3ae18716`: `ctest -R guest_legacy_freetype` **4/4 passed in each of 3 runs**. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release, `aeca597988` merged with upstream `04ab293bc2`: `ctest -R guest_legacy_freetype` **4/4 passed in each of 3 runs**, including the read-only page checks. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (406 libraries, 30,649 exports): passed. - `python tools/pr_overlap.py --branch claude/freetype-bitmap-blend` (1,883 open PRs): no shared exports. It shares the new `core/libs/prx/libfreetype/CMakeLists.txt` and neighbouring lines of `Export.cpp`, `LegacyExports.hpp`, `libfreetype.hpp` and the debt file with #15408, #15439, #15442, #15444, #15447 and #15468, which implement other libfreetype exports, so whichever lands later merges `main` and keeps every source and test. No open PR adds or removes `FT_Bitmap_Blend` or its NID. No console or retail-title test. ### 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) - [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: #16394 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
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!16399
No description provided.