diff options
Diffstat (limited to 'components/layout')
-rw-r--r-- | components/layout/Cargo.toml | 1 | ||||
-rw-r--r-- | components/layout/context.rs | 16 | ||||
-rw-r--r-- | components/layout/display_list_builder.rs | 17 | ||||
-rw-r--r-- | components/layout/lib.rs | 1 |
4 files changed, 27 insertions, 8 deletions
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index e3e2c76c2f4..16f82f2236f 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -34,6 +34,7 @@ script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} selectors = { path = "../selectors" } serde = "1.0" +servo_atoms = {path = "../atoms"} servo_geometry = {path = "../geometry"} serde_json = "1.0" servo_config = {path = "../config"} diff --git a/components/layout/context.rs b/components/layout/context.rs index d261fe5d8a7..cda3811421a 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -4,6 +4,7 @@ //! Data needed by the layout thread. +use fnv::FnvHashMap; use fnv::FnvHasher; use gfx::display_list::{WebRenderImageInfo, OpaqueNode}; use gfx::font_cache_thread::FontCacheThread; @@ -15,8 +16,9 @@ use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder}; use opaque_node::OpaqueNodeMethods; use parking_lot::RwLock; use script_layout_interface::{PendingImage, PendingImageState}; -use script_traits::PaintWorkletExecutor; +use script_traits::Painter; use script_traits::UntrustedNodeAddress; +use servo_atoms::Atom; use servo_url::ServoUrl; use std::cell::{RefCell, RefMut}; use std::collections::HashMap; @@ -24,6 +26,7 @@ use std::hash::BuildHasherDefault; use std::sync::{Arc, Mutex}; use std::thread; use style::context::SharedStyleContext; +use style::properties::PropertyId; thread_local!(static FONT_CONTEXT_KEY: RefCell<Option<FontContext>> = RefCell::new(None)); @@ -69,8 +72,8 @@ pub struct LayoutContext<'a> { WebRenderImageInfo, BuildHasherDefault<FnvHasher>>>>, - /// The executor for worklets - pub paint_worklet_executor: Option<Arc<PaintWorkletExecutor>>, + /// Paint worklets + pub registered_painters: Arc<RwLock<FnvHashMap<Atom, RegisteredPainter>>>, /// 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. @@ -175,3 +178,10 @@ impl<'a> LayoutContext<'a> { } } } + +/// A registered paint worklet. +pub struct RegisteredPainter { + pub name: Atom, + pub properties: FnvHashMap<Atom, PropertyId>, + pub painter: Arc<Painter>, +} diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 9aa9301eef8..32439819d9b 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -1165,17 +1165,24 @@ impl FragmentDisplayListBuilding for Fragment { let size = unbordered_box.size.to_physical(style.writing_mode); let name = paint_worklet.name.clone(); - // If the script thread has not added any paint worklet modules, there is nothing to do! - let executor = match state.layout_context.paint_worklet_executor { - Some(ref executor) => executor, - None => return debug!("Worklet {} called before any paint modules are added.", name), + // Get the painter, and the computed values for its properties. + let (properties, painter) = match state.layout_context.registered_painters.read().get(&name) { + Some(registered_painter) => ( + registered_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() + ), + 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.width.to_px(), size.height.to_px()); let (sender, receiver) = ipc::channel().unwrap(); - executor.draw_a_paint_image(name, size, sender); + painter.draw_a_paint_image(size, properties, sender); // TODO: timeout let webrender_image = match receiver.recv() { diff --git a/components/layout/lib.rs b/components/layout/lib.rs index af108249c42..f7ed79be750 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -37,6 +37,7 @@ extern crate script_layout_interface; extern crate script_traits; #[macro_use] extern crate serde; extern crate serde_json; +extern crate servo_atoms; extern crate servo_config; extern crate servo_geometry; extern crate servo_url; |