mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #864
864: Remove `power` module r=kvark a=GabrielMajeri **Connections** Closes #859 **Description** Removes the `power.rs` module. If the user wants to detect the battery status and choose between low-power and high-performance, they can do so themselves. **Testing** Tested with core. Co-authored-by: Gabriel Majeri <gabriel.majeri6@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::{
|
||||
device::Device,
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
id::{AdapterId, DeviceId, SurfaceId, Valid},
|
||||
power, span, LifeGuard, PrivateFeatures, Stored, MAX_BIND_GROUPS,
|
||||
span, LifeGuard, PrivateFeatures, Stored, MAX_BIND_GROUPS,
|
||||
};
|
||||
|
||||
use wgt::{Backend, BackendBit, DeviceDescriptor, PowerPreference, BIND_BUFFER_ALIGNMENT};
|
||||
@@ -500,18 +500,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
|
||||
let preferred_gpu = match desc.power_preference {
|
||||
PowerPreference::Default => match power::is_battery_discharging() {
|
||||
Ok(false) => discrete.or(integrated).or(other).or(virt),
|
||||
Ok(true) => integrated.or(discrete).or(other).or(virt),
|
||||
Err(err) => {
|
||||
tracing::debug!(
|
||||
"Power info unavailable, preferring integrated gpu ({})",
|
||||
err
|
||||
);
|
||||
integrated.or(discrete).or(other).or(virt)
|
||||
}
|
||||
},
|
||||
PowerPreference::LowPower => integrated.or(other).or(discrete).or(virt),
|
||||
PowerPreference::Default | PowerPreference::LowPower => {
|
||||
integrated.or(other).or(discrete).or(virt)
|
||||
}
|
||||
PowerPreference::HighPerformance => discrete.or(other).or(integrated).or(virt),
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ pub mod id;
|
||||
pub mod instance;
|
||||
pub mod logging;
|
||||
pub mod pipeline;
|
||||
pub mod power;
|
||||
pub mod resource;
|
||||
pub mod swap_chain;
|
||||
mod track;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("battery status is unsupported on this platform")]
|
||||
Unsupported,
|
||||
#[error("battery status retrieval failed: {0}")]
|
||||
Error(Box<dyn std::error::Error>),
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "battery",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
)
|
||||
))]
|
||||
mod platform {
|
||||
use super::Error;
|
||||
use battery::{self, Manager, State};
|
||||
|
||||
impl From<battery::errors::Error> for Error {
|
||||
fn from(err: battery::errors::Error) -> Error {
|
||||
// Box the error so that the battery::errors::Error type does
|
||||
// not leak out of this module.
|
||||
Error::Error(Box::new(err))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_battery_discharging() -> Result<bool, Error> {
|
||||
let manager = Manager::new()?;
|
||||
for battery in manager.batteries()? {
|
||||
if battery?.state() == State::Discharging {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
not(feature = "battery"),
|
||||
not(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
))
|
||||
))]
|
||||
mod platform {
|
||||
use super::Error;
|
||||
|
||||
pub fn is_battery_discharging() -> Result<bool, Error> {
|
||||
Err(Error::Unsupported)
|
||||
}
|
||||
}
|
||||
|
||||
pub use platform::is_battery_discharging;
|
||||
Reference in New Issue
Block a user