Skip to content

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

Merged
merged 2 commits into from
Dec 1, 2016
Merged

Conversation

nical
Copy link
Contributor

@nical nical commented Nov 28, 2016

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 Reviewable

Copy link
Member

@kvark kvark left a 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};
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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> {
Copy link
Member

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)
Copy link
Member

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

Copy link
Contributor Author

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.

@bors-servo
Copy link
Contributor

☔ 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)
Copy link
Member

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.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #585) made this pull request unmergeable. Please resolve the merge conflicts.

@glennw
Copy link
Member

glennw commented Nov 30, 2016

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.

@glennw
Copy link
Member

glennw commented Nov 30, 2016

@nical CI is failing - I guess wrench / sample / replay may need to be updated.

@nical
Copy link
Contributor Author

nical commented Nov 30, 2016

Ah, wrench landed \o/, I'm rebasing it now.

@glennw
Copy link
Member

glennw commented Dec 1, 2016

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 70caab6 has been approved by glennw

@bors-servo
Copy link
Contributor

🔒 Merge conflict

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #611) made this pull request unmergeable. Please resolve the merge conflicts.

@glennw
Copy link
Member

glennw commented Dec 1, 2016

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 28bc050 has been approved by glennw

@bors-servo
Copy link
Contributor

⚡ Test exempted - status

@bors-servo bors-servo merged commit 28bc050 into servo:master Dec 1, 2016
bors-servo pushed a commit that referenced this pull request Dec 1, 2016
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 -->
@nical nical deleted the more-units-api branch December 5, 2016 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants