introduce frame_size and window_rect

This commit is contained in:
Paul Rouget 2017-03-07 02:46:06 +01:00
parent c62973b77b
commit 2a05534efb
4 changed files with 50 additions and 11 deletions

View file

@ -9,6 +9,7 @@ use compositor_thread::{InitialCompositorState, Msg, RenderListener};
use delayed_composition::DelayedCompositionTimerProxy; use delayed_composition::DelayedCompositionTimerProxy;
use euclid::Point2D; use euclid::Point2D;
use euclid::point::TypedPoint2D; use euclid::point::TypedPoint2D;
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor; use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
use gfx_traits::{Epoch, FragmentType, ScrollRootId}; use gfx_traits::{Epoch, FragmentType, ScrollRootId};
@ -140,8 +141,11 @@ pub struct IOCompositor<Window: WindowMethods> {
/// The scene scale, to allow for zooming and high-resolution painting. /// The scene scale, to allow for zooming and high-resolution painting.
scale: ScaleFactor<f32, LayerPixel, DevicePixel>, scale: ScaleFactor<f32, LayerPixel, DevicePixel>,
/// The application window size. /// The size of the rendering area.
window_size: TypedSize2D<u32, DevicePixel>, frame_size: TypedSize2D<u32, DevicePixel>,
/// The position and size of the window within the rendering area.
window_rect: TypedRect<u32, DevicePixel>,
/// The overridden viewport. /// The overridden viewport.
viewport: Option<(TypedPoint2D<u32, DevicePixel>, TypedSize2D<u32, DevicePixel>)>, viewport: Option<(TypedPoint2D<u32, DevicePixel>, TypedSize2D<u32, DevicePixel>)>,
@ -376,7 +380,8 @@ impl webrender_traits::RenderDispatcher for CompositorThreadDispatcher {
impl<Window: WindowMethods> IOCompositor<Window> { impl<Window: WindowMethods> IOCompositor<Window> {
fn new(window: Rc<Window>, state: InitialCompositorState) fn new(window: Rc<Window>, state: InitialCompositorState)
-> IOCompositor<Window> { -> IOCompositor<Window> {
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 scale_factor = window.hidpi_factor();
let composite_target = match opts::get().output_file { let composite_target = match opts::get().output_file {
Some(_) => CompositeTarget::PngFile, Some(_) => CompositeTarget::PngFile,
@ -388,7 +393,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
port: state.receiver, port: state.receiver,
root_pipeline: None, root_pipeline: None,
pipeline_details: HashMap::new(), pipeline_details: HashMap::new(),
window_size: window_size, frame_size: frame_size,
window_rect: window_rect,
scale: ScaleFactor::new(1.0), scale: ScaleFactor::new(1.0),
viewport: None, viewport: None,
scale_factor: scale_factor, scale_factor: scale_factor,
@ -756,7 +762,18 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn send_window_size(&self, size_type: WindowSizeType) { fn send_window_size(&self, size_type: WindowSizeType) {
let dppx = self.page_zoom * self.hidpi_factor(); 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 { let msg = ConstellationMsg::WindowSize(WindowSizeData {
device_pixel_ratio: dppx, device_pixel_ratio: dppx,
initial_viewport: initial_viewport, initial_viewport: initial_viewport,
@ -892,11 +909,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.update_zoom_transform(); 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; return;
} }
self.window_size = new_size; self.frame_size = new_size;
self.window_rect = new_window_rect;
self.send_window_size(WindowSizeType::Resize); self.send_window_size(WindowSizeType::Resize);
} }
@ -1485,7 +1507,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
target: CompositeTarget) target: CompositeTarget)
-> Result<Option<Image>, UnableToComposite> { -> Result<Option<Image>, UnableToComposite> {
let (width, height) = 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) { if !self.window.prepare_for_composite(width, height) {
return Err(UnableToComposite::WindowUnprepared) return Err(UnableToComposite::WindowUnprepared)
} }
@ -1523,7 +1545,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
debug!("compositor: compositing"); debug!("compositor: compositing");
// Paint the scene. // 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); self.webrender.render(size);
}); });

View file

@ -7,6 +7,7 @@
use compositor_thread::{CompositorProxy, CompositorReceiver}; use compositor_thread::{CompositorProxy, CompositorReceiver};
use euclid::{Point2D, Size2D}; use euclid::{Point2D, Size2D};
use euclid::point::TypedPoint2D; use euclid::point::TypedPoint2D;
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor; use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
use msg::constellation_msg::{Key, KeyModifiers, KeyState}; use msg::constellation_msg::{Key, KeyModifiers, KeyState};
@ -106,8 +107,10 @@ impl Debug for WindowEvent {
} }
pub trait WindowMethods { 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<u32, DevicePixel>; fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>;
/// Returns the position and size of the window within the rendering area.
fn window_rect(&self) -> TypedRect<u32, DevicePixel>;
/// Returns the size of the window in density-independent "px" units. /// Returns the size of the window in density-independent "px" units.
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel>; fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel>;
/// Presents the window to the screen (perhaps by page flipping). /// Presents the window to the screen (perhaps by page flipping).

View file

@ -19,7 +19,8 @@ use wrappers::CefWrap;
use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver}; use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods}; 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::scale_factor::ScaleFactor;
use euclid::size::{Size2D, TypedSize2D}; use euclid::size::{Size2D, TypedSize2D};
use gleam::gl; use gleam::gl;
@ -206,6 +207,12 @@ impl WindowMethods for Window {
} }
} }
fn window_rect(&self) -> TypedRect<u32, DevicePixel> {
let size = self.framebuffer_size();
let origin = TypedPoint2D::zero();
TypedRect::new(origin, size)
}
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> { fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> {
let browser = self.cef_browser.borrow(); let browser = self.cef_browser.borrow();
match *browser { match *browser {

View file

@ -9,6 +9,7 @@ use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg}; use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg};
use compositing::windowing::{WindowEvent, WindowMethods}; use compositing::windowing::{WindowEvent, WindowMethods};
use euclid::{Point2D, Size2D, TypedPoint2D}; use euclid::{Point2D, Size2D, TypedPoint2D};
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor; use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -797,6 +798,12 @@ impl WindowMethods for Window {
} }
} }
fn window_rect(&self) -> TypedRect<u32, DevicePixel> {
let size = self.framebuffer_size();
let origin = TypedPoint2D::zero();
TypedRect::new(origin, size)
}
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> { fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> {
match self.kind { match self.kind {
WindowKind::Window(ref window) => { WindowKind::Window(ref window) => {