Crates.io | skulpin |
lib.rs | skulpin |
version | 0.14.1 |
source | src |
created_at | 2019-11-03 05:00:39.899984 |
updated_at | 2021-10-31 00:08:24.689219 |
description | This crate provides an easy option for drawing hardware-accelerated 2D by combining Vulkan and Skia. |
homepage | https://github.com/aclysma/skulpin |
repository | https://github.com/aclysma/skulpin |
max_upload_size | |
id | 177670 |
size | 147,653 |
Skia + Vulkan = Skulpin
This crate provides an easy option for drawing hardware-accelerated 2D by combining vulkan and skia.
This crate mainly depends on:
NOTE: See skia-bindings for more info on how a skia binary acquired. In many cases, this crate will download a binary created by their project's CI.
This crate integrates with raw-window-handle, which allows it to be used with sdl2, winit, and any other windowing framework that supports raw-window-handle.
First, ensure that the below requirements are met depending on OS. Afterwards, the examples can be run normally.
The interactive example is good to look at for an easy way to get keyboard/mouse input.
# winit 0.24
cargo run --example interactive_winit_app --features winit-app,winit-25
# sdl2
cargo run --example interactive_sdl2
The physics demo is fun too.
cargo run --example physics --features winit-app,winit-25
Here's a video of the physics and interactive examples.
This crate is in "maintenance" mode - I'm not adding features or planning any API reworks, but I do plan to make fixes as necessary to address issues that might come up and maintain compatibility with the broader rust ecosystem.
Originally this was just a proof-of-concept, but it is now being used by neovide.
Flutter, Google's new UI framework, uses a Skia + Vulkan stack to achieve 60+ FPS on mobile devices. Because Google is deeply invested in this stack, I anticipate relatively long term support of this type of usage in Skia.
Currently there are two ways to use this library with winit
.
skulpin::Window
. Implementations for sdl2
and
winit
are provided.If you prefer sdl2
you'll need to use the renderer directly. See sdl2 renderer only
Don't forget to install the prerequisites below appropriate to your platform! (See "Requirements")
skia-complete
- Includes all the below skia features. ** This is on by default **skia-shaper
- Enables text shaping with Harfbuzz and ICUskia-svg
- This feature enables the SVG rendering backendskia-textlayout
- Makes the Skia module skparagraph available, which contains types that are used to lay out paragraphsThe skia-bindings
prebuilt binaries are only available for certain combinations of features. As of this writing, it is
available for none, each feature individually, or all features enabled. The vulkan
feature is required and implicitly
used, so enabling any features individually will substantially increase build times. It's recommended to use all
features (default behavior), or disable all features. (use default-features = false
)
winit-app
- Include the winit app wrapper. It's less flexbile than using the renderer directly but is easy to use.If using winit-app, you MUST specify a winit version feature flag (see below)
winit-21
winit-22
winit-23
winit-24
winit-25
winit-latest
(These feature names match the imgui-rs crate.)
# Pull in all skia features and support for all backends (sdl2 and winit)
skulpin = "0"
# Pull in all skia features but not the winit app wrapper
skulpin = { version = "0", default-features = false, features = ["skia-complete"] }
# Pull in all skia features and include the winit app wrapper
skulpin = { version = "0", default-features = false, features = ["skia-complete", "winit-app"] }
Skulpin can be built and used with many versions of skia-safe. In order to be accomodating to users of the library, the required version has been left open-ended. This allows new projects to use more recent versions of these libraries while not forcing old projects to update.
You can force a particular version of skia safe by using cargo update
cargo update -p skia-safe --precise 0.32
Documentation fails to build on docs.rs because the skia_safe crate requires an internet connection to build. (It will either grab skia source code, or grab a prebuilt binary.) So the best way to view docs is to build them yourself:
cargo doc -p skulpin --open
Minimum required rust version: 1.43.0
sdl2 = { version = ">=0.33", features = ["bundled", "static-link"] }
to you Cargo.toml. These are enabled by default for the examples.PATH
.
An easy way to get started is to use the LunarG Vulkan SDKsdl2 = { version = ">=0.33", features = ["bundled", "static-link"] }
to you Cargo.toml. These are enabled by default for the examples.PATH
.
An easy way to get started is to use the LunarG Vulkan SDKsdl2 = { version = ">=0.33", features = ["bundled", "static-link"] }
to you Cargo.toml. These are enabled by default for the examples.libbz2-dev
, libfreetype6-dev
, libfontconfig1-dev
, and libgl-dev
. (And
libvulkan-dev
to pick up the Vulkan SDK)PATH
.
An easy way to get started is to use the LunarG Vulkan SDKIt may be possible to build this for mobile platforms, but I've not investigated this yet.
For the common case, you can draw to the skia canvas using "logical" coordinates and not worry about dpi/scaling issues.
Internally, the skia surface will match the swapchain size, but this size is not necessarily LogicalSize or PhysicalSize of the window. In order to produce consistently-sized results, the renderer will apply a scaling factor to the skia canvas before handing it off to your draw implementation.
There are a few primary choices you should consider when configuring how your app runs
Logical
- Use logical coordinates, which are pixels with a factor applied to count for high resolution displaysPhysical
- Use raw pixels for coordinatesVisibleRange
- Try to fit the given range to the windowFixedWidth
- Use the given X extents and aspect ratio to calculate Y extentsNone
- Do not modify the canvas matrixFifo
(VK_PRESENT_MODE_FIFO_KHR
) is the default behavior and is always present on devices that fully comply to
spec. This will be VSync,shouldn't ever screen tear, and will generally run at display refresh rate.Mailbox
(VK_PRESENT_MODE_MAILBOX_KHR
) will render as quickly as possible. The frames are queued and the latest
complete frame will be drawn. Other frames will be dropped. This rendering method will produce the lowest latency,
but is not always available, and could be an unnecessary drain on battery life for laptops and mobile devices.prefer_fifo_present_mode
/prefer_mailbox_present_mode
for a simple way to choose between the two recommended
options or present_mode_priority
for full control.PresentMode
and the Vulkan spec.Discrete
(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
) - When available, this is likely to be the device with best
performanceIntegrated
(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
) - This will generally be more power efficient that a
Discrete GPU.prefer_integrated_gpu
/prefer_discrete_gpu
for a simple way to choose between the two recommended options or
physical_device_type_priority
for full controlPhysicalDeviceType
and the Vulkan spec.use_vulkan_debug_layer
turns all logging on/offvalidation_layer_debug_report_flags
allows choosing specific log levelsLicensed under either of
at your option.
The fonts directory contains several fonts under their own licenses:
mplus-1p-regular.ttf
, available under its own license.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See LICENSE-APACHE and LICENSE-MIT.