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

Use strongly typed geometry - Part 2 #602

Merged
merged 2 commits into from Dec 1, 2016
Merged

Conversation

@nical
Copy link
Collaborator

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 left a comment

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};

This comment has been minimized.

Copy link
@kvark

kvark Nov 28, 2016

Member

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.

This comment has been minimized.

Copy link
@nical

nical Nov 29, 2016

Author Collaborator

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,

This comment has been minimized.

Copy link
@kvark

kvark Nov 28, 2016

Member

I believe this should really be LayerSize

This comment has been minimized.

Copy link
@nical

nical Nov 29, 2016

Author Collaborator

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);

This comment has been minimized.

Copy link
@kvark

kvark Nov 28, 2016

Member

sweeet

}
}
}

pub fn resize(&mut self, size: &Size2D<i32>) -> Result<(), &'static str> {
pub fn resize(&mut self, size: &DeviceIntSize) -> Result<(), &'static str> {

This comment has been minimized.

Copy link
@kvark

kvark Nov 28, 2016

Member

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)

This comment has been minimized.

Copy link
@kvark

kvark Nov 28, 2016

Member

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

This comment has been minimized.

Copy link
@nical

nical Nov 29, 2016

Author Collaborator

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

bors-servo commented Nov 28, 2016

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)

This comment has been minimized.

Copy link
@glennw

glennw Nov 28, 2016

Member

cursor is in world space.

@nical nical force-pushed the nical:more-units-api branch from ddd39f9 to 3c613a9 Nov 29, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Nov 29, 2016

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.

@nical nical force-pushed the nical:more-units-api branch from 3c613a9 to b5bd8ff Nov 30, 2016
@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
Collaborator 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
Copy link
Contributor

bors-servo commented Dec 1, 2016

📌 Commit 70caab6 has been approved by glennw

@bors-servo
Copy link
Contributor

bors-servo commented Dec 1, 2016

🔒 Merge conflict

@bors-servo
Copy link
Contributor

bors-servo commented Dec 1, 2016

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

@nical nical force-pushed the nical:more-units-api branch from 70caab6 to 28bc050 Dec 1, 2016
@glennw
Copy link
Member

glennw commented Dec 1, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 1, 2016

📌 Commit 28bc050 has been approved by glennw

@bors-servo
Copy link
Contributor

bors-servo commented Dec 1, 2016

Test exempted - status

@bors-servo bors-servo merged commit 28bc050 into servo:master Dec 1, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test exempted
Details
bors-servo added 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 nical:more-units-api branch Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.