Skip to content

Commit

Permalink
Auto merge of #11314 - metajack:window-hi-dpi, r=mbrubeck
Browse files Browse the repository at this point in the history
Make Servo DPI aware on Windows

Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data:
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

Either:
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because testing would be overly difficult

Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process.

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.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11314)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 21, 2016
2 parents 5fc511a + e016499 commit 3c26907
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 45 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
41 changes: 22 additions & 19 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>

3 changes: 3 additions & 0 deletions ports/cef/Cargo.lock

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

12 changes: 6 additions & 6 deletions ports/geckolib/Cargo.lock

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

5 changes: 5 additions & 0 deletions ports/glutin/Cargo.toml
Expand Up @@ -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"
9 changes: 4 additions & 5 deletions ports/glutin/lib.rs
Expand Up @@ -22,9 +22,11 @@ extern crate style_traits;
extern crate url;
extern crate util;
#[cfg(target_os = "linux")] extern crate x11;
#[cfg(target_os = "windows")] extern crate winapi;
#[cfg(target_os = "windows")] extern crate user32;
#[cfg(target_os = "windows")] extern crate gdi32;

use compositing::windowing::WindowEvent;
use euclid::scale_factor::ScaleFactor;
use std::rc::Rc;
use util::opts;
use window::Window;
Expand All @@ -41,10 +43,7 @@ pub fn create_window(parent: Option<WindowID>) -> Rc<Window> {
// Read command-line options.
let opts = opts::get();
let foreground = opts.output_file.is_none() && !opts.headless;
let scale_factor = ScaleFactor::new(opts.device_pixels_per_px.unwrap_or(1.0));
let size_f32 = opts.initial_window_size.as_f32() * scale_factor;
let size_u32 = size_f32.as_uint().cast().expect("Window size should fit in a u32.");

// Open a window.
Window::new(foreground, size_u32, parent)
Window::new(foreground, opts.initial_window_size, parent)
}

0 comments on commit 3c26907

Please sign in to comment.