winit: Simplify internal renderer trait

Don't require the creation of an Rc<winit window>, leave
that to the caller.
This commit is contained in:
Simon Hausmann 2023-05-09 18:10:32 +02:00 committed by Simon Hausmann
parent 0475b91daf
commit c3cee1c3d9
5 changed files with 13 additions and 13 deletions

View file

@ -24,7 +24,7 @@ pub enum SlintUserEvent {
}
mod renderer {
use std::rc::{Rc, Weak};
use std::rc::Weak;
use i_slint_core::api::PhysicalSize;
use i_slint_core::platform::PlatformError;
@ -37,7 +37,7 @@ mod renderer {
window_adapter_weak: &Weak<dyn WindowAdapter>,
window_builder: winit::window::WindowBuilder,
#[cfg(target_arch = "wasm32")] canvas_id: &str,
) -> Result<(Self, Rc<winit::window::Window>), PlatformError>
) -> Result<(Self, winit::window::Window), PlatformError>
where
Self: Sized;

View file

@ -3,7 +3,7 @@
use std::cell::RefCell;
use std::pin::Pin;
use std::rc::{Rc, Weak};
use std::rc::Weak;
use i_slint_core::api::{
GraphicsAPI, PhysicalSize as PhysicalWindowSize, RenderingNotifier, RenderingState,
@ -60,7 +60,7 @@ impl super::WinitCompatibleRenderer for GlutinFemtoVGRenderer {
window_adapter_weak: &Weak<dyn WindowAdapter>,
window_builder: winit::window::WindowBuilder,
#[cfg(target_arch = "wasm32")] canvas_id: &str,
) -> Result<(Self, Rc<winit::window::Window>), PlatformError> {
) -> Result<(Self, winit::window::Window), PlatformError> {
let (winit_window, opengl_context) = crate::event_loop::with_window_target(|event_loop| {
glcontext::OpenGLContext::new_context(
window_builder,
@ -80,7 +80,7 @@ impl super::WinitCompatibleRenderer for GlutinFemtoVGRenderer {
Ok((
Self { rendering_notifier: Default::default(), renderer, opengl_context },
Rc::new(winit_window),
winit_window,
))
}

View file

@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
use std::rc::{Rc, Weak};
use std::rc::Weak;
use i_slint_core::api::PhysicalSize as PhysicalWindowSize;
use i_slint_core::platform::PlatformError;
@ -17,12 +17,12 @@ impl super::WinitCompatibleRenderer for SkiaRenderer {
fn new(
window_adapter_weak: &Weak<dyn WindowAdapter>,
window_builder: winit::window::WindowBuilder,
) -> Result<(Self, Rc<winit::window::Window>), PlatformError> {
let winit_window = Rc::new(crate::event_loop::with_window_target(|event_loop| {
) -> Result<(Self, winit::window::Window), PlatformError> {
let winit_window = 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)
})
})?);
})?;
let size: winit::dpi::PhysicalSize<u32> = winit_window.inner_size();

View file

@ -10,7 +10,7 @@ use i_slint_core::software_renderer::PremultipliedRgbaColor;
pub use i_slint_core::software_renderer::SoftwareRenderer;
use i_slint_core::window::WindowAdapter;
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::rc::Weak;
pub struct WinitSoftwareRenderer {
renderer: SoftwareRenderer,
@ -23,7 +23,7 @@ impl super::WinitCompatibleRenderer for WinitSoftwareRenderer {
fn new(
window_adapter_weak: &Weak<dyn WindowAdapter>,
window_builder: winit::window::WindowBuilder,
) -> Result<(Self, Rc<winit::window::Window>), PlatformError> {
) -> Result<(Self, winit::window::Window), PlatformError> {
let winit_window = 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 software rendering: {}", winit_os_error)
@ -43,7 +43,7 @@ impl super::WinitCompatibleRenderer for WinitSoftwareRenderer {
),
canvas: RefCell::new(canvas),
},
Rc::new(winit_window),
winit_window,
))
}

View file

@ -164,7 +164,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WinitWindowAdapter<Renderer> {
}) {
Ok((new_renderer, winit_window)) => {
result.renderer = OnceCell::with_value(new_renderer);
result.winit_window = Some(winit_window);
result.winit_window = Some(Rc::new(winit_window));
}
Err(err) => {
platform_error = Some(err);