diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index dc3313fb595..a4061351939 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -9,6 +9,7 @@ use compositor_thread::{InitialCompositorState, Msg, RenderListener}; use delayed_composition::DelayedCompositionTimerProxy; use euclid::Point2D; use euclid::point::TypedPoint2D; +use euclid::rect::TypedRect; use euclid::scale_factor::ScaleFactor; use euclid::size::TypedSize2D; use gfx_traits::{Epoch, FragmentType, ScrollRootId}; @@ -140,8 +141,11 @@ pub struct IOCompositor { /// The scene scale, to allow for zooming and high-resolution painting. scale: ScaleFactor, - /// The application window size. - window_size: TypedSize2D, + /// The size of the rendering area. + frame_size: TypedSize2D, + + /// The position and size of the window within the rendering area. + window_rect: TypedRect, /// The overridden viewport. viewport: Option<(TypedPoint2D, TypedSize2D)>, @@ -376,7 +380,8 @@ impl webrender_traits::RenderDispatcher for CompositorThreadDispatcher { impl IOCompositor { fn new(window: Rc, state: InitialCompositorState) -> IOCompositor { - let window_size = window.framebuffer_size(); + let frame_size = window.framebuffer_size(); + let window_rect = window.window_rect(); let scale_factor = window.hidpi_factor(); let composite_target = match opts::get().output_file { Some(_) => CompositeTarget::PngFile, @@ -388,7 +393,8 @@ impl IOCompositor { port: state.receiver, root_pipeline: None, pipeline_details: HashMap::new(), - window_size: window_size, + frame_size: frame_size, + window_rect: window_rect, scale: ScaleFactor::new(1.0), viewport: None, scale_factor: scale_factor, @@ -756,7 +762,18 @@ impl IOCompositor { fn send_window_size(&self, size_type: WindowSizeType) { let dppx = self.page_zoom * self.hidpi_factor(); - let initial_viewport = self.window_size.to_f32() / dppx; + + let window_rect = { + let offset = webrender_traits::DeviceUintPoint::new(self.window_rect.origin.x, self.window_rect.origin.y); + let size = webrender_traits::DeviceUintSize::new(self.window_rect.size.width, self.window_rect.size.height); + webrender_traits::DeviceUintRect::new(offset, size) + }; + + let frame_size = webrender_traits::DeviceUintSize::new(self.frame_size.width, self.frame_size.height); + self.webrender_api.set_window_parameters(frame_size, window_rect); + + let initial_viewport = self.window_rect.size.to_f32() / dppx; + let msg = ConstellationMsg::WindowSize(WindowSizeData { device_pixel_ratio: dppx, initial_viewport: initial_viewport, @@ -892,11 +909,16 @@ impl IOCompositor { self.update_zoom_transform(); } - if self.window_size == new_size { + let new_window_rect = self.window.window_rect(); + let new_frame_size = self.window.framebuffer_size(); + + if self.window_rect == new_window_rect && + self.frame_size == new_frame_size { return; } - self.window_size = new_size; + self.frame_size = new_size; + self.window_rect = new_window_rect; self.send_window_size(WindowSizeType::Resize); } @@ -1485,7 +1507,7 @@ impl IOCompositor { target: CompositeTarget) -> Result, UnableToComposite> { let (width, height) = - (self.window_size.width as usize, self.window_size.height as usize); + (self.frame_size.width as usize, self.frame_size.height as usize); if !self.window.prepare_for_composite(width, height) { return Err(UnableToComposite::WindowUnprepared) } @@ -1523,7 +1545,7 @@ impl IOCompositor { debug!("compositor: compositing"); // Paint the scene. - let size = webrender_traits::DeviceUintSize::from_untyped(&self.window_size.to_untyped()); + let size = webrender_traits::DeviceUintSize::from_untyped(&self.frame_size.to_untyped()); self.webrender.render(size); }); diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 85d73af2f9f..84a1365af0d 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -7,6 +7,7 @@ use compositor_thread::{CompositorProxy, CompositorReceiver}; use euclid::{Point2D, Size2D}; use euclid::point::TypedPoint2D; +use euclid::rect::TypedRect; use euclid::scale_factor::ScaleFactor; use euclid::size::TypedSize2D; use msg::constellation_msg::{Key, KeyModifiers, KeyState}; @@ -106,8 +107,10 @@ impl Debug for WindowEvent { } pub trait WindowMethods { - /// Returns the size of the window in hardware pixels. + /// Returns the rendering area size in hardware pixels. fn framebuffer_size(&self) -> TypedSize2D; + /// Returns the position and size of the window within the rendering area. + fn window_rect(&self) -> TypedRect; /// Returns the size of the window in density-independent "px" units. fn size(&self) -> TypedSize2D; /// Presents the window to the screen (perhaps by page flipping). diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 4c31a890774..ecf8a1f2984 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -19,7 +19,8 @@ use wrappers::CefWrap; use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; -use euclid::point::Point2D; +use euclid::point::{Point2D, TypedPoint2D}; +use euclid::rect::TypedRect; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; use gleam::gl; @@ -206,6 +207,12 @@ impl WindowMethods for Window { } } + fn window_rect(&self) -> TypedRect { + let size = self.framebuffer_size(); + let origin = TypedPoint2D::zero(); + TypedRect::new(origin, size) + } + fn size(&self) -> TypedSize2D { let browser = self.cef_browser.borrow(); match *browser { diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 79582972de7..04cc8fbe2b0 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -9,6 +9,7 @@ use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg}; use compositing::windowing::{WindowEvent, WindowMethods}; use euclid::{Point2D, Size2D, TypedPoint2D}; +use euclid::rect::TypedRect; use euclid::scale_factor::ScaleFactor; use euclid::size::TypedSize2D; #[cfg(target_os = "windows")] @@ -797,6 +798,12 @@ impl WindowMethods for Window { } } + fn window_rect(&self) -> TypedRect { + let size = self.framebuffer_size(); + let origin = TypedPoint2D::zero(); + TypedRect::new(origin, size) + } + fn size(&self) -> TypedSize2D { match self.kind { WindowKind::Window(ref window) => {