Skip to content
Permalink
Browse files

Make Servo DPI aware on Windows

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 568d454ca628181d41a29418d584489cbfc83c12
@@ -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>,

@@ -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
@@ -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,
@@ -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();
}

@@ -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
}
}
}
@@ -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;

Some generated files are not rendered by default. Learn more.

@@ -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,
}
};

@@ -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>

Some generated files are not rendered by default. Learn more.

@@ -252,7 +252,7 @@ impl WindowMethods for Window {
}
}

fn hidpi_factor(&self) -> ScaleFactor<ScreenPx,DevicePixel,f32> {
fn scale_factor(&self) -> ScaleFactor<ScreenPx,DevicePixel,f32> {
if cfg!(target_os="macos") {
let browser = self.cef_browser.borrow();
match *browser {

Some generated files are not rendered by default. Learn more.

@@ -27,3 +27,8 @@ x11 = "2.0.0"

[target.'cfg(target_os = "android")'.dependencies]
servo-egl = "0.2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.2"
user32-sys = "0.2"
gdi32-sys = "0.2"

0 comments on commit 568d454

Please sign in to comment.
You can’t perform that action at this time.