Skip to content

Commit

Permalink
Recording support for loaded captures
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 10, 2018
1 parent f3bc809 commit 34e765b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
1 change: 0 additions & 1 deletion examples/common/boilerplate.rs
Expand Up @@ -243,7 +243,6 @@ pub fn main_wrapper<E: Example>(
2.0
),
winit::VirtualKeyCode::M => api.notify_memory_pressure(),
#[cfg(feature = "capture")]
winit::VirtualKeyCode::C => {
let path: PathBuf = "../captures/example".into();
//TODO: switch between SCENE/FRAME capture types
Expand Down
24 changes: 24 additions & 0 deletions webrender/src/render_backend.rs
Expand Up @@ -783,7 +783,31 @@ impl RenderBackend {
window_size: doc.view.window_size,
};
tx.send(captured).unwrap();

// notify the active recorder
if let Some(ref mut r) = self.recorder {
let pipeline_id = doc.scene.root_pipeline_id.unwrap();
let epoch = doc.scene.pipeline_epochs[&pipeline_id];
let pipeline = &doc.scene.pipelines[&pipeline_id];
let scene_msg = SceneMsg::SetDisplayList {
list_descriptor: pipeline.display_list.descriptor().clone(),
epoch,
pipeline_id,
background: pipeline.background_color,
viewport_size: pipeline.viewport_size,
content_size: pipeline.content_size,
preserve_frame_state: false,
};
let txn = TransactionMsg::scene_message(scene_msg);
r.write_msg(*frame_counter, &ApiMsg::UpdateDocument(*id, txn));
r.write_payload(*frame_counter, &Payload::construct_data(
epoch,
pipeline_id,
pipeline.display_list.data(),
));
}
}

// Note: we can't pass `LoadCapture` here since it needs to arrive
// before the `PublishDocument` messages sent by `load_capture`.
return true;
Expand Down
4 changes: 2 additions & 2 deletions webrender_api/src/api.rs
Expand Up @@ -382,7 +382,7 @@ impl TransactionMsg {
}

// TODO: We only need this for a few RenderApi methods which we should remove.
fn frame_message(msg: FrameMsg) -> Self {
pub fn frame_message(msg: FrameMsg) -> Self {
TransactionMsg {
scene_ops: Vec::new(),
frame_ops: vec![msg],
Expand All @@ -393,7 +393,7 @@ impl TransactionMsg {
}
}

fn scene_message(msg: SceneMsg) -> Self {
pub fn scene_message(msg: SceneMsg) -> Self {
TransactionMsg {
scene_ops: vec![msg],
frame_ops: Vec::new(),
Expand Down
27 changes: 16 additions & 11 deletions webrender_api/src/channel.rs
Expand Up @@ -24,22 +24,27 @@ pub struct Payload {
impl Payload {
/// Convert the payload to a raw byte vector, in order for it to be
/// efficiently shared via shmem, for example.
///
/// TODO(emilio, #1049): Consider moving the IPC boundary to the
/// constellation in Servo and remove this complexity from WR.
pub fn to_data(&self) -> Vec<u8> {
/// This is a helper static method working on a slice.
pub fn construct_data(epoch: Epoch, pipeline_id: PipelineId, dl_data: &[u8]) -> Vec<u8> {
let mut data = Vec::with_capacity(
mem::size_of::<u32>() + 2 * mem::size_of::<u32>() + mem::size_of::<u64>() +
self.display_list_data.len(),
mem::size_of::<u32>() + 2 * mem::size_of::<u32>() + mem::size_of::<u64>() + dl_data.len(),
);
data.write_u32::<LittleEndian>(self.epoch.0).unwrap();
data.write_u32::<LittleEndian>(self.pipeline_id.0).unwrap();
data.write_u32::<LittleEndian>(self.pipeline_id.1).unwrap();
data.write_u64::<LittleEndian>(self.display_list_data.len() as u64)
data.write_u32::<LittleEndian>(epoch.0).unwrap();
data.write_u32::<LittleEndian>(pipeline_id.0).unwrap();
data.write_u32::<LittleEndian>(pipeline_id.1).unwrap();
data.write_u64::<LittleEndian>(dl_data.len() as u64)
.unwrap();
data.extend_from_slice(&self.display_list_data);
data.extend_from_slice(dl_data);
data
}
/// Convert the payload to a raw byte vector, in order for it to be
/// efficiently shared via shmem, for example.
///
/// TODO(emilio, #1049): Consider moving the IPC boundary to the
/// constellation in Servo and remove this complexity from WR.
pub fn to_data(&self) -> Vec<u8> {
Self::construct_data(self.epoch, self.pipeline_id, &self.display_list_data)
}

/// Deserializes the given payload from a raw byte vector.
pub fn from_data(data: &[u8]) -> Payload {
Expand Down

0 comments on commit 34e765b

Please sign in to comment.