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

Rename prefix/postfix messages into scene/frame messages.

  • Loading branch information
nical committed Feb 21, 2018
commit 392c62b2d00878905bb46cc84005efe81a3a68b6
@@ -67,14 +67,14 @@ pub fn should_record_msg(msg: &ApiMsg) -> bool {
ApiMsg::AddDocument { .. } |
ApiMsg::DeleteDocument(..) => true,
ApiMsg::UpdateDocument(_, ref msgs) => {
for msg in &msgs.prefix_ops {
for msg in &msgs.scene_ops {
match *msg {
DocumentMsg::GetScrollNodeState(..) |
DocumentMsg::HitTest(..) => {}
_ => { return true; }
}
}
for msg in &msgs.postfix_ops {
for msg in &msgs.frame_ops {
match *msg {
DocumentMsg::GetScrollNodeState(..) |
DocumentMsg::HitTest(..) => {}
@@ -206,7 +206,7 @@ impl Document {
scene_tx.send(SceneBuilderRequest::Transaction {
scene: scene_request,
resource_updates: txn.resource_updates,
document_ops: txn.postfix_ops,
frame_ops: txn.frame_ops,
render: txn.generate_frame,
document_id,
}).unwrap();
@@ -457,8 +457,6 @@ impl RenderBackend {
}
DocumentMsg::UpdateEpoch(pipeline_id, epoch) => {
doc.pending.scene.update_epoch(pipeline_id, epoch);
// TODO: we need to not do this here with async scene building, but when
// we receive the built scene instead.
doc.frame_ctx.update_epoch(pipeline_id, epoch);
DocumentOps::nop()
}
@@ -558,9 +556,9 @@ impl RenderBackend {
SceneBuilderMsg::Transaction {
document_id,
mut built_scene,
document_ops,
render,
resource_updates,
frame_ops,
render,
} => {
if let Some(doc) = self.documents.get_mut(&document_id) {
if let Some(mut built_scene) = built_scene.take() {
@@ -581,8 +579,8 @@ impl RenderBackend {
}

let txn = TransactionMsg {

This comment has been minimized.

@mrobinson

mrobinson Feb 20, 2018

Member

I think that transaction_msg might be a better name here.

prefix_ops: Vec::new(),
postfix_ops: document_ops,
scene_ops: Vec::new(),
frame_ops,
resource_updates,
generate_frame: render,
use_scene_builder_thread: false,
@@ -784,10 +782,7 @@ impl RenderBackend {
) {
let mut op = DocumentOps::nop();

// TODO: This is a little awkward that we are applying prefix ops here, this
// will most likely change soon.
let prefix_ops = replace(&mut txn.prefix_ops, Vec::new());
for doc_msg in prefix_ops {
for doc_msg in replace(&mut txn.scene_ops, Vec::new()) {
let _timer = profile_counters.total_time.timer();
op.combine(
self.process_document(
@@ -817,7 +812,7 @@ impl RenderBackend {
&mut profile_counters.resources,
);

for doc_msg in txn.postfix_ops {
for doc_msg in txn.frame_ops {
let _timer = profile_counters.total_time.timer();
op.combine(
self.process_document(
@@ -1193,7 +1188,7 @@ pub enum SceneBuilderRequest {
document_id: DocumentId,
scene: Option<SceneRequest>,
resource_updates: ResourceUpdates,
document_ops: Vec<DocumentMsg>,
frame_ops: Vec<DocumentMsg>,
render: bool,
},
Stop
@@ -1205,7 +1200,7 @@ pub enum SceneBuilderMsg {
document_id: DocumentId,
built_scene: Option<BuiltScene>,
resource_updates: ResourceUpdates,
document_ops: Vec<DocumentMsg>,
frame_ops: Vec<DocumentMsg>,
render: bool,
},
}
@@ -1275,7 +1270,7 @@ impl SceneBuilder {
document_id,
scene,
resource_updates,
document_ops,
frame_ops,
render,
} => {
let built_scene = scene.map(|request|{
@@ -1288,7 +1283,7 @@ impl SceneBuilder {
document_id,
built_scene,
resource_updates,
document_ops,
frame_ops,
render,
}).unwrap();

@@ -131,10 +131,8 @@ impl ResourceUpdates {
/// - no redundant work is performed if two commands in the same transaction cause the scene or
/// the frame to be rebuilt.
pub struct Transaction {
// Operations to apply before scene building.
prefix_ops: Vec<DocumentMsg>,
// Operations to apply after scene building.
postfix_ops: Vec<DocumentMsg>,
scene_ops: Vec<DocumentMsg>,
frame_ops: Vec<DocumentMsg>,

// Additional display list data.
payloads: Vec<Payload>,
@@ -152,8 +150,8 @@ pub struct Transaction {
impl Transaction {
pub fn new() -> Self {
Transaction {
prefix_ops: Vec::new(),
postfix_ops: Vec::new(),
scene_ops: Vec::new(),
frame_ops: Vec::new(),
resource_updates: ResourceUpdates::new(),
payloads: Vec::new(),
use_scene_builder_thread: false, // TODO: make this true by default.
@@ -174,13 +172,13 @@ impl Transaction {

pub fn is_empty(&self) -> bool {
!self.generate_frame &&
self.prefix_ops.is_empty() &&
self.postfix_ops.is_empty() &&
self.scene_ops.is_empty() &&
self.frame_ops.is_empty() &&
self.resource_updates.updates.is_empty()
}

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

/// Sets the root pipeline.
@@ -196,14 +194,14 @@ impl Transaction {
/// # }
/// ```
pub fn set_root_pipeline(&mut self, pipeline_id: PipelineId) {
self.prefix_ops.push(DocumentMsg::SetRootPipeline(pipeline_id));
self.scene_ops.push(DocumentMsg::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.prefix_ops.push(DocumentMsg::RemovePipeline(pipeline_id));
self.scene_ops.push(DocumentMsg::RemovePipeline(pipeline_id));
}

/// Supplies a new frame to WebRender.
@@ -237,7 +235,7 @@ impl Transaction {
preserve_frame_state: bool,
) {
let (display_list_data, list_descriptor) = display_list.into_data();
self.prefix_ops.push(
self.scene_ops.push(
DocumentMsg::SetDisplayList {
epoch,
pipeline_id,
@@ -261,7 +259,7 @@ impl Transaction {
inner_rect: DeviceUintRect,
device_pixel_ratio: f32,
) {
self.prefix_ops.push(
self.scene_ops.push(
DocumentMsg::SetWindowParameters {
window_size,
inner_rect,
@@ -280,7 +278,7 @@ impl Transaction {
cursor: WorldPoint,
phase: ScrollEventPhase,
) {
self.postfix_ops.push(DocumentMsg::Scroll(scroll_location, cursor, phase));
self.frame_ops.push(DocumentMsg::Scroll(scroll_location, cursor, phase));
}

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

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

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

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

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

/// Generate a new frame.
@@ -316,20 +314,20 @@ 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.postfix_ops.push(DocumentMsg::UpdateDynamicProperties(properties));
self.frame_ops.push(DocumentMsg::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.postfix_ops.push(DocumentMsg::EnableFrameOutput(pipeline_id, enable));
self.frame_ops.push(DocumentMsg::EnableFrameOutput(pipeline_id, enable));
}

fn finalize(self) -> (TransactionMsg, Vec<Payload>) {
(
TransactionMsg {
prefix_ops: self.prefix_ops,
postfix_ops: self.postfix_ops,
scene_ops: self.scene_ops,
frame_ops: self.frame_ops,
resource_updates: self.resource_updates,
use_scene_builder_thread: self.use_scene_builder_thread,
generate_frame: self.generate_frame,
@@ -342,8 +340,8 @@ impl Transaction {
/// Represents a transaction in the format sent through the channel.
#[derive(Clone, Deserialize, Serialize)]
pub struct TransactionMsg {
pub prefix_ops: Vec<DocumentMsg>,
pub postfix_ops: Vec<DocumentMsg>,
pub scene_ops: Vec<DocumentMsg>,
pub frame_ops: Vec<DocumentMsg>,
pub resource_updates: ResourceUpdates,
pub generate_frame: bool,
pub use_scene_builder_thread: bool,
@@ -352,16 +350,16 @@ pub struct TransactionMsg {
impl TransactionMsg {
pub fn is_empty(&self) -> bool {
!self.generate_frame &&
self.prefix_ops.is_empty() &&
self.postfix_ops.is_empty() &&
self.scene_ops.is_empty() &&
self.frame_ops.is_empty() &&
self.resource_updates.updates.is_empty()
}

// TODO: We only need this for a few RenderApi methods which we should remove.
fn single_message(msg: DocumentMsg) -> Self {
TransactionMsg {
prefix_ops: Vec::new(),
postfix_ops: vec![msg],
scene_ops: Vec::new(),
frame_ops: vec![msg],
resource_updates: ResourceUpdates::new(),
generate_frame: false,
use_scene_builder_thread: false,
@@ -432,9 +430,15 @@ pub struct AddFontInstance {
pub variations: Vec<FontVariation>,
}

// TODO: Split this in two emums.
// I am postponing this because while it is a trivial change, it is a hard one to rebase.

This comment has been minimized.

@mrobinson

mrobinson Feb 20, 2018

Member

Will you do this now? If not, probably better to remove this comment and open a bug tracking this.

#[derive(Clone, Deserialize, Serialize)]
pub enum DocumentMsg {
HitTest(Option<PipelineId>, WorldPoint, HitTestFlags, MsgSender<HitTestResult>),
// Scene messages (apply before building the scene).
SetPageZoom(ZoomFactor),
SetPinchZoom(ZoomFactor),
SetRootPipeline(PipelineId),
RemovePipeline(PipelineId),
SetDisplayList {
list_descriptor: BuiltDisplayListDescriptor,
epoch: Epoch,
@@ -444,18 +448,17 @@ pub enum DocumentMsg {
content_size: LayoutSize,
preserve_frame_state: bool,
},
UpdateEpoch(PipelineId, Epoch),
SetPageZoom(ZoomFactor),
SetPinchZoom(ZoomFactor),
SetPan(DeviceIntPoint),
SetRootPipeline(PipelineId),
RemovePipeline(PipelineId),
EnableFrameOutput(PipelineId, bool),
SetWindowParameters {
window_size: DeviceUintSize,
inner_rect: DeviceUintRect,
device_pixel_ratio: f32,
},

// Frame messages (apply after building the scene).
HitTest(Option<PipelineId>, WorldPoint, HitTestFlags, MsgSender<HitTestResult>),
UpdateEpoch(PipelineId, Epoch),
SetPan(DeviceIntPoint),
EnableFrameOutput(PipelineId, bool),
Scroll(ScrollLocation, WorldPoint, ScrollEventPhase),
ScrollNodeWithId(LayoutPoint, ExternalScrollId, ScrollClamping),
TickScrollingBounce,
@@ -144,7 +144,7 @@ impl WrenchThing for BinaryFrameReader {
if txn.generate_frame {
found_frame_marker = true;
}
for doc_msg in &txn.prefix_ops {
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList { .. } => {
found_frame_marker = false;
@@ -280,7 +280,7 @@ impl webrender::ApiRecordingReceiver for JsonFrameWriter {

ApiMsg::UpdateDocument(_, ref txn) => {
self.update_resources(&txn.resource_updates);
for doc_msg in &txn.prefix_ops {
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
ref epoch,
@@ -158,7 +158,7 @@ impl webrender::ApiRecordingReceiver for RonFrameWriter {
ApiMsg::UpdateResources(ref updates) => self.update_resources(updates),
ApiMsg::UpdateDocument(_, ref txn) => {
self.update_resources(&txn.resource_updates);
for doc_msg in &txn.prefix_ops {
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
ref epoch,
@@ -1126,7 +1126,7 @@ impl webrender::ApiRecordingReceiver for YamlFrameWriterReceiver {
}
ApiMsg::UpdateDocument(_, ref txn) => {
self.frame_writer.update_resources(&txn.resource_updates);
for doc_msg in &txn.prefix_ops {
for doc_msg in &txn.scene_ops {
match *doc_msg {
DocumentMsg::SetDisplayList {
ref epoch,
@@ -1154,7 +1154,7 @@ impl webrender::ApiRecordingReceiver for YamlFrameWriterReceiver {
_ => {}
}
}
for doc_msg in &txn.postfix_ops {
for doc_msg in &txn.frame_ops {
match *doc_msg {
DocumentMsg::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.