Implemented paint worklet properties.

This commit is contained in:
Alan Jeffrey 2017-06-14 18:14:54 -05:00
parent de331c6bc8
commit ef033b8362
29 changed files with 353 additions and 118 deletions

View file

@ -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"}

View file

@ -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>,
}

View file

@ -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() {

View file

@ -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;