Cairo (Vector graphic)
a 2D graphics library with support for multiple output devices … - Home / github / wikipedia
Cairo is in a maintenance-only mode. - HN (2024)
When it comes to 2D rendering libraries there is in general not too many options if you want to target CPU or both CPU+GPU. Targeting GPU-only is bad for users that run on a hardware where GPU doesn’t perform well or is not available at all due to driver issues or just not present (like servers). - HN (2024)
- Cairo (CPU only)
- Skia (CPU + GPU) - choosen by ladybug browser
- Tiny Skia (CPU only, not focused on performance)
- GPU only libs (there is many in C++ and Rust)
- Qt’s QPainter (CPU only, GPU without anti-aliasing / deprecated)
The cairo API provides operations similar to the drawing operators of PostScript and PDF. Operations in cairo including stroking and filling cubic Bézier splines, transforming and compositing translucent images, and antialiased text rendering. All drawing operations can be transformed by any affine transformation (scale, rotation, shear, etc.)
Used by
see also
- cairomm - A C++ API for cairo. / doc
- AskGTK: Cairo, Skia and Gtk
Tutorial
Example
- Cairo samples - samples of cairo’s rendered output and the code snippets used to create them.
- Surfaces
- Basic drawing in Cairo
- Drawing Arcs and Circles
Text
Fortunately, the pango library exists and does do sophisticated text layout, shaping, etc. and integrates very nicely with cairo. We heartily recommend that “real” applications wanting to display text with cairo use pango to do it.
SVG
OpenGL / Vulkan
- vkvg - an open-source 2D graphics library written in C using Vulkan as backend. The API follows the same pattern as Cairo, but new functions and original drawing mechanics may be added.
- Using cairo with OpenGL - advice is to render to a glTexture and display it after.
Perf
- Cairo CPU : 1.00
- Cairo GL : 0.25
- Cairo Xlib: 1.60
- Qt Raster : 0.98
- Qt GL : 0.66
- Qt Native : 0.26
- Skia GL : 1.68
- FastUIDraw: 9.20
Build
Use meson now.
Alternatives & Comparison
The proposed c++ 2d graphics standard is based on Cairo. - HN
-
A Proposal to Add 2D GraphicsRendering and Display to C++ / github
- skia / github / HN / wikipedia
- WebKit switching to Skia for 2d graphics rendering (HN 2024) - Skia is a great library, but as all things Google it’s a pain to build.
- Skia Path Ops : High Performance Set Operations for Geometry
- It serves as the graphics engine for Google Chrome and Chrome OS, Android, Mozilla Firefox and Firefox OS, and many other products.
- We use both internally in our products. We find that Cairo is better documented and easier to compile and use, while Skia on the other hand is somewhat faster. - 1
- Cairo and Skia are for high performance 2D vector graphics.
- lyon (rust)
- A crate I want: 2d graphics