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 17, 2024
1 parent 9d46f05 commit bc541b2
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::{
CpalAudioBackend, DesktopExternalInterfaceProvider, DesktopFSCommandProvider,
DesktopNavigatorInterface, DesktopUiBackend,
};
use crate::cli::GameModePreference;
use crate::custom_event::RuffleEvent;
use crate::gui::{FilePicker, MovieView};
use crate::preferences::GlobalPreferences;
Expand All @@ -21,6 +22,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 @@ -117,6 +119,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 @@ -249,6 +254,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 @@ -379,7 +396,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 bc541b2

Please sign in to comment.