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

@ -10,6 +10,7 @@ use string_cache::Atom;
/// The identifier is an absolute path, and the bytes
/// field is the loaded data that can be passed to
/// freetype and azure directly.
#[derive(Deserialize, Serialize)]
pub struct FontTemplateData {
pub bytes: Vec<u8>,
pub identifier: Atom,

View file

@ -64,7 +64,7 @@ impl FontHandleMethods for FontHandle {
Some(s) => s.to_f64_px(),
None => 0.0
};
match template.ctfont {
match *template.ctfont {
Some(ref ctfont) => {
Ok(FontHandle {
font_data: template.clone(),

View file

@ -7,14 +7,27 @@ use core_graphics::font::CGFont;
use core_text::font::CTFont;
use core_text;
use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::ToOwned;
use std::ops::Deref;
use string_cache::Atom;
/// Platform specific font representation for mac.
/// The identifier is a PostScript font name. The
/// CTFont object is cached here for use by the
/// paint functions that create CGFont references.
#[derive(Deserialize, Serialize)]
pub struct FontTemplateData {
pub ctfont: Option<CTFont>,
/// The `CTFont` object, if present. This is cached here so that we don't have to keep creating
/// `CTFont` instances over and over. It can always be recreated from the `identifier` and/or
/// `font_data` fields.
///
/// When sending a `FontTemplateData` instance across processes, this will be set to `None` on
/// the other side, because `CTFont` instances cannot be sent across processes. This is
/// harmless, however, because it can always be recreated.
pub ctfont: CachedCTFont,
pub identifier: Atom,
pub font_data: Option<Vec<u8>>
}
@ -39,9 +52,43 @@ impl FontTemplateData {
};
FontTemplateData {
ctfont: ctfont,
ctfont: CachedCTFont(ctfont),
identifier: identifier.to_owned(),
font_data: font_data
}
}
}
pub struct CachedCTFont(Option<CTFont>);
impl Deref for CachedCTFont {
type Target = Option<CTFont>;
fn deref(&self) -> &Option<CTFont> {
&self.0
}
}
impl Serialize for CachedCTFont {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
serializer.visit_none()
}
}
impl Deserialize for CachedCTFont {
fn deserialize<D>(deserializer: &mut D) -> Result<CachedCTFont, D::Error>
where D: Deserializer {
struct NoneOptionVisitor;
impl Visitor for NoneOptionVisitor {
type Value = CachedCTFont;
#[inline]
fn visit_none<E>(&mut self) -> Result<CachedCTFont,E> where E: Error {
Ok(CachedCTFont(None))
}
}
deserializer.visit_option(NoneOptionVisitor)
}
}