From e57e2121b27b09ceb8c87d3463f09f9c227b0565 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 4 Jun 2019 21:39:59 -0700 Subject: [PATCH] Get the `servo` crate building with the new WebRender --- components/compositing/compositor.rs | 16 ++++++++++++---- components/compositing/windowing.rs | 4 ++-- components/servo/lib.rs | 9 ++++++++- ports/glutin/headed_window.rs | 7 +++---- ports/glutin/headless_window.rs | 4 ++-- ports/glutin/window_trait.rs | 2 +- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index dcff6ef66fef..c440796453b9 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -32,7 +32,7 @@ use script_traits::{ MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId, WheelDelta, }; use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType}; -use servo_geometry::DeviceIndependentPixel; +use servo_geometry::{DeviceIndependentPixel, FramebufferUintLength}; use std::collections::HashMap; use std::env; use std::fs::{create_dir_all, File}; @@ -1268,7 +1268,9 @@ impl IOCompositor { CompositeTarget::Window => gl::RenderTargetInfo::default(), #[cfg(feature = "gl")] CompositeTarget::WindowAndPng | CompositeTarget::PngFile => { - gl::initialize_png(&*self.window.gl(), width, height) + gl::initialize_png(&*self.window.gl(), + FramebufferUintLength::new(width.get()), + FramebufferUintLength::new(height.get())) }, #[cfg(not(feature = "gl"))] _ => (), @@ -1330,7 +1332,10 @@ impl IOCompositor { CompositeTarget::Window => None, #[cfg(feature = "gl")] CompositeTarget::WindowAndPng => { - let img = gl::draw_img(&*self.window.gl(), rt_info, width, height); + let img = gl::draw_img(&*self.window.gl(), + rt_info, + FramebufferUintLength::new(width.get()), + FramebufferUintLength::new(height.get())); Some(Image { width: img.width(), height: img.height(), @@ -1349,7 +1354,10 @@ impl IOCompositor { || match self.output_file.as_ref() { Some(path) => match File::create(path) { Ok(mut file) => { - let img = gl::draw_img(gl, rt_info, width, height); + let img = gl::draw_img(gl, + rt_info, + FramebufferUintLength::new(width.get()), + FramebufferUintLength::new(height.get())); let dynamic_image = DynamicImage::ImageRgb8(img); if let Err(e) = dynamic_image.write_to(&mut file, ImageFormat::PNG) { diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index aa0bdc213849..90ced19bc09c 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -21,7 +21,7 @@ use std::time::Duration; use style_traits::DevicePixel; use webrender_api::ScrollLocation; use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize}; -use webrender_api::units::{DevicePoint, FramebufferIntSize}; +use webrender_api::units::DevicePoint; use webvr::VRServiceManager; use webvr_traits::WebVRMainThreadHeartbeat; @@ -191,7 +191,7 @@ pub struct EmbedderCoordinates { /// Size of the native window. pub window: (DeviceIntSize, DeviceIntPoint), /// Size of the GL buffer in the window. - pub framebuffer: FramebufferIntSize, + pub framebuffer: DeviceIntSize, /// Coordinates of the document within the framebuffer. pub viewport: DeviceIntRect, } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index b75433bb2135..feb31036fdc1 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -84,6 +84,7 @@ use constellation::{FromCompositorLogger, FromScriptLogger}; use crossbeam_channel::{unbounded, Sender}; use embedder_traits::{EmbedderMsg, EmbedderProxy, EmbedderReceiver, EventLoopWaker}; use env_logger::Builder as EnvLoggerBuilder; +use euclid::TypedSize2D; #[cfg(all( not(target_os = "windows"), not(target_os = "ios"), @@ -303,11 +304,16 @@ where let render_notifier = Box::new(RenderNotifier::new(compositor_proxy.clone())); + // Cast from `DeviceIndependentPixel` to `DevicePixel` + let device_pixel_ratio = coordinates.hidpi_factor.get(); + let window_size = TypedSize2D::from_untyped( + &(opts.initial_window_size.to_f32() / device_pixel_ratio).to_i32().to_untyped()); + webrender::Renderer::new( window.gl(), render_notifier, webrender::RendererOptions { - device_pixel_ratio: coordinates.hidpi_factor.get(), + device_pixel_ratio, resource_override_path: opts.shaders_dir.clone(), enable_aa: opts.enable_text_antialiasing, debug_flags: debug_flags, @@ -323,6 +329,7 @@ where ..Default::default() }, None, + window_size, ) .expect("Unable to initialize webrender!") }; diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index c19d2bdb63bd..fa416cbcc61f 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -27,9 +27,8 @@ use servo::script_traits::{TouchEventType, WheelMode, WheelDelta}; use servo::servo_config::{opts, pref}; use servo::servo_geometry::DeviceIndependentPixel; use servo::style_traits::DevicePixel; -use servo::webrender_api::{ - DeviceIntPoint, DeviceIntRect, DeviceIntSize, FramebufferIntSize, ScrollLocation, -}; +use servo::webrender_api::ScrollLocation; +use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize}; use servo_media::player::context::{GlApi, GlContext as PlayerGLContext, NativeDisplay}; use std::cell::{Cell, RefCell}; use std::mem; @@ -500,7 +499,7 @@ impl WindowMethods for Window { .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()); + let framebuffer = DeviceIntSize::from_untyped(&viewport.size.to_untyped()); EmbedderCoordinates { viewport, diff --git a/ports/glutin/headless_window.rs b/ports/glutin/headless_window.rs index 63b45cc5de70..a91e073ed1dd 100644 --- a/ports/glutin/headless_window.rs +++ b/ports/glutin/headless_window.rs @@ -13,7 +13,7 @@ use servo::compositing::windowing::{EmbedderCoordinates, WindowMethods}; use servo::servo_config::opts; use servo::servo_geometry::DeviceIndependentPixel; use servo::style_traits::DevicePixel; -use servo::webrender_api::{DeviceIntRect, FramebufferIntSize}; +use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize}; use servo_media::player::context as MediaPlayerCtxt; use std::cell::Cell; #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -178,7 +178,7 @@ impl WindowMethods for Window { let size = (TypedSize2D::new(self.context.width, self.context.height).to_f32() * dpr).to_i32(); let viewport = DeviceIntRect::new(TypedPoint2D::zero(), size); - let framebuffer = FramebufferIntSize::from_untyped(&size.to_untyped()); + let framebuffer = DeviceIntSize::from_untyped(&size.to_untyped()); EmbedderCoordinates { viewport, framebuffer, diff --git a/ports/glutin/window_trait.rs b/ports/glutin/window_trait.rs index 83b208fe9938..2f1fbebd9731 100644 --- a/ports/glutin/window_trait.rs +++ b/ports/glutin/window_trait.rs @@ -8,7 +8,7 @@ use glutin; use servo::compositing::windowing::{WindowEvent, WindowMethods}; use servo::embedder_traits::Cursor; -use servo::webrender_api::{DeviceIntPoint, DeviceIntSize}; +use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize}; // This should vary by zoom level and maybe actual text size (focused or under cursor) pub const LINE_HEIGHT: f32 = 38.0;