Skip to content

Commit

Permalink
desktop: Use gamemode when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh committed Sep 18, 2024
1 parent a6c99ce commit 7f1f8ab
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion desktop/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::backends::{
DesktopExternalInterfaceProvider, DesktopFSCommandProvider, DesktopNavigatorInterface,
DesktopUiBackend,
};
use crate::cli::GameModePreference;
use crate::custom_event::RuffleEvent;
use crate::gui::{FilePicker, MovieView};
use crate::preferences::GlobalPreferences;
Expand All @@ -22,6 +23,7 @@ use ruffle_frontend_utils::recents::Recent;
use ruffle_render::backend::RenderBackend;
use ruffle_render::quality::StageQuality;
use ruffle_render_wgpu::backend::WgpuRenderBackend;
use ruffle_render_wgpu::clap::PowerPreference;
use ruffle_render_wgpu::descriptors::Descriptors;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -118,6 +120,9 @@ impl PollRequester for WinitWaker {
struct ActivePlayer {
player: Arc<Mutex<Player>>,
executor: Arc<AsyncExecutor<WinitWaker>>,

#[cfg(target_os = "linux")]
_gamemode_session: crate::dbus::GameModeSession,
}

impl ActivePlayer {
Expand Down Expand Up @@ -250,6 +255,18 @@ impl ActivePlayer {
}
}

let gamemode_enable = match preferences.gamemode_preference() {
GameModePreference::Default => {
preferences.graphics_power_preference() == PowerPreference::High
}
GameModePreference::On => true,
GameModePreference::Off => false,
};

if cfg!(not(target_os = "linux")) && gamemode_enable {
tracing::warn!("Cannot enable GameMode, as it is supported only on Linux");
}

let renderer = WgpuRenderBackend::new(descriptors, movie_view)
.map_err(|e| anyhow!(e.to_string()))
.expect("Couldn't create wgpu rendering backend");
Expand Down Expand Up @@ -380,7 +397,12 @@ impl ActivePlayer {
);
}

Self { player, executor }
Self {
player,
executor,
#[cfg(target_os = "linux")]
_gamemode_session: crate::dbus::GameModeSession::new(gamemode_enable),
}
}
}

Expand Down

0 comments on commit 7f1f8ab

Please sign in to comment.