#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
use num_traits::ToPrimitive as _;
use waterui_graphics::gpu_surface::GpuFrame;
use crate::CefPageHandle;
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
use crate::input::{CefInputGpuView, CefSurfaceInput};
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
mod presenter;
#[cfg(target_os = "windows")]
mod windows;
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
fn sync_browser_viewport(page: &CefPageHandle, frame: &GpuFrame<'_>) -> f64 {
let scale = frame.scale();
let logical_width = (f64::from(frame.width) / scale).round().max(1.0);
let logical_height = (f64::from(frame.height) / scale).round().max(1.0);
page.set_viewport(
logical_width
.to_u32()
.expect("CEF logical width exceeds u32"),
logical_height
.to_u32()
.expect("CEF logical height exceeds u32"),
scale.to_f32().expect("CEF scale exceeds f32"),
);
scale
}
#[cfg(target_os = "macos")]
fn request_browser_frame(page: &CefPageHandle, _frame: &mut GpuFrame<'_>) {
page.request_frame();
}
#[cfg(not(target_os = "macos"))]
fn request_browser_frame(page: &CefPageHandle, frame: &mut GpuFrame<'_>) {
page.request_frame();
frame.request_redraw();
}
#[cfg(target_os = "linux")]
#[must_use]
pub fn gpu_view(page: CefPageHandle) -> impl waterui_graphics::gpu_surface::GpuView {
linux::gpu_view(page)
}
#[cfg(target_os = "macos")]
#[must_use]
pub fn gpu_view(page: CefPageHandle) -> impl waterui_graphics::gpu_surface::GpuView {
macos::CefGpuView::new(page)
}
#[cfg(target_os = "windows")]
#[must_use]
pub fn gpu_view(page: CefPageHandle) -> impl waterui_graphics::gpu_surface::GpuView {
windows::CefGpuView::new(page)
}
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
#[must_use]
pub fn gpu_view_with_input(page: CefPageHandle) -> impl waterui_graphics::gpu_surface::GpuView {
CefInputGpuView::new(gpu_view(page.clone()), CefSurfaceInput::new(page))
}