Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the plumbing for paint worklets #17150

Merged
merged 1 commit into from Jun 7, 2017

Conversation

asajeffrey
Copy link
Member

@asajeffrey asajeffrey commented Jun 3, 2017

This PR implements the plumbing for paint worklets:

  • Adding CSS values for paint worklets.
  • Implementing a skeleton for the PaintWorkletGlobalScope webidl.
  • Implementing an executor for paint worklet tasks, and passing it from script to layout.
  • Building the display list items for paint worklet images.

This PR does not implement registering or calling paint worklets in JS.

Before it merges, this PR needs a reftest added for basic paint worklet functionality.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes

This change is Reviewable

@asajeffrey asajeffrey added A-content/css Interacting with CSS from web content (parsing, serializing, introspection) A-content/script Related to the script thread S-needs-tests New tests have been requested by a reviewer. labels Jun 3, 2017
@highfive
Copy link

highfive commented Jun 3, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/values/specified/image.rs, components/style/values/generics/image.rs
  • @KiChjang: components/script_layout_interface/message.rs, components/script/dom/webidls/PaintWorkletGlobalScope.webidl, components/script/dom/mod.rs, components/script_traits/Cargo.toml, components/script_traits/Cargo.toml and 10 more
  • @fitzgen: components/script_layout_interface/message.rs, components/script/dom/webidls/PaintWorkletGlobalScope.webidl, components/script/dom/mod.rs, components/script_traits/Cargo.toml, components/script_traits/Cargo.toml and 7 more
  • @emilio: components/layout/display_list_builder.rs, components/style/values/specified/image.rs, components/style/values/generics/image.rs, components/layout/context.rs

@highfive
Copy link

highfive commented Jun 3, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify style, layout, net, and script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 3, 2017
@asajeffrey
Copy link
Member Author

cc @jdm @metajack @tschneidereit

@@ -98,6 +99,9 @@ impl Parse for Image {
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
return Ok(GenericImage::Gradient(gradient));
}
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're going to remove this path for Gecko, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, that sounded quite inquisitive, I meant "You're going to need to remove" :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -673,6 +677,18 @@ impl Parse for ColorStop {
}
}

