Skip to content

Commit

Permalink
Make Servo DPI aware on Windows
Browse files Browse the repository at this point in the history
This implements system level DPI awareness for Windows. It has three
parts:

1. Add a application manifest which is copied alongside servo.exe during
build that declares our DPI awareness level. This is needed otherwise
DPI queries will return 96dpi and our application will be upscaled on
high DPI displays.

2. Rename hidpi_factor to avoid confusion with Glutin's hidpi_factor
which does something else.

3. Correctly convert windows sizes on window creation for
Windows. Unlike OS X, Windows uses device pixels for window creation.
  • Loading branch information
metajack committed May 21, 2016
1 parent b9650b5 commit 08f8763
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 75 deletions.
14 changes: 7 additions & 7 deletions components/compositing/compositor.rs
Expand Up @@ -144,7 +144,7 @@ pub struct IOCompositor<Window: WindowMethods> {
page_zoom: ScaleFactor<ViewportPx, ScreenPx, f32>,

/// The device pixel ratio for this window.
hidpi_factor: ScaleFactor<ScreenPx, DevicePixel, f32>,
scale_factor: ScaleFactor<ScreenPx, DevicePixel, f32>,

channel_to_self: Box<CompositorProxy + Send>,

Expand Down Expand Up @@ -405,7 +405,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
mem::ProfilerMsg::RegisterReporter(reporter_name(), reporter));

let window_size = window.framebuffer_size();
let hidpi_factor = window.hidpi_factor();
let scale_factor = window.scale_factor();
let composite_target = match opts::get().output_file {
Some(_) => CompositeTarget::PngFile,
None => CompositeTarget::Window
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}),
window_size: window_size,
viewport: None,
hidpi_factor: hidpi_factor,
scale_factor: scale_factor,
channel_to_self: state.sender.clone_compositor_proxy(),
delayed_composition_timer: DelayedCompositionTimerProxy::new(state.sender),
composition_request: CompositionRequest::NoCompositingNecessary,
Expand Down Expand Up @@ -1315,9 +1315,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
debug!("compositor resizing to {:?}", new_size.to_untyped());

// A size change could also mean a resolution change.
let new_hidpi_factor = self.window.hidpi_factor();
if self.hidpi_factor != new_hidpi_factor {
self.hidpi_factor = new_hidpi_factor;
let new_scale_factor = self.window.scale_factor();
if self.scale_factor != new_scale_factor {
self.scale_factor = new_scale_factor;
self.update_zoom_transform();
}

Expand Down Expand Up @@ -1744,7 +1744,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px),
None => match opts::get().output_file {
Some(_) => ScaleFactor::new(1.0),
None => self.hidpi_factor
None => self.scale_factor
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/windowing.rs
Expand Up @@ -133,8 +133,8 @@ pub trait WindowMethods {
/// Called when the <head> tag has finished parsing
fn head_parsed(&self);

/// Returns the hidpi factor of the monitor.
fn hidpi_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>;
/// Returns the scale factor of the system (device pixels / screen pixels).
fn scale_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>;

/// Gets the OS native graphics display for this window.
fn native_display(&self) -> NativeDisplay;
Expand Down
44 changes: 28 additions & 16 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/servo/lib.rs
Expand Up @@ -129,12 +129,12 @@ impl Browser {
resource_path.push("shaders");

// TODO(gw): Duplicates device_pixels_per_screen_px from compositor. Tidy up!
let hidpi_factor = window.hidpi_factor().get();
let scale_factor = window.scale_factor().get();
let device_pixel_ratio = match opts.device_pixels_per_px {
Some(device_pixels_per_px) => device_pixels_per_px,
None => match opts.output_file {
Some(_) => 1.0,
None => hidpi_factor,
None => scale_factor,
}
};

Expand Down
24 changes: 24 additions & 0 deletions components/servo/servo.exe.manifest
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity type="win32"
name="servo.Servo"
version="0.1.0.0"/>

<compatibility>
<application>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> <!-- Windows 7 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <!-- Windows 8 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <!-- Windows 8.1 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> <!-- Windows 10 -->
</application>
</compatibility>

<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

0 comments on commit 08f8763

Please sign in to comment.