WR multi-document update

This commit is contained in:
Dzmitry Malyshau 2017-07-26 12:28:38 -04:00
parent a15d13a6ec
commit 8c588e8c36
14 changed files with 111 additions and 86 deletions

View file

@ -6,7 +6,7 @@ use CompositionPipeline;
use SendableFrameTree;
use compositor_thread::{CompositorProxy, CompositorReceiver};
use compositor_thread::{InitialCompositorState, Msg, RenderListener};
use euclid::{Point2D, TypedPoint2D, TypedVector2D, TypedRect, ScaleFactor, TypedSize2D};
use euclid::{Point2D, TypedPoint2D, TypedVector2D, ScaleFactor};
use gfx_traits::Epoch;
use gleam::gl;
use image::{DynamicImage, ImageFormat, RgbImage};
@ -34,7 +34,8 @@ use style_traits::viewport::ViewportConstraints;
use time::{precise_time_ns, precise_time_s};
use touch::{TouchHandler, TouchAction};
use webrender;
use webrender_api::{self, ClipId, LayoutPoint, LayoutVector2D, ScrollEventPhase, ScrollLocation, ScrollClamping};
use webrender_api::{self, ClipId, DeviceUintRect, DeviceUintSize, LayoutPoint, LayoutVector2D};
use webrender_api::{ScrollEventPhase, ScrollLocation, ScrollClamping};
use windowing::{self, MouseWindowEvent, WindowEvent, WindowMethods};
#[derive(Debug, PartialEq)]
@ -110,10 +111,10 @@ pub struct IOCompositor<Window: WindowMethods> {
scale: ScaleFactor<f32, LayerPixel, DevicePixel>,
/// The size of the rendering area.
frame_size: TypedSize2D<u32, DevicePixel>,
frame_size: DeviceUintSize,
/// The position and size of the window within the rendering area.
window_rect: TypedRect<u32, DevicePixel>,
window_rect: DeviceUintRect,
/// "Mobile-style" zoom that does not reflow the page.
viewport_zoom: PinchZoomFactor,
@ -179,6 +180,9 @@ pub struct IOCompositor<Window: WindowMethods> {
/// The webrender renderer.
webrender: webrender::Renderer,
/// The active webrender document.
webrender_document: webrender_api::DocumentId,
/// The webrender interface, if enabled.
webrender_api: webrender_api::RenderApi,
@ -378,7 +382,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
scroll_in_progress: false,
in_scroll_transaction: None,
webrender: state.webrender,
webrender_api: state.webrender_api_sender.create_api(),
webrender_document: state.webrender_document,
webrender_api: state.webrender_api,
}
}
@ -675,8 +680,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.root_pipeline = Some(frame_tree.pipeline.clone());
let pipeline_id = frame_tree.pipeline.id.to_webrender();
self.webrender_api.set_root_pipeline(pipeline_id);
self.webrender_api.generate_frame(None);
self.webrender_api.set_root_pipeline(self.webrender_document, pipeline_id);
self.webrender_api.generate_frame(self.webrender_document, None);
self.create_pipeline_details_for_frame_tree(&frame_tree);
@ -700,14 +705,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn send_window_size(&self, size_type: WindowSizeType) {
let dppx = self.page_zoom * self.hidpi_factor();
let window_rect = {
let offset = webrender_api::DeviceUintPoint::new(self.window_rect.origin.x, self.window_rect.origin.y);
let size = webrender_api::DeviceUintSize::new(self.window_rect.size.width, self.window_rect.size.height);
webrender_api::DeviceUintRect::new(offset, size)
};
let frame_size = webrender_api::DeviceUintSize::new(self.frame_size.width, self.frame_size.height);
self.webrender_api.set_window_parameters(frame_size, window_rect);
self.webrender_api.set_window_parameters(self.webrender_document, self.frame_size, self.window_rect);
let initial_viewport = self.window_rect.size.to_f32() / dppx;
@ -727,7 +725,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
fn scroll_fragment_to_point(&mut self, id: ClipId, point: Point2D<f32>) {
self.webrender_api.scroll_node_with_id(LayoutPoint::from_untyped(&point), id,
self.webrender_api.scroll_node_with_id(self.webrender_document,
LayoutPoint::from_untyped(&point),
id,
ScrollClamping::ToContentBounds);
}
@ -821,12 +821,12 @@ impl<Window: WindowMethods> IOCompositor<Window> {
WindowEvent::ToggleWebRenderProfiler => {
let profiler_enabled = self.webrender.get_profiler_enabled();
self.webrender.set_profiler_enabled(!profiler_enabled);
self.webrender_api.generate_frame(None);
self.webrender_api.generate_frame(self.webrender_document, None);
}
}
}
fn on_resize_window_event(&mut self, new_size: TypedSize2D<u32, DevicePixel>) {
fn on_resize_window_event(&mut self, new_size: DeviceUintSize) {
debug!("compositor resizing to {:?}", new_size.to_untyped());
// A size change could also mean a resolution change.
@ -1123,7 +1123,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
(combined_event.cursor.to_f32() / self.scale).to_untyped();
let location = webrender_api::ScrollLocation::Delta(delta);
let cursor = webrender_api::WorldPoint::from_untyped(&cursor);
self.webrender_api.scroll(location, cursor, combined_event.phase);
self.webrender_api.scroll(self.webrender_document, location, cursor, combined_event.phase);
last_combined_event = None
}
}
@ -1179,7 +1179,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
};
let cursor = (combined_event.cursor.to_f32() / self.scale).to_untyped();
let cursor = webrender_api::WorldPoint::from_untyped(&cursor);
self.webrender_api.scroll(scroll_location, cursor, combined_event.phase);
self.webrender_api.scroll(self.webrender_document, scroll_location, cursor, combined_event.phase);
self.waiting_for_results_of_scroll = true
}
@ -1277,7 +1277,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn update_page_zoom_for_webrender(&mut self) {
let page_zoom = webrender_api::ZoomFactor::new(self.page_zoom.get());
self.webrender_api.set_page_zoom(page_zoom);
self.webrender_api.set_page_zoom(self.webrender_document, page_zoom);
}
/// Simulate a pinch zoom
@ -1315,7 +1315,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn send_viewport_rects(&self) {
let mut scroll_states_per_pipeline = HashMap::new();
for scroll_layer_state in self.webrender_api.get_scroll_node_state() {
for scroll_layer_state in self.webrender_api.get_scroll_node_state(self.webrender_document) {
if scroll_layer_state.id.external_id().is_none() &&
!scroll_layer_state.id.is_root_scroll_node() {
continue;
@ -1464,8 +1464,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
debug!("compositor: compositing");
// Paint the scene.
let size = webrender_api::DeviceUintSize::from_untyped(&self.frame_size.to_untyped());
self.webrender.render(size);
self.webrender.render(self.frame_size);
});
let rv = match target {
@ -1565,7 +1564,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
if self.webrender.layers_are_bouncing_back() {
self.webrender_api.tick_scrolling_bounce_animations();
self.webrender_api.tick_scrolling_bounce_animations(self.webrender_document);
self.send_viewport_rects()
}
}

View file

@ -194,5 +194,6 @@ pub struct InitialCompositorState {
pub mem_profiler_chan: mem::ProfilerChan,
/// Instance of webrender API
pub webrender: webrender::Renderer,
pub webrender_api_sender: webrender_api::RenderApiSender,
pub webrender_document: webrender_api::DocumentId,
pub webrender_api: webrender_api::RenderApi,
}

View file

@ -6,7 +6,7 @@
use compositor_thread::EventLoopWaker;
use euclid::{Point2D, Size2D};
use euclid::{TypedPoint2D, TypedRect, ScaleFactor, TypedSize2D};
use euclid::{ScaleFactor, TypedPoint2D, TypedSize2D};
use gleam::gl;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::{Key, KeyModifiers, KeyState, TraversalDirection};
@ -18,7 +18,7 @@ use std::fmt::{Debug, Error, Formatter};
use std::rc::Rc;
use style_traits::DevicePixel;
use style_traits::cursor::Cursor;
use webrender_api::ScrollLocation;
use webrender_api::{DeviceUintSize, DeviceUintRect, ScrollLocation};
#[derive(Clone)]
pub enum MouseWindowEvent {
@ -41,7 +41,7 @@ pub enum WindowEvent {
/// message, the window must make the same GL context as in `PrepareRenderingEvent` current.
Refresh,
/// Sent when the window is resized.
Resize(TypedSize2D<u32, DevicePixel>),
Resize(DeviceUintSize),
/// Touchpad Pressure
TouchpadPressure(TypedPoint2D<f32, DevicePixel>, f32, TouchpadPressurePhase),
/// Sent when a new URL is to be loaded.
@ -105,9 +105,9 @@ pub enum AnimationState {
pub trait WindowMethods {
/// Returns the rendering area size in hardware pixels.
fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>;
fn framebuffer_size(&self) -> DeviceUintSize;
/// Returns the position and size of the window within the rendering area.
fn window_rect(&self) -> TypedRect<u32, DevicePixel>;
fn window_rect(&self) -> DeviceUintRect;
/// Returns the size of the window in density-independent "px" units.
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel>;
/// Presents the window to the screen (perhaps by page flipping).