-
Notifications
You must be signed in to change notification settings - Fork 35
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 truncation instead of rounding to resolve percentages into app units #102
Conversation
Since we want to test this before publishing a new release of app units, let's inline the code here for now. |
BTW, when creating a PR it's better not to use your main branch. |
Signed-off-by: Oriol Brufau <[email protected]>
Signed-off-by: Oriol Brufau <[email protected]>
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 may make more sense to modify this instead:
stylo/style/values/computed/length.rs
Lines 496 to 501 in 7e529e8
impl From<CSSPixelLength> for Au { | |
#[inline] | |
fn from(len: CSSPixelLength) -> Self { | |
Au::from_f32_px(len.0) | |
} | |
} |
I thought that would be more likely to affect Firefox, but I have tried commenting that (and its callers) out, and Firefox compiles fine, so it's not used.
6259dd8
to
8fd98ee
Compare
I'm sorry that the code you commit is overwitten by mistake, can you push the code again? @Loirooriol |
What code, 83dad25 ? |
Yes. And this opration that truncate in au construction not only in the percentage will expose another problem of #servo34714. The parameter of Timing Function style is f32 while it is f64 data type used in bezier function calculation. Loss can be produced in this progress. Could we just use truncate method in percentage, just like firefox? |
Sure, you can try that. But currently the logic first resolves LengthPercentage into a Length and then to an Au. You will need to remove the middle step. |
Signed-off-by: Asun0204 <[email protected]>
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Signed-off-by: Oriol Brufau <[email protected]>
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Signed-off-by: Oriol Brufau <[email protected]>
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Signed-off-by: Oriol Brufau <[email protected]>
6cf7f42
to
5e04a73
Compare
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.
Don't revert e2c385d
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.
The PR is still including unrelated commits.
Do we need to test the code? change truncate conversion to appunit from float in percentage calcuation is the final version code and the other commits are used fo testing temporary. |
Remove f588e85 |
I don't know what's going on with f588e85 but there is a lot of crates in this commit. It can not compile without it. |
You need to rebase your changes on top of the latest |
I completed it. There is only one commit base on the latest main. Do we need to import app_units pr? |
.map(Au::from) | ||
if let Unpacked::Percentage(_) = self.unpack() { | ||
return self.maybe_percentage_relative_to(container_len.map(Length::from)) | ||
.map(|length| Au::from_f32_px_trunc(length.px())); |
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.
This won't compile because the app_units PR hasn't landed.
Please make sure everything compiles so that I can run tests.
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 push a commit to import app_units pr for compiling it.
It's ok now.
if let Unpacked::Percentage(_) = self.unpack() { | ||
return self.maybe_percentage_relative_to(container_len.map(Length::from)) | ||
.map(|length| Au::from_f32_px_trunc(length.px())); | ||
} | ||
self.maybe_percentage_relative_to(container_len.map(Length::from)).map(Au::from) |
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.
No need to repeat self.maybe_percentage_relative_to(container_len.map(Length::from))
if let Unpacked::Percentage(_) = self.unpack() { | |
return self.maybe_percentage_relative_to(container_len.map(Length::from)) | |
.map(|length| Au::from_f32_px_trunc(length.px())); | |
} | |
self.maybe_percentage_relative_to(container_len.map(Length::from)).map(Au::from) | |
self.maybe_percentage_relative_to(container_len.map(Length::from)) | |
.map(if let Unpacked::Percentage(_) = self.unpack() { | |
|length| Au::from_f32_px_trunc(length.px()) | |
} else { | |
Length::from | |
}) | |
} |
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.
fixed.
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.
Also you should cover to_used_value
for consistency.
if let Unpacked::Percentage(_) = self.unpack() { | ||
return Au::from_f32_px_trunc(self.to_pixel_length(containing_length).px()); | ||
} | ||
Au::from(self.to_pixel_length(containing_length)) |
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 would also avoid repeating self.to_pixel_length(containing_length)
here:
if let Unpacked::Percentage(_) = self.unpack() { | |
return Au::from_f32_px_trunc(self.to_pixel_length(containing_length).px()); | |
} | |
Au::from(self.to_pixel_length(containing_length)) | |
let value = self.to_pixel_length(containing_length); | |
if let Unpacked::Percentage(_) = self.unpack() { | |
Au::from_f32_px_trunc(value.px()); | |
} else { | |
Au::from(value) | |
} |
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.
fixed
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.
app_units 0.7.8 has been released, so you can upgrade to it.
Also please use a clearer title like "Use truncation instead of rounding to resolve percentages into app units" or similar.
You keep using "calcuation" instead of "calculation". |
Signed-off-by: Asun0204 <[email protected]>
servo/stylo@a93e7ef...4add86f - servo/stylo#134 Remove unnecessary imports - servo/stylo#133 Reinstate missing gecko-specific import - servo/stylo#135 fix: add atoms "show" - servo/stylo#102 Use truncation instead of rounding to resolve percentages into app units Signed-off-by: Oriol Brufau <[email protected]>
servo/stylo@a93e7ef...4add86f - servo/stylo#134 Remove unnecessary imports - servo/stylo#133 Reinstate missing gecko-specific import - servo/stylo#135 fix: add atoms "show" - servo/stylo#102 Use truncation instead of rounding to resolve percentages into app units Signed-off-by: Oriol Brufau <[email protected]> Co-authored-by: Oriol Brufau <[email protected]>
change conversion to appunit from float of percentage calcuation, prevent child box size is calculated too large.
Servo PR: servo/servo#34714