gfx: Make display lists serializable using serde.

This commit introduces the `serde` dependency, which we will use to
serialize messages going between processes in multiprocess Servo.

This also adds a new debugging flag, `-Z print-display-list-json`,
allowing the output of display list serialization to be visualized.
This will be useful for our experiments with alternate rasterizers.
This commit is contained in:
Patrick Walton 2015-07-08 16:15:23 -07:00
parent b6b95085fb
commit 6eacb0c995
30 changed files with 320 additions and 124 deletions

View file

@ -9,7 +9,7 @@ use std::ascii::AsciiExt;
macro_rules! define_cursor {
($( $css: expr => $variant: ident = $value: expr, )+) => {
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Serialize)]
#[repr(u8)]
pub enum Cursor {
$( $variant = $value ),+

View file

@ -4,8 +4,81 @@
//! Utility functions for doubly-linked lists.
use mem::HeapSizeOf;
use serde::de::{Error, SeqVisitor, Visitor};
use serde::ser::impls::SeqIteratorVisitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::LinkedList;
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
pub struct SerializableLinkedList<T>(LinkedList<T>);
impl<T> SerializableLinkedList<T> {
pub fn new(linked_list: LinkedList<T>) -> SerializableLinkedList<T> {
SerializableLinkedList(linked_list)
}
}
impl<T> Deref for SerializableLinkedList<T> {
type Target = LinkedList<T>;
fn deref(&self) -> &LinkedList<T> {
&self.0
}
}
impl<T> DerefMut for SerializableLinkedList<T> {
fn deref_mut(&mut self) -> &mut LinkedList<T> {
&mut self.0
}
}
impl<T: HeapSizeOf> HeapSizeOf for SerializableLinkedList<T> {
fn heap_size_of_children(&self) -> usize {
self.0.heap_size_of_children()
}
}
impl<T> Serialize for SerializableLinkedList<T> where T: Serialize {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
serializer.visit_seq(SeqIteratorVisitor::new(self.0.iter(), Some(self.0.len())))
}
}
impl<T> Deserialize for SerializableLinkedList<T> where T: Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<SerializableLinkedList<T>, D::Error>
where D: Deserializer {
struct SerializableLinkedListVisitor<T> {
marker: PhantomData<T>,
}
impl<T> Visitor for SerializableLinkedListVisitor<T> where T: Deserialize {
type Value = SerializableLinkedList<T>;
#[inline]
fn visit_seq<V>(&mut self, mut visitor: V)
-> Result<SerializableLinkedList<T>, V::Error>
where V: SeqVisitor {
let mut list = LinkedList::new();
for _ in 0..visitor.size_hint().0 {
match try!(visitor.visit()) {
Some(element) => list.push_back(element),
None => return Err(Error::end_of_stream_error()),
}
}
try!(visitor.end());
Ok(SerializableLinkedList(list))
}
}
deserializer.visit_seq(SerializableLinkedListVisitor {
marker: PhantomData,
})
}
}
/// Splits the head off a list in O(1) time, and returns the head.
pub fn split_off_head<T>(list: &mut LinkedList<T>) -> LinkedList<T> {

View file

@ -140,6 +140,9 @@ pub struct Opts {
/// Dumps the display list after a layout.
pub dump_display_list: bool,
/// Dumps the display list in JSON form after a layout.
pub dump_display_list_json: bool,
/// Dumps the display list after optimization (post layout, at painting time).
pub dump_display_list_optimized: bool,
@ -178,6 +181,7 @@ pub fn print_debug_usage(app: &str) -> ! {
print_option("disable-text-aa", "Disable antialiasing of rendered text.");
print_option("dump-flow-tree", "Print the flow tree after each layout.");
print_option("dump-display-list", "Print the display list after each layout.");
print_option("dump-display-list-json", "Print the display list in JSON form.");
print_option("dump-display-list-optimized", "Print optimized display list (at paint time).");
print_option("relayout-event", "Print notifications when there is a relayout.");
print_option("profile-tasks", "Instrument each task, writing the output to a file.");
@ -248,6 +252,7 @@ pub fn default_opts() -> Opts {
user_agent: None,
dump_flow_tree: false,
dump_display_list: false,
dump_display_list_json: false,
dump_display_list_optimized: false,
relayout_event: false,
validate_display_list_geometry: false,
@ -424,6 +429,7 @@ pub fn from_cmdline_args(args: &[String]) {
enable_canvas_antialiasing: !debug_options.contains(&"disable-canvas-aa"),
dump_flow_tree: debug_options.contains(&"dump-flow-tree"),
dump_display_list: debug_options.contains(&"dump-display-list"),
dump_display_list_json: debug_options.contains(&"dump-display-list-json"),
dump_display_list_optimized: debug_options.contains(&"dump-display-list-optimized"),
relayout_event: debug_options.contains(&"relayout-event"),
validate_display_list_geometry: debug_options.contains(&"validate-display-list-geometry"),

View file

@ -124,7 +124,7 @@ macro_rules! int_range_index {
}
/// A range of indices
#[derive(Clone, RustcEncodable, Copy)]
#[derive(Clone, RustcEncodable, Copy, Deserialize, Serialize)]
pub struct Range<I> {
begin: I,
length: I,