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

Add serialization branch to record display lists #316

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

move record code into separate file

  • Loading branch information
lanamorgan committed Aug 18, 2016
commit 1fbba17b0586cc3ad4f9c0f7a01ec3cdb77a296e
@@ -21,6 +21,7 @@ log = "0.3"
#notify = {git = "https://github.com/glennw/rsnotify.git", branch = "inotify-modify"}
num-traits = "0.1.32"
offscreen_gl_context = {version = "0.1.9", features = ["serde_serialization"]}
rayon = "0.4.0"
scoped_threadpool = "0.1.6"
time = "0.1"
webrender_traits = {git = "https://github.com/servo/webrender_traits", default-features = false}
@@ -59,6 +59,7 @@ mod geometry;
mod internal_types;
mod layer;
mod profiler;
mod record;
mod render_backend;
mod resource_cache;
mod resource_list;
@@ -2,9 +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 bincode;
use bincode::serde::serialize;
use byteorder::{LittleEndian, WriteBytesExt, ReadBytesExt};
use byteorder::{LittleEndian, ReadBytesExt};
use frame::Frame;
use internal_types::{FontTemplate, ResultMsg, RendererFrame};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcReceiver};
@@ -13,19 +11,21 @@ use resource_cache::ResourceCache;
use scene::Scene;
use scoped_threadpool;
use std::collections::HashMap;
use std::fs::{self, File, OpenOptions};
use std::io::{Cursor, Read, Write};
use std::fs;
use std::io::{Cursor, Read};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use texture_cache::TextureCache;
use webrender_traits::{ApiMsg, AuxiliaryLists, BuiltDisplayList, IdNamespace};
use webrender_traits::{PipelineId, RenderNotifier, WebGLContextId};
use batch::new_id;
use device::TextureId;
use record;
use tiling::FrameBuilderConfig;
use offscreen_gl_context::{ColorAttachmentType, GLContext};
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle};


pub struct RenderBackend {
api_rx: IpcReceiver<ApiMsg>,
payload_rx: IpcBytesReceiver,
@@ -85,30 +85,30 @@ impl RenderBackend {
webgl_contexts: HashMap::new(),
current_bound_webgl_context_id: None,
enable_recording: enable_recording,
}
}
}

pub fn run(&mut self) {
let mut profile_counters = BackendProfileCounters::new();
let mut frame_counter:u32 = 0;
if self.enable_recording{
fs::create_dir("record").ok();
}
loop {
if self.enable_recording{
fs::create_dir("record").ok();
}
loop {
let msg = self.api_rx.recv();
match msg {

This comment has been minimized.

@emilio

emilio Jul 28, 2016

Member

I think it might be clearer if you did something like this above this line:

if self.enable_recording {
    let mut file = OpenOptions::new().append(true).create(true).open("resources.bin").unwrap();
    let buff = serialize(&msg, bincode::SizeLimit::Infinite).unwrap();
    write_msg(&mut file, &buff);
}

That should remove a lot of code duplication. Also, I'd consider opening the file just once above the loop, and not using unwrap() so heavily, but handling the error. That being said, given it's behind an option, maybe it's not such a big deal :)

Ok(msg) => {
if self.enable_recording{
write_msg(frame_counter, &msg);
}
match msg {
ApiMsg::AddRawFont(id, bytes) => {
if self.enable_recording{
record::write_msg(frame_counter, &msg);
}
match msg {
ApiMsg::AddRawFont(id, bytes) => {
profile_counters.font_templates.inc(bytes.len());
self.resource_cache
.add_font_template(id, FontTemplate::Raw(Arc::new(bytes)));
}
ApiMsg::AddNativeFont(id, native_font_handle) => {
self.resource_cache
ApiMsg::AddNativeFont(id, native_font_handle) => {
self.resource_cache
.add_font_template(id, FontTemplate::Native(native_font_handle));
}
ApiMsg::AddImage(id, width, height, format, bytes) => {
@@ -169,17 +169,13 @@ impl RenderBackend {
}
leftover_auxiliary_data.push(auxiliary_data)
}
for leftover_auxiliary_data in leftover_auxiliary_data {
self.payload_tx.send(&leftover_auxiliary_data[..]).unwrap()
}

if self.enable_recording{
let filename = format!("record/frame_{}.bin", frame_counter);
let mut file = OpenOptions::new().append(true).open(filename).unwrap();
file.write_u32::<LittleEndian>(auxiliary_data.len() as u32).ok();
file.write(&auxiliary_data).ok();
frame_counter += 1;
}
for leftover_auxiliary_data in leftover_auxiliary_data {
self.payload_tx.send(&leftover_auxiliary_data[..]).unwrap()
}
if self.enable_recording{
record::write_data(frame_counter, &auxiliary_data);
frame_counter += 1;
}
let mut auxiliary_data = Cursor::new(&mut auxiliary_data[8..]);
for (display_list_id,
display_list_descriptor) in display_lists.into_iter() {
@@ -210,8 +206,7 @@ impl RenderBackend {
background_color,
viewport_size,
&mut self.resource_cache,
auxiliary_lists);

auxiliary_lists);
self.build_scene();
self.render()
});
@@ -437,23 +432,4 @@ impl RenderBackend {
}
}

fn write_msg(frame: u32, msg: &ApiMsg){
match msg{
ref msg @ &ApiMsg::AddRawFont(..) |
ref msg @ &ApiMsg::AddNativeFont(..) |
ref msg @ &ApiMsg::AddImage(..) |
ref msg @ &ApiMsg::SetRootPipeline(..) |
ref msg @ &ApiMsg::UpdateImage(..) |
ref msg @ &ApiMsg::Scroll(..)|
ref msg @ &ApiMsg::TickScrollingBounce|
ref msg @ &ApiMsg::DeleteImage(..)|
ref msg @ &ApiMsg::SetRootStackingContext(..) =>{
let filename = format!("record/frame_{}.bin", frame);
let mut file = OpenOptions::new().append(true).create(true).open(filename).unwrap();
let buff = serialize(msg, bincode::SizeLimit::Infinite).unwrap();
file.write_u32::<LittleEndian>(buff.len() as u32).unwrap();
file.write(&buff).unwrap();
}
_ => {}
}
}

@@ -444,7 +444,7 @@ impl Renderer {
let debug = options.debug;
let (device_pixel_ratio, enable_aa) = (options.device_pixel_ratio, options.enable_aa);
let payload_tx_for_backend = payload_tx.clone();
let enable_recording = options.enable_recording;
let enable_recording = options.enable_recording;
thread::spawn(move || {
let mut backend = RenderBackend::new(api_rx,
payload_rx,
@@ -457,7 +457,7 @@ impl Renderer {
context_handle,
config,
debug,
enable_recording);
enable_recording);
backend.run();
});

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.