From 11eea85f0e4791ca22766666319fd56cabed2fda Mon Sep 17 00:00:00 2001 From: modeco80 Date: Mon, 27 Jan 2025 22:12:22 -0500 Subject: [PATCH] letsplay_runner_core: Make GraphicsContexts clonable It currently consists solely of smart poitners, so cloning just adds a reference count, it doesn't deep copy anything. --- .../letsplay_runner_core/src/client/graphics_contexts.rs | 2 ++ crates/letsplay_runner_retro/src/main.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/crates/letsplay_runner_core/src/client/graphics_contexts.rs b/crates/letsplay_runner_core/src/client/graphics_contexts.rs index 7802268..538165f 100644 --- a/crates/letsplay_runner_core/src/client/graphics_contexts.rs +++ b/crates/letsplay_runner_core/src/client/graphics_contexts.rs @@ -11,6 +11,7 @@ use letsplay_gpu::egl_helpers::DeviceContext; use std::sync::{Arc, Mutex}; #[cfg(feature = "av-nvidia")] +#[derive(Clone)] pub struct GraphicsContexts { pub egl_device_context: Arc>, pub cuda_context: Arc, @@ -18,6 +19,7 @@ pub struct GraphicsContexts { } #[cfg(not(feature = "av-nvidia"))] +#[derive(Clone)] pub struct GraphicsContexts { pub egl_device_context: Arc>, } diff --git a/crates/letsplay_runner_retro/src/main.rs b/crates/letsplay_runner_retro/src/main.rs index 41e87d2..1180137 100644 --- a/crates/letsplay_runner_retro/src/main.rs +++ b/crates/letsplay_runner_retro/src/main.rs @@ -4,6 +4,7 @@ use std::{ time::{Duration, Instant}, }; +use client::GraphicsContexts; use letsplay_core::sleep; use letsplay_gpu::{self as gpu, egl_helpers::DeviceContext}; use letsplay_retro_frontend::{ @@ -14,6 +15,8 @@ use letsplay_runner_core::*; /// Libretro game. very much TODO pub struct RetroGame { + graphics_contexts: Option, + devices: BTreeMap, frontend: Option>, @@ -25,6 +28,7 @@ pub struct RetroGame { impl RetroGame { fn new() -> Box { let mut s = Box::new(Self { + graphics_contexts: None, devices: BTreeMap::new(), frontend: None, frame_duration: Duration::new(0, 0), @@ -57,6 +61,9 @@ impl client::Game for RetroGame { let lk = graphics_contexts.egl_device_context.lock().expect("???"); lk.make_current(); } + + // Scary but these are all Arc<> pointers anyways so its not a big deal + self.graphics_contexts = Some(graphics_contexts.clone()); } fn reset(&mut self) {