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 19, 2024
1 parent edef63b commit 4a20978
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 @@ -251,6 +256,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 @@ -381,7 +398,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 4a20978

Please sign in to comment.