euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

impl DirectGpuSpyCounters {
    pub(crate) fn new_shared() -> Arc<Self> {
        Arc::new(Self {
            gpu_presents: AtomicUsize::new(0),
            fb_presents: AtomicUsize::new(0),
        })
    }
}

impl DirectGpuSpyBackend {
    pub(crate) fn new(counters: Arc<DirectGpuSpyCounters>, inject_device_lost: bool) -> Self {
        Self {
            inner: HeadlessPlatform::default(),
            counters,
            inject_device_lost,
        }
    }
}

impl WindowController for DirectGpuSpyBackend {
    fn apply_command(&mut self, command: WindowCommand) -> Result<(), PlatformError> {
        self.inner.apply_command(command)
    }
}

impl PlatformBackend for DirectGpuSpyBackend {
    fn kind(&self) -> PlatformKind {
        PlatformKind::MacOs
    }

    fn capabilities(&self) -> PlatformCapabilities {
        PlatformCapabilities::for_platform(PlatformKind::MacOs)
    }

    fn create_window(&mut self, config: &WindowConfig) -> Result<WindowState, PlatformError> {
        self.inner.create_window(config)
    }

    fn window_state(&self, id: WindowId) -> Option<WindowState> {
        self.inner.window_state(id)
    }

    fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle {
        self.inner.raw_window_handle(id)
    }

    fn poll_events(&mut self) -> Vec<WindowEvent> {
        self.inner.poll_events()
    }

    fn present_framebuffer(
        &mut self,
        id: WindowId,
        framebuffer: &Framebuffer,
    ) -> Result<(), PlatformError> {
        let _: usize = self.counters.fb_presents.fetch_add(1, Ordering::Relaxed);
        self.inner.present_framebuffer(id, framebuffer)
    }

    fn present_gpu_frame(
        &mut self,
        _id: WindowId,
        submission: &GpuFrameSubmission,
    ) -> Result<GpuPresentReceipt, PlatformError> {
        let _: usize = self.counters.gpu_presents.fetch_add(1, Ordering::Relaxed);
        if self.inject_device_lost {
            return Ok(GpuPresentReceipt::new(false, 0, 0, 0, 0, true));
        }
        Ok(GpuPresentReceipt::new(
            true,
            submission.get_batches().len().max(1),
            submission.total_primitive_count(),
            123_456,
            42_000,
            false,
        ))
    }

    fn read_clipboard(&self) -> Option<String> {
        self.inner.read_clipboard()
    }

    fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError> {
        self.inner.write_clipboard(text)
    }

    fn system_theme(&self) -> ThemeMode {
        self.inner.system_theme()
    }
}