1use std::sync::Arc;
28
29use iced::widget::image;
30
31pub mod engines;
33pub use engines::{Engine, PageType, PixelFormat, ViewId};
34
35mod webview;
36pub use basic::{Action, WebView};
37pub use webview::{advanced, basic};
38
39#[cfg(feature = "blitz")]
40pub use engines::blitz::Blitz;
41
42#[cfg(feature = "litehtml")]
43pub use engines::litehtml::Litehtml;
44
45#[cfg(feature = "servo")]
46pub use engines::servo::Servo;
47
48#[cfg(feature = "cef")]
49pub use engines::cef_engine::{cef_subprocess_check, Cef};
50
51pub(crate) mod util;
52
53#[cfg(any(feature = "litehtml", feature = "blitz"))]
54pub(crate) mod fetch;
55
56#[derive(Clone, Debug)]
58pub struct ImageInfo {
59 width: u32,
60 height: u32,
61 handle: image::Handle,
62 raw_pixels: Arc<Vec<u8>>,
63}
64
65impl Default for ImageInfo {
66 fn default() -> Self {
67 let pixels = vec![255; (Self::WIDTH as usize * Self::HEIGHT as usize) * 4];
68 let raw_pixels = Arc::new(pixels.clone());
69 Self {
70 width: Self::WIDTH,
71 height: Self::HEIGHT,
72 handle: image::Handle::from_rgba(Self::WIDTH, Self::HEIGHT, pixels),
73 raw_pixels,
74 }
75 }
76}
77
78impl ImageInfo {
79 const WIDTH: u32 = 800;
81 const HEIGHT: u32 = 800;
82
83 fn new(mut pixels: Vec<u8>, format: PixelFormat, width: u32, height: u32) -> Self {
84 assert_eq!(pixels.len() % 4, 0);
86
87 if let PixelFormat::Bgra = format {
88 pixels.chunks_mut(4).for_each(|chunk| chunk.swap(0, 2));
89 }
90
91 let raw_pixels = Arc::new(pixels.clone());
92 Self {
93 width,
94 height,
95 handle: image::Handle::from_rgba(width, height, pixels),
96 raw_pixels,
97 }
98 }
99
100 pub fn as_handle(&self) -> image::Handle {
102 self.handle.clone()
103 }
104
105 pub fn image_width(&self) -> u32 {
107 self.width
108 }
109
110 pub fn image_height(&self) -> u32 {
112 self.height
113 }
114
115 pub fn pixels(&self) -> Arc<Vec<u8>> {
117 Arc::clone(&self.raw_pixels)
118 }
119
120 fn blank(width: u32, height: u32) -> Self {
121 let pixels = vec![255; (width as usize * height as usize) * 4];
122 let raw_pixels = Arc::new(pixels.clone());
123 Self {
124 width,
125 height,
126 handle: image::Handle::from_rgba(width, height, pixels),
127 raw_pixels,
128 }
129 }
130}