mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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:
parent
d877962ee8
commit
850e59f98e
14 changed files with 181 additions and 115 deletions
|
@ -17,7 +17,7 @@ use script_traits::{
|
|||
GamepadEvent, MediaSessionActionType, MouseButton, TouchEventType, TouchId, TraversalDirection,
|
||||
WheelDelta,
|
||||
};
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize, DeviceIndependentPixel};
|
||||
use servo_url::ServoUrl;
|
||||
use style_traits::DevicePixel;
|
||||
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, DeviceRect};
|
||||
|
@ -241,11 +241,11 @@ pub struct EmbedderCoordinates {
|
|||
/// The pixel density of the display.
|
||||
pub hidpi_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>,
|
||||
/// Size of the screen.
|
||||
pub screen_size: DeviceIntSize,
|
||||
pub screen_size: DeviceIndependentIntSize,
|
||||
/// Size of the available screen space (screen without toolbars and docks).
|
||||
pub available_screen_size: DeviceIntSize,
|
||||
pub available_screen_size: DeviceIndependentIntSize,
|
||||
/// Position and size of the native window.
|
||||
pub window_rect: DeviceIntRect,
|
||||
pub window_rect: DeviceIndependentIntRect,
|
||||
/// Size of the GL buffer in the window.
|
||||
pub framebuffer: DeviceIntSize,
|
||||
/// Coordinates of the document within the framebuffer.
|
||||
|
@ -278,23 +278,23 @@ impl EmbedderCoordinates {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use euclid::{Point2D, Scale, Size2D};
|
||||
use euclid::{Box2D, Point2D, Scale, Size2D};
|
||||
use webrender_api::units::DeviceIntRect;
|
||||
|
||||
use super::EmbedderCoordinates;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let pos = Point2D::zero();
|
||||
let viewport = Size2D::new(800, 600);
|
||||
let screen = Size2D::new(1080, 720);
|
||||
let screen_size = Size2D::new(1080, 720);
|
||||
let viewport = Box2D::from_origin_and_size(Point2D::zero(), Size2D::new(800, 600));
|
||||
let window_rect = Box2D::from_origin_and_size(Point2D::zero(), Size2D::new(800, 600));
|
||||
let coordinates = EmbedderCoordinates {
|
||||
hidpi_factor: Scale::new(1.),
|
||||
screen_size: screen,
|
||||
available_screen_size: screen,
|
||||
window_rect: DeviceIntRect::from_origin_and_size(pos, viewport),
|
||||
framebuffer: viewport,
|
||||
viewport: DeviceIntRect::from_origin_and_size(pos, viewport),
|
||||
screen_size,
|
||||
available_screen_size: screen_size,
|
||||
window_rect,
|
||||
framebuffer: viewport.size(),
|
||||
viewport,
|
||||
};
|
||||
|
||||
// Check if viewport conversion is correct.
|
||||
|
|
|
@ -83,6 +83,10 @@ pub struct Opts {
|
|||
/// The initial requested size of the window.
|
||||
pub initial_window_size: Size2D<u32, DeviceIndependentPixel>,
|
||||
|
||||
/// An override for the screen resolution. This is useful for testing behavior on different screen sizes,
|
||||
/// such as the screen of a mobile device.
|
||||
pub screen_size_override: Option<Size2D<u32, DeviceIndependentPixel>>,
|
||||
|
||||
/// Whether we're running in multiprocess mode.
|
||||
pub multiprocess: bool,
|
||||
|
||||
|
@ -410,6 +414,7 @@ pub fn default_opts() -> Opts {
|
|||
devtools_server_enabled: false,
|
||||
webdriver_port: None,
|
||||
initial_window_size: Size2D::new(1024, 740),
|
||||
screen_size_override: None,
|
||||
multiprocess: false,
|
||||
background_hang_monitor: false,
|
||||
random_pipeline_closure_probability: None,
|
||||
|
@ -503,7 +508,18 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
|
|||
"Start remote WebDriver server on port",
|
||||
"7000",
|
||||
);
|
||||
opts.optopt("", "resolution", "Set window resolution.", "1024x740");
|
||||
opts.optopt(
|
||||
"",
|
||||
"window-size",
|
||||
"Set the initial window size in logical (device independenrt) pixels",
|
||||
"1024x740",
|
||||
);
|
||||
opts.optopt(
|
||||
"",
|
||||
"screen-size",
|
||||
"Override the screen resolution in logical (device independent) pixels",
|
||||
"1024x768",
|
||||
);
|
||||
opts.optflag("M", "multiprocess", "Run in multiprocess mode");
|
||||
opts.optflag("B", "bhm", "Background Hang Monitor enabled");
|
||||
opts.optflag("S", "sandbox", "Run in a sandbox if multiprocess");
|
||||
|
@ -694,21 +710,33 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
|
|||
})
|
||||
});
|
||||
|
||||
let initial_window_size = match opt_match.opt_str("resolution") {
|
||||
Some(res_string) => {
|
||||
let res: Vec<u32> = res_string
|
||||
.split('x')
|
||||
.map(|r| {
|
||||
r.parse().unwrap_or_else(|err| {
|
||||
args_fail(&format!("Error parsing option: --resolution ({})", err))
|
||||
})
|
||||
let parse_resolution_string = |string: String| {
|
||||
let components: Vec<u32> = string
|
||||
.split('x')
|
||||
.map(|component| {
|
||||
component.parse().unwrap_or_else(|error| {
|
||||
args_fail(&format!("Error parsing resolution '{string}': {error}"));
|
||||
})
|
||||
.collect();
|
||||
Size2D::new(res[0], res[1])
|
||||
},
|
||||
None => Size2D::new(1024, 740),
|
||||
})
|
||||
.collect();
|
||||
Size2D::new(components[0], components[1])
|
||||
};
|
||||
|
||||
let screen_size_override = opt_match
|
||||
.opt_str("screen-size")
|
||||
.map(parse_resolution_string);
|
||||
|
||||
// Make sure the default window size is not larger than any provided screen size.
|
||||
let default_window_size = Size2D::new(1024, 740);
|
||||
let default_window_size = screen_size_override
|
||||
.map_or(default_window_size, |screen_size_override| {
|
||||
default_window_size.min(screen_size_override)
|
||||
});
|
||||
|
||||
let initial_window_size = opt_match
|
||||
.opt_str("window-size")
|
||||
.map_or(default_window_size, parse_resolution_string);
|
||||
|
||||
if opt_match.opt_present("M") {
|
||||
MULTIPROCESS.store(true, Ordering::SeqCst)
|
||||
}
|
||||
|
@ -753,6 +781,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
|
|||
devtools_server_enabled,
|
||||
webdriver_port,
|
||||
initial_window_size,
|
||||
screen_size_override,
|
||||
multiprocess: opt_match.opt_present("M"),
|
||||
background_hang_monitor: opt_match.opt_present("B"),
|
||||
sandbox: opt_match.opt_present("S"),
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
use std::f32;
|
||||
|
||||
use app_units::{Au, MAX_AU, MIN_AU};
|
||||
use euclid::default::{Point2D, Rect, Size2D};
|
||||
use euclid::Length;
|
||||
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect, Size2D as UntypedSize2D};
|
||||
use euclid::{Box2D, Length, Point2D, SideOffsets2D, Size2D, Vector2D};
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use webrender_api::units::{FramebufferPixel, LayoutPoint, LayoutRect, LayoutSize};
|
||||
|
||||
|
@ -30,6 +30,19 @@ pub type FramebufferUintLength = Length<u32, FramebufferPixel>;
|
|||
#[derive(Clone, Copy, Debug, MallocSizeOf)]
|
||||
pub enum DeviceIndependentPixel {}
|
||||
|
||||
pub type DeviceIndependentIntRect = Box2D<i32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentIntPoint = Point2D<i32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentIntSize = Size2D<i32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentIntLength = Length<i32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentIntSideOffsets = SideOffsets2D<i32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentIntVector2D = Vector2D<i32, DeviceIndependentPixel>;
|
||||
|
||||
pub type DeviceIndependentRect = Box2D<f32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentBox2D = Box2D<f32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentPoint = Point2D<f32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentVector2D = Vector2D<f32, DeviceIndependentPixel>;
|
||||
pub type DeviceIndependentSize = Size2D<f32, DeviceIndependentPixel>;
|
||||
|
||||
// An Au is an "App Unit" and represents 1/60th of a CSS pixel. It was
|
||||
// originally proposed in 2002 as a standard unit of measure in Gecko.
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
|
||||
|
@ -38,20 +51,20 @@ pub trait MaxRect {
|
|||
fn max_rect() -> Self;
|
||||
}
|
||||
|
||||
impl MaxRect for Rect<Au> {
|
||||
impl MaxRect for UntypedRect<Au> {
|
||||
#[inline]
|
||||
fn max_rect() -> Rect<Au> {
|
||||
Rect::new(
|
||||
Point2D::new(MIN_AU / 2, MIN_AU / 2),
|
||||
Size2D::new(MAX_AU, MAX_AU),
|
||||
fn max_rect() -> Self {
|
||||
Self::new(
|
||||
UntypedPoint2D::new(MIN_AU / 2, MIN_AU / 2),
|
||||
UntypedSize2D::new(MAX_AU, MAX_AU),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl MaxRect for LayoutRect {
|
||||
#[inline]
|
||||
fn max_rect() -> LayoutRect {
|
||||
LayoutRect::from_origin_and_size(
|
||||
fn max_rect() -> Self {
|
||||
Self::from_origin_and_size(
|
||||
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
|
||||
LayoutSize::new(f32::MAX, f32::MAX),
|
||||
)
|
||||
|
@ -59,8 +72,8 @@ impl MaxRect for LayoutRect {
|
|||
}
|
||||
|
||||
/// A helper function to convert a rect of `f32` pixels to a rect of app units.
|
||||
pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> {
|
||||
Rect::new(
|
||||
pub fn f32_rect_to_au_rect(rect: UntypedRect<f32>) -> UntypedRect<Au> {
|
||||
UntypedRect::new(
|
||||
Point2D::new(
|
||||
Au::from_f32_px(rect.origin.x),
|
||||
Au::from_f32_px(rect.origin.y),
|
||||
|
@ -73,8 +86,8 @@ pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> {
|
|||
}
|
||||
|
||||
/// A helper function to convert a rect of `Au` pixels to a rect of f32 units.
|
||||
pub fn au_rect_to_f32_rect(rect: Rect<Au>) -> Rect<f32> {
|
||||
Rect::new(
|
||||
pub fn au_rect_to_f32_rect(rect: UntypedRect<Au>) -> UntypedRect<f32> {
|
||||
UntypedRect::new(
|
||||
Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()),
|
||||
Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px()),
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,5 +21,6 @@ log = { workspace = true }
|
|||
libc = { workspace = true }
|
||||
webrender_api = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
servo_geometry = { path = "../../geometry" }
|
||||
surfman = { workspace = true }
|
||||
|
||||
|
|
|
@ -14,12 +14,13 @@ use std::sync::{Arc, Mutex};
|
|||
use base::id::PipelineId;
|
||||
use display_list::{CompositorDisplayListInfo, ScrollTreeNodeId};
|
||||
use embedder_traits::Cursor;
|
||||
use euclid::default::Size2D;
|
||||
use euclid::default::Size2D as UntypedSize2D;
|
||||
use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
|
||||
use libc::c_void;
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePoint, LayoutPoint, TexelRect};
|
||||
use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
|
||||
use webrender_api::units::{DevicePoint, LayoutPoint, TexelRect};
|
||||
use webrender_api::{
|
||||
BuiltDisplayList, BuiltDisplayListDescriptor, ExternalImage, ExternalImageData,
|
||||
ExternalImageHandler, ExternalImageId, ExternalImageSource, ExternalScrollId,
|
||||
|
@ -77,12 +78,12 @@ pub enum CrossProcessCompositorMessage {
|
|||
RemoveFonts(Vec<FontKey>, Vec<FontInstanceKey>),
|
||||
|
||||
/// Get the client window size and position.
|
||||
GetClientWindowRect(IpcSender<DeviceIntRect>),
|
||||
GetClientWindowRect(IpcSender<DeviceIndependentIntRect>),
|
||||
/// Get the size of the screen that the client window inhabits.
|
||||
GetScreenSize(IpcSender<DeviceIntSize>),
|
||||
GetScreenSize(IpcSender<DeviceIndependentIntSize>),
|
||||
/// Get the available screen size (without toolbars and docks) for the screen
|
||||
/// the client window inhabits.
|
||||
GetAvailableScreenSize(IpcSender<DeviceIntSize>),
|
||||
GetAvailableScreenSize(IpcSender<DeviceIndependentIntSize>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for CrossProcessCompositorMessage {
|
||||
|
@ -291,7 +292,7 @@ impl CrossProcessCompositorApi {
|
|||
/// This trait is used to notify lock/unlock messages and get the
|
||||
/// required info that WR needs.
|
||||
pub trait WebrenderExternalImageApi {
|
||||
fn lock(&mut self, id: u64) -> (WebrenderImageSource, Size2D<i32>);
|
||||
fn lock(&mut self, id: u64) -> (WebrenderImageSource, UntypedSize2D<i32>);
|
||||
fn unlock(&mut self, id: u64);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue