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

Next

record display lists for one session

  • Loading branch information
lanamorgan committed Aug 5, 2016
commit b09946a53ea6004a784388592f0908c02d8927b7
@@ -1,3 +1,4 @@
.cargo/
Cargo.lock
target/

@@ -10,6 +10,7 @@ serde_macros = ["webrender_traits/serde_macros"]
[dependencies]
app_units = "0.2.5"
bit-set = "0.4"
bincode = "0.5.9"

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

@nox Is introducing this dependency likely to cause us any problems with WR + CI issues?

This comment has been minimized.

@nox

nox Aug 9, 2016

Member

Could the actual serialising live in webrender_traits instead?

This comment has been minimized.

@nox

nox Aug 9, 2016

Member

I think we should reexport serde and bincode from WR_traits instead.

This comment has been minimized.

@lanamorgan

lanamorgan Aug 9, 2016

Author Contributor

@nox I don't see why it couldn't although I thought wr-traits was being moved into webrender soon?

This comment has been minimized.

@nox

nox Aug 9, 2016

Member

Yeah I guess it's fine for now.

byteorder = "0.5"
euclid = "0.7.1"
fnv="1.0"
@@ -95,6 +95,7 @@ extern crate core_text;
extern crate freetype;

extern crate app_units;
extern crate bincode;
extern crate euclid;
extern crate fnv;
extern crate gleam;
@@ -2,7 +2,9 @@
* 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 byteorder::{LittleEndian, ReadBytesExt};
use bincode;
use bincode::serde::serialize;
use byteorder::{LittleEndian, WriteBytesExt, ReadBytesExt};
use frame::Frame;
use internal_types::{FontTemplate, ResultMsg, RendererFrame};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcReceiver};
@@ -11,7 +13,8 @@ use resource_cache::ResourceCache;
use scene::Scene;
use scoped_threadpool;
use std::collections::HashMap;
use std::io::{Cursor, Read};
use std::fs::{self, File, OpenOptions};
use std::io::{Cursor, Read, Write};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use texture_cache::TextureCache;
@@ -42,6 +45,8 @@ pub struct RenderBackend {
webrender_context_handle: Option<NativeGLContextHandle>,
webgl_contexts: HashMap<WebGLContextId, GLContext<NativeGLContext>>,
current_bound_webgl_context_id: Option<WebGLContextId>,

enable_recording: bool,
}

impl RenderBackend {
@@ -55,7 +60,8 @@ impl RenderBackend {
notifier: Arc<Mutex<Option<Box<RenderNotifier>>>>,
webrender_context_handle: Option<NativeGLContextHandle>,
config: FrameBuilderConfig,
debug: bool) -> RenderBackend {
debug: bool,
enable_recording: bool) -> RenderBackend {
let mut thread_pool = scoped_threadpool::Pool::new(8);

let resource_cache = ResourceCache::new(&mut thread_pool,
@@ -78,24 +84,31 @@ impl RenderBackend {
webrender_context_handle: webrender_context_handle,
webgl_contexts: HashMap::new(),
current_bound_webgl_context_id: None,
}
enable_recording: enable_recording,
}

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

}

pub fn run(&mut self) {
let mut profile_counters = BackendProfileCounters::new();

loop {
let mut frame_counter:u32 = 0;
if self.enable_recording{

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

fs::create_dir("record").ok();
}
loop {
let msg = self.api_rx.recv();

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

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) => {
match msg {
ApiMsg::AddRawFont(id, bytes) => {
profile_counters.font_templates.inc(bytes.len());
if self.enable_recording{
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) => {
@@ -131,7 +144,7 @@ impl RenderBackend {
viewport_size,
stacking_contexts,
display_lists,
auxiliary_lists_descriptor) => {
auxiliary_lists_descriptor) => {

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

for (id, stacking_context) in stacking_contexts.into_iter() {
self.scene.add_stacking_context(id,
pipeline_id,
@@ -160,6 +173,13 @@ impl RenderBackend {
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;
}
let mut auxiliary_data = Cursor::new(&mut auxiliary_data[8..]);
for (display_list_id,
display_list_descriptor) in display_lists.into_iter() {
@@ -191,15 +211,15 @@ impl RenderBackend {
viewport_size,
&mut self.resource_cache,
auxiliary_lists);

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

self.build_scene();
self.render()
});

self.publish_frame_and_notify_compositor(frame, &mut profile_counters);
}
ApiMsg::SetRootPipeline(pipeline_id) => {
let frame = profile_counters.total_time.profile(|| {
ApiMsg::SetRootPipeline(pipeline_id) => {
let frame = profile_counters.total_time.profile(|| {

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

self.scene.set_root_pipeline_id(pipeline_id);

self.build_scene();
@@ -417,3 +437,23 @@ 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,6 +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;

This comment has been minimized.

@glennw

glennw Aug 8, 2016

Member

nit: indentation / spaces / tabs

thread::spawn(move || {
let mut backend = RenderBackend::new(api_rx,
payload_rx,
@@ -455,7 +456,8 @@ impl Renderer {
backend_notifier,
context_handle,
config,
debug);
debug,
enable_recording);
backend.run();
});

@@ -1663,4 +1665,5 @@ pub struct RendererOptions {
pub enable_msaa: bool,
pub enable_profiler: bool,
pub debug: bool,
pub enable_recording: bool,
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.