Add WebRender integration to Servo.

WebRender is an experimental GPU accelerated rendering backend for Servo.

The WebRender backend can be specified by running Servo with the -w option (otherwise the default rendering backend will be used).

WebRender has many bugs, and missing features - but it is usable to browse most websites - please report any WebRender specific rendering bugs you encounter!
This commit is contained in:
Glenn Watson 2016-02-18 07:57:31 +10:00
parent f7f0eea470
commit c0531c312f
75 changed files with 2869 additions and 888 deletions

View file

@ -24,12 +24,19 @@ use url::Url;
use util::prefs;
use util::str::LowercaseString;
use util::thread::spawn_named;
use webrender_traits;
/// A list of font templates that make up a given font family.
struct FontTemplates {
templates: Vec<FontTemplate>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct FontTemplateInfo {
pub font_template: Arc<FontTemplateData>,
pub font_key: Option<webrender_traits::FontKey>,
}
impl FontTemplates {
fn new() -> FontTemplates {
FontTemplates {
@ -73,7 +80,8 @@ impl FontTemplates {
}
}
let template = FontTemplate::new(identifier, maybe_data);
let template = FontTemplate::new(identifier,
maybe_data);
self.templates.push(template);
}
}
@ -91,7 +99,7 @@ pub enum Command {
/// Reply messages sent from the font cache thread to the FontContext caller.
#[derive(Deserialize, Serialize, Debug)]
pub enum Reply {
GetFontTemplateReply(Option<Arc<FontTemplateData>>),
GetFontTemplateReply(Option<FontTemplateInfo>),
}
/// The font cache thread itself. It maintains a list of reference counted
@ -104,6 +112,8 @@ struct FontCache {
web_families: HashMap<LowercaseString, FontTemplates>,
font_context: FontContextHandle,
resource_thread: ResourceThread,
webrender_api: Option<webrender_traits::RenderApi>,
webrender_fonts: HashMap<Atom, webrender_traits::FontKey>,
}
fn populate_generic_fonts() -> HashMap<FontFamily, LowercaseString> {
@ -285,24 +295,46 @@ impl FontCache {
}
}
fn get_font_template_info(&mut self, template: Arc<FontTemplateData>) -> FontTemplateInfo {
let webrender_fonts = &mut self.webrender_fonts;
let font_key = self.webrender_api.as_ref().map(|webrender_api| {
*webrender_fonts.entry(template.identifier.clone()).or_insert_with(|| {
match (template.bytes_if_in_memory(), template.native_font()) {
(Some(bytes), _) => webrender_api.add_raw_font(bytes),
(None, Some(native_font)) => webrender_api.add_native_font(native_font),
(None, None) => webrender_api.add_raw_font(template.bytes().clone()),
}
})
});
FontTemplateInfo {
font_template: template,
font_key: font_key,
}
}
fn find_font_template(&mut self, family: &FontFamily, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
self.find_font_in_web_family(family, desc)
-> Option<FontTemplateInfo> {
let template = self.find_font_in_web_family(family, desc)
.or_else(|| {
let transformed_family = self.transform_family(family);
self.find_font_in_local_family(&transformed_family, desc)
})
});
template.map(|template| {
self.get_font_template_info(template)
})
}
fn last_resort_font_template(&mut self, desc: &FontTemplateDescriptor)
-> Arc<FontTemplateData> {
-> FontTemplateInfo {
let last_resort = last_resort_font_families();
for family in &last_resort {
let family = LowercaseString::new(family);
let maybe_font_in_family = self.find_font_in_local_family(&family, desc);
if let Some(family) = maybe_font_in_family {
return family;
return self.get_font_template_info(family)
}
}
@ -318,7 +350,8 @@ pub struct FontCacheThread {
}
impl FontCacheThread {
pub fn new(resource_thread: ResourceThread) -> FontCacheThread {
pub fn new(resource_thread: ResourceThread,
webrender_api: Option<webrender_traits::RenderApi>) -> FontCacheThread {
let (chan, port) = ipc::channel().unwrap();
let channel_to_self = chan.clone();
@ -334,6 +367,8 @@ impl FontCacheThread {
web_families: HashMap::new(),
font_context: FontContextHandle::new(),
resource_thread: resource_thread,
webrender_api: webrender_api,
webrender_fonts: HashMap::new(),
};
cache.refresh_local_families();
@ -346,7 +381,7 @@ impl FontCacheThread {
}
pub fn find_font_template(&self, family: FontFamily, desc: FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
-> Option<FontTemplateInfo> {
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetFontTemplate(family, desc, response_chan)).unwrap();
@ -361,7 +396,7 @@ impl FontCacheThread {
}
pub fn last_resort_font_template(&self, desc: FontTemplateDescriptor)
-> Arc<FontTemplateData> {
-> FontTemplateInfo {
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetLastResortFontTemplate(desc, response_chan)).unwrap();