-
Notifications
You must be signed in to change notification settings - Fork 290
Use strongly typed geometry - Part 2 #602
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great in general, got a few things to address
use gleam::gl; | ||
use std::io::Read; | ||
use std::fs::File; | ||
use std::path::{Path, PathBuf}; | ||
use std::env; | ||
use webrender_traits::{RenderApi, PipelineId}; | ||
use webrender_traits::{RenderApi, PipelineId, LayerSize, DeviceUintSize}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having DeviceIntRect
, DeviceUintRect
, and just DeviceRect
now, the first thing that comes to mind is that the latter is inconsistent. Would be more consistent if it was DeviceFloatRect
. But really, it would be much simpler to just have DeviceRect<i32>
, DeviceRect<u32>
, and so forth - we'd still get the safe units but with somewhat clearer semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand this is the naming convention used for all geometry in Gecko which is a different kind of consistency but an appreciable one if gecko and servo are to share more code in the future.
The rationale is that we tend to manipulate float-based geometry more often so they get the short name. Typically there is no need for, say, a LayoutIntPoint (and we probably don't really need DeviceUintPoint as the choice between DeviceIntPoint and DeviceUintPoint is a bit inconsistent right now. In gecko we just used signed integers and floats for geometries).
I'm not found of typing "<>" brackets all over the place but I admit that's hardly an argument.
Let's open a separate issue about this and change it if enough people feel strongly one way or another.
@@ -331,8 +331,8 @@ impl Frame { | |||
|
|||
/// Returns true if any layers actually changed position or false otherwise. | |||
pub fn scroll(&mut self, | |||
mut delta: Point2D<f32>, | |||
cursor: Point2D<f32>, | |||
mut delta: LayerPoint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should really be LayerSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have proposed the addition of vector classes in euclid (separate from points which are currently used as vectors in a lot of places when size types are not used instead). The pull request is open and hopefully we can bikeshed and maybe merge it by the end of the workweek.
Let's wait a little bit before fixing the insistent point-vs-size-for-vectors situation.
@@ -472,9 +472,9 @@ impl Frame { | |||
// Insert global position: fixed elements layer | |||
debug_assert!(self.layers.is_empty()); | |||
let root_fixed_layer_id = ScrollLayerId::create_fixed(root_pipeline_id); | |||
let root_viewport = LayerRect::new(LayerPoint::zero(), LayerSize::from_untyped(&root_pipeline.viewport_size)); | |||
let root_viewport = LayerRect::new(LayerPoint::zero(), root_pipeline.viewport_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweeet
} | ||
} | ||
} | ||
|
||
pub fn resize(&mut self, size: &Size2D<i32>) -> Result<(), &'static str> { | ||
pub fn resize(&mut self, size: &DeviceIntSize) -> Result<(), &'static str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it rubs me the wrong way to see Int
there, but I can see that it was this way before you
@@ -207,8 +207,8 @@ impl RenderApi { | |||
} | |||
|
|||
/// Translates a point from viewport coordinates to layer space | |||
pub fn translate_point_to_layer_space(&self, point: &Point2D<f32>) | |||
-> (Point2D<f32>, PipelineId) { | |||
pub fn translate_point_to_layer_space(&self, point: &LayoutPoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, this one makes me worried. The function is supposed to translate a point from one space to another, yet our type system does not reflect that here, using LayoutPoint
on both ends
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I think that it should take a WorldPoint and return a LayoutPoint. I made the change locally, that said the implementation is panic!("unused api - remove from webrender_traits");
so I guess it won't stick around for long.
☔ The latest upstream changes (presumably #595) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -236,7 +236,7 @@ impl Frame { | |||
old_layer_scrolling_states | |||
} | |||
|
|||
pub fn get_scroll_layer(&self, cursor: &Point2D<f32>, scroll_layer_id: ScrollLayerId) | |||
pub fn get_scroll_layer(&self, cursor: &LayerPoint, scroll_layer_id: ScrollLayerId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cursor is in world space.
ddd39f9
to
3c613a9
Compare
☔ The latest upstream changes (presumably #585) made this pull request unmergeable. Please resolve the merge conflicts. |
Although there's a couple of rough edges in places, this seems like a net improvement - let's get it rebased and then I'll merge it. |
3c613a9
to
b5bd8ff
Compare
@nical CI is failing - I guess wrench / sample / replay may need to be updated. |
Ah, wrench landed \o/, I'm rebasing it now. |
@bors-servo r+ |
📌 Commit 70caab6 has been approved by |
🔒 Merge conflict |
☔ The latest upstream changes (presumably #611) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors-servo r+ |
📌 Commit 28bc050 has been approved by |
⚡ Test exempted - status |
Use strongly typed geometry - Part 2 Use strongly typed geometry in the public API. This changeset adds the LayoutPixel unit which is basically an alias to LayerPixel. I think that it's best to keep the "Layer" terminology internal to webrender, and since the 1-1 correspondence between the api's layout pixels and internal layer pixels is somewhat coincidental, it will help to have separate names if things like async zoom introduce an actual difference between the two coordinate spaces (as it does in Gecko). Using an alias instead of a separate type comes from a mix of laziness (not having to cast from layout t layer pixels all over frame.rs) and the fact that currently layer and layout pixels are the same thing, but I'll add a separate unit if there is a preference for it. I did not introduce ParentLayoutPixel. I don't know the API well enough yet to be sure whether some geometry is passed in a stacking context's parent coordinate space, but if so we should consider introducing a special unit for it, if only for the sake of proper documentation. This PR is a lot easier to rebase than part 1 and is a breaking change to the public API, so it's fine to wait a bit if there are cross-crates changes that we want to coordinate before having to adapt servo to this (although it should be easy to do). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/602) <!-- Reviewable:end -->
Use strongly typed geometry in the public API. This changeset adds the LayoutPixel unit which is basically an alias to LayerPixel.
I think that it's best to keep the "Layer" terminology internal to webrender, and since the 1-1 correspondence between the api's layout pixels and internal layer pixels is somewhat coincidental, it will help to have separate names if things like async zoom introduce an actual difference between the two coordinate spaces (as it does in Gecko). Using an alias instead of a separate type comes from a mix of laziness (not having to cast from layout t layer pixels all over frame.rs) and the fact that currently layer and layout pixels are the same thing, but I'll add a separate unit if there is a preference for it.
I did not introduce ParentLayoutPixel. I don't know the API well enough yet to be sure whether some geometry is passed in a stacking context's parent coordinate space, but if so we should consider introducing a special unit for it, if only for the sake of proper documentation.
This PR is a lot easier to rebase than part 1 and is a breaking change to the public API, so it's fine to wait a bit if there are cross-crates changes that we want to coordinate before having to adapt servo to this (although it should be easy to do).
This change is