Centralize definitions of window sizes and DPI in compositor/constellation during startup.

This commit is contained in:
Josh Matthews 2019-11-06 16:10:36 -05:00
parent fd260f78c8
commit 7c365b0324
6 changed files with 34 additions and 76 deletions

View file

@ -209,9 +209,6 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// True to translate mouse input into touch events.
convert_mouse_to_touch: bool,
/// Ratio of device pixels per px at the default scale.
device_pixels_per_px: Option<f32>,
}
#[derive(Clone, Copy)]
@ -284,7 +281,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test: bool,
exit_after_load: bool,
convert_mouse_to_touch: bool,
device_pixels_per_px: Option<f32>,
) -> Self {
let composite_target = match output_file {
Some(_) => CompositeTarget::PngFile,
@ -327,7 +323,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test,
exit_after_load,
convert_mouse_to_touch,
device_pixels_per_px,
}
}
@ -338,7 +333,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test: bool,
exit_after_load: bool,
convert_mouse_to_touch: bool,
device_pixels_per_px: Option<f32>,
) -> Self {
let mut compositor = IOCompositor::new(
window,
@ -347,7 +341,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test,
exit_after_load,
convert_mouse_to_touch,
device_pixels_per_px,
);
// Set the size of the root layer.
@ -1081,13 +1074,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}
fn hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
match self.device_pixels_per_px {
Some(device_pixels_per_px) => Scale::new(device_pixels_per_px),
None => match self.output_file {
Some(_) => Scale::new(1.0),
None => self.embedder_coordinates.hidpi_factor,
},
if self.output_file.is_some() {
return Scale::new(1.0);
}
self.embedder_coordinates.hidpi_factor
}
fn device_pixels_per_page_px(&self) -> Scale<f32, CSSPixel, DevicePixel> {

View file

@ -112,7 +112,7 @@ use compositing::SendableFrameTree;
use crossbeam_channel::{after, never, unbounded, Receiver, Sender};
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg};
use embedder_traits::{Cursor, EmbedderMsg, EmbedderProxy, EventLoopWaker};
use euclid::{default::Size2D as UntypedSize2D, Scale, Size2D};
use euclid::{default::Size2D as UntypedSize2D, Size2D};
use gfx::font_cache_thread::FontCacheThread;
use gfx_traits::Epoch;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
@ -157,7 +157,6 @@ use script_traits::{MessagePortMsg, PortMessageTask, StructuredSerializedData};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use serde::{Deserialize, Serialize};
use servo_config::{opts, pref};
use servo_geometry::DeviceIndependentPixel;
use servo_rand::{random, Rng, ServoRng, SliceRandom};
use servo_remutex::ReentrantMutex;
use servo_url::{Host, ImmutableOrigin, ServoUrl};
@ -463,10 +462,6 @@ pub struct Constellation<Message, LTF, STF> {
/// Mechanism to force the compositor to process events.
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
/// The ratio of device pixels per px at the default scale. If unspecified, will use the
/// platform default setting.
device_pixels_per_px: Option<f32>,
}
/// State needed to construct a constellation.
@ -523,10 +518,6 @@ pub struct InitialConstellationState {
/// Mechanism to force the compositor to process events.
pub event_loop_waker: Option<Box<dyn EventLoopWaker>>,
/// The ratio of device pixels per px at the default scale. If unspecified, will use the
/// platform default setting.
pub device_pixels_per_px: Option<f32>,
}
/// Data needed for webdriver
@ -702,8 +693,7 @@ where
/// Create a new constellation thread.
pub fn start(
state: InitialConstellationState,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
initial_window_size: WindowSizeData,
random_pipeline_closure_probability: Option<f32>,
random_pipeline_closure_seed: Option<usize>,
is_running_problem_test: bool,
@ -811,10 +801,7 @@ where
next_pipeline_namespace_id: PipelineNamespaceId(2),
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
window_size: WindowSizeData {
initial_viewport: initial_window_size.to_f32() * Scale::new(1.0),
device_pixel_ratio: Scale::new(device_pixels_per_px.unwrap_or(1.0)),
},
window_size: initial_window_size,
phantom: PhantomData,
webdriver: WebDriverData::new(),
timer_scheduler: TimerScheduler::new(),
@ -844,7 +831,6 @@ where
glplayer_threads: state.glplayer_threads,
player_context: state.player_context,
event_loop_waker: state.event_loop_waker,
device_pixels_per_px,
};
constellation.run();
@ -1074,10 +1060,12 @@ where
resource_threads,
time_profiler_chan: self.time_profiler_chan.clone(),
mem_profiler_chan: self.mem_profiler_chan.clone(),
window_size: initial_window_size,
window_size: WindowSizeData {
initial_viewport: initial_window_size,
device_pixel_ratio: self.window_size.device_pixel_ratio,
},
event_loop,
load_data,
device_pixel_ratio: self.window_size.device_pixel_ratio,
prev_visibility: is_visible,
webrender_api_sender: self.webrender_api_sender.clone(),
webrender_document: self.webrender_document,
@ -1089,7 +1077,6 @@ where
webxr_registry: self.webxr_registry.clone(),
player_context: self.player_context.clone(),
event_loop_waker: self.event_loop_waker.as_ref().map(|w| (*w).clone_box()),
device_pixels_per_px: self.device_pixels_per_px,
});
let pipeline = match result {

View file

@ -12,7 +12,6 @@ use compositing::CompositorProxy;
use crossbeam_channel::{unbounded, Sender};
use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg};
use embedder_traits::EventLoopWaker;
use euclid::{Scale, Size2D};
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
@ -47,8 +46,6 @@ use std::process;
use std::rc::Rc;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use style_traits::CSSPixel;
use style_traits::DevicePixel;
use webvr_traits::WebVRMsg;
/// A `Pipeline` is the constellation's view of a `Document`. Each pipeline has an
@ -165,10 +162,7 @@ pub struct InitialPipelineState {
pub mem_profiler_chan: profile_mem::ProfilerChan,
/// Information about the initial window size.
pub window_size: Size2D<f32, CSSPixel>,
/// Information about the device pixel ratio.
pub device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
pub window_size: WindowSizeData,
/// The ID of the pipeline namespace for this script thread.
pub pipeline_namespace_id: PipelineNamespaceId,
@ -205,10 +199,6 @@ pub struct InitialPipelineState {
/// Mechanism to force the compositor to process events.
pub event_loop_waker: Option<Box<dyn EventLoopWaker>>,
/// The ratio of device pixels per px at the default scale. If unspecified, will use the
/// platform default setting.
pub device_pixels_per_px: Option<f32>,
}
pub struct NewPipeline {
@ -228,11 +218,6 @@ impl Pipeline {
// probably requires a general low-memory strategy.
let (pipeline_chan, pipeline_port) = ipc::channel().expect("Pipeline main chan");
let window_size = WindowSizeData {
initial_viewport: state.window_size,
device_pixel_ratio: state.device_pixel_ratio,
};
let (script_chan, sampler_chan) = match state.event_loop {
Some(script_chan) => {
let new_layout_info = NewLayoutInfo {
@ -242,7 +227,7 @@ impl Pipeline {
top_level_browsing_context_id: state.top_level_browsing_context_id,
opener: state.opener,
load_data: state.load_data.clone(),
window_size: window_size,
window_size: state.window_size,
pipeline_port: pipeline_port,
};
@ -301,7 +286,7 @@ impl Pipeline {
resource_threads: state.resource_threads,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
window_size: window_size,
window_size: state.window_size,
layout_to_constellation_chan: state.layout_to_constellation_chan,
script_chan: script_chan.clone(),
load_data: state.load_data.clone(),
@ -316,7 +301,6 @@ impl Pipeline {
webvr_chan: state.webvr_chan,
webxr_registry: state.webxr_registry,
player_context: state.player_context,
device_pixels_per_px: state.device_pixels_per_px,
};
// Spawn the child process.
@ -523,7 +507,6 @@ pub struct UnprivilegedPipelineContent {
webvr_chan: Option<IpcSender<WebVRMsg>>,
webxr_registry: webxr_api::Registry,
player_context: WindowGLContext,
device_pixels_per_px: Option<f32>,
}
impl UnprivilegedPipelineContent {
@ -614,8 +597,7 @@ impl UnprivilegedPipelineContent {
paint_time_metrics,
layout_thread_busy_flag.clone(),
self.opts.load_webfonts_synchronously,
self.opts.initial_window_size,
self.device_pixels_per_px,
self.window_size,
self.opts.dump_display_list,
self.opts.dump_display_list_json,
self.opts.dump_style_tree,

View file

@ -84,7 +84,7 @@ use constellation::{FromCompositorLogger, FromScriptLogger};
use crossbeam_channel::{unbounded, Sender};
use embedder_traits::{EmbedderMsg, EmbedderProxy, EmbedderReceiver, EventLoopWaker};
use env_logger::Builder as EnvLoggerBuilder;
use euclid::Size2D;
use euclid::{Scale, Size2D};
#[cfg(all(
not(target_os = "windows"),
not(target_os = "ios"),
@ -104,7 +104,9 @@ use profile::mem as profile_mem;
use profile::time as profile_time;
use profile_traits::mem;
use profile_traits::time;
use script_traits::{ConstellationMsg, SWManagerSenders, ScriptToConstellationChan};
use script_traits::{
ConstellationMsg, SWManagerSenders, ScriptToConstellationChan, WindowSizeData,
};
use servo_config::opts;
use servo_config::{pref, prefs};
use servo_media::player::context::GlContext;
@ -313,11 +315,7 @@ impl<Window> Servo<Window>
where
Window: WindowMethods + 'static + ?Sized,
{
pub fn new(
mut embedder: Box<dyn EmbedderMethods>,
window: Rc<Window>,
device_pixels_per_px: Option<f32>,
) -> Servo<Window> {
pub fn new(mut embedder: Box<dyn EmbedderMethods>, window: Rc<Window>) -> Servo<Window> {
// Global configuration options, parsed from the command line.
let opts = opts::get();
@ -358,6 +356,8 @@ where
let devtools_chan = opts.devtools_port.map(|port| devtools::start_server(port));
let coordinates = window.get_coordinates();
let device_pixel_ratio = coordinates.hidpi_factor.get();
let viewport_size = coordinates.viewport.size.to_f32() / device_pixel_ratio;
let (mut webrender, webrender_api_sender) = {
let renderer_kind = if opts::get().should_use_osmesa() {
@ -380,12 +380,7 @@ where
let render_notifier = Box::new(RenderNotifier::new(compositor_proxy.clone()));
// Cast from `DeviceIndependentPixel` to `DevicePixel`
let device_pixel_ratio = coordinates.hidpi_factor.get();
let window_size = Size2D::from_untyped(
(opts.initial_window_size.to_f32() / device_pixel_ratio)
.to_i32()
.to_untyped(),
);
let window_size = Size2D::from_untyped(viewport_size.to_i32().to_untyped());
webrender::Renderer::new(
window.gl(),
@ -492,6 +487,13 @@ where
let event_loop_waker = None;
// The division by 1 represents the page's default zoom of 100%,
// and gives us the appropriate CSSPixel type for the viewport.
let window_size = WindowSizeData {
initial_viewport: viewport_size / Scale::new(1.0),
device_pixel_ratio: Scale::new(device_pixel_ratio),
};
// Create the constellation, which maintains the engine
// pipelines, including the script and layout threads, as well
// as the navigation context.
@ -513,7 +515,7 @@ where
webvr_constellation_sender,
glplayer_threads,
event_loop_waker,
device_pixels_per_px,
window_size,
);
// Send the constellation's swmanager sender to service worker manager thread
@ -545,7 +547,6 @@ where
opts.is_running_problem_test,
opts.exit_after_load,
opts.convert_mouse_to_touch,
device_pixels_per_px,
);
Servo {
@ -828,7 +829,7 @@ fn create_constellation(
webvr_constellation_sender: Option<Sender<Sender<ConstellationMsg>>>,
glplayer_threads: Option<GLPlayerThreads>,
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
device_pixels_per_px: Option<f32>,
initial_window_size: WindowSizeData,
) -> (Sender<ConstellationMsg>, SWManagerSenders) {
// Global configuration options, parsed from the command line.
let opts = opts::get();
@ -871,7 +872,6 @@ fn create_constellation(
glplayer_threads,
player_context,
event_loop_waker,
device_pixels_per_px,
};
let (constellation_chan, from_swmanager_sender) = Constellation::<
script_layout_interface::message::Msg,
@ -879,8 +879,7 @@ fn create_constellation(
script::script_thread::ScriptThread,
>::start(
initial_state,
opts.initial_window_size,
device_pixels_per_px,
initial_window_size,
opts.random_pipeline_closure_probability,
opts.random_pipeline_closure_seed,
opts.is_running_problem_test,

View file

@ -70,7 +70,7 @@ impl App {
// Handle browser state.
let browser = Browser::new(window.clone());
let mut servo = Servo::new(embedder, window.clone(), device_pixels_per_px);
let mut servo = Servo::new(embedder, window.clone());
let browser_id = BrowserId::new();
servo.handle_events(vec![WindowEvent::NewBrowser(get_default_url(), browser_id)]);
servo.setup_logging();

View file

@ -211,7 +211,7 @@ pub fn init(
gl: gl.clone(),
});
let servo = Servo::new(embedder_callbacks, window_callbacks.clone(), None);
let servo = Servo::new(embedder_callbacks, window_callbacks.clone());
SERVO.with(|s| {
let mut servo_glue = ServoGlue {