servoshell: Allow overriding screen resolution with a command-line argument (#34038)

There is a command-line argument to override the default window size,
but not one for overriding the default screen resolution. This is
important for testing pages that use screen size to have different
behavior.

In addition to adding the new option this change:

 - Renames the `--resolution` command-line argument to `--window-size`
   to remove ambiguity with the `--screen-size` argument.
 - Passes the screen size as device independent (device pixels scaled by
   HiDPI factor) to Servo internals. Not only it make it simpler to pass
   the `--window-size` override, it makes more sense. Different screens
   can have different HiDPI factors and these can be different from the
   scale of the window. This makes the screen HiDPI factor totally
   independent of the one that Servo uses for the window.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-10-30 12:54:13 +01:00 committed by GitHub
parent d877962ee8
commit 850e59f98e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 181 additions and 115 deletions

View file

@ -5,8 +5,8 @@
use dom_struct::dom_struct;
use euclid::Size2D;
use profile_traits::ipc;
use servo_geometry::DeviceIndependentIntSize;
use style_traits::CSSPixel;
use webrender_api::units::DeviceIntSize;
use webrender_traits::CrossProcessCompositorMessage;
use crate::dom::bindings::codegen::Bindings::ScreenBinding::ScreenMethods;
@ -35,28 +35,28 @@ impl Screen {
fn screen_size(&self) -> Size2D<u32, CSSPixel> {
let (send, recv) =
ipc::channel::<DeviceIntSize>(self.global().time_profiler_chan().clone()).unwrap();
ipc::channel::<DeviceIndependentIntSize>(self.global().time_profiler_chan().clone())
.unwrap();
self.window
.compositor_api()
.sender()
.send(CrossProcessCompositorMessage::GetScreenSize(send))
.unwrap();
let dpr = self.window.device_pixel_ratio();
let screen = recv.recv().unwrap_or(Size2D::zero());
(screen.to_f32() / dpr).to_u32()
let size = recv.recv().unwrap_or(Size2D::zero()).to_u32();
Size2D::new(size.width, size.height)
}
fn screen_avail_size(&self) -> Size2D<u32, CSSPixel> {
let (send, recv) =
ipc::channel::<DeviceIntSize>(self.global().time_profiler_chan().clone()).unwrap();
ipc::channel::<DeviceIndependentIntSize>(self.global().time_profiler_chan().clone())
.unwrap();
self.window
.compositor_api()
.sender()
.send(CrossProcessCompositorMessage::GetAvailableScreenSize(send))
.unwrap();
let dpr = self.window.device_pixel_ratio();
let screen = recv.recv().unwrap_or(Size2D::zero());
(screen.to_f32() / dpr).to_u32()
let size = recv.recv().unwrap_or(Size2D::zero()).to_u32();
Size2D::new(size.width, size.height)
}
}

View file

@ -63,7 +63,7 @@ use selectors::attr::CaseSensitivity;
use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_config::pref;
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
use servo_geometry::{f32_rect_to_au_rect, DeviceIndependentIntRect, MaxRect};
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use style::dom::OpaqueNode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
@ -76,7 +76,7 @@ use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{CssRuleType, Origin, UrlExtraData};
use style_traits::{CSSPixel, DevicePixel, ParsingMode};
use url::Position;
use webrender_api::units::{DeviceIntRect, LayoutPixel};
use webrender_api::units::LayoutPixel;
use webrender_api::{DocumentId, ExternalScrollId};
use webrender_traits::CrossProcessCompositorApi;
@ -1782,16 +1782,16 @@ impl Window {
fn client_window(&self) -> (Size2D<u32, CSSPixel>, Point2D<i32, CSSPixel>) {
let timer_profile_chan = self.global().time_profiler_chan().clone();
let (send, recv) = ProfiledIpc::channel::<DeviceIntRect>(timer_profile_chan).unwrap();
let (send, recv) =
ProfiledIpc::channel::<DeviceIndependentIntRect>(timer_profile_chan).unwrap();
let _ = self
.compositor_api
.sender()
.send(webrender_traits::CrossProcessCompositorMessage::GetClientWindowRect(send));
let rect = recv.recv().unwrap_or_default();
let dpr = self.device_pixel_ratio();
let rect = recv.recv().unwrap_or_default().to_u32();
(
(rect.size().to_f32() / dpr).to_u32(),
(rect.min.to_f32() / dpr).to_i32(),
Size2D::new(rect.size().width, rect.size().height),
Point2D::new(rect.min.x as i32, rect.min.y as i32),
)
}