[NFC] servoshell: clarify that device_pixels_per_px is an override (#30342)

This commit is contained in:
Delan Azabani 2023-09-12 17:29:26 +08:00 committed by GitHub
parent 8299868bd5
commit 5c8fd98aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 15 deletions

View file

@ -47,7 +47,7 @@ enum PumpResult {
impl App { impl App {
pub fn run( pub fn run(
no_native_titlebar: bool, no_native_titlebar: bool,
device_pixels_per_px: Option<f32>, device_pixel_ratio_override: Option<f32>,
user_agent: Option<String>, user_agent: Option<String>,
url: Option<String>, url: Option<String>,
) { ) {
@ -55,13 +55,16 @@ impl App {
// Implements window methods, used by compositor. // Implements window methods, used by compositor.
let window = if opts::get().headless { let window = if opts::get().headless {
headless_window::Window::new(opts::get().initial_window_size, device_pixels_per_px) headless_window::Window::new(
opts::get().initial_window_size,
device_pixel_ratio_override,
)
} else { } else {
Rc::new(headed_window::Window::new( Rc::new(headed_window::Window::new(
opts::get().initial_window_size, opts::get().initial_window_size,
&events_loop, &events_loop,
no_native_titlebar, no_native_titlebar,
device_pixels_per_px, device_pixel_ratio_override,
)) ))
}; };

View file

@ -60,7 +60,7 @@ pub struct Window {
keys_down: RefCell<HashMap<VirtualKeyCode, Key>>, keys_down: RefCell<HashMap<VirtualKeyCode, Key>>,
animation_state: Cell<AnimationState>, animation_state: Cell<AnimationState>,
fullscreen: Cell<bool>, fullscreen: Cell<bool>,
device_pixels_per_px: Option<f32>, device_pixel_ratio_override: Option<f32>,
xr_window_poses: RefCell<Vec<Rc<XRWindowPose>>>, xr_window_poses: RefCell<Vec<Rc<XRWindowPose>>>,
modifiers_state: Cell<ModifiersState>, modifiers_state: Cell<ModifiersState>,
} }
@ -82,7 +82,7 @@ impl Window {
win_size: Size2D<u32, DeviceIndependentPixel>, win_size: Size2D<u32, DeviceIndependentPixel>,
events_loop: &EventsLoop, events_loop: &EventsLoop,
no_native_titlebar: bool, no_native_titlebar: bool,
device_pixels_per_px: Option<f32>, device_pixel_ratio_override: Option<f32>,
) -> Window { ) -> Window {
let opts = opts::get(); let opts = opts::get();
@ -157,7 +157,7 @@ impl Window {
inner_size: Cell::new(inner_size), inner_size: Cell::new(inner_size),
primary_monitor, primary_monitor,
screen_size, screen_size,
device_pixels_per_px, device_pixel_ratio_override,
xr_window_poses: RefCell::new(vec![]), xr_window_poses: RefCell::new(vec![]),
modifiers_state: Cell::new(ModifiersState::empty()), modifiers_state: Cell::new(ModifiersState::empty()),
toolbar_height: Cell::new(0.0), toolbar_height: Cell::new(0.0),
@ -291,8 +291,8 @@ impl Window {
} }
fn servo_hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> { fn servo_hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
match self.device_pixels_per_px { match self.device_pixel_ratio_override {
Some(device_pixels_per_px) => Scale::new(device_pixels_per_px), Some(override_value) => Scale::new(override_value),
_ => match opts::get().output_file { _ => match opts::get().output_file {
Some(_) => Scale::new(1.0), Some(_) => Scale::new(1.0),
None => self.device_hidpi_factor(), None => self.device_hidpi_factor(),

View file

@ -25,13 +25,13 @@ pub struct Window {
webrender_surfman: WebrenderSurfman, webrender_surfman: WebrenderSurfman,
animation_state: Cell<AnimationState>, animation_state: Cell<AnimationState>,
fullscreen: Cell<bool>, fullscreen: Cell<bool>,
device_pixels_per_px: Option<f32>, device_pixel_ratio_override: Option<f32>,
} }
impl Window { impl Window {
pub fn new( pub fn new(
size: Size2D<u32, DeviceIndependentPixel>, size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>, device_pixel_ratio_override: Option<f32>,
) -> Rc<dyn WindowPortsMethods> { ) -> Rc<dyn WindowPortsMethods> {
// Initialize surfman // Initialize surfman
let connection = Connection::new().expect("Failed to create connection"); let connection = Connection::new().expect("Failed to create connection");
@ -47,15 +47,15 @@ impl Window {
webrender_surfman, webrender_surfman,
animation_state: Cell::new(AnimationState::Idle), animation_state: Cell::new(AnimationState::Idle),
fullscreen: Cell::new(false), fullscreen: Cell::new(false),
device_pixels_per_px, device_pixel_ratio_override,
}; };
Rc::new(window) Rc::new(window)
} }
fn servo_hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> { fn servo_hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
match self.device_pixels_per_px { match self.device_pixel_ratio_override {
Some(device_pixels_per_px) => Scale::new(device_pixels_per_px), Some(override_value) => Scale::new(override_value),
_ => Scale::new(1.0), _ => Scale::new(1.0),
} }
} }

View file

@ -121,7 +121,7 @@ pub fn main() {
let clean_shutdown = opts_matches.opt_present("clean-shutdown"); let clean_shutdown = opts_matches.opt_present("clean-shutdown");
let do_not_use_native_titlebar = let do_not_use_native_titlebar =
opts_matches.opt_present("no-native-titlebar") || !(pref!(shell.native_titlebar.enabled)); opts_matches.opt_present("no-native-titlebar") || !(pref!(shell.native_titlebar.enabled));
let device_pixels_per_px = opts_matches.opt_str("device-pixel-ratio").map(|dppx_str| { let device_pixel_ratio_override = opts_matches.opt_str("device-pixel-ratio").map(|dppx_str| {
dppx_str.parse().unwrap_or_else(|err| { dppx_str.parse().unwrap_or_else(|err| {
error!("Error parsing option: --device-pixel-ratio ({})", err); error!("Error parsing option: --device-pixel-ratio ({})", err);
process::exit(1); process::exit(1);
@ -138,7 +138,7 @@ pub fn main() {
App::run( App::run(
do_not_use_native_titlebar, do_not_use_native_titlebar,
device_pixels_per_px, device_pixel_ratio_override,
user_agent, user_agent,
url_opt.map(|s| s.to_string()), url_opt.map(|s| s.to_string()),
); );