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 paint worklets invoking worklet scripts. #17239

Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implemented paint worklets invoking worklet scripts.

  • Loading branch information
asajeffrey committed Jun 29, 2017
commit 3db4761767e96d85bf9ebef6c6f7fad6e47f8ef9
@@ -1172,6 +1172,7 @@ impl FragmentDisplayListBuilding for Fragment {
};

// 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 mut image = match executor.draw_a_paint_image(name, size) {
Ok(image) => image,
@@ -32,6 +32,7 @@
//! | sequences | `Vec<T>` |
//! | union types | `T` |

use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::num::Finite;
@@ -48,15 +49,15 @@ use js::glue::{GetProxyPrivate, IsWrapper};
use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext, JSObject, JSString};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending};
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue};
use js::jsval::{ObjectValue, StringValue};
use js::jsval::{ObjectValue, StringValue, UndefinedValue};
use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value};
use libc;
use num_traits::Float;
use servo_config::opts;
use std::{char, ptr, slice};
use std::{char, ffi, ptr, slice};

/// A trait to check whether a given `JSObject` implements an IDL interface.
pub trait IDLInterface {
@@ -481,3 +482,45 @@ pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool {
assert!(JS_IsArrayObject(cx, value, &mut result));
result
}

/// Get a property from a JS object.
pub unsafe fn get_property_jsval(cx: *mut JSContext,
object: HandleObject,
name: &str,
rval: MutableHandleValue)
-> Fallible<()>
{
rval.set(UndefinedValue());
let cname = match ffi::CString::new(name) {
Ok(cname) => cname,
Err(_) => return Ok(()),
};
JS_GetProperty(cx, object, cname.as_ptr(), rval);
if JS_IsExceptionPending(cx) {
return Err(Error::JSFailed);
}
Ok(())
}

/// Get a property from a JS object, and convert it to a Rust value.
pub unsafe fn get_property<T>(cx: *mut JSContext,
object: HandleObject,
name: &str,
option: T::Config)
-> Fallible<Option<T>> where
T: FromJSValConvertible
{
debug!("Getting property {}.", name);
rooted!(in(cx) let mut result = UndefinedValue());
get_property_jsval(cx, object, name, result.handle_mut())?;
if result.is_undefined() {
debug!("No property {}.", name);
return Ok(None);
}
debug!("Converting property {}.", name);
match T::from_jsval(cx, result.handle(), option) {
Ok(ConversionResult::Success(value)) => Ok(Some(value)),
Ok(ConversionResult::Failure(_)) => Ok(None),
Err(()) => Err(Error::JSFailed),
}
}
@@ -391,6 +391,8 @@ pub mod node;
pub mod nodeiterator;
pub mod nodelist;
pub mod pagetransitionevent;
pub mod paintrenderingcontext2d;
pub mod paintsize;
pub mod paintworkletglobalscope;
pub mod performance;
pub mod performancetiming;
@@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::Bindings::PaintRenderingContext2DBinding;
use dom::bindings::js::Root;
use dom::bindings::reflector::Reflector;
use dom::bindings::reflector::reflect_dom_object;
use dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use dom_struct::dom_struct;

#[dom_struct]
pub struct PaintRenderingContext2D {
reflector: Reflector,
}

impl PaintRenderingContext2D {
fn new_inherited() -> PaintRenderingContext2D {
PaintRenderingContext2D {
reflector: Reflector::new(),
}
}

pub fn new(global: &PaintWorkletGlobalScope) -> Root<PaintRenderingContext2D> {
reflect_dom_object(box PaintRenderingContext2D::new_inherited(),
global,
PaintRenderingContext2DBinding::Wrap)
}
}
@@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use app_units::Au;
use dom::bindings::codegen::Bindings::PaintSizeBinding;
use dom::bindings::codegen::Bindings::PaintSizeBinding::PaintSizeMethods;
use dom::bindings::js::Root;
use dom::bindings::num::Finite;
use dom::bindings::reflector::Reflector;
use dom::bindings::reflector::reflect_dom_object;
use dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use dom_struct::dom_struct;
use euclid::Size2D;

#[dom_struct]
pub struct PaintSize {
reflector: Reflector,
width: Finite<f64>,
height: Finite<f64>,
}

impl PaintSize {
fn new_inherited(size: Size2D<Au>) -> PaintSize {
PaintSize {
reflector: Reflector::new(),
width: Finite::wrap(size.width.to_px().abs() as f64),
height: Finite::wrap(size.height.to_px().abs() as f64),
}
}

pub fn new(global: &PaintWorkletGlobalScope, size: Size2D<Au>) -> Root<PaintSize> {
reflect_dom_object(box PaintSize::new_inherited(size), global, PaintSizeBinding::Wrap)
}
}

impl PaintSizeMethods for PaintSize {
/// https://drafts.css-houdini.org/css-paint-api/#paintsize
fn Width(&self) -> Finite<f64> {
self.width
}

/// https://drafts.css-houdini.org/css-paint-api/#paintsize
fn Height(&self) -> Finite<f64> {
self.height
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.