From a76b982ff9a3d53d5e46eb57e76cadb51487fee0 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 2 Jun 2014 09:20:35 -0700 Subject: [PATCH] Add an option to set device pixel ratio --- src/components/embedding/core.rs | 1 + src/components/main/compositing/compositor.rs | 5 ++++- src/components/util/opts.rs | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/embedding/core.rs b/src/components/embedding/core.rs index d67e03dbaba..d2c9a601b80 100644 --- a/src/components/embedding/core.rs +++ b/src/components/embedding/core.rs @@ -50,6 +50,7 @@ pub extern "C" fn cef_run_message_loop() { n_render_threads: 1, cpu_painting: false, tile_size: 512, + device_pixels_per_px: None, profiler_period: None, layout_threads: 1, //layout_threads: cmp::max(rt::default_sched_threads() * 3 / 4, 1), diff --git a/src/components/main/compositing/compositor.rs b/src/components/main/compositing/compositor.rs index b14b5513bbf..c7a820acc1c 100644 --- a/src/components/main/compositing/compositor.rs +++ b/src/components/main/compositing/compositor.rs @@ -125,7 +125,10 @@ impl IOCompositor { let root_layer = Rc::new(ContainerLayer()); let window_size = window.size(); - let hidpi_factor = window.hidpi_factor(); + let hidpi_factor = match opts.device_pixels_per_px { + Some(dppx) => dppx, + None => window.hidpi_factor(), + }; root_layer.common.borrow_mut().set_transform(identity().scale(hidpi_factor, hidpi_factor, 1f32)); IOCompositor { diff --git a/src/components/util/opts.rs b/src/components/util/opts.rs index 96f3f36b6c7..c18132dec1f 100644 --- a/src/components/util/opts.rs +++ b/src/components/util/opts.rs @@ -34,6 +34,10 @@ pub struct Opts { /// The maximum size of each tile in pixels (`-s`). pub tile_size: uint, + /// 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, + /// `None` to disable the profiler or `Some` with an interval in seconds to enable it and cause /// it to produce output on that interval (`-p`). pub profiler_period: Option, @@ -75,6 +79,7 @@ pub fn from_cmdline_args(args: &[~str]) -> Option { getopts::optopt("o", "output", "Output file", "output.png"), getopts::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."), getopts::optopt("s", "size", "Size of tiles", "512"), + getopts::optopt("", "device-pixel-ratio", "Device pixels per px", ""), getopts::optopt("t", "threads", "Number of render threads", "1"), getopts::optflagopt("p", "profile", "Profiler flag and output interval", "10"), getopts::optflag("x", "exit", "Exit after load flag"), @@ -130,6 +135,10 @@ pub fn from_cmdline_args(args: &[~str]) -> Option { None => 512, }; + let device_pixels_per_px = opt_match.opt_str("device-pixel-ratio").map(|dppx_str| + from_str(dppx_str).unwrap() + ); + let n_render_threads: uint = match opt_match.opt_str("t") { Some(n_render_threads_str) => from_str(n_render_threads_str).unwrap(), None => 1, // FIXME: Number of cores. @@ -153,6 +162,7 @@ pub fn from_cmdline_args(args: &[~str]) -> Option { n_render_threads: n_render_threads, cpu_painting: cpu_painting, tile_size: tile_size, + device_pixels_per_px: device_pixels_per_px, profiler_period: profiler_period, layout_threads: layout_threads, exit_after_load: opt_match.opt_present("x"),