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

Async scene building. #2362

Merged
merged 18 commits into from Feb 22, 2018
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Split DocumentMsg into SceneMsg and FrameMsg.

  • Loading branch information
nical committed Feb 22, 2018
commit 6993945637008f4d988bd17c8d1cfea0235891f1
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{ApiMsg, DocumentMsg};
use api::{ApiMsg, FrameMsg};
use bincode::{serialize, Infinite};
use byteorder::{LittleEndian, WriteBytesExt};
use std::any::TypeId;
@@ -69,8 +69,8 @@ pub fn should_record_msg(msg: &ApiMsg) -> bool {
ApiMsg::UpdateDocument(_, ref msgs) => {
for msg in &msgs.frame_ops {
match *msg {
DocumentMsg::GetScrollNodeState(..) |
DocumentMsg::HitTest(..) => {}
FrameMsg::GetScrollNodeState(..) |
FrameMsg::HitTest(..) => {}
_ => { return true; }
}
}

Large diffs are not rendered by default.

@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{DocumentId, PipelineId, Epoch, ApiMsg, DocumentMsg, ResourceUpdates};
use api::{DocumentId, PipelineId, Epoch, ApiMsg, FrameMsg, ResourceUpdates};
use api::channel::MsgSender;
use frame::build_scene;
use frame_builder::{FrameBuilderConfig, FrameBuilder};
@@ -19,7 +19,7 @@ pub enum SceneBuilderRequest {
document_id: DocumentId,
scene: Option<SceneRequest>,
resource_updates: ResourceUpdates,
frame_ops: Vec<DocumentMsg>,
frame_ops: Vec<FrameMsg>,
render: bool,
},
Stop
@@ -31,7 +31,7 @@ pub enum SceneBuilderResult {
document_id: DocumentId,
built_scene: Option<BuiltScene>,
resource_updates: ResourceUpdates,
frame_ops: Vec<DocumentMsg>,
frame_ops: Vec<FrameMsg>,
render: bool,
},
}
@@ -132,9 +132,9 @@ impl ResourceUpdates {
/// the frame to be rebuilt.
pub struct Transaction {
// Operations affecting the scene (applied before scene building).
scene_ops: Vec<DocumentMsg>,
scene_ops: Vec<SceneMsg>,
// Operations affecting the generation of frames (applied after scene building).
frame_ops: Vec<DocumentMsg>,
frame_ops: Vec<FrameMsg>,

// Additional display list data.
payloads: Vec<Payload>,
@@ -180,7 +180,7 @@ impl Transaction {
}

pub fn update_epoch(&mut self, pipeline_id: PipelineId, epoch: Epoch) {
self.frame_ops.push(DocumentMsg::UpdateEpoch(pipeline_id, epoch));
self.frame_ops.push(FrameMsg::UpdateEpoch(pipeline_id, epoch));
}

/// Sets the root pipeline.
@@ -196,14 +196,14 @@ impl Transaction {
/// # }
/// ```
pub fn set_root_pipeline(&mut self, pipeline_id: PipelineId) {
self.scene_ops.push(DocumentMsg::SetRootPipeline(pipeline_id));
self.scene_ops.push(SceneMsg::SetRootPipeline(pipeline_id));
}

/// Removes data associated with a pipeline from the internal data structures.
/// If the specified `pipeline_id` is for the root pipeline, the root pipeline
/// is reset back to `None`.
pub fn remove_pipeline(&mut self, pipeline_id: PipelineId) {
self.scene_ops.push(DocumentMsg::RemovePipeline(pipeline_id));
self.scene_ops.push(SceneMsg::RemovePipeline(pipeline_id));
}

/// Supplies a new frame to WebRender.
@@ -238,7 +238,7 @@ impl Transaction {
) {
let (display_list_data, list_descriptor) = display_list.into_data();
self.scene_ops.push(
DocumentMsg::SetDisplayList {
SceneMsg::SetDisplayList {
epoch,
pipeline_id,
background,
@@ -262,7 +262,7 @@ impl Transaction {
device_pixel_ratio: f32,
) {
self.scene_ops.push(
DocumentMsg::SetWindowParameters {
SceneMsg::SetWindowParameters {
window_size,
inner_rect,
device_pixel_ratio,
@@ -280,7 +280,7 @@ impl Transaction {
cursor: WorldPoint,
phase: ScrollEventPhase,
) {
self.frame_ops.push(DocumentMsg::Scroll(scroll_location, cursor, phase));
self.frame_ops.push(FrameMsg::Scroll(scroll_location, cursor, phase));
}

pub fn scroll_node_with_id(
@@ -289,23 +289,23 @@ impl Transaction {
id: ExternalScrollId,
clamp: ScrollClamping,
) {
self.frame_ops.push(DocumentMsg::ScrollNodeWithId(origin, id, clamp));
self.frame_ops.push(FrameMsg::ScrollNodeWithId(origin, id, clamp));
}

pub fn set_page_zoom(&mut self, page_zoom: ZoomFactor) {
self.scene_ops.push(DocumentMsg::SetPageZoom(page_zoom));
self.scene_ops.push(SceneMsg::SetPageZoom(page_zoom));
}

pub fn set_pinch_zoom(&mut self, pinch_zoom: ZoomFactor) {
self.scene_ops.push(DocumentMsg::SetPinchZoom(pinch_zoom));
self.scene_ops.push(SceneMsg::SetPinchZoom(pinch_zoom));
}

pub fn set_pan(&mut self, pan: DeviceIntPoint) {
self.frame_ops.push(DocumentMsg::SetPan(pan));
self.frame_ops.push(FrameMsg::SetPan(pan));
}

pub fn tick_scrolling_bounce_animations(&mut self) {
self.frame_ops.push(DocumentMsg::TickScrollingBounce);
self.frame_ops.push(FrameMsg::TickScrollingBounce);
}

/// Generate a new frame.
@@ -316,13 +316,13 @@ impl Transaction {
/// Supply a list of animated property bindings that should be used to resolve
/// bindings in the current display list.
pub fn update_dynamic_properties(&mut self, properties: DynamicProperties) {
self.frame_ops.push(DocumentMsg::UpdateDynamicProperties(properties));
self.frame_ops.push(FrameMsg::UpdateDynamicProperties(properties));
}

/// Enable copying of the output of this pipeline id to
/// an external texture for callers to consume.
pub fn enable_frame_output(&mut self, pipeline_id: PipelineId, enable: bool) {
self.frame_ops.push(DocumentMsg::EnableFrameOutput(pipeline_id, enable));
self.frame_ops.push(FrameMsg::EnableFrameOutput(pipeline_id, enable));
}

fn finalize(self) -> (TransactionMsg, Vec<Payload>) {
@@ -342,8 +342,8 @@ impl Transaction {
/// Represents a transaction in the format sent through the channel.
#[derive(Clone, Deserialize, Serialize)]
pub struct TransactionMsg {
pub scene_ops: Vec<DocumentMsg>,
pub frame_ops: Vec<DocumentMsg>,
pub scene_ops: Vec<SceneMsg>,
pub frame_ops: Vec<FrameMsg>,
pub resource_updates: ResourceUpdates,
pub generate_frame: bool,
pub use_scene_builder_thread: bool,
@@ -358,7 +358,7 @@ impl TransactionMsg {
}

// TODO: We only need this for a few RenderApi methods which we should remove.
fn single_message(msg: DocumentMsg) -> Self {
fn frame_message(msg: FrameMsg) -> Self {
TransactionMsg {
scene_ops: Vec::new(),
frame_ops: vec![msg],
@@ -367,6 +367,16 @@ impl TransactionMsg {
use_scene_builder_thread: false,
}
}

fn scene_message(msg: SceneMsg) -> Self {
TransactionMsg {
scene_ops: vec![msg],
frame_ops: Vec::new(),
resource_updates: ResourceUpdates::new(),
generate_frame: false,
use_scene_builder_thread: false,
}
}
}

#[derive(Clone, Deserialize, Serialize)]
@@ -432,11 +442,9 @@ pub struct AddFontInstance {
pub variations: Vec<FontVariation>,
}

// TODO: Split this in two emums.
// Review note: this will be done just before landing.
// Frame messages affect building the scene.
#[derive(Clone, Deserialize, Serialize)]
pub enum DocumentMsg {
// Scene messages (apply before building the scene).
pub enum SceneMsg {
SetPageZoom(ZoomFactor),
SetPinchZoom(ZoomFactor),
SetRootPipeline(PipelineId),
@@ -455,8 +463,11 @@ pub enum DocumentMsg {
inner_rect: DeviceUintRect,
device_pixel_ratio: f32,
},
}

// Frame messages (apply after building the scene).
// Frame messages affect frame generation (applied after building the scene).
#[derive(Clone, Deserialize, Serialize)]
pub enum FrameMsg {
HitTest(Option<PipelineId>, WorldPoint, HitTestFlags, MsgSender<HitTestResult>),
UpdateEpoch(PipelineId, Epoch),
SetPan(DeviceIntPoint),
@@ -468,24 +479,31 @@ pub enum DocumentMsg {
UpdateDynamicProperties(DynamicProperties),
}

impl fmt::Debug for DocumentMsg {
impl fmt::Debug for SceneMsg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
DocumentMsg::SetDisplayList { .. } => "DocumentMsg::SetDisplayList",
DocumentMsg::HitTest(..) => "DocumentMsg::HitTest",
DocumentMsg::SetPageZoom(..) => "DocumentMsg::SetPageZoom",
DocumentMsg::SetPinchZoom(..) => "DocumentMsg::SetPinchZoom",
DocumentMsg::SetPan(..) => "DocumentMsg::SetPan",
DocumentMsg::SetRootPipeline(..) => "DocumentMsg::SetRootPipeline",
DocumentMsg::RemovePipeline(..) => "DocumentMsg::RemovePipeline",
DocumentMsg::SetWindowParameters { .. } => "DocumentMsg::SetWindowParameters",
DocumentMsg::Scroll(..) => "DocumentMsg::Scroll",
DocumentMsg::ScrollNodeWithId(..) => "DocumentMsg::ScrollNodeWithId",
DocumentMsg::TickScrollingBounce => "DocumentMsg::TickScrollingBounce",
DocumentMsg::GetScrollNodeState(..) => "DocumentMsg::GetScrollNodeState",
DocumentMsg::EnableFrameOutput(..) => "DocumentMsg::EnableFrameOutput",
DocumentMsg::UpdateEpoch(..) => "DocumentMsg::UpdateEpoch",
DocumentMsg::UpdateDynamicProperties(..) => "DocumentMsg::UpdateDynamicProperties",
SceneMsg::SetDisplayList { .. } => "SceneMsg::SetDisplayList",
SceneMsg::SetPageZoom(..) => "SceneMsg::SetPageZoom",
SceneMsg::SetPinchZoom(..) => "SceneMsg::SetPinchZoom",
SceneMsg::RemovePipeline(..) => "SceneMsg::RemovePipeline",
SceneMsg::SetWindowParameters { .. } => "SceneMsg::SetWindowParameters",
SceneMsg::SetRootPipeline(..) => "SceneMsg::SetRootPipeline",
})
}
}

impl fmt::Debug for FrameMsg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
FrameMsg::HitTest(..) => "FrameMsg::HitTest",
FrameMsg::SetPan(..) => "FrameMsg::SetPan",
FrameMsg::Scroll(..) => "FrameMsg::Scroll",
FrameMsg::ScrollNodeWithId(..) => "FrameMsg::ScrollNodeWithId",
FrameMsg::TickScrollingBounce => "FrameMsg::TickScrollingBounce",
FrameMsg::GetScrollNodeState(..) => "FrameMsg::GetScrollNodeState",
FrameMsg::EnableFrameOutput(..) => "FrameMsg::EnableFrameOutput",
FrameMsg::UpdateDynamicProperties(..) => "FrameMsg::UpdateDynamicProperties",
FrameMsg::UpdateEpoch(..) => "FrameMsg::UpdateEpoch",
})
}
}
@@ -835,12 +853,22 @@ impl RenderApi {
}

/// A helper method to send document messages.
fn send(&self, document_id: DocumentId, msg: DocumentMsg) {
fn send_scene_msg(&self, document_id: DocumentId, msg: SceneMsg) {
// This assertion fails on Servo use-cases, because it creates different
// `RenderApi` instances for layout and compositor.
//assert_eq!(document_id.0, self.namespace_id);
self.api_sender
.send(ApiMsg::UpdateDocument(document_id, TransactionMsg::scene_message(msg)))
.unwrap()
}

/// A helper method to send document messages.
fn send_frame_msg(&self, document_id: DocumentId, msg: FrameMsg) {
// This assertion fails on Servo use-cases, because it creates different
// `RenderApi` instances for layout and compositor.
//assert_eq!(document_id.0, self.namespace_id);
self.api_sender
.send(ApiMsg::UpdateDocument(document_id, TransactionMsg::single_message(msg)))
.send(ApiMsg::UpdateDocument(document_id, TransactionMsg::frame_message(msg)))
.unwrap()
}

@@ -865,9 +893,10 @@ impl RenderApi {
flags: HitTestFlags)
-> HitTestResult {
let (tx, rx) = channel::msg_channel().unwrap();
self.send(

self.send_frame_msg(
document_id,
DocumentMsg::HitTest(pipeline_id, point, flags, tx)
FrameMsg::HitTest(pipeline_id, point, flags, tx)
);
rx.recv().unwrap()
}
@@ -879,15 +908,15 @@ impl RenderApi {
inner_rect: DeviceUintRect,
device_pixel_ratio: f32,
) {
self.send(
self.send_scene_msg(
document_id,
DocumentMsg::SetWindowParameters { window_size, inner_rect, device_pixel_ratio, },
SceneMsg::SetWindowParameters { window_size, inner_rect, device_pixel_ratio, },
);
}

pub fn get_scroll_node_state(&self, document_id: DocumentId) -> Vec<ScrollNodeState> {
let (tx, rx) = channel::msg_channel().unwrap();
self.send(document_id, DocumentMsg::GetScrollNodeState(tx));
self.send_frame_msg(document_id, FrameMsg::GetScrollNodeState(tx));
rx.recv().unwrap()
}

@@ -11,7 +11,7 @@ use std::io::{Read, Seek, SeekFrom};
use std::path::{Path, PathBuf};
use std::{mem, process};
use webrender::WEBRENDER_RECORDING_HEADER;
use webrender::api::{ApiMsg, DocumentMsg};
use webrender::api::{ApiMsg, SceneMsg};
use wrench::{Wrench, WrenchThing};

#[derive(Clone)]
@@ -146,11 +146,11 @@ impl WrenchThing for BinaryFrameReader {
}
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList { .. } => {
SceneMsg::SetDisplayList { .. } => {
found_frame_marker = false;
found_display_list = true;
}
DocumentMsg::SetRootPipeline(..) => {
SceneMsg::SetRootPipeline(..) => {
found_frame_marker = false;
found_pipeline = true;
}
@@ -282,7 +282,7 @@ impl webrender::ApiRecordingReceiver for JsonFrameWriter {
self.update_resources(&txn.resource_updates);
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
SceneMsg::SetDisplayList {
ref epoch,
ref pipeline_id,
ref background,
@@ -160,7 +160,7 @@ impl webrender::ApiRecordingReceiver for RonFrameWriter {
self.update_resources(&txn.resource_updates);
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
SceneMsg::SetDisplayList {
ref epoch,
ref pipeline_id,
ref background,
@@ -1128,7 +1128,7 @@ impl webrender::ApiRecordingReceiver for YamlFrameWriterReceiver {
self.frame_writer.update_resources(&txn.resource_updates);
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
SceneMsg::SetDisplayList {
ref epoch,
ref pipeline_id,
ref background,
@@ -1145,18 +1145,18 @@ impl webrender::ApiRecordingReceiver for YamlFrameWriterReceiver {
list_descriptor,
);
}
DocumentMsg::SetRootPipeline(ref pipeline_id) => {
SceneMsg::SetRootPipeline(ref pipeline_id) => {
self.scene.set_root_pipeline_id(pipeline_id.clone());
}
DocumentMsg::RemovePipeline(ref pipeline_id) => {
SceneMsg::RemovePipeline(ref pipeline_id) => {
self.scene.remove_pipeline(pipeline_id);
}
_ => {}
}
}
for doc_msg in &txn.frame_ops {
match *doc_msg {
DocumentMsg::UpdateDynamicProperties(ref properties) => {
FrameMsg::UpdateDynamicProperties(ref properties) => {
self.scene.properties.set_properties(properties);
}
_ => {}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.