mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
winit: Always make skia-opengl
available
The Skia OpenGL renderer is portable and sometimes esp. on Windows produces better results, so make it always available as an open if `renderer-skia` is enabled. `renderer-skia-opengl` continues to select the GL renderer as default.
This commit is contained in:
parent
866300c34b
commit
93142bf417
5 changed files with 46 additions and 3 deletions
|
@ -15,6 +15,7 @@ The Winit backend supports different renderers. They can be explicitly selected
|
|||
| FemtoVG | OpenGL | `winit-femtovg` |
|
||||
| Skia | OpenGL, Metal, Direct3D, Software-rendering | `winit-skia` |
|
||||
| Skia Software | Software-only rendering with Skia | `winit-skia-software` |
|
||||
| Skia OpenGL | OpenGL rendering with Skia | `winit-skia-opengl` |
|
||||
| software | Software-rendering, no GPU required | `winit-software` |
|
||||
|
||||
|
||||
|
|
|
@ -177,6 +177,8 @@ impl Backend {
|
|||
Some("gl") | Some("femtovg") => renderer::femtovg::GlutinFemtoVGRenderer::new,
|
||||
#[cfg(enable_skia_renderer)]
|
||||
Some("skia") => renderer::skia::WinitSkiaRenderer::new,
|
||||
#[cfg(enable_skia_renderer)]
|
||||
Some("skia-opengl") => renderer::skia::WinitSkiaRenderer::new_opengl,
|
||||
#[cfg(all(enable_skia_renderer, not(target_os = "android")))]
|
||||
Some("skia-software") => renderer::skia::WinitSkiaRenderer::new_software,
|
||||
#[cfg(feature = "renderer-software")]
|
||||
|
|
|
@ -58,6 +58,29 @@ impl WinitSkiaRenderer {
|
|||
|
||||
Ok((Box::new(Self { renderer }), winit_window))
|
||||
}
|
||||
|
||||
pub fn new_opengl(
|
||||
window_builder: winit::window::WindowBuilder,
|
||||
) -> Result<(Box<dyn super::WinitCompatibleRenderer>, Rc<winit::window::Window>), PlatformError>
|
||||
{
|
||||
let winit_window = Rc::new(crate::event_loop::with_window_target(|event_loop| {
|
||||
window_builder.build(event_loop.event_loop_target()).map_err(|winit_os_error| {
|
||||
format!("Error creating native window for Skia rendering: {}", winit_os_error)
|
||||
.into()
|
||||
})
|
||||
})?);
|
||||
|
||||
let renderer = i_slint_renderer_skia::SkiaRenderer::default_opengl();
|
||||
|
||||
renderer.set_pre_present_callback(Some(Box::new({
|
||||
let winit_window = winit_window.clone();
|
||||
move || {
|
||||
winit_window.pre_present_notify();
|
||||
}
|
||||
})));
|
||||
|
||||
Ok((Box::new(Self { renderer }), winit_window))
|
||||
}
|
||||
}
|
||||
|
||||
impl super::WinitCompatibleRenderer for WinitSkiaRenderer {
|
||||
|
|
|
@ -21,7 +21,7 @@ path = "lib.rs"
|
|||
[features]
|
||||
wayland = ["glutin/wayland", "softbuffer/wayland", "softbuffer/wayland-dlopen"]
|
||||
x11 = ["glutin/x11", "glutin/glx", "softbuffer/x11", "softbuffer/x11-dlopen"]
|
||||
opengl = ["skia-safe/gl"]
|
||||
opengl = []
|
||||
vulkan = ["skia-safe/vulkan", "ash", "vulkano"]
|
||||
kms = ["softbuffer/kms"]
|
||||
default = []
|
||||
|
@ -42,7 +42,7 @@ pin-weak = "1"
|
|||
scoped-tls-hkt = "0.1"
|
||||
raw-window-handle = { version = "0.5", features = ["std"] }
|
||||
|
||||
skia-safe = { version = "0.69.0", features = ["textlayout"] }
|
||||
skia-safe = { version = "0.69.0", features = ["textlayout", "gl"] }
|
||||
glow = { version = "0.13" }
|
||||
unicode-segmentation = { version = "1.8.0" }
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ pub mod d3d_surface;
|
|||
#[cfg(skia_backend_vulkan)]
|
||||
pub mod vulkan_surface;
|
||||
|
||||
#[cfg(skia_backend_opengl)]
|
||||
pub mod opengl_surface;
|
||||
|
||||
pub use skia_safe;
|
||||
|
@ -135,6 +134,24 @@ impl SkiaRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a new SkiaRenderer that will always use Skia's OpenGL renderer.
|
||||
pub fn default_opengl() -> Self {
|
||||
Self {
|
||||
maybe_window_adapter: Default::default(),
|
||||
rendering_notifier: Default::default(),
|
||||
image_cache: Default::default(),
|
||||
path_cache: Default::default(),
|
||||
rendering_metrics_collector: Default::default(),
|
||||
rendering_first_time: Default::default(),
|
||||
surface: Default::default(),
|
||||
surface_factory: |window_handle, display_handle, size| {
|
||||
opengl_surface::OpenGLSurface::new(window_handle, display_handle, size)
|
||||
.map(|r| Box::new(r) as Box<dyn Surface>)
|
||||
},
|
||||
pre_present_callback: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new renderer is associated with the provided window adapter.
|
||||
pub fn new(
|
||||
window_handle: raw_window_handle::WindowHandle<'_>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue