mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
parent
2ff7cb5a37
commit
3d57c22e9c
133 changed files with 686 additions and 596 deletions
|
@ -18,7 +18,7 @@ gl = ["gleam", "pixels"]
|
|||
[dependencies]
|
||||
crossbeam-channel = "0.3"
|
||||
embedder_traits = {path = "../embedder_traits"}
|
||||
euclid = "0.19"
|
||||
euclid = "0.20"
|
||||
gfx_traits = {path = "../gfx_traits"}
|
||||
gleam = {version = "0.6", optional = true}
|
||||
image = "0.21"
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::CompositionPipeline;
|
|||
use crate::SendableFrameTree;
|
||||
use crossbeam_channel::Sender;
|
||||
use embedder_traits::Cursor;
|
||||
use euclid::{TypedPoint2D, TypedScale, TypedVector2D};
|
||||
use euclid::{Point2D, Scale, Vector2D};
|
||||
use gfx_traits::Epoch;
|
||||
#[cfg(feature = "gl")]
|
||||
use image::{DynamicImage, ImageFormat};
|
||||
|
@ -115,7 +115,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
|
|||
pipeline_details: HashMap<PipelineId, PipelineDetails>,
|
||||
|
||||
/// The scene scale, to allow for zooming and high-resolution painting.
|
||||
scale: TypedScale<f32, LayerPixel, DevicePixel>,
|
||||
scale: Scale<f32, LayerPixel, DevicePixel>,
|
||||
|
||||
/// "Mobile-style" zoom that does not reflow the page.
|
||||
viewport_zoom: PinchZoomFactor,
|
||||
|
@ -125,7 +125,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
|
|||
max_viewport_zoom: Option<PinchZoomFactor>,
|
||||
|
||||
/// "Desktop-style" zoom that resizes the viewport to fit the window.
|
||||
page_zoom: TypedScale<f32, CSSPixel, DeviceIndependentPixel>,
|
||||
page_zoom: Scale<f32, CSSPixel, DeviceIndependentPixel>,
|
||||
|
||||
/// The type of composition to perform
|
||||
composite_target: CompositeTarget,
|
||||
|
@ -296,14 +296,14 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
port: state.receiver,
|
||||
root_pipeline: None,
|
||||
pipeline_details: HashMap::new(),
|
||||
scale: TypedScale::new(1.0),
|
||||
scale: Scale::new(1.0),
|
||||
composition_request: CompositionRequest::NoCompositingNecessary,
|
||||
touch_handler: TouchHandler::new(),
|
||||
pending_scroll_zoom_events: Vec::new(),
|
||||
waiting_for_results_of_scroll: false,
|
||||
composite_target,
|
||||
shutdown_state: ShutdownState::NotShuttingDown,
|
||||
page_zoom: TypedScale::new(1.0),
|
||||
page_zoom: Scale::new(1.0),
|
||||
viewport_zoom: PinchZoomFactor::new(1.0),
|
||||
min_viewport_zoom: None,
|
||||
max_viewport_zoom: None,
|
||||
|
@ -741,7 +741,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let scaled_point = (point / dppx).to_untyped();
|
||||
|
||||
let world_cursor = webrender_api::units::WorldPoint::from_untyped(&scaled_point);
|
||||
let world_cursor = webrender_api::units::WorldPoint::from_untyped(scaled_point);
|
||||
self.webrender_api.hit_test(
|
||||
self.webrender_document,
|
||||
None,
|
||||
|
@ -845,15 +845,15 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
fn on_touch_move(&mut self, identifier: TouchId, point: DevicePoint) {
|
||||
match self.touch_handler.on_touch_move(identifier, point) {
|
||||
TouchAction::Scroll(delta) => self.on_scroll_window_event(
|
||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(&delta.to_untyped())),
|
||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
||||
point.cast(),
|
||||
),
|
||||
TouchAction::Zoom(magnification, scroll_delta) => {
|
||||
let cursor = TypedPoint2D::new(-1, -1); // Make sure this hits the base layer.
|
||||
let cursor = Point2D::new(-1, -1); // Make sure this hits the base layer.
|
||||
self.pending_scroll_zoom_events.push(ScrollZoomEvent {
|
||||
magnification: magnification,
|
||||
scroll_location: ScrollLocation::Delta(LayoutVector2D::from_untyped(
|
||||
&scroll_delta.to_untyped(),
|
||||
scroll_delta.to_untyped(),
|
||||
)),
|
||||
cursor: cursor,
|
||||
event_count: 1,
|
||||
|
@ -942,7 +942,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
*last_combined_event = Some(ScrollZoomEvent {
|
||||
magnification: scroll_event.magnification,
|
||||
scroll_location: ScrollLocation::Delta(LayoutVector2D::from_untyped(
|
||||
&this_delta.to_untyped(),
|
||||
this_delta.to_untyped(),
|
||||
)),
|
||||
cursor: this_cursor,
|
||||
event_count: 1,
|
||||
|
@ -954,11 +954,9 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
// nasty-looking "pops". To mitigate this, during a fling we average
|
||||
// deltas instead of summing them.
|
||||
if let ScrollLocation::Delta(delta) = last_combined_event.scroll_location {
|
||||
let old_event_count =
|
||||
TypedScale::new(last_combined_event.event_count as f32);
|
||||
let old_event_count = Scale::new(last_combined_event.event_count as f32);
|
||||
last_combined_event.event_count += 1;
|
||||
let new_event_count =
|
||||
TypedScale::new(last_combined_event.event_count as f32);
|
||||
let new_event_count = Scale::new(last_combined_event.event_count as f32);
|
||||
last_combined_event.scroll_location = ScrollLocation::Delta(
|
||||
(delta * old_event_count + this_delta) / new_event_count,
|
||||
);
|
||||
|
@ -971,17 +969,16 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
if let Some(combined_event) = last_combined_event {
|
||||
let scroll_location = match combined_event.scroll_location {
|
||||
ScrollLocation::Delta(delta) => {
|
||||
let scaled_delta = (TypedVector2D::from_untyped(&delta.to_untyped()) /
|
||||
self.scale)
|
||||
.to_untyped();
|
||||
let calculated_delta = LayoutVector2D::from_untyped(&scaled_delta);
|
||||
let scaled_delta =
|
||||
(Vector2D::from_untyped(delta.to_untyped()) / self.scale).to_untyped();
|
||||
let calculated_delta = LayoutVector2D::from_untyped(scaled_delta);
|
||||
ScrollLocation::Delta(calculated_delta)
|
||||
},
|
||||
// Leave ScrollLocation unchanged if it is Start or End location.
|
||||
sl @ ScrollLocation::Start | sl @ ScrollLocation::End => sl,
|
||||
};
|
||||
let cursor = (combined_event.cursor.to_f32() / self.scale).to_untyped();
|
||||
let cursor = webrender_api::units::WorldPoint::from_untyped(&cursor);
|
||||
let cursor = webrender_api::units::WorldPoint::from_untyped(cursor);
|
||||
let mut txn = webrender_api::Transaction::new();
|
||||
txn.scroll(scroll_location, cursor);
|
||||
if combined_event.magnification != 1.0 {
|
||||
|
@ -1063,34 +1060,34 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
}
|
||||
}
|
||||
|
||||
fn hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
||||
fn hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
|
||||
match self.device_pixels_per_px {
|
||||
Some(device_pixels_per_px) => TypedScale::new(device_pixels_per_px),
|
||||
Some(device_pixels_per_px) => Scale::new(device_pixels_per_px),
|
||||
None => match self.output_file {
|
||||
Some(_) => TypedScale::new(1.0),
|
||||
Some(_) => Scale::new(1.0),
|
||||
None => self.embedder_coordinates.hidpi_factor,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn device_pixels_per_page_px(&self) -> TypedScale<f32, CSSPixel, DevicePixel> {
|
||||
fn device_pixels_per_page_px(&self) -> Scale<f32, CSSPixel, DevicePixel> {
|
||||
self.page_zoom * self.hidpi_factor()
|
||||
}
|
||||
|
||||
fn update_zoom_transform(&mut self) {
|
||||
let scale = self.device_pixels_per_page_px();
|
||||
self.scale = TypedScale::new(scale.get());
|
||||
self.scale = Scale::new(scale.get());
|
||||
}
|
||||
|
||||
pub fn on_zoom_reset_window_event(&mut self) {
|
||||
self.page_zoom = TypedScale::new(1.0);
|
||||
self.page_zoom = Scale::new(1.0);
|
||||
self.update_zoom_transform();
|
||||
self.send_window_size(WindowSizeType::Resize);
|
||||
self.update_page_zoom_for_webrender();
|
||||
}
|
||||
|
||||
pub fn on_zoom_window_event(&mut self, magnification: f32) {
|
||||
self.page_zoom = TypedScale::new(
|
||||
self.page_zoom = Scale::new(
|
||||
(self.page_zoom.get() * magnification)
|
||||
.max(MIN_ZOOM)
|
||||
.min(MAX_ZOOM),
|
||||
|
@ -1113,8 +1110,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
pub fn on_pinch_zoom_window_event(&mut self, magnification: f32) {
|
||||
self.pending_scroll_zoom_events.push(ScrollZoomEvent {
|
||||
magnification: magnification,
|
||||
scroll_location: ScrollLocation::Delta(TypedVector2D::zero()), // TODO: Scroll to keep the center in view?
|
||||
cursor: TypedPoint2D::new(-1, -1), // Make sure this hits the base layer.
|
||||
scroll_location: ScrollLocation::Delta(Vector2D::zero()), // TODO: Scroll to keep the center in view?
|
||||
cursor: Point2D::new(-1, -1), // Make sure this hits the base layer.
|
||||
event_count: 1,
|
||||
});
|
||||
}
|
||||
|
@ -1127,7 +1124,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
{
|
||||
let scroll_state = ScrollState {
|
||||
scroll_id: scroll_layer_state.id,
|
||||
scroll_offset: scroll_layer_state.scroll_offset.to_untyped(),
|
||||
scroll_offset: scroll_layer_state.scroll_offset,
|
||||
};
|
||||
|
||||
scroll_states_per_pipeline
|
||||
|
@ -1243,12 +1240,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
&mut self,
|
||||
target: CompositeTarget,
|
||||
) -> Result<Option<Image>, UnableToComposite> {
|
||||
let width = self.embedder_coordinates.framebuffer.to_u32().width_typed();
|
||||
let height = self
|
||||
.embedder_coordinates
|
||||
.framebuffer
|
||||
.to_u32()
|
||||
.height_typed();
|
||||
let size = self.embedder_coordinates.framebuffer.to_u32();
|
||||
|
||||
self.window.prepare_for_composite();
|
||||
self.webrender.update();
|
||||
|
@ -1279,8 +1271,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
#[cfg(feature = "gl")]
|
||||
CompositeTarget::WindowAndPng | CompositeTarget::PngFile => gl::initialize_png(
|
||||
&*self.window.gl(),
|
||||
FramebufferUintLength::new(width.get()),
|
||||
FramebufferUintLength::new(height.get()),
|
||||
FramebufferUintLength::new(size.width),
|
||||
FramebufferUintLength::new(size.height),
|
||||
),
|
||||
#[cfg(not(feature = "gl"))]
|
||||
_ => (),
|
||||
|
@ -1293,9 +1285,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
|| {
|
||||
debug!("compositor: compositing");
|
||||
|
||||
let size = DeviceIntSize::from_untyped(
|
||||
&self.embedder_coordinates.framebuffer.to_untyped(),
|
||||
);
|
||||
let size =
|
||||
DeviceIntSize::from_untyped(self.embedder_coordinates.framebuffer.to_untyped());
|
||||
|
||||
// Paint the scene.
|
||||
// TODO(gw): Take notice of any errors the renderer returns!
|
||||
|
@ -1346,8 +1337,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
let img = gl::draw_img(
|
||||
&*self.window.gl(),
|
||||
rt_info,
|
||||
FramebufferUintLength::new(width.get()),
|
||||
FramebufferUintLength::new(height.get()),
|
||||
FramebufferUintLength::new(size.width),
|
||||
FramebufferUintLength::new(size.height),
|
||||
);
|
||||
Some(Image {
|
||||
width: img.width(),
|
||||
|
@ -1370,8 +1361,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
let img = gl::draw_img(
|
||||
gl,
|
||||
rt_info,
|
||||
FramebufferUintLength::new(width.get()),
|
||||
FramebufferUintLength::new(height.get()),
|
||||
FramebufferUintLength::new(size.width),
|
||||
FramebufferUintLength::new(size.height),
|
||||
);
|
||||
let dynamic_image = DynamicImage::ImageRgb8(img);
|
||||
if let Err(e) = dynamic_image.write_to(&mut file, ImageFormat::PNG)
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use self::TouchState::*;
|
||||
use euclid::TypedScale;
|
||||
use euclid::{TypedPoint2D, TypedVector2D};
|
||||
use euclid::{Point2D, Scale, Vector2D};
|
||||
use script_traits::{EventResult, TouchId};
|
||||
use style_traits::DevicePixel;
|
||||
|
||||
|
@ -19,11 +18,11 @@ pub struct TouchHandler {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TouchPoint {
|
||||
pub id: TouchId,
|
||||
pub point: TypedPoint2D<f32, DevicePixel>,
|
||||
pub point: Point2D<f32, DevicePixel>,
|
||||
}
|
||||
|
||||
impl TouchPoint {
|
||||
pub fn new(id: TouchId, point: TypedPoint2D<f32, DevicePixel>) -> Self {
|
||||
pub fn new(id: TouchId, point: Point2D<f32, DevicePixel>) -> Self {
|
||||
TouchPoint {
|
||||
id: id,
|
||||
point: point,
|
||||
|
@ -60,9 +59,9 @@ pub enum TouchAction {
|
|||
/// Simulate a mouse click.
|
||||
Click,
|
||||
/// Scroll by the provided offset.
|
||||
Scroll(TypedVector2D<f32, DevicePixel>),
|
||||
Scroll(Vector2D<f32, DevicePixel>),
|
||||
/// Zoom by a magnification factor and scroll by the provided offset.
|
||||
Zoom(f32, TypedVector2D<f32, DevicePixel>),
|
||||
Zoom(f32, Vector2D<f32, DevicePixel>),
|
||||
/// Send a JavaScript event to content.
|
||||
DispatchEvent,
|
||||
/// Don't do anything.
|
||||
|
@ -77,7 +76,7 @@ impl TouchHandler {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn on_touch_down(&mut self, id: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||
pub fn on_touch_down(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) {
|
||||
let point = TouchPoint::new(id, point);
|
||||
self.active_touch_points.push(point);
|
||||
|
||||
|
@ -90,11 +89,7 @@ impl TouchHandler {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn on_touch_move(
|
||||
&mut self,
|
||||
id: TouchId,
|
||||
point: TypedPoint2D<f32, DevicePixel>,
|
||||
) -> TouchAction {
|
||||
pub fn on_touch_move(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) -> TouchAction {
|
||||
let idx = match self.active_touch_points.iter_mut().position(|t| t.id == id) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
|
@ -128,7 +123,7 @@ impl TouchHandler {
|
|||
let (d1, c1) = self.pinch_distance_and_center();
|
||||
|
||||
let magnification = d1 / d0;
|
||||
let scroll_delta = c1 - c0 * TypedScale::new(magnification);
|
||||
let scroll_delta = c1 - c0 * Scale::new(magnification);
|
||||
|
||||
TouchAction::Zoom(magnification, scroll_delta)
|
||||
},
|
||||
|
@ -145,11 +140,7 @@ impl TouchHandler {
|
|||
action
|
||||
}
|
||||
|
||||
pub fn on_touch_up(
|
||||
&mut self,
|
||||
id: TouchId,
|
||||
_point: TypedPoint2D<f32, DevicePixel>,
|
||||
) -> TouchAction {
|
||||
pub fn on_touch_up(&mut self, id: TouchId, _point: Point2D<f32, DevicePixel>) -> TouchAction {
|
||||
match self.active_touch_points.iter().position(|t| t.id == id) {
|
||||
Some(i) => {
|
||||
self.active_touch_points.swap_remove(i);
|
||||
|
@ -182,7 +173,7 @@ impl TouchHandler {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn on_touch_cancel(&mut self, id: TouchId, _point: TypedPoint2D<f32, DevicePixel>) {
|
||||
pub fn on_touch_cancel(&mut self, id: TouchId, _point: Point2D<f32, DevicePixel>) {
|
||||
match self.active_touch_points.iter().position(|t| t.id == id) {
|
||||
Some(i) => {
|
||||
self.active_touch_points.swap_remove(i);
|
||||
|
@ -225,7 +216,7 @@ impl TouchHandler {
|
|||
self.active_touch_points.len()
|
||||
}
|
||||
|
||||
fn pinch_distance_and_center(&self) -> (f32, TypedPoint2D<f32, DevicePixel>) {
|
||||
fn pinch_distance_and_center(&self) -> (f32, Point2D<f32, DevicePixel>) {
|
||||
debug_assert_eq!(self.touch_count(), 2);
|
||||
let p0 = self.active_touch_points[0].point;
|
||||
let p1 = self.active_touch_points[1].point;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! Abstract windowing methods. The concrete implementations of these can be found in `platform/`.
|
||||
|
||||
use embedder_traits::EventLoopWaker;
|
||||
use euclid::TypedScale;
|
||||
use euclid::Scale;
|
||||
#[cfg(feature = "gl")]
|
||||
use gleam::gl;
|
||||
use keyboard_types::KeyboardEvent;
|
||||
|
@ -183,7 +183,7 @@ pub trait EmbedderMethods {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct EmbedderCoordinates {
|
||||
/// The pixel density of the display.
|
||||
pub hidpi_factor: TypedScale<f32, DeviceIndependentPixel, DevicePixel>,
|
||||
pub hidpi_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>,
|
||||
/// Size of the screen.
|
||||
pub screen: DeviceIntSize,
|
||||
/// Size of the available screen space (screen without toolbars and docks).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue