Update euclid.

There are a few canvas2d-related dependencies that haven't updated, but they
only use euclid internally so that's not blocking landing the rest of the
changes.

Given the size of this patch, I think it's useful to get this landed as-is.
This commit is contained in:
Emilio Cobos Álvarez 2019-07-22 12:49:39 +02:00
parent 2ff7cb5a37
commit 3d57c22e9c
133 changed files with 686 additions and 596 deletions

View file

@ -55,11 +55,8 @@ use crossbeam_channel::{Receiver, Sender};
use cssparser::RGBA;
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
use encoding_rs::{Decoder, Encoding};
use euclid::default::{Point2D, Rect, Rotation3D, Transform2D, Transform3D};
use euclid::Length as EuclidLength;
use euclid::{
Point2D, Rect, RigidTransform3D, Rotation3D, Transform2D, Transform3D, TypedRect,
TypedRigidTransform3D, TypedScale, TypedSize2D, Vector2D,
};
use html5ever::buffer_queue::BufferQueue;
use html5ever::{LocalName, Namespace, Prefix, QualName};
use http::header::HeaderMap;
@ -510,8 +507,8 @@ unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
unsafe_no_jsmanaged_fields!(Timespec);
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
unsafe_no_jsmanaged_fields!(Rotation3D<f64>, Transform2D<f32>, Transform3D<f64>);
unsafe_no_jsmanaged_fields!(Point2D<f32>, Vector2D<f32>, Rect<Au>);
unsafe_no_jsmanaged_fields!(Rect<f32>, RigidTransform3D<f64>);
unsafe_no_jsmanaged_fields!(Point2D<f32>, Rect<Au>);
unsafe_no_jsmanaged_fields!(Rect<f32>);
unsafe_no_jsmanaged_fields!(CascadeData);
unsafe_no_jsmanaged_fields!(WindowGLContext);
@ -605,14 +602,28 @@ where
}
}
unsafe impl<T, U> JSTraceable for TypedScale<f32, T, U> {
unsafe impl<U> JSTraceable for euclid::Vector2D<f32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<T, U> JSTraceable for TypedRigidTransform3D<f32, T, U> {
unsafe impl<T, U> JSTraceable for euclid::Scale<f32, T, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<T, U> JSTraceable for euclid::RigidTransform3D<f32, T, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<T, U> JSTraceable for euclid::RigidTransform3D<f64, T, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
@ -626,28 +637,28 @@ unsafe impl<T> JSTraceable for EuclidLength<u64, T> {
}
}
unsafe impl<U> JSTraceable for TypedSize2D<i32, U> {
unsafe impl<U> JSTraceable for euclid::Size2D<i32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<U> JSTraceable for TypedSize2D<f32, U> {
unsafe impl<U> JSTraceable for euclid::Size2D<f32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<U> JSTraceable for TypedSize2D<u32, U> {
unsafe impl<U> JSTraceable for euclid::Size2D<u32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}
unsafe impl<U> JSTraceable for TypedRect<i32, U> {
unsafe impl<U> JSTraceable for euclid::Rect<i32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing

View file

@ -9,7 +9,7 @@ use crate::dom::canvasgradient::ToFillOrStrokeStyle;
use crate::dom::globalscope::GlobalScope;
use canvas_traits::canvas::{FillOrStrokeStyle, RepetitionStyle, SurfaceStyle};
use dom_struct::dom_struct;
use euclid::Size2D;
use euclid::default::Size2D;
// https://html.spec.whatwg.org/multipage/#canvaspattern
#[dom_struct]

View file

@ -32,7 +32,10 @@ use canvas_traits::canvas::{RadialGradientStyle, RepetitionStyle};
use cssparser::Color as CSSColor;
use cssparser::{Parser, ParserInput, RGBA};
use dom_struct::dom_struct;
use euclid::{vec2, Point2D, Rect, Size2D, Transform2D};
use euclid::{
default::{Point2D, Rect, Size2D, Transform2D},
vec2,
};
use ipc_channel::ipc::{self, IpcSender};
use net_traits::image_cache::CanRequestImages;
use net_traits::image_cache::ImageCache;
@ -1223,7 +1226,7 @@ impl CanvasState {
let (sin, cos) = (angle.sin(), angle.cos());
let transform = self.state.borrow().transform;
self.state.borrow_mut().transform = transform.pre_mul(&Transform2D::row_major(
self.state.borrow_mut().transform = transform.pre_transform(&Transform2D::row_major(
cos as f32,
sin as f32,
-sin as f32,
@ -1258,7 +1261,7 @@ impl CanvasState {
}
let transform = self.state.borrow().transform;
self.state.borrow_mut().transform = transform.pre_mul(&Transform2D::row_major(
self.state.borrow_mut().transform = transform.pre_transform(&Transform2D::row_major(
a as f32, b as f32, c as f32, d as f32, e as f32, f as f32,
));
self.update_transform()

View file

@ -113,7 +113,7 @@ use devtools_traits::ScriptToDevtoolsControlMsg;
use dom_struct::dom_struct;
use embedder_traits::EmbedderMsg;
use encoding_rs::{Encoding, UTF_8};
use euclid::Point2D;
use euclid::default::Point2D;
use html5ever::{LocalName, Namespace, QualName};
use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender};

View file

@ -13,7 +13,7 @@ use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::node::{self, Node, VecPreOrderInsertionHelper};
use crate::dom::window::Window;
use crate::stylesheet_set::StylesheetSetRef;
use euclid::Point2D;
use euclid::default::Point2D;
use js::jsapi::JS_GetRuntime;
use script_layout_interface::message::{NodesFromPointQueryType, QueryMsg};
use script_traits::UntrustedNodeAddress;

View file

@ -18,7 +18,7 @@ use crate::dom::dommatrixreadonly::{
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use euclid::Transform3D;
use euclid::default::Transform3D;
use js::rust::CustomAutoRooterGuard;
use js::typedarray::{Float32Array, Float64Array};

View file

@ -20,7 +20,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use cssparser::{Parser, ParserInput};
use dom_struct::dom_struct;
use euclid::{Angle, Transform3D};
use euclid::{default::Transform3D, Angle};
use js::jsapi::{JSContext, JSObject};
use js::rust::CustomAutoRooterGuard;
use js::typedarray::CreateWith;
@ -180,7 +180,7 @@ impl DOMMatrixReadOnly {
dommatrixinit_to_matrix(&other).map(|(is2D, other_matrix)| {
// Step 2.
let mut matrix = self.matrix.borrow_mut();
*matrix = other_matrix.post_mul(&matrix);
*matrix = other_matrix.post_transform(&matrix);
// Step 3.
if !is2D {
self.is2D.set(false);
@ -195,7 +195,7 @@ impl DOMMatrixReadOnly {
dommatrixinit_to_matrix(&other).map(|(is2D, other_matrix)| {
// Step 2.
let mut matrix = self.matrix.borrow_mut();
*matrix = other_matrix.pre_mul(&matrix);
*matrix = other_matrix.pre_transform(&matrix);
// Step 3.
if !is2D {
self.is2D.set(false);
@ -209,7 +209,7 @@ impl DOMMatrixReadOnly {
// Step 1.
let translation = Transform3D::create_translation(tx, ty, tz);
let mut matrix = self.matrix.borrow_mut();
*matrix = translation.post_mul(&matrix);
*matrix = translation.post_transform(&matrix);
// Step 2.
if tz != 0.0 {
self.is2D.set(false);
@ -235,7 +235,7 @@ impl DOMMatrixReadOnly {
{
let scale3D = Transform3D::create_scale(scaleX, scaleY, scaleZ);
let mut matrix = self.matrix.borrow_mut();
*matrix = scale3D.post_mul(&matrix);
*matrix = scale3D.post_transform(&matrix);
}
// Step 4.
originX = -originX;
@ -258,7 +258,7 @@ impl DOMMatrixReadOnly {
{
let scale3D = Transform3D::create_scale(scale, scale, scale);
let mut matrix = self.matrix.borrow_mut();
*matrix = scale3D.post_mul(&matrix);
*matrix = scale3D.post_transform(&matrix);
}
// Step 3.
self.translate_self(-originX, -originY, -originZ);
@ -291,7 +291,7 @@ impl DOMMatrixReadOnly {
let rotation =
Transform3D::create_rotation(0.0, 0.0, -1.0, Angle::radians(rotZ.to_radians()));
let mut matrix = self.matrix.borrow_mut();
*matrix = rotation.post_mul(&matrix);
*matrix = rotation.post_transform(&matrix);
}
if rotY != 0.0 {
// Step 6.
@ -299,7 +299,7 @@ impl DOMMatrixReadOnly {
let rotation =
Transform3D::create_rotation(0.0, -1.0, 0.0, Angle::radians(rotY.to_radians()));
let mut matrix = self.matrix.borrow_mut();
*matrix = rotation.post_mul(&matrix);
*matrix = rotation.post_transform(&matrix);
}
if rotX != 0.0 {
// Step 7.
@ -307,7 +307,7 @@ impl DOMMatrixReadOnly {
let rotation =
Transform3D::create_rotation(-1.0, 0.0, 0.0, Angle::radians(rotX.to_radians()));
let mut matrix = self.matrix.borrow_mut();
*matrix = rotation.post_mul(&matrix);
*matrix = rotation.post_transform(&matrix);
}
// Step 8 in DOMMatrix.RotateSelf
}
@ -321,7 +321,7 @@ impl DOMMatrixReadOnly {
// Beware: pass negated value until https://github.com/servo/euclid/issues/354
let rotation = Transform3D::create_rotation(0.0, 0.0, -1.0, rotZ);
let mut matrix = self.matrix.borrow_mut();
*matrix = rotation.post_mul(&matrix);
*matrix = rotation.post_transform(&matrix);
}
// Step 2 in DOMMatrix.RotateFromVectorSelf
}
@ -338,7 +338,7 @@ impl DOMMatrixReadOnly {
Angle::radians(angle.to_radians()),
);
let mut matrix = self.matrix.borrow_mut();
*matrix = rotation.post_mul(&matrix);
*matrix = rotation.post_transform(&matrix);
// Step 2.
if x != 0.0 || y != 0.0 {
self.is2D.set(false);
@ -351,7 +351,7 @@ impl DOMMatrixReadOnly {
// Step 1.
let skew = Transform3D::create_skew(Angle::radians(sx.to_radians()), Angle::radians(0.0));
let mut matrix = self.matrix.borrow_mut();
*matrix = skew.post_mul(&matrix);
*matrix = skew.post_transform(&matrix);
// Step 2 in DOMMatrix.SkewXSelf
}
@ -360,7 +360,7 @@ impl DOMMatrixReadOnly {
// Step 1.
let skew = Transform3D::create_skew(Angle::radians(0.0), Angle::radians(sy.to_radians()));
let mut matrix = self.matrix.borrow_mut();
*matrix = skew.post_mul(&matrix);
*matrix = skew.post_transform(&matrix);
// Step 2 in DOMMatrix.SkewYSelf
}
@ -629,7 +629,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
let flip = Transform3D::row_major(
-1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
);
let matrix = flip.post_mul(&self.matrix.borrow());
let matrix = flip.post_transform(&self.matrix.borrow());
DOMMatrix::new(&self.global(), is2D, matrix)
}
@ -639,7 +639,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
let flip = Transform3D::row_major(
1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
);
let matrix = flip.post_mul(&self.matrix.borrow());
let matrix = flip.post_transform(&self.matrix.borrow());
DOMMatrix::new(&self.global(), is2D, matrix)
}

View file

@ -11,8 +11,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::{TypedPoint2D, TypedRect, TypedSize2D};
use euclid::{TypedRigidTransform3D, TypedRotation3D, TypedTransform3D, TypedVector3D};
use euclid::{Point2D, Rect, Size2D};
use euclid::{RigidTransform3D, Rotation3D, Transform3D, Vector3D};
use ipc_channel::ipc::IpcSender;
use webxr_api::{MockDeviceMsg, View, Views};
@ -67,23 +67,23 @@ pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<Views> {
let mut proj_r = [0.; 16];
let v: Vec<_> = left.projectionMatrix.iter().map(|x| **x).collect();
proj_l.copy_from_slice(&v);
let proj_l = TypedTransform3D::from_array(proj_l);
let proj_l = Transform3D::from_array(proj_l);
let v: Vec<_> = right.projectionMatrix.iter().map(|x| **x).collect();
proj_r.copy_from_slice(&v);
let proj_r = TypedTransform3D::from_array(proj_r);
let proj_r = Transform3D::from_array(proj_r);
// spec defines offsets as origins, but mock API expects the inverse transform
let offset_l = get_origin(&left.viewOffset)?.inverse();
let offset_r = get_origin(&right.viewOffset)?.inverse();
let size_l = TypedSize2D::new(views[0].resolution.width, views[0].resolution.height);
let size_r = TypedSize2D::new(views[1].resolution.width, views[1].resolution.height);
let size_l = Size2D::new(views[0].resolution.width, views[0].resolution.height);
let size_r = Size2D::new(views[1].resolution.width, views[1].resolution.height);
let origin_l = TypedPoint2D::new(0, 0);
let origin_r = TypedPoint2D::new(size_l.width, 0);
let origin_l = Point2D::new(0, 0);
let origin_r = Point2D::new(size_l.width, 0);
let viewport_l = TypedRect::new(origin_l, size_l);
let viewport_r = TypedRect::new(origin_r, size_r);
let viewport_l = Rect::new(origin_l, size_l);
let viewport_r = Rect::new(origin_r, size_r);
let left = View {
projection: proj_l,
@ -100,23 +100,23 @@ pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<Views> {
pub fn get_origin<T, U>(
origin: &FakeXRRigidTransformInit,
) -> Fallible<TypedRigidTransform3D<f32, T, U>> {
) -> Fallible<RigidTransform3D<f32, T, U>> {
if origin.position.len() != 3 || origin.orientation.len() != 4 {
return Err(Error::Type("Incorrectly sized array".into()));
}
let p = TypedVector3D::new(
let p = Vector3D::new(
*origin.position[0],
*origin.position[1],
*origin.position[2],
);
let o = TypedRotation3D::unit_quaternion(
let o = Rotation3D::unit_quaternion(
*origin.orientation[0],
*origin.orientation[1],
*origin.orientation[2],
*origin.orientation[3],
);
Ok(TypedRigidTransform3D::new(o, p))
Ok(RigidTransform3D::new(o, p))
}
impl FakeXRDeviceMethods for FakeXRDevice {

View file

@ -18,7 +18,7 @@ use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::Node;
use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use euclid::Point2D;
use euclid::default::Point2D;
use html5ever::{LocalName, Prefix};
use std::default::Default;
use std::f32;

View file

@ -32,7 +32,7 @@ use base64;
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromScriptMsg};
use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
use dom_struct::dom_struct;
use euclid::{Rect, Size2D};
use euclid::default::{Rect, Size2D};
use html5ever::{LocalName, Prefix};
use image::png::PNGEncoder;
use image::ColorType;

View file

@ -28,7 +28,7 @@ use crate::dom::windowproxy::WindowProxy;
use crate::script_thread::ScriptThread;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use euclid::TypedSize2D;
use euclid::Size2D;
use html5ever::{LocalName, Prefix};
use ipc_channel::ipc;
use msg::constellation_msg::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
@ -202,10 +202,7 @@ impl HTMLIFrameElement {
window_size: WindowSizeData {
initial_viewport: {
let rect = self.upcast::<Node>().bounding_content_box_or_zero();
TypedSize2D::new(
rect.size.width.to_f32_px(),
rect.size.height.to_f32_px(),
)
Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px())
},
device_pixel_ratio: window.device_pixel_ratio(),
},

View file

@ -65,7 +65,7 @@ use crate::script_thread::ScriptThread;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use embedder_traits::resources::{self, Resource as EmbedderResource};
use euclid::Size2D;
use euclid::default::Size2D;
use headers::{ContentLength, ContentRange, HeaderMapExt};
use html5ever::{LocalName, Prefix};
use http::header::{self, HeaderMap, HeaderValue};

View file

@ -9,7 +9,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::{Rect, Size2D};
use euclid::default::{Rect, Size2D};
use ipc_channel::ipc::IpcSharedMemory;
use js::jsapi::{Heap, JSContext, JSObject};
use js::rust::Runtime;

View file

@ -15,7 +15,7 @@ use crate::dom::eventtarget::EventTarget;
use crate::dom::uievent::UIEvent;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use euclid::Point2D;
use euclid::default::Point2D;
use servo_config::pref;
use std::cell::Cell;
use std::default::Default;

View file

@ -64,7 +64,7 @@ use crate::script_thread::ScriptThread;
use app_units::Au;
use devtools_traits::NodeInfo;
use dom_struct::dom_struct;
use euclid::{Point2D, Rect, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use html5ever::{Namespace, Prefix, QualName};
use js::jsapi::{JSContext, JSObject, JSRuntime};
use libc::{self, c_void, uintptr_t};
@ -778,7 +778,7 @@ impl Node {
pub fn scroll_offset(&self) -> Vector2D<f32> {
let document = self.owner_doc();
let window = document.window();
window.scroll_offset_query(self)
window.scroll_offset_query(self).to_untyped()
}
// https://dom.spec.whatwg.org/#dom-childnode-before

View file

@ -16,7 +16,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D;
use dom_struct::dom_struct;
use euclid::Size2D;
use euclid::default::Size2D;
use js::jsapi::JSContext;
use js::rust::HandleValue;
use ref_filter_map;

View file

@ -24,7 +24,7 @@ use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
use crate::dom::offscreencanvas::OffscreenCanvas;
use dom_struct::dom_struct;
use euclid::Size2D;
use euclid::default::Size2D;
#[dom_struct]
pub struct OffscreenCanvasRenderingContext2D {

View file

@ -25,9 +25,7 @@ use canvas_traits::canvas::CanvasImageData;
use canvas_traits::canvas::CanvasMsg;
use canvas_traits::canvas::FromLayoutMsg;
use dom_struct::dom_struct;
use euclid::Size2D;
use euclid::TypedScale;
use euclid::TypedSize2D;
use euclid::{Scale, Size2D};
use ipc_channel::ipc::IpcSender;
use servo_url::ServoUrl;
use std::cell::Cell;
@ -37,7 +35,7 @@ use style_traits::DevicePixel;
#[dom_struct]
pub struct PaintRenderingContext2D {
context: CanvasRenderingContext2D,
device_pixel_ratio: Cell<TypedScale<f32, CSSPixel, DevicePixel>>,
device_pixel_ratio: Cell<Scale<f32, CSSPixel, DevicePixel>>,
}
impl PaintRenderingContext2D {
@ -45,7 +43,7 @@ impl PaintRenderingContext2D {
let size = Size2D::zero();
PaintRenderingContext2D {
context: CanvasRenderingContext2D::new_inherited(global.upcast(), None, size),
device_pixel_ratio: Cell::new(TypedScale::new(1.0)),
device_pixel_ratio: Cell::new(Scale::new(1.0)),
}
}
@ -71,8 +69,8 @@ impl PaintRenderingContext2D {
pub fn set_bitmap_dimensions(
&self,
size: TypedSize2D<f32, CSSPixel>,
device_pixel_ratio: TypedScale<f32, CSSPixel, DevicePixel>,
size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
) {
let size = size * device_pixel_ratio;
self.device_pixel_ratio.set(device_pixel_ratio);

View file

@ -10,7 +10,7 @@ use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot;
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use dom_struct::dom_struct;
use euclid::TypedSize2D;
use euclid::Size2D;
use style_traits::CSSPixel;
#[dom_struct]
@ -21,7 +21,7 @@ pub struct PaintSize {
}
impl PaintSize {
fn new_inherited(size: TypedSize2D<f32, CSSPixel>) -> PaintSize {
fn new_inherited(size: Size2D<f32, CSSPixel>) -> PaintSize {
PaintSize {
reflector: Reflector::new(),
width: Finite::wrap(size.width as f64),
@ -31,7 +31,7 @@ impl PaintSize {
pub fn new(
global: &PaintWorkletGlobalScope,
size: TypedSize2D<f32, CSSPixel>,
size: Size2D<f32, CSSPixel>,
) -> DomRoot<PaintSize> {
reflect_dom_object(
Box::new(PaintSize::new_inherited(size)),

View file

@ -25,8 +25,8 @@ use crate::dom::workletglobalscope::WorkletGlobalScopeInit;
use crate::dom::workletglobalscope::WorkletTask;
use crossbeam_channel::{unbounded, Sender};
use dom_struct::dom_struct;
use euclid::TypedScale;
use euclid::TypedSize2D;
use euclid::Scale;
use euclid::Size2D;
use js::jsapi::HandleValueArray;
use js::jsapi::Heap;
use js::jsapi::IsCallable;
@ -81,9 +81,9 @@ pub struct PaintWorkletGlobalScope {
/// The most recent name the worklet was called with
cached_name: DomRefCell<Atom>,
/// The most recent size the worklet was drawn at
cached_size: Cell<TypedSize2D<f32, CSSPixel>>,
cached_size: Cell<Size2D<f32, CSSPixel>>,
/// The most recent device pixel ratio the worklet was drawn at
cached_device_pixel_ratio: Cell<TypedScale<f32, CSSPixel, DevicePixel>>,
cached_device_pixel_ratio: Cell<Scale<f32, CSSPixel, DevicePixel>>,
/// The most recent properties the worklet was drawn at
cached_properties: DomRefCell<Vec<(Atom, String)>>,
/// The most recent arguments the worklet was drawn at
@ -116,8 +116,8 @@ impl PaintWorkletGlobalScope {
paint_definitions: Default::default(),
paint_class_instances: Default::default(),
cached_name: DomRefCell::new(Atom::from("")),
cached_size: Cell::new(TypedSize2D::zero()),
cached_device_pixel_ratio: Cell::new(TypedScale::new(1.0)),
cached_size: Cell::new(Size2D::zero()),
cached_device_pixel_ratio: Cell::new(Scale::new(1.0)),
cached_properties: Default::default(),
cached_arguments: Default::default(),
cached_result: DomRefCell::new(DrawAPaintImageResult {
@ -211,13 +211,13 @@ impl PaintWorkletGlobalScope {
fn draw_a_paint_image(
&self,
name: &Atom,
size_in_px: TypedSize2D<f32, CSSPixel>,
device_pixel_ratio: TypedScale<f32, CSSPixel, DevicePixel>,
size_in_px: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
properties: &StylePropertyMapReadOnly,
arguments: &[String],
) -> DrawAPaintImageResult {
let size_in_dpx = size_in_px * device_pixel_ratio;
let size_in_dpx = TypedSize2D::new(
let size_in_dpx = Size2D::new(
size_in_dpx.width.abs() as u32,
size_in_dpx.height.abs() as u32,
);
@ -240,9 +240,9 @@ impl PaintWorkletGlobalScope {
fn invoke_a_paint_callback(
&self,
name: &Atom,
size_in_px: TypedSize2D<f32, CSSPixel>,
size_in_dpx: TypedSize2D<u32, DevicePixel>,
device_pixel_ratio: TypedScale<f32, CSSPixel, DevicePixel>,
size_in_px: Size2D<f32, CSSPixel>,
size_in_dpx: Size2D<u32, DevicePixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
properties: &StylePropertyMapReadOnly,
arguments: &[String],
) -> DrawAPaintImageResult {
@ -383,7 +383,7 @@ impl PaintWorkletGlobalScope {
// https://drafts.csswg.org/css-images-4/#invalid-image
fn invalid_image(
&self,
size: TypedSize2D<u32, DevicePixel>,
size: Size2D<u32, DevicePixel>,
missing_image_urls: Vec<ServoUrl>,
) -> DrawAPaintImageResult {
debug!("Returning an invalid image.");
@ -420,8 +420,8 @@ impl PaintWorkletGlobalScope {
impl Painter for WorkletPainter {
fn draw_a_paint_image(
&self,
size: TypedSize2D<f32, CSSPixel>,
device_pixel_ratio: TypedScale<f32, CSSPixel, DevicePixel>,
size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
properties: Vec<(Atom, String)>,
arguments: Vec<String>,
) -> Result<DrawAPaintImageResult, PaintWorkletError> {
@ -458,8 +458,8 @@ impl PaintWorkletGlobalScope {
pub enum PaintWorkletTask {
DrawAPaintImage(
Atom,
TypedSize2D<f32, CSSPixel>,
TypedScale<f32, CSSPixel, DevicePixel>,
Size2D<f32, CSSPixel>,
Scale<f32, CSSPixel, DevicePixel>,
Vec<(Atom, String)>,
Vec<String>,
Sender<DrawAPaintImageResult>,

View file

@ -12,7 +12,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use euclid::TypedSize2D;
use euclid::Size2D;
use profile_traits::ipc;
use script_traits::ScriptMsg;
use style_traits::CSSPixel;
@ -40,7 +40,7 @@ impl Screen {
)
}
fn screen_size(&self) -> TypedSize2D<u32, CSSPixel> {
fn screen_size(&self) -> Size2D<u32, CSSPixel> {
let (send, recv) =
ipc::channel::<DeviceIntSize>(self.global().time_profiler_chan().clone()).unwrap();
self.window
@ -49,11 +49,11 @@ impl Screen {
.send(ScriptMsg::GetScreenSize(send))
.unwrap();
let dpr = self.window.device_pixel_ratio();
let screen = recv.recv().unwrap_or(TypedSize2D::zero());
let screen = recv.recv().unwrap_or(Size2D::zero());
(screen.to_f32() / dpr).to_u32()
}
fn screen_avail_size(&self) -> TypedSize2D<u32, CSSPixel> {
fn screen_avail_size(&self) -> Size2D<u32, CSSPixel> {
let (send, recv) =
ipc::channel::<DeviceIntSize>(self.global().time_profiler_chan().clone()).unwrap();
self.window
@ -62,7 +62,7 @@ impl Screen {
.send(ScriptMsg::GetScreenAvailSize(send))
.unwrap();
let dpr = self.window.device_pixel_ratio();
let screen = recv.recv().unwrap_or(TypedSize2D::zero());
let screen = recv.recv().unwrap_or(Size2D::zero());
(screen.to_f32() / dpr).to_u32()
}
}

View file

@ -32,7 +32,7 @@ use crate::dom::window::Window;
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/webgl.idl
use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
use dom_struct::dom_struct;
use euclid::Size2D;
use euclid::default::Size2D;
use js::jsapi::{JSContext, JSObject};
use js::jsval::JSVal;
use js::rust::CustomAutoRooterGuard;

View file

@ -59,7 +59,7 @@ use canvas_traits::webgl::{
YAxisTreatment,
};
use dom_struct::dom_struct;
use euclid::{Point2D, Rect, Size2D};
use euclid::default::{Point2D, Rect, Size2D};
use ipc_channel::ipc::{self, IpcSharedMemory};
use js::jsapi::{JSContext, JSObject, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, UInt32Value};

View file

@ -74,7 +74,8 @@ use cssparser::{Parser, ParserInput, SourceLocation};
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
use dom_struct::dom_struct;
use embedder_traits::EmbedderMsg;
use euclid::{Point2D, Rect, Size2D, TypedPoint2D, TypedScale, TypedSize2D, Vector2D};
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect};
use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
use ipc_channel::ipc::{channel, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoRealm;
@ -131,7 +132,7 @@ use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::CssRuleType;
use style_traits::{CSSPixel, DevicePixel, ParsingMode};
use url::Position;
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use webrender_api::units::{DeviceIntPoint, DeviceIntSize, LayoutPixel};
use webrender_api::{DocumentId, ExternalScrollId, RenderApiSender};
use webvr_traits::WebVRMsg;
@ -229,7 +230,7 @@ pub struct Window {
/// An enlarged rectangle around the page contents visible in the viewport, used
/// to prevent creating display list items for content that is far away from the viewport.
page_clip_rect: Cell<Rect<Au>>,
page_clip_rect: Cell<UntypedRect<Au>>,
/// Flag to suppress reflows. The first reflow will come either with
/// RefreshTick or with FirstLoad. Until those first reflows, we want to
@ -246,12 +247,12 @@ pub struct Window {
/// The current state of the window object
current_state: Cell<WindowState>,
current_viewport: Cell<Rect<Au>>,
current_viewport: Cell<UntypedRect<Au>>,
error_reporter: CSSErrorReporter,
/// A list of scroll offsets for each scrollable element.
scroll_offsets: DomRefCell<HashMap<OpaqueNode, Vector2D<f32>>>,
scroll_offsets: DomRefCell<HashMap<OpaqueNode, Vector2D<f32, LayoutPixel>>>,
/// All the MediaQueryLists we need to update
media_query_lists: DOMTracker<MediaQueryList>,
@ -423,11 +424,11 @@ impl Window {
/// Sets a new list of scroll offsets.
///
/// This is called when layout gives us new ones and WebRender is in use.
pub fn set_scroll_offsets(&self, offsets: HashMap<OpaqueNode, Vector2D<f32>>) {
pub fn set_scroll_offsets(&self, offsets: HashMap<OpaqueNode, Vector2D<f32, LayoutPixel>>) {
*self.scroll_offsets.borrow_mut() = offsets
}
pub fn current_viewport(&self) -> Rect<Au> {
pub fn current_viewport(&self) -> UntypedRect<Au> {
self.current_viewport.clone().get()
}
@ -1093,7 +1094,7 @@ impl WindowMethods for Window {
// Step 1
//TODO determine if this operation is allowed
let dpr = self.device_pixel_ratio();
let size = TypedSize2D::new(width, height).to_f32() * dpr;
let size = Size2D::new(width, height).to_f32() * dpr;
self.send_to_embedder(EmbedderMsg::ResizeTo(size.to_i32()));
}
@ -1112,7 +1113,7 @@ impl WindowMethods for Window {
// Step 1
//TODO determine if this operation is allowed
let dpr = self.device_pixel_ratio();
let point = TypedPoint2D::new(x, y).to_f32() * dpr;
let point = Point2D::new(x, y).to_f32() * dpr;
let msg = EmbedderMsg::MoveTo(point.to_i32());
self.send_to_embedder(msg);
}
@ -1377,18 +1378,16 @@ impl Window {
self.current_viewport.set(new_viewport)
}
pub fn device_pixel_ratio(&self) -> TypedScale<f32, CSSPixel, DevicePixel> {
pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel> {
self.window_size.get().device_pixel_ratio
}
fn client_window(&self) -> (TypedSize2D<u32, CSSPixel>, TypedPoint2D<i32, CSSPixel>) {
fn client_window(&self) -> (Size2D<u32, CSSPixel>, Point2D<i32, CSSPixel>) {
let timer_profile_chan = self.global().time_profiler_chan().clone();
let (send, recv) =
ProfiledIpc::channel::<(DeviceIntSize, DeviceIntPoint)>(timer_profile_chan).unwrap();
self.send_to_constellation(ScriptMsg::GetClientWindow(send));
let (size, point) = recv
.recv()
.unwrap_or((TypedSize2D::zero(), TypedPoint2D::zero()));
let (size, point) = recv.recv().unwrap_or((Size2D::zero(), Point2D::zero()));
let dpr = self.device_pixel_ratio();
(
(size.to_f32() / dpr).to_u32(),
@ -1626,7 +1625,7 @@ impl Window {
&*self.layout_rpc
}
pub fn content_box_query(&self, node: &Node) -> Option<Rect<Au>> {
pub fn content_box_query(&self, node: &Node) -> Option<UntypedRect<Au>> {
if !self.layout_reflow(QueryMsg::ContentBoxQuery(node.to_opaque())) {
return None;
}
@ -1634,7 +1633,7 @@ impl Window {
rect
}
pub fn content_boxes_query(&self, node: &Node) -> Vec<Rect<Au>> {
pub fn content_boxes_query(&self, node: &Node) -> Vec<UntypedRect<Au>> {
if !self.layout_reflow(QueryMsg::ContentBoxesQuery(node.to_opaque())) {
return vec![];
}
@ -1642,21 +1641,21 @@ impl Window {
rects
}
pub fn client_rect_query(&self, node: &Node) -> Rect<i32> {
pub fn client_rect_query(&self, node: &Node) -> UntypedRect<i32> {
if !self.layout_reflow(QueryMsg::NodeGeometryQuery(node.to_opaque())) {
return Rect::zero();
}
self.layout_rpc.node_geometry().client_rect
}
pub fn scroll_area_query(&self, node: &Node) -> Rect<i32> {
pub fn scroll_area_query(&self, node: &Node) -> UntypedRect<i32> {
if !self.layout_reflow(QueryMsg::NodeScrollGeometryQuery(node.to_opaque())) {
return Rect::zero();
}
self.layout_rpc.node_scroll_area().client_rect
}
pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32> {
pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32, LayoutPixel> {
if let Some(scroll_offset) = self.scroll_offsets.borrow().get(&node.to_opaque()) {
return *scroll_offset;
}
@ -1702,7 +1701,7 @@ impl Window {
}
#[allow(unsafe_code)]
pub fn offset_parent_query(&self, node: &Node) -> (Option<DomRoot<Element>>, Rect<Au>) {
pub fn offset_parent_query(&self, node: &Node) -> (Option<DomRoot<Element>>, UntypedRect<Au>) {
if !self.layout_reflow(QueryMsg::OffsetParentQuery(node.to_opaque())) {
return (None, Rect::zero());
}
@ -1726,7 +1725,11 @@ impl Window {
self.layout_rpc.style().0
}
pub fn text_index_query(&self, node: &Node, point_in_node: Point2D<f32>) -> TextIndexResponse {
pub fn text_index_query(
&self,
node: &Node,
point_in_node: UntypedPoint2D<f32>,
) -> TextIndexResponse {
if !self.layout_reflow(QueryMsg::TextIndexQuery(node.to_opaque(), point_in_node)) {
return TextIndexResponse(None);
}
@ -1891,7 +1894,7 @@ impl Window {
event
}
pub fn set_page_clip_rect_with_new_viewport(&self, viewport: Rect<f32>) -> bool {
pub fn set_page_clip_rect_with_new_viewport(&self, viewport: UntypedRect<f32>) -> bool {
let rect = f32_rect_to_au_rect(viewport.clone());
self.current_viewport.set(rect);
// We use a clipping rectangle that is five times the size of the of the viewport,
@ -2184,8 +2187,8 @@ impl Window {
}
}
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
let clip_rect = Rect::new(
fn should_move_clip_rect(clip_rect: UntypedRect<Au>, new_viewport: UntypedRect<f32>) -> bool {
let clip_rect = UntypedRect::new(
Point2D::new(
clip_rect.origin.x.to_f32_px(),
clip_rect.origin.y.to_f32_px(),

View file

@ -95,7 +95,7 @@ impl XRFrameMethods for XRFrame {
}
let space = space.get_pose(&self.data);
let relative_to = relative_to.get_pose(&self.data);
let pose = relative_to.inverse().pre_mul(&space);
let pose = relative_to.inverse().pre_transform(&space);
Ok(Some(XRPose::new(&self.global(), pose)))
}
}

View file

@ -13,7 +13,7 @@ use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::{cast_transform, ApiPose, ApiRigidTransform, ApiViewerPose, XRSession};
use crate::dom::xrspace::XRSpace;
use dom_struct::dom_struct;
use euclid::{TypedRigidTransform3D, TypedVector3D};
use euclid::{RigidTransform3D, Vector3D};
use webxr_api::Frame;
#[dom_struct]
@ -64,7 +64,7 @@ impl XRReferenceSpace {
impl XRReferenceSpaceMethods for XRReferenceSpace {
/// https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace
fn GetOffsetReferenceSpace(&self, new: &XRRigidTransform) -> DomRoot<Self> {
let offset = new.transform().pre_mul(&self.offset.transform());
let offset = new.transform().pre_transform(&self.offset.transform());
let offset = XRRigidTransform::new(&self.global(), offset);
Self::new_offset(
&self.global(),
@ -92,7 +92,7 @@ impl XRReferenceSpace {
// = offset.inverse() * get_unoffset_viewer_pose(space)
let offset = self.offset.transform();
let inverse = offset.inverse();
inverse.pre_mul(&pose)
inverse.pre_transform(&pose)
}
/// Gets pose of the viewer with respect to this space
@ -120,13 +120,13 @@ impl XRReferenceSpace {
// = Translate(2) * viewer_pose
// assume approximate user height of 2 meters
let floor_to_eye: ApiRigidTransform = TypedVector3D::new(0., 2., 0.).into();
floor_to_eye.pre_mul(&viewer_pose)
let floor_to_eye: ApiRigidTransform = Vector3D::new(0., 2., 0.).into();
floor_to_eye.pre_transform(&viewer_pose)
},
XRReferenceSpaceType::Viewer => {
// This reference space follows the viewer around, so the viewer is
// always at an identity transform with respect to it
TypedRigidTransform3D::identity()
RigidTransform3D::identity()
},
_ => unimplemented!(),
}
@ -142,7 +142,7 @@ impl XRReferenceSpace {
// This may change, see https://github.com/immersive-web/webxr/issues/567
let offset = self.offset.transform();
offset.post_mul(&pose)
offset.post_transform(&pose)
}
/// Gets pose represented by this space
@ -153,14 +153,14 @@ impl XRReferenceSpace {
XRReferenceSpaceType::Local => {
// The eye-level pose is basically whatever the headset pose was at t=0, which
// for most devices is (0, 0, 0)
TypedRigidTransform3D::identity()
RigidTransform3D::identity()
},
XRReferenceSpaceType::Local_floor => {
// XXXManishearth support getting floor info from stage parameters
// Assume approximate height of 2m
// the floor-level space is 2m below the eye-level space, which is (0, 0, 0)
TypedVector3D::new(0., -2., 0.).into()
Vector3D::new(0., -2., 0.).into()
},
XRReferenceSpaceType::Viewer => cast_transform(base_pose.transform),
_ => unimplemented!(),

View file

@ -16,7 +16,7 @@ use crate::dom::vrframedata::create_typed_array;
use crate::dom::window::Window;
use crate::dom::xrsession::ApiRigidTransform;
use dom_struct::dom_struct;
use euclid::{TypedRigidTransform3D, TypedRotation3D, TypedVector3D};
use euclid::{RigidTransform3D, Rotation3D, Vector3D};
use js::jsapi::{Heap, JSContext, JSObject};
use std::ptr::NonNull;
@ -53,7 +53,7 @@ impl XRRigidTransform {
}
pub fn identity(window: &GlobalScope) -> DomRoot<XRRigidTransform> {
let transform = TypedRigidTransform3D::identity();
let transform = RigidTransform3D::identity();
XRRigidTransform::new(window, transform)
}
@ -70,8 +70,8 @@ impl XRRigidTransform {
)));
}
let translate = TypedVector3D::new(position.x as f32, position.y as f32, position.z as f32);
let rotate = TypedRotation3D::unit_quaternion(
let translate = Vector3D::new(position.x as f32, position.y as f32, position.z as f32);
let rotate = Rotation3D::unit_quaternion(
orientation.x as f32,
orientation.y as f32,
orientation.z as f32,
@ -83,7 +83,7 @@ impl XRRigidTransform {
// value for each element. This is preferable to checking for zero.
return Err(Error::InvalidState);
}
let transform = TypedRigidTransform3D::new(rotate, translate);
let transform = RigidTransform3D::new(rotate, translate);
Ok(XRRigidTransform::new(&window.global(), transform))
}
}

View file

@ -38,7 +38,7 @@ use crate::dom::xrspace::XRSpace;
use crate::dom::xrwebgllayer::XRWebGLLayer;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use euclid::TypedRigidTransform3D;
use euclid::RigidTransform3D;
use ipc_channel::ipc::IpcSender;
use ipc_channel::router::ROUTER;
use profile_traits::ipc;
@ -403,15 +403,15 @@ impl XRSessionMethods for XRSession {
#[derive(Clone, Copy, Debug)]
pub struct ApiSpace;
// The pose of an object in native-space. Should never be exposed.
pub type ApiPose = TypedRigidTransform3D<f32, ApiSpace, webxr_api::Native>;
pub type ApiPose = RigidTransform3D<f32, ApiSpace, webxr_api::Native>;
// The pose of the viewer in some api-space.
pub type ApiViewerPose = TypedRigidTransform3D<f32, webxr_api::Viewer, ApiSpace>;
pub type ApiViewerPose = RigidTransform3D<f32, webxr_api::Viewer, ApiSpace>;
// A transform between objects in some API-space
pub type ApiRigidTransform = TypedRigidTransform3D<f32, ApiSpace, ApiSpace>;
pub type ApiRigidTransform = RigidTransform3D<f32, ApiSpace, ApiSpace>;
#[allow(unsafe_code)]
pub fn cast_transform<T, U, V, W>(
transform: TypedRigidTransform3D<f32, T, U>,
) -> TypedRigidTransform3D<f32, V, W> {
transform: RigidTransform3D<f32, T, U>,
) -> RigidTransform3D<f32, V, W> {
unsafe { mem::transmute(transform) }
}

View file

@ -20,7 +20,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use euclid::TypedRigidTransform3D;
use euclid::RigidTransform3D;
use ipc_channel::ipc::IpcSender;
use ipc_channel::router::ROUTER;
use profile_traits::ipc;
@ -103,7 +103,7 @@ impl XRTestMethods for XRTest {
},
}
} else {
TypedRigidTransform3D::identity()
RigidTransform3D::identity()
};
let floor_origin = if let Some(ref o) = init.floorOrigin {
@ -115,7 +115,7 @@ impl XRTestMethods for XRTest {
},
}
} else {
TypedRigidTransform3D::identity()
RigidTransform3D::identity()
};
let views = match get_views(&init.views) {

View file

@ -53,7 +53,7 @@ impl XRView {
// from the viewer space to the eye space. We invert it to get the pose of the eye in the viewer space.
let offset = view.transform.inverse();
let transform = pose.pre_mul(&offset);
let transform = pose.pre_transform(&offset);
let transform = XRRigidTransform::new(global, cast_transform(transform));
let ret = reflect_dom_object(

View file

@ -8,24 +8,24 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::TypedRect;
use euclid::Rect;
use webxr_api::Viewport;
#[dom_struct]
pub struct XRViewport {
reflector_: Reflector,
viewport: TypedRect<i32, Viewport>,
viewport: Rect<i32, Viewport>,
}
impl XRViewport {
fn new_inherited(viewport: TypedRect<i32, Viewport>) -> XRViewport {
fn new_inherited(viewport: Rect<i32, Viewport>) -> XRViewport {
XRViewport {
reflector_: Reflector::new(),
viewport,
}
}
pub fn new(global: &GlobalScope, viewport: TypedRect<i32, Viewport>) -> DomRoot<XRViewport> {
pub fn new(global: &GlobalScope, viewport: Rect<i32, Viewport>) -> DomRoot<XRViewport> {
reflect_dom_object(
Box::new(XRViewport::new_inherited(viewport)),
global,