Skip to content

Commit

Permalink
embedding: fix logical screen size calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Mukilan Thiyagarajan <[email protected]>
  • Loading branch information
mukilan committed Nov 1, 2024
1 parent ea3056d commit 708b989
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions ports/servoshell/desktop/headed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl Window {
|| (monitor.size(), monitor.scale_factor()),
|size| (PhysicalSize::new(size.width, size.height), 1.0),
);
let screen_scale: Scale<f64, DevicePixel, DeviceIndependentPixel> =
let screen_scale: Scale<f64, DeviceIndependentPixel, DevicePixel> =
Scale::new(screen_scale);
let screen_size = (winit_size_to_euclid_size(screen_size).to_f64() * screen_scale).to_u32();
let screen_size = (winit_size_to_euclid_size(screen_size).to_f64() / screen_scale).to_u32();

// Initialize surfman
let display_handle = winit_window
Expand Down Expand Up @@ -534,9 +534,9 @@ impl WindowMethods for Window {
let window_origin = self.winit_window.outer_position().unwrap_or_default();
let window_origin = winit_position_to_euclid_point(window_origin).to_i32();
let window_rect = DeviceIntRect::from_origin_and_size(window_origin, window_size);
let window_scale: Scale<f64, DevicePixel, DeviceIndependentPixel> =
let window_scale: Scale<f64, DeviceIndependentPixel, DevicePixel> =
Scale::new(self.winit_window.scale_factor());
let window_rect = (window_rect.to_f64() * window_scale).to_i32();
let window_rect = (window_rect.to_f64() / window_scale).to_i32();

let viewport_origin = DeviceIntPoint::zero(); // bottom left
let viewport_size = winit_size_to_euclid_size(self.winit_window.inner_size()).to_f32();
Expand Down
11 changes: 6 additions & 5 deletions ports/servoshell/egl/servo_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
use servo::script_traits::{
MediaSessionActionType, MouseButton, TouchEventType, TouchId, TraversalDirection,
};
use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::units::DeviceIntRect;
use servo::webrender_api::ScrollLocation;
Expand Down Expand Up @@ -56,21 +57,21 @@ impl Coordinates {
pub(super) struct ServoWindowCallbacks {
host_callbacks: Box<dyn HostTrait>,
coordinates: RefCell<Coordinates>,
density: f32,
hidpi_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>,
rendering_context: RenderingContext,
}

impl ServoWindowCallbacks {
pub(super) fn new(
host_callbacks: Box<dyn HostTrait>,
coordinates: RefCell<Coordinates>,
density: f32,
hidpi_factor: f32,
rendering_context: RenderingContext,
) -> Self {
Self {
host_callbacks,
coordinates,
density,
hidpi_factor: Scale::new(hidpi_factor),
rendering_context,
}
}
Expand Down Expand Up @@ -690,14 +691,14 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
impl WindowMethods for ServoWindowCallbacks {
fn get_coordinates(&self) -> EmbedderCoordinates {
let coords = self.coordinates.borrow();
let screen_size = (coords.viewport.size.to_f32() * Scale::new(self.density)).to_i32();
let screen_size = (coords.viewport.size.to_f32() / self.hidpi_factor).to_i32();
EmbedderCoordinates {
viewport: coords.viewport.to_box2d(),
framebuffer: coords.framebuffer,
window_rect: Box2D::from_origin_and_size(Point2D::zero(), screen_size),
screen_size,
available_screen_size: screen_size,
hidpi_factor: Scale::new(self.density),
hidpi_factor: self.hidpi_factor,
}
}

Expand Down

0 comments on commit 708b989

Please sign in to comment.