Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WR multi-document update #17892

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/compositing/compositor_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
10 changes: 5 additions & 5 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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).
Expand Down
26 changes: 17 additions & 9 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ pub struct Constellation<Message, LTF, STF> {
/// timer thread.
scheduler_chan: IpcSender<TimerSchedulerMsg>,

/// A single WebRender document the constellation operates on.
webrender_document: webrender_api::DocumentId,

/// A channel for the constellation to send messages to the
/// Webrender thread.
/// WebRender thread.
webrender_api_sender: webrender_api::RenderApiSender,

/// The set of all event loops in the browser. We generate a new
Expand Down Expand Up @@ -325,6 +328,9 @@ pub struct InitialConstellationState {
/// A channel to the memory profiler thread.
pub mem_profiler_chan: mem::ProfilerChan,

/// Webrender document ID.
pub webrender_document: webrender_api::DocumentId,

/// Webrender API.
pub webrender_api_sender: webrender_api::RenderApiSender,

Expand Down Expand Up @@ -561,6 +567,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
webdriver: WebDriverData::new(),
scheduler_chan: TimerScheduler::start(),
document_states: HashMap::new(),
webrender_document: state.webrender_document,
webrender_api_sender: state.webrender_api_sender,
shutting_down: false,
handled_warnings: VecDeque::new(),
Expand Down Expand Up @@ -664,9 +671,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>

let result = Pipeline::spawn::<Message, LTF, STF>(InitialPipelineState {
id: pipeline_id,
browsing_context_id: browsing_context_id,
top_level_browsing_context_id: top_level_browsing_context_id,
parent_info: parent_info,
browsing_context_id,
top_level_browsing_context_id,
parent_info,
constellation_chan: self.script_sender.clone(),
layout_to_constellation_chan: self.layout_sender.clone(),
scheduler_chan: self.scheduler_chan.clone(),
Expand All @@ -675,17 +682,18 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
bluetooth_thread: self.bluetooth_thread.clone(),
swmanager_thread: self.swmanager_sender.clone(),
font_cache_thread: self.font_cache_thread.clone(),
resource_threads: resource_threads,
resource_threads,
time_profiler_chan: self.time_profiler_chan.clone(),
mem_profiler_chan: self.mem_profiler_chan.clone(),
window_size: initial_window_size,
event_loop: event_loop,
load_data: load_data,
event_loop,
load_data,
device_pixel_ratio: self.window_size.device_pixel_ratio,
pipeline_namespace_id: self.next_pipeline_namespace_id(),
prev_visibility: prev_visibility,
prev_visibility,
webrender_api_sender: self.webrender_api_sender.clone(),
is_private: is_private,
webrender_document: self.webrender_document,
is_private,
webvr_thread: self.webvr_thread.clone()
});

Expand Down
7 changes: 7 additions & 0 deletions components/constellation/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub struct InitialPipelineState {
/// Information about the page to load.
pub load_data: LoadData,


/// The ID of the pipeline namespace for this script thread.
pub pipeline_namespace_id: PipelineNamespaceId,

Expand All @@ -165,6 +166,9 @@ pub struct InitialPipelineState {
/// Webrender api.
pub webrender_api_sender: webrender_api::RenderApiSender,

/// The ID of the document processed by this script thread.
pub webrender_document: webrender_api::DocumentId,

/// Whether this pipeline is considered private.
pub is_private: bool,
/// A channel to the webvr thread.
Expand Down Expand Up @@ -265,6 +269,7 @@ impl Pipeline {
script_content_process_shutdown_chan: script_content_process_shutdown_chan,
script_content_process_shutdown_port: script_content_process_shutdown_port,
webrender_api_sender: state.webrender_api_sender,
webrender_document: state.webrender_document,
webvr_thread: state.webvr_thread,
};

Expand Down Expand Up @@ -464,6 +469,7 @@ pub struct UnprivilegedPipelineContent {
script_content_process_shutdown_chan: IpcSender<()>,
script_content_process_shutdown_port: IpcReceiver<()>,
webrender_api_sender: webrender_api::RenderApiSender,
webrender_document: webrender_api::DocumentId,
webvr_thread: Option<IpcSender<WebVRMsg>>,
}

Expand Down Expand Up @@ -510,6 +516,7 @@ impl UnprivilegedPipelineContent {
self.mem_profiler_chan,
Some(self.layout_content_process_shutdown_chan),
self.webrender_api_sender,
self.webrender_document,
self.prefs.get("layout.threads").expect("exists").value()
.as_u64().expect("count") as usize,
paint_time_metrics);
Expand Down
Loading