libcairo: build it from the Cairo and pixman sources instead of reimplementing the API #19098

Closed
opened 2026-11-12 19:13:26 +00:00 by BSchneppe · 0 comments
BSchneppe commented 2026-11-12 19:13:26 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by BSchneppe on 2026-11-12T19:13:26Z.


libcairo is a hand-written reimplementation of the Cairo API. 90 of its 161 exports are implemented (matrices, image surfaces, contexts, paths, regions, font options, PNG writing), and the pull requests that added them were checked against native Cairo 1.18. Nothing draws yet: cairo_set_source_rgb, cairo_paint, cairo_fill, cairo_stroke, cairo_clip, cairo_mask, the pattern exports and the text and font exports still call NotImplemented_nid_no_patch. What is left is the rasterizer, compositing, patterns and font rendering, which is most of Cairo's code.

Proposal

Add Cairo and pixman as submodules under 3rdparty/, build them from source with CMake as is already done for harfbuzz and fontconfig, and turn core/libs/prx/libcairo into a guest-ABI wrapper around them.

  • The output is Cairo's own, antialiasing included, instead of a reimplementation that is compared against it.
  • The 71 remaining exports become thin wrappers.
  • Cairo is LGPL-2.1 or MPL-1.1 and pixman is MIT, so both can go into a GPL-2.0 project. #15208 already ports code from Cairo's src/cairo-pattern.c with its copyright notice.

What it costs

  • CMake build files for both libraries. Cairo 1.18 builds only with Meson, so its build has to be written for CMake.
  • A guest-ABI shim for each export, and guest-ABI calls for the callbacks Cairo takes: cairo_write_func_t, cairo_read_func_t and the cairo_destroy_func_t of user data.
  • The cairo_ft_* exports take an FT_Face and an FcPattern that the guest got from libfreetype and libfontconfig. The wrapper has to accept the objects those two libraries hand out.
  • The 90 hand-written functions would be replaced, not extended, because Cairo's own surfaces and contexts cannot be mixed with them. Their tests against native Cairo can stay as regression tests.
  • Five open pull requests add or test hand-written exports: #15208, #18404, #18406, #18499 and #18969.

Open questions

  1. Which Cairo and pixman versions does the console's libcairo.sprx carry? docs/dev/debt/libSceNKWebKitRequirements.md compares that module's exports with cairo 1.18.2 and pixman 0.42.2. Nobody has checked libcairo.sprx itself.
  2. Is replacing the hand-written code acceptable? If it is, should the five open pull requests merge first, or wait?

I can do the port if this direction is accepted.

AI-assisted: yes. Claude Code read the libcairo sources, the debt files and the open pull requests, and drafted this issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6357189238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/19098). Originally posted by [BSchneppe](https://github.com/BSchneppe) on 2026-11-12T19:13:26Z. --- libcairo is a hand-written reimplementation of the Cairo API. 90 of its 161 exports are implemented (matrices, image surfaces, contexts, paths, regions, font options, PNG writing), and the pull requests that added them were checked against native Cairo 1.18. Nothing draws yet: `cairo_set_source_rgb`, `cairo_paint`, `cairo_fill`, `cairo_stroke`, `cairo_clip`, `cairo_mask`, the pattern exports and the text and font exports still call `NotImplemented_nid_no_patch`. What is left is the rasterizer, compositing, patterns and font rendering, which is most of Cairo's code. ## Proposal Add Cairo and pixman as submodules under `3rdparty/`, build them from source with CMake as is already done for harfbuzz and fontconfig, and turn `core/libs/prx/libcairo` into a guest-ABI wrapper around them. - The output is Cairo's own, antialiasing included, instead of a reimplementation that is compared against it. - The 71 remaining exports become thin wrappers. - Cairo is LGPL-2.1 or MPL-1.1 and pixman is MIT, so both can go into a GPL-2.0 project. #15208 already ports code from Cairo's `src/cairo-pattern.c` with its copyright notice. ## What it costs - CMake build files for both libraries. Cairo 1.18 builds only with Meson, so its build has to be written for CMake. - A guest-ABI shim for each export, and guest-ABI calls for the callbacks Cairo takes: `cairo_write_func_t`, `cairo_read_func_t` and the `cairo_destroy_func_t` of user data. - The `cairo_ft_*` exports take an `FT_Face` and an `FcPattern` that the guest got from libfreetype and libfontconfig. The wrapper has to accept the objects those two libraries hand out. - The 90 hand-written functions would be replaced, not extended, because Cairo's own surfaces and contexts cannot be mixed with them. Their tests against native Cairo can stay as regression tests. - Five open pull requests add or test hand-written exports: #15208, #18404, #18406, #18499 and #18969. ## Open questions 1. Which Cairo and pixman versions does the console's `libcairo.sprx` carry? `docs/dev/debt/libSceNKWebKitRequirements.md` compares that module's exports with cairo 1.18.2 and pixman 0.42.2. Nobody has checked `libcairo.sprx` itself. 2. Is replacing the hand-written code acceptable? If it is, should the five open pull requests merge first, or wait? I can do the port if this direction is accepted. AI-assisted: yes. Claude Code read the libcairo sources, the debt files and the open pull requests, and drafted this issue.
Sign in to join this conversation.
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#19098
No description provided.