| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | #![doc = include_str!("README.md" )] |
| 5 | #![doc (html_logo_url = "https://slint.dev/logo/slint-logo-square-light.svg" )] |
| 6 | |
| 7 | #[cfg (target_os = "linux" )] |
| 8 | mod fullscreenwindowadapter; |
| 9 | |
| 10 | #[cfg (target_os = "linux" )] |
| 11 | use std::os::fd::OwnedFd; |
| 12 | |
| 13 | #[cfg (target_os = "linux" )] |
| 14 | type DeviceOpener<'a> = dyn Fn(&std::path::Path) -> Result<std::rc::Rc<OwnedFd>, i_slint_core::platform::PlatformError> |
| 15 | + 'a; |
| 16 | |
| 17 | #[cfg (all(target_os = "linux" , feature = "drm" ))] |
| 18 | mod drmoutput; |
| 19 | |
| 20 | #[cfg (target_os = "linux" )] |
| 21 | mod display; |
| 22 | |
| 23 | #[cfg (target_os = "linux" )] |
| 24 | mod renderer { |
| 25 | use i_slint_core::platform::PlatformError; |
| 26 | |
| 27 | use crate::fullscreenwindowadapter::FullscreenRenderer; |
| 28 | |
| 29 | #[cfg (any(feature = "renderer-skia-opengl" , feature = "renderer-skia-vulkan" ))] |
| 30 | pub mod skia; |
| 31 | |
| 32 | #[cfg (feature = "renderer-femtovg" )] |
| 33 | pub mod femtovg; |
| 34 | |
| 35 | #[cfg (feature = "renderer-software" )] |
| 36 | pub mod sw; |
| 37 | |
| 38 | pub fn try_skia_then_femtovg_then_software( |
| 39 | _device_opener: &crate::DeviceOpener, |
| 40 | ) -> Result<Box<dyn FullscreenRenderer>, PlatformError> { |
| 41 | #[allow (unused)] |
| 42 | type FactoryFn = |
| 43 | fn(&crate::DeviceOpener) -> Result<Box<(dyn FullscreenRenderer)>, PlatformError>; |
| 44 | |
| 45 | let renderers = [ |
| 46 | #[cfg (any(feature = "renderer-skia-opengl" , feature = "renderer-skia-vulkan" ))] |
| 47 | ( |
| 48 | "Skia" , |
| 49 | skia::SkiaRendererAdapter::new_try_vulkan_then_opengl_then_software as FactoryFn, |
| 50 | ), |
| 51 | #[cfg (feature = "renderer-femtovg" )] |
| 52 | ("FemtoVG" , femtovg::FemtoVGRendererAdapter::new as FactoryFn), |
| 53 | #[cfg (feature = "renderer-software" )] |
| 54 | ("Software" , sw::SoftwareRendererAdapter::new as FactoryFn), |
| 55 | ("" , |_| Err(PlatformError::NoPlatform)), |
| 56 | ]; |
| 57 | |
| 58 | let mut renderer_errors: Vec<String> = Vec::new(); |
| 59 | for (name, factory) in renderers { |
| 60 | match factory(_device_opener) { |
| 61 | Ok(renderer) => return Ok(renderer), |
| 62 | Err(err) => { |
| 63 | renderer_errors.push(if !name.is_empty() { |
| 64 | format!("Error from {} renderer: {}" , name, err).into() |
| 65 | } else { |
| 66 | "No renderers configured." .into() |
| 67 | }); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | Err(PlatformError::Other(format!( |
| 73 | "Could not initialize any renderer for LinuxKMS backend. \n{}" , |
| 74 | renderer_errors.join(" \n" ) |
| 75 | ))) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #[cfg (target_os = "linux" )] |
| 80 | mod calloop_backend; |
| 81 | |
| 82 | #[cfg (target_os = "linux" )] |
| 83 | pub use calloop_backend::*; |
| 84 | |
| 85 | #[cfg (not(target_os = "linux" ))] |
| 86 | mod noop_backend; |
| 87 | #[cfg (not(target_os = "linux" ))] |
| 88 | pub use noop_backend::*; |
| 89 | |
| 90 | #[doc (hidden)] |
| 91 | pub type NativeWidgets = (); |
| 92 | #[doc (hidden)] |
| 93 | pub type NativeGlobals = (); |
| 94 | #[doc (hidden)] |
| 95 | pub const HAS_NATIVE_STYLE: bool = false; |
| 96 | #[doc (hidden)] |
| 97 | pub mod native_widgets {} |
| 98 | |