Skip to content
Permalink
Browse files

WR update: new viewport semantic

  • Loading branch information...
paulrouget committed Mar 7, 2019
1 parent 58ea662 commit 4c94f54eb979359db32cc4da8fc7d2a63de0930f
@@ -151,7 +151,7 @@ impl webrender::OutputImageHandler for OutputHandler {
fn lock(
&mut self,
id: webrender_api::PipelineId,
) -> Option<(u32, webrender_api::DeviceIntSize)> {
) -> Option<(u32, webrender_api::FramebufferIntSize)> {
// Insert a fence in the WR command queue
let gl_sync = self
.webrender_gl
@@ -164,7 +164,7 @@ impl webrender::OutputImageHandler for OutputHandler {
self.lock_channel.1.recv().unwrap().map(|(tex_id, size)| {
(
tex_id,
webrender_api::DeviceIntSize::new(size.width, size.height),
webrender_api::FramebufferIntSize::new(size.width, size.height),
)
})
}
@@ -41,7 +41,10 @@ use std::rc::Rc;
use style_traits::viewport::ViewportConstraints;
use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor};
use time::{now, precise_time_ns, precise_time_s};
use webrender_api::{self, DeviceIntPoint, DevicePoint, HitTestFlags, HitTestResult};
use webrender_api::{
self, DeviceIntPoint, DevicePoint, FramebufferIntRect, FramebufferIntSize, HitTestFlags,
HitTestResult,
};
use webrender_api::{LayoutVector2D, ScrollLocation};
use webvr_traits::WebVRMainThreadHeartbeat;

@@ -575,10 +578,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn send_window_size(&self, size_type: WindowSizeType) {
let dppx = self.page_zoom * self.embedder_coordinates.hidpi_factor;

self.webrender_api.set_window_parameters(
let flipped_viewport = {
let fb_height = self.embedder_coordinates.framebuffer.height;
let mut view = self.embedder_coordinates.viewport.clone();
view.origin.y = fb_height - view.origin.y - view.size.height;
FramebufferIntRect::from_untyped(&view.to_untyped())
};

self.webrender_api.set_document_view(
self.webrender_document,
self.embedder_coordinates.framebuffer,
self.embedder_coordinates.viewport,
flipped_viewport,
self.embedder_coordinates.hidpi_factor.get(),
);

@@ -612,9 +621,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.update_zoom_transform();
}

if self.embedder_coordinates.viewport == old_coords.viewport &&
self.embedder_coordinates.framebuffer == old_coords.framebuffer
{
if self.embedder_coordinates.viewport == old_coords.viewport {
return;
}

@@ -1203,11 +1210,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|| {
debug!("compositor: compositing");

let size = FramebufferIntSize::from_untyped(
&self.embedder_coordinates.framebuffer.to_untyped(),
);

// Paint the scene.
// TODO(gw): Take notice of any errors the renderer returns!
self.webrender
.render(self.embedder_coordinates.framebuffer)
.ok();
self.webrender.render(size).ok();
},
);

@@ -4,7 +4,7 @@

use gleam::gl;
use image::RgbImage;
use servo_geometry::DeviceUintLength;
use servo_geometry::FramebufferUintLength;

#[derive(Default)]
pub struct RenderTargetInfo {
@@ -15,8 +15,8 @@ pub struct RenderTargetInfo {

pub fn initialize_png(
gl: &dyn gl::Gl,
width: DeviceUintLength,
height: DeviceUintLength,
width: FramebufferUintLength,
height: FramebufferUintLength,
) -> RenderTargetInfo {
let framebuffer_ids = gl.gen_framebuffers(1);
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);
@@ -82,8 +82,8 @@ pub fn initialize_png(
pub fn draw_img(
gl: &dyn gl::Gl,
render_target_info: RenderTargetInfo,
width: DeviceUintLength,
height: DeviceUintLength,
width: FramebufferUintLength,
height: FramebufferUintLength,
) -> RgbImage {
let width = width.get() as usize;
let height = height.get() as usize;
@@ -17,7 +17,9 @@ use std::fmt::{Debug, Error, Formatter};
#[cfg(feature = "gl")]
use std::rc::Rc;
use style_traits::DevicePixel;
use webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, ScrollLocation};
use webrender_api::{
DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, FramebufferIntSize, ScrollLocation,
};
use webvr::VRServiceManager;
use webvr_traits::WebVRMainThreadHeartbeat;

@@ -167,7 +169,7 @@ pub struct EmbedderCoordinates {
/// Size of the native window.
pub window: (DeviceIntSize, DeviceIntPoint),
/// Size of the GL buffer in the window.
pub framebuffer: DeviceIntSize,
pub framebuffer: FramebufferIntSize,
/// Coordinates of the document within the framebuffer.
pub viewport: DeviceIntRect,
}
@@ -8,12 +8,11 @@ extern crate malloc_size_of_derive;
use app_units::{Au, MAX_AU, MIN_AU};
use euclid::{Length, Point2D, Rect, Size2D};
use std::f32;
use style_traits::DevicePixel;
use webrender_api::{LayoutPoint, LayoutRect, LayoutSize};
use webrender_api::{FramebufferPixel, LayoutPoint, LayoutRect, LayoutSize};

// Units for use with euclid::length and euclid::scale_factor.

pub type DeviceUintLength = Length<u32, DevicePixel>;
pub type FramebufferUintLength = Length<u32, FramebufferPixel>;

/// A normalized "pixel" at the default resolution for the display.
///
@@ -565,13 +565,15 @@ impl WindowMethods for ServoCallbacks {
}

fn get_coordinates(&self) -> EmbedderCoordinates {
let size = TypedSize2D::new(self.width.get() as i32, self.height.get() as i32);
let fb_size = TypedSize2D::new(self.width.get() as i32, self.height.get() as i32);
let pixel_size = TypedSize2D::new(self.width.get() as i32, self.height.get() as i32);
let viewport = webrender_api::DeviceIntRect::new(TypedPoint2D::zero(), pixel_size);
EmbedderCoordinates {
viewport: webrender_api::DeviceIntRect::new(TypedPoint2D::zero(), size),
framebuffer: size,
window: (size, TypedPoint2D::new(0, 0)),
screen: size,
screen_avail: size,
viewport,
framebuffer: fb_size,
window: (pixel_size, TypedPoint2D::new(0, 0)),
screen: pixel_size,
screen_avail: pixel_size,
hidpi_factor: TypedScale::new(self.density),
}
}
@@ -19,7 +19,7 @@ use servo::servo_config::opts;
use servo::servo_config::prefs::PREFS;
use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, ScrollLocation};
use servo::webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, FramebufferIntSize, ScrollLocation};
use servo::webvr::VRServiceManager;
use servo::webvr_traits::WebVRMainThreadHeartbeat;
use std::cell::{Cell, RefCell};
@@ -703,12 +703,12 @@ impl WindowMethods for Window {
.get_inner_size()
.expect("Failed to get window inner size.");
let inner_size = (TypedSize2D::new(width as f32, height as f32) * dpr).to_i32();

let viewport = DeviceIntRect::new(TypedPoint2D::zero(), inner_size);
let framebuffer = FramebufferIntSize::from_untyped(&viewport.size.to_untyped());

EmbedderCoordinates {
viewport: viewport,
framebuffer: inner_size,
viewport,
framebuffer,
window: (win_size, win_origin),
screen: screen,
// FIXME: Glutin doesn't have API for available size. Fallback to screen size
@@ -720,9 +720,11 @@ impl WindowMethods for Window {
let dpr = self.servo_hidpi_factor();
let size =
(TypedSize2D::new(context.width, context.height).to_f32() * dpr).to_i32();
let viewport = DeviceIntRect::new(TypedPoint2D::zero(), size);
let framebuffer = FramebufferIntSize::from_untyped(&size.to_untyped());
EmbedderCoordinates {
viewport: DeviceIntRect::new(TypedPoint2D::zero(), size),
framebuffer: size,
viewport,
framebuffer,
window: (size, TypedPoint2D::zero()),
screen: size,
screen_avail: size,

0 comments on commit 4c94f54

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