mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 18:29:09 +00:00
Make the SkiaRenderer public in the Rust API
It's also public in the C++ API and this is the equivalent change on the Rust API side.
This commit is contained in:
parent
040019c7b6
commit
9d27f0cc96
3 changed files with 36 additions and 19 deletions
|
@ -134,13 +134,13 @@ renderer-winit-software = ["renderer-software"]
|
|||
renderer-femtovg = ["i-slint-backend-selector/renderer-femtovg", "std"]
|
||||
|
||||
## Render using [Skia](https://skia.org/).
|
||||
renderer-skia = ["i-slint-backend-selector/renderer-skia", "std"]
|
||||
renderer-skia = ["i-slint-backend-selector/renderer-skia", "dep:i-slint-renderer-skia", "std"]
|
||||
|
||||
## Same as `renderer-skia`, but Skia will always use OpenGL.
|
||||
renderer-skia-opengl = ["i-slint-backend-selector/renderer-skia-opengl", "std"]
|
||||
renderer-skia-opengl = ["i-slint-backend-selector/renderer-skia-opengl", "dep:i-slint-renderer-skia", "std"]
|
||||
|
||||
## Same as `renderer-skia`, but Skia will always use Vulkan.
|
||||
renderer-skia-vulkan = ["i-slint-backend-selector/renderer-skia-vulkan", "std"]
|
||||
renderer-skia-vulkan = ["i-slint-backend-selector/renderer-skia-vulkan", "dep:i-slint-renderer-skia", "std"]
|
||||
|
||||
## Render using the software renderer.
|
||||
renderer-software = ["i-slint-backend-selector/renderer-software", "i-slint-core/software-renderer"]
|
||||
|
@ -153,6 +153,7 @@ backend-linuxkms = ["i-slint-backend-selector/backend-linuxkms", "std"]
|
|||
i-slint-core = { version = "=1.2.0", path = "../../../internal/core", default-features = false }
|
||||
slint-macros = { version = "=1.2.0", path = "../macros" }
|
||||
i-slint-backend-selector = { version = "=1.2.0", path = "../../../internal/backends/selector" }
|
||||
i-slint-renderer-skia = { version = "=1.2.0", path = "../../../internal/renderers/skia", optional = true, default-features = false }
|
||||
|
||||
const-field-offset = { version = "0.1.2", path = "../../../helper_crates/const-field-offset" }
|
||||
document-features = { version = "0.2.0", optional = true }
|
||||
|
@ -177,4 +178,4 @@ rustdoc-args = [
|
|||
"--html-in-header",
|
||||
"docs/resources/slint-docs-highlight.html",
|
||||
]
|
||||
features = ["document-features", "log", "gettext", "renderer-software", "renderer-femtovg"]
|
||||
features = ["document-features", "log", "gettext", "renderer-software", "renderer-femtovg", "renderer-skia"]
|
||||
|
|
|
@ -349,6 +349,14 @@ macro_rules! init_translations {
|
|||
/// The [Slint on Microcontrollers](crate::docs::mcu) documentation has additional examples.
|
||||
pub mod platform {
|
||||
pub use i_slint_core::platform::*;
|
||||
|
||||
/// This module contains the [`skia_renderer::SkiaRenderer`] and related types.
|
||||
///
|
||||
/// It is only enabled when the `renderer-skia` Slint feature is enabled.
|
||||
#[cfg(any(feature = "renderer-skia", feature = "renderer-skia-opengl", feature = "renderer-skia-vulkan"))]
|
||||
pub mod skia_renderer {
|
||||
pub use i_slint_renderer_skia::SkiaRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper type that helps checking that the generated code is generated for the right version
|
||||
|
|
|
@ -68,7 +68,13 @@ pub struct SkiaRenderer {
|
|||
}
|
||||
|
||||
impl SkiaRenderer {
|
||||
/// Creates a new renderer is associated with the provided window adapter.
|
||||
/// Creates a new renderer for the given window/display handle. The provided size
|
||||
/// must match the size of the underlying native window.
|
||||
///
|
||||
/// Subsequent calls to [`Self::render()`] will render into the window.
|
||||
///
|
||||
/// Safety: It is the caller's responsibility to ensure that the underlying native
|
||||
/// window exists and remains valid for the life-time of the SkiaRenderer.
|
||||
pub fn new(
|
||||
window_handle: raw_window_handle::WindowHandle<'_>,
|
||||
display_handle: raw_window_handle::DisplayHandle<'_>,
|
||||
|
@ -79,20 +85,7 @@ impl SkiaRenderer {
|
|||
Ok(Self::new_with_surface(surface))
|
||||
}
|
||||
|
||||
/// Creates a new renderer with the given surface trait implementation.
|
||||
pub fn new_with_surface(surface: impl Surface + 'static) -> 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: Cell::new(true),
|
||||
surface: Box::new(surface),
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the scene in the previously associated window.
|
||||
/// Render the scene to the window.
|
||||
pub fn render(&self) -> Result<(), i_slint_core::platform::PlatformError> {
|
||||
self.internal_render_with_post_callback(None)
|
||||
}
|
||||
|
@ -436,6 +429,8 @@ pub trait Surface {
|
|||
}
|
||||
|
||||
pub trait SkiaRendererExt {
|
||||
fn new_with_surface(surface: impl Surface + 'static) -> Self;
|
||||
|
||||
fn render_with_post_callback(
|
||||
&self,
|
||||
post_render_cb: Option<&dyn Fn(&mut dyn ItemRenderer)>,
|
||||
|
@ -443,6 +438,19 @@ pub trait SkiaRendererExt {
|
|||
}
|
||||
|
||||
impl SkiaRendererExt for SkiaRenderer {
|
||||
/// Creates a new renderer with the given surface trait implementation.
|
||||
fn new_with_surface(surface: impl Surface + 'static) -> 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: Cell::new(true),
|
||||
surface: Box::new(surface),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_with_post_callback(
|
||||
&self,
|
||||
post_render_cb: Option<&dyn Fn(&mut dyn ItemRenderer)>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue