Skia Graphics Engine 🚧
Skia does one thing really well, 2D graphics.
The original “Skia” was the development name for QuickDraw GX.
This Skia—which, again, doesn’t share code with either of its predecessors—is a kind of version 3, with a tribute name back to that original Skia. - HN / wikipedia
- Skia vs Cairo vs Direct2D, which is the most feature rich? - It is far not that trivial to integrate Skia with existing 3D OpenGL code. Even Skia can work with OpenGL backend it changes state of OpenGL device and that creates problems.
Cairo emphasizes ease of use and high-quality, device-independent rendering with a stateful API, while Skia targets performance and flexibility, especially in GPU-accelerated environments, with a stateless, more granular control of each drawing operation. Depending on whether the focus is on performance or precision, one library might be a better fit than the other. - ChatGPT
Overview
Drawing Text ? 🚧
Example
Setup
Skia doesn’t seems to be already available as binary and you need to compile it yourself.
One way is to use chromium depot_tools
Procedure doesn’t install gn
tools, one easy way is to build it directly.
see gn.
Here is a a detail procedure
Install Depot Tools
# Clone Depot Tools
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# Set Environment Variables
$ export PATH="$PATH:/path/to/depot_tools"
Build gn binary May require clang to be installed
$ git clone https://gn.googlesource.com/gn
$ cd gn
$ python build/gen.py # --allow-warning if you want to build with warnings.
$ ninja -C out
# To run tests:
$ out/gn_unittests
Build skia
# go back to your project directory
# Fetch Skia Source Code
$ gclient config --name=skia https://skia.googlesource.com/skia.git
$ gclient sync
# link gn where it belongs
$ mkdir -p skia/buildtools/linux64
$ cd skia/buildtools/linux64
$ ln -s <path to gn>/out/gn .
$ cd -
# skia need also a link in ./bin or it will failed in is_official_build=false while trying to build dm
$ mkdir -p skia/bin
$ cd skia/bin
$ ln -s <path to gn>/out/gn .
$ cd -
# The next command may failed silently when gn is not present: normal output is build.ninja file
# different flags combination can be used
# is_official_build=false: Ensures all test and example programs (including dm) are built.
# gn gen out/Release --args='is_debug=false'
# gn gen out/Release --args='is_official_build=false is_debug=false skia_use_gl=true skia_use_expat=true skia_use_libpng=true skia_use_zlib=true'
$ gn gen out/Release --args='is_official_build=false is_debug=false skia_use_gl=true'
# You can also check the args.gn file in the out/Release directory to confirm that skia_use_gl=true is set.
# if everything is ok, you now have a build.ninja
# launch compile and go for a coffee
$ ninja -C out/Release skia
# You should see built files and libraries related to Skia.
$ ls out/Release
# Run the dm (Drawing Manager) to test different backends: This will test Skia’s OpenGL rendering.
# this is only build/buildable if is_official_build=false has been set
$ ninja -C out/Release dm
$ out/Release/dm --config gl
Adding Skia to a meson project
project('my_project', 'cpp')
# Step 1: Locate Skia
skia_inc_dir = '/path/to/skia/include'
skia_lib_dir = '/path/to/skia/out/Release'
# Step 2: Declare Skia dependency manually
skia_dep = declare_dependency(
include_directories: [skia_inc_dir],
link_args: [
skia_lib_dir + '/libskia.a', # Link to the built static library
skia_lib_dir + '/libskshaper.a', # Other Skia modules if necessary
],
dependencies: [
dependency('freetype2'), # Skia uses freetype for font rendering
dependency('fontconfig', required: false), # Optional, based on your needs
# Add more system dependencies here if Skia needs them (e.g., icu, harfbuzz)
]
)
# Step 3: Your source files
executable(
'my_executable',
sources: ['main.cpp'],
dependencies: [skia_dep],
install: true
)