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.
  • Loading branch information
tronical committed Jan 31, 2023
1 parent f34b1bd commit 5f8e9a9
Show file tree
Hide file tree
Showing 17 changed files with 602 additions and 425 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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: 5 additions & 20 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", "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 @@ -50,42 +50,27 @@ raw-window-handle = { version = "0.5", features = ["alloc"] }
scopeguard = { version = "1.1.0", default-features = false }

# For the FemtoVG renderer
femtovg = { version = "0.4.0", optional = true }
fontdb = { version = "0.10.0", optional = true, default-features = false }
ttf-parser = { version = "0.17.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 = "=0.3.4", path = "../../renderers/femtovg", optional = true }

# For the Skia renderer
i-slint-renderer-skia = { version = "=0.3.4", 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.10", 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"] }

[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 }

[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 @@ -57,7 +57,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 @@ -69,7 +69,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 @@ -97,7 +97,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 5f8e9a9

Please sign in to comment.