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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1,3 +1,4 @@
.cargo/
Cargo.lock
target/

@@ -12,6 +12,7 @@ serde_macros = ["webrender_traits/serde_macros"]
[dependencies]
app_units = "0.3"
bit-set = "0.4"
bincode = "0.5.9"
byteorder = "0.5"
euclid = "0.9"
fnv="1.0"
@@ -21,7 +22,6 @@ lazy_static = "0.2"
log = "0.3"
num-traits = "0.1.32"
offscreen_gl_context = {version = "0.3", features = ["serde_serialization"]}
rayon = "0.4.0"
time = "0.1"
webrender_traits = {path = "../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;
@@ -95,6 +96,7 @@ extern crate core_text;
extern crate freetype;

extern crate app_units;
extern crate bincode;
extern crate euclid;
extern crate fnv;
extern crate gleam;
@@ -0,0 +1,34 @@
use bincode;
use byteorder::{LittleEndian, WriteBytesExt};
use std::fs::OpenOptions;
use std::io::Write;
use webrender_traits::ApiMsg;

pub fn write_data(frame_counter:u32, auxiliary_data: &Vec<u8>){
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();
}


pub 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 = bincode::serde::serialize(msg, bincode::SizeLimit::Infinite).unwrap();
file.write_u32::<LittleEndian>(buff.len() as u32).unwrap();
file.write(&buff).unwrap();
}
_ => {}
}
}
@@ -10,6 +10,7 @@ use profiler::BackendProfileCounters;
use resource_cache::ResourceCache;
use scene::Scene;
use std::collections::HashMap;
use std::fs;
use std::io::{Cursor, Read};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
@@ -18,10 +19,12 @@ 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,
@@ -40,6 +43,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 {
@@ -53,7 +58,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 resource_cache = ResourceCache::new(texture_cache,
device_pixel_ratio,
enable_aa);
@@ -72,24 +78,31 @@ impl RenderBackend {
webrender_context_handle: webrender_context_handle,
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 {
let msg = self.api_rx.recv();
match msg {
Ok(msg) => {
match msg {
ApiMsg::AddRawFont(id, bytes) => {
profile_counters.font_templates.inc(bytes.len());
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
self.resource_cache
.add_font_template(id, FontTemplate::Native(native_font_handle));
}
ApiMsg::AddImage(id, width, height, format, bytes) => {
@@ -125,7 +138,7 @@ impl RenderBackend {
viewport_size,
stacking_contexts,
display_lists,
auxiliary_lists_descriptor) => {
auxiliary_lists_descriptor) => {
for (id, stacking_context) in stacking_contexts.into_iter() {
self.scene.add_stacking_context(id,
pipeline_id,
@@ -150,10 +163,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()
}

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() {
@@ -184,16 +200,15 @@ impl RenderBackend {
background_color,
viewport_size,
&mut self.resource_cache,
auxiliary_lists);

auxiliary_lists);
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(|| {
self.scene.set_root_pipeline_id(pipeline_id);

self.build_scene();
@@ -408,3 +423,4 @@ impl RenderBackend {
}
}


@@ -467,6 +467,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;
thread::spawn(move || {
let mut backend = RenderBackend::new(api_rx,
payload_rx,
@@ -478,7 +479,8 @@ impl Renderer {
backend_notifier,
context_handle,
config,
debug);
debug,
enable_recording);
backend.run();
});

@@ -1606,4 +1608,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.