use std::sync::Arc;
use iced::widget::image;
pub mod engines;
pub use engines::{Engine, PageType, PixelFormat, ViewId};
mod webview;
pub use basic::{Action, WebView};
pub use webview::{advanced, basic};
#[cfg(feature = "blitz")]
pub use engines::blitz::Blitz;
#[cfg(feature = "litehtml")]
pub use engines::litehtml::Litehtml;
#[cfg(feature = "servo")]
pub use engines::servo::Servo;
#[cfg(feature = "cef")]
pub use engines::cef_engine::{cef_subprocess_check, Cef};
pub(crate) mod util;
#[cfg(any(feature = "litehtml", feature = "blitz"))]
pub(crate) mod fetch;
#[derive(Clone, Debug)]
pub struct ImageInfo {
width: u32,
height: u32,
handle: image::Handle,
raw_pixels: Arc<Vec<u8>>,
}
impl Default for ImageInfo {
fn default() -> Self {
Self::blank(Self::WIDTH, Self::HEIGHT)
}
}
impl ImageInfo {
const WIDTH: u32 = 800;
const HEIGHT: u32 = 800;
#[allow(dead_code)]
fn new(mut pixels: Vec<u8>, format: PixelFormat, width: u32, height: u32) -> Self {
assert_eq!(pixels.len() % 4, 0);
if let PixelFormat::Bgra = format {
pixels.chunks_mut(4).for_each(|chunk| chunk.swap(0, 2));
}
let raw_pixels = Arc::new(pixels);
Self {
width,
height,
handle: image::Handle::from_rgba(width, height, (*raw_pixels).clone()),
raw_pixels,
}
}
#[allow(dead_code)]
pub(crate) fn from_shader_pixels(pixels: Vec<u8>, width: u32, height: u32) -> Self {
debug_assert_eq!(pixels.len() % 4, 0);
Self {
width,
height,
handle: image::Handle::from_rgba(1, 1, vec![0u8; 4]),
raw_pixels: Arc::new(pixels),
}
}
pub fn as_handle(&self) -> image::Handle {
self.handle.clone()
}
pub fn image_width(&self) -> u32 {
self.width
}
pub fn image_height(&self) -> u32 {
self.height
}
pub fn pixels(&self) -> Arc<Vec<u8>> {
Arc::clone(&self.raw_pixels)
}
fn blank(width: u32, height: u32) -> Self {
let (w, h) = (width as usize)
.checked_mul(height as usize)
.and_then(|n| n.checked_mul(4))
.map_or((1u32, 1u32), |_| (width, height));
let pixels = vec![255; (w as usize * h as usize) * 4];
let raw_pixels = Arc::new(pixels.clone());
Self {
width: w,
height: h,
handle: image::Handle::from_rgba(w, h, pixels),
raw_pixels,
}
}
}