Skip to content

Commit

Permalink
letsplay_runner_core: Make GraphicsContexts clonable
Browse files Browse the repository at this point in the history
It currently consists solely of smart poitners, so cloning just adds a reference count, it doesn't deep copy anything.
  • Loading branch information
modeco80 committed Jan 28, 2025
1 parent b64eea9 commit 11eea85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/letsplay_runner_core/src/client/graphics_contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 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<Mutex<DeviceContext>>,
pub cuda_context: Arc<CudaDevice>,
pub cuda_interop_context: Arc<Mutex<GraphicsResource>>,
}

#[cfg(not(feature = "av-nvidia"))]
#[derive(Clone)]
pub struct GraphicsContexts {
pub egl_device_context: Arc<Mutex<DeviceContext>>,
}
Expand Down
7 changes: 7 additions & 0 deletions crates/letsplay_runner_retro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -14,6 +15,8 @@ use letsplay_runner_core::*;

/// Libretro game. very much TODO
pub struct RetroGame {
graphics_contexts: Option<GraphicsContexts>,

devices: BTreeMap<i32, AnyDevice>,

frontend: Option<Box<Frontend>>,
Expand All @@ -25,6 +28,7 @@ pub struct RetroGame {
impl RetroGame {
fn new() -> Box<Self> {
let mut s = Box::new(Self {
graphics_contexts: None,
devices: BTreeMap::new(),
frontend: None,
frame_duration: Duration::new(0, 0),
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 11eea85

Please sign in to comment.