mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Speculatively evaluate paint functions during style.
This commit is contained in:
parent
b35791f86f
commit
936dd3ef63
13 changed files with 279 additions and 52 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
//! Data needed by the layout thread.
|
||||
|
||||
use fnv::FnvHashMap;
|
||||
use fnv::FnvHasher;
|
||||
use gfx::display_list::{WebRenderImageInfo, OpaqueNode};
|
||||
use gfx::font_cache_thread::FontCacheThread;
|
||||
|
@ -25,8 +24,8 @@ use std::collections::HashMap;
|
|||
use std::hash::BuildHasherDefault;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use style::context::RegisteredSpeculativePainter;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::properties::PropertyId;
|
||||
|
||||
thread_local!(static FONT_CONTEXT_KEY: RefCell<Option<FontContext>> = RefCell::new(None));
|
||||
|
||||
|
@ -73,7 +72,7 @@ pub struct LayoutContext<'a> {
|
|||
BuildHasherDefault<FnvHasher>>>>,
|
||||
|
||||
/// Paint worklets
|
||||
pub registered_painters: Arc<RwLock<FnvHashMap<Atom, RegisteredPainter>>>,
|
||||
pub registered_painters: &'a RegisteredPainters,
|
||||
|
||||
/// A list of in-progress image loads to be shared with the script thread.
|
||||
/// A None value means that this layout was not initiated by the script thread.
|
||||
|
@ -179,9 +178,11 @@ impl<'a> LayoutContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A registered paint worklet.
|
||||
pub struct RegisteredPainter {
|
||||
pub name: Atom,
|
||||
pub properties: FnvHashMap<Atom, PropertyId>,
|
||||
pub painter: Arc<Painter>,
|
||||
/// A registered painter
|
||||
pub trait RegisteredPainter: RegisteredSpeculativePainter + Painter {}
|
||||
|
||||
/// A set of registered painters
|
||||
pub trait RegisteredPainters: Sync {
|
||||
/// Look up a painter
|
||||
fn get(&self, name: &Atom) -> Option<&RegisteredPainter>;
|
||||
}
|
||||
|
|
|
@ -1181,24 +1181,18 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
.map(|argument| argument.to_css_string())
|
||||
.collect();
|
||||
|
||||
// Get the painter, and the computed values for its properties.
|
||||
// TODO: less copying.
|
||||
let (properties, painter) = match state.layout_context.registered_painters.read().get(&name) {
|
||||
Some(registered_painter) => (
|
||||
registered_painter.properties
|
||||
.iter()
|
||||
let mut draw_result = match state.layout_context.registered_painters.get(&name) {
|
||||
Some(painter) => {
|
||||
debug!("Drawing a paint image {}({},{}).", name, size_in_px.width, size_in_px.height);
|
||||
let properties = painter.properties().iter()
|
||||
.filter_map(|(name, id)| id.as_shorthand().err().map(|id| (name, id)))
|
||||
.map(|(name, id)| (name.clone(), style.computed_value_to_string(id)))
|
||||
.collect(),
|
||||
registered_painter.painter.clone()
|
||||
),
|
||||
.collect();
|
||||
painter.draw_a_paint_image(size_in_px, device_pixel_ratio, properties, arguments)
|
||||
},
|
||||
None => return debug!("Worklet {} called before registration.", name),
|
||||
};
|
||||
|
||||
// TODO: add a one-place cache to avoid drawing the paint image every time.
|
||||
// https://github.com/servo/servo/issues/17369
|
||||
debug!("Drawing a paint image {}({},{}).", name, size_in_px.width, size_in_px.height);
|
||||
let mut draw_result = painter.draw_a_paint_image(size_in_px, device_pixel_ratio, properties, arguments);
|
||||
let webrender_image = WebRenderImageInfo {
|
||||
width: draw_result.width,
|
||||
height: draw_result.height,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue