Skip to content

Commit

Permalink
Extract the FemtoVG renderer into a separate crate
Browse files Browse the repository at this point in the history
This will be needed for a future experiment. Unlike the Skia renderer,
which operates on raw window handles, the FemtoVG renderer exposes a
different interface where it assumes that the caller takes care of the
OpenGL context state. This means more boilerplate remains in the winit
backend, including the glutin dependency. The upside is that it will
allow using the FemtoVG renderer in environments without glutin.

In order to work in an environment without fontconfig or memmap, the
crate has two features:

  - fontconfig (set when we anticipate fontconfig to be available at
    run-time and libloading being available at compile time).
  - diskfonts (set when we want to be able to load fonts from disk)

The winit crate enables fontconfig on "Linux" and diskfonts on !wasm.
  • Loading branch information
tronical committed Feb 22, 2023
1 parent 87cb949 commit fb20256
Show file tree
Hide file tree
Showing 19 changed files with 630 additions and 471 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
'internal/backends/selector',
'internal/backends/testing',
'internal/renderers/skia',
'internal/renderers/femtovg',
'internal/common',
'internal/compiler',
'internal/compiler/parser-test-macro',
Expand Down
25 changes: 7 additions & 18 deletions internal/backends/winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "lib.rs"
[features]
wayland = ["winit/wayland", "glutin/wayland", "copypasta/wayland", "i-slint-renderer-skia?/wayland"]
x11 = ["winit/x11", "glutin/x11", "glutin/glx", "copypasta/x11", "i-slint-renderer-skia?/x11"]
renderer-winit-femtovg = ["femtovg", "fontdb", "libc", "yeslogic-fontconfig-sys", "winapi", "dwrote", "imgref", "unicode-script", "ttf-parser", "rgb", "i-slint-core/box-shadow-cache"]
renderer-winit-femtovg = ["i-slint-renderer-femtovg"]
renderer-winit-skia = ["i-slint-renderer-skia"]
renderer-winit-skia-opengl = ["renderer-winit-skia", "i-slint-renderer-skia/opengl"]
renderer-winit-software = ["softbuffer", "imgref", "rgb", "i-slint-core/systemfonts"]
Expand Down Expand Up @@ -49,45 +49,34 @@ raw-window-handle = { version = "0.5", features = ["alloc"] }
scopeguard = { version = "1.1.0", default-features = false }

# For the FemtoVG renderer
femtovg = { version = "0.6.0", optional = true }
fontdb = { version = "0.12.0", optional = true, default-features = false }
ttf-parser = { version = "0.18.0", optional = true } # Use the same version was femtovg's rustybuzz, to avoid duplicate crates
unicode-script = { version = "0.5.4", optional = true } # Use the same version was femtovg's rustybuzz, to avoid duplicate crates
imgref = { version = "1.6.1", optional = true }
rgb = { version = "0.8.27", optional = true }
i-slint-renderer-femtovg = { version = "=1.0.0", path = "../../renderers/femtovg", optional = true }

# For the Skia renderer
i-slint-renderer-skia = { version = "=1.0.0", path = "../../renderers/skia", optional = true }

# For the software renderer
softbuffer = { version = "0.2.0", optional = true }
imgref = { version = "1.6.1", optional = true }
rgb = { version = "0.8.27", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features=["console", "WebGlContextAttributes", "CanvasRenderingContext2d", "HtmlInputElement", "HtmlCanvasElement", "Window", "Document", "CssStyleDeclaration", "Event", "KeyboardEvent", "InputEvent", "CompositionEvent"] }
web-sys = { version = "0.3", features=["HtmlInputElement", "HtmlCanvasElement", "Window", "Document", "Event", "KeyboardEvent", "InputEvent", "CompositionEvent"] }
wasm-bindgen = { version = "0.2" }
send_wrapper = "0.6.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
fontdb = { version = "0.12", optional = true, features = ["memmap", "fontconfig"] }
glutin = { version = "0.30", optional = true, default-features = false, features = ["egl", "wgl"] }

# For the FemtoVG renderer
[target.'cfg(target_family = "windows")'.dependencies]
dwrote = { version = "0.11.0", optional = true }
winapi = { version = "0.3", optional = true, features = ["dwrite"] }
i-slint-renderer-femtovg = { version = "=1.0.0", path = "../../renderers/femtovg", optional = true, features = ["diskfonts"] }

[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies]
libc = { version = "0.2", optional = true }
yeslogic-fontconfig-sys = { version = "3.2", optional = true }
i-slint-renderer-femtovg = { version = "=1.0.0", path = "../../renderers/femtovg", optional = true, features = ["fontconfig"] }

[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))'.dependencies]
dark-light = "1.0"

[target.'cfg(target_os = "macos")'.dependencies]
# For GL rendering
cocoa = { version = "0.24.0" }
core-foundation = { version = "0.9.1" }
core-text = { version = "19.1.0" }

[build-dependencies]
cfg_aliases = "0.1.0"
8 changes: 5 additions & 3 deletions internal/backends/winit/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod wasm_input_helper;

#[cfg(target_arch = "wasm32")]
pub fn create_gl_window_with_canvas_id(canvas_id: String) -> Rc<dyn WindowAdapter> {
GLWindow::<crate::renderer::femtovg::FemtoVGRenderer>::new(canvas_id)
GLWindow::<crate::renderer::femtovg::GlutinFemtoVGRenderer>::new(canvas_id)
}

fn window_factory_fn<R: WinitCompatibleRenderer + 'static>() -> Rc<dyn WindowAdapter> {
Expand All @@ -70,7 +70,7 @@ fn window_factory_fn<R: WinitCompatibleRenderer + 'static>() -> Rc<dyn WindowAda

cfg_if::cfg_if! {
if #[cfg(feature = "renderer-winit-femtovg")] {
type DefaultRenderer = renderer::femtovg::FemtoVGRenderer;
type DefaultRenderer = renderer::femtovg::GlutinFemtoVGRenderer;
} else if #[cfg(enable_skia_renderer)] {
type DefaultRenderer = renderer::skia::SkiaRenderer;
} else if #[cfg(feature = "renderer-winit-software")] {
Expand Down Expand Up @@ -98,7 +98,9 @@ impl Backend {
pub fn new(renderer_name: Option<&str>) -> Self {
let window_factory_fn = match renderer_name {
#[cfg(feature = "renderer-winit-femtovg")]
Some("gl") | Some("femtovg") => window_factory_fn::<renderer::femtovg::FemtoVGRenderer>,
Some("gl") | Some("femtovg") => {
window_factory_fn::<renderer::femtovg::GlutinFemtoVGRenderer>
}
#[cfg(enable_skia_renderer)]
Some("skia") => window_factory_fn::<renderer::skia::SkiaRenderer>,
#[cfg(feature = "renderer-winit-software")]
Expand Down
Loading

0 comments on commit fb20256

Please sign in to comment.