impl Parse for PaintWorklet {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
input.try(|i| i.expect_function_matching("paint"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No input.try needed here, afaict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let task = WorkletTask::Paint(PaintWorkletTask::DrawAPaintImage(name, concrete_object_size, sender));
let timeout = Duration::from_millis(PAINT_TIMEOUT_MILLISECONDS);
self.schedule_a_worklet_task(task);
receiver.recv_timeout(timeout)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, glad recv_timeout was useful after all!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

}
}

pub fn draw_a_paint_image(&self,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably no need to be pub?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -371,6 +374,14 @@ impl Window {
self.webvr_thread.clone()
}

pub fn new_paint_worklet(&self) -> Root<Worklet> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for pub here either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -689,6 +695,10 @@ impl LayoutThread {
Msg::SetFinalUrl(final_url) => {
self.url = final_url;
},
Msg::SetPaintWorkletExecutor(executor) => {
debug!("Setting the paint worklet executor");
self.paint_worklet_executor = Some(executor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug_assert!(self.paint_worklet_executor.is_none())? This would need to be refactored if/when we fix #14885

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member Author

@asajeffrey asajeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review!

@@ -689,6 +695,10 @@ impl LayoutThread {
Msg::SetFinalUrl(final_url) => {
self.url = final_url;
},
Msg::SetPaintWorkletExecutor(executor) => {
debug!("Setting the paint worklet executor");
self.paint_worklet_executor = Some(executor);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}

pub fn draw_a_paint_image(&self,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -371,6 +374,14 @@ impl Window {
self.webvr_thread.clone()
}

pub fn new_paint_worklet(&self) -> Root<Worklet> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let task = WorkletTask::Paint(PaintWorkletTask::DrawAPaintImage(name, concrete_object_size, sender));
let timeout = Duration::from_millis(PAINT_TIMEOUT_MILLISECONDS);
self.schedule_a_worklet_task(task);
receiver.recv_timeout(timeout)?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

@@ -98,6 +99,9 @@ impl Parse for Image {
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
return Ok(GenericImage::Gradient(gradient));
}
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -673,6 +677,18 @@ impl Parse for ColorStop {
}
}

impl Parse for PaintWorklet {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
input.try(|i| i.expect_function_matching("paint"))?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS and display list building bits look fine to me with the nits, assuming build_display_list_for_webrender_image is just moved code.

The dom bits look harmless, but I haven't been following along enough the worklet stuff to consider myself confident enough to stamp it, so better if you get @jdm to do that.

Also, as you've already pointed out, a test would be quite nice :)

fn draw_a_paint_image(&self,
name: Atom,
concrete_object_size: Size2D<Au>,
sender: Sender<Result<Image, PaintWorkletError>>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,

@@ -561,7 +578,9 @@ impl WorkletThread {
// TODO: Caching.
// TODO: Avoid re-parsing the origin as a URL.
let resource_fetcher = self.global_init.resource_threads.sender();
let origin_url = ServoUrl::parse(&*origin.unicode_serialization()).expect("Failed to parse origin as URL.");
let origin_url = ServoUrl::parse(&*origin.unicode_serialization())
.or_else(|_| ServoUrl::parse("about:blank"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unwrap_or_else instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

impl ToCss for PaintWorklet {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str("paint(")?;
dest.write_str(&*self.name)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to use serialize_identifier to handle escaping properly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member Author

@asajeffrey asajeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

fn draw_a_paint_image(&self,
name: Atom,
concrete_object_size: Size2D<Au>,
sender: Sender<Result<Image, PaintWorkletError>>)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,

@@ -561,7 +578,9 @@ impl WorkletThread {
// TODO: Caching.
// TODO: Avoid re-parsing the origin as a URL.
let resource_fetcher = self.global_init.resource_threads.sender();
let origin_url = ServoUrl::parse(&*origin.unicode_serialization()).expect("Failed to parse origin as URL.");
let origin_url = ServoUrl::parse(&*origin.unicode_serialization())
.or_else(|_| ServoUrl::parse("about:blank"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

impl ToCss for PaintWorklet {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str("paint(")?;
dest.write_str(&*self.name)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@asajeffrey
Copy link
Member Author

r? @jdm do you want to have a look at the script/worklet side of things?

@highfive highfive assigned jdm and unassigned emilio Jun 3, 2017
asajeffrey pushed a commit to asajeffrey/servo that referenced this pull request Jun 5, 2017
pub struct PaintWorkletGlobalScope {
// The worklet global for this object
worklet_global: WorkletGlobalScope,
// A buffer to draw into
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these ///?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

debug!("Creating paint worklet global scope for pipeline {}.", pipeline_id);
let global = box PaintWorkletGlobalScope {
worklet_global: WorkletGlobalScope::new_inherited(pipeline_id, base_url, init),
buffer: DOMRefCell::new(Vec::new()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default::default()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

name: Atom,
concrete_object_size: Size2D<Au>,
sender: Sender<Result<Image, PaintWorkletError>>)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: { on the previous line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, though I prefer the brace-on-its-own-line style when the fn defn ended up being multi-line.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 5, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jun 6, 2017
Copy link
Member Author

@asajeffrey asajeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes.

pub struct PaintWorkletGlobalScope {
// The worklet global for this object
worklet_global: WorkletGlobalScope,
// A buffer to draw into
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

debug!("Creating paint worklet global scope for pipeline {}.", pipeline_id);
let global = box PaintWorkletGlobalScope {
worklet_global: WorkletGlobalScope::new_inherited(pipeline_id, base_url, init),
buffer: DOMRefCell::new(Vec::new()),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

name: Atom,
concrete_object_size: Size2D<Au>,
sender: Sender<Result<Image, PaintWorkletError>>)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, though I prefer the brace-on-its-own-line style when the fn defn ended up being multi-line.

@jdm jdm added S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 6, 2017
@jdm
Copy link
Member

jdm commented Jun 6, 2017

Looks good. Just needs squashing and a test.

@jdm
Copy link
Member

jdm commented Jun 6, 2017

And this:

cargo build -v

error: failed to parse lock file at: /home/travis/build/servo/servo/Cargo.lock

Caused by:

  package `app_units 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)` is specified as a dependency, but is missing from the package list

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 7, 2017
@asajeffrey asajeffrey force-pushed the script-paint-worklets-plumbing branch from bc84493 to e8db3ea Compare June 7, 2017 18:35
@asajeffrey asajeffrey force-pushed the script-paint-worklets-plumbing branch from 2e133b0 to fd17dcd Compare June 7, 2017 18:49
@asajeffrey
Copy link
Member Author

@bors-servo r=jdm

@bors-servo
Copy link
Contributor

📌 Commit fd17dcd has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-squash Some (or all) of the commits in the PR should be combined. labels Jun 7, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit fd17dcd with merge bf46da0...

bors-servo pushed a commit that referenced this pull request Jun 7, 2017
Implemented the plumbing for paint worklets

<!-- Please describe your changes on the following line: -->

This PR implements the plumbing for paint worklets:

* Adding CSS values for paint worklets.
* Implementing a skeleton for the `PaintWorkletGlobalScope` webidl.
* Implementing an executor for paint worklet tasks, and passing it from script to layout.
* Building the display list items for paint worklet images.

This PR does not implement registering or calling paint worklets in JS.

Before it merges, this PR needs a reftest added for basic paint worklet functionality.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17150)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing bf46da0 to master...

@bors-servo bors-servo merged commit fd17dcd into servo:master Jun 7, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/css Interacting with CSS from web content (parsing, serializing, introspection) A-content/script Related to the script thread S-needs-tests New tests have been requested by a reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants