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 truncation instead of rounding to resolve percentages into app units #102

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

Asun0204
Copy link
Contributor

@Asun0204 Asun0204 commented Dec 26, 2024

change conversion to appunit from float of percentage calcuation, prevent child box size is calculated too large.

Servo PR: servo/servo#34714

@Asun0204 Asun0204 changed the title [fixbug] change conversion to appunit from float of percentage calcuation change conversion to appunit from float of percentage calcuation Dec 26, 2024
@Loirooriol
Copy link
Contributor

Since we want to test this before publishing a new release of app units, let's inline the code here for now.

@Loirooriol
Copy link
Contributor

BTW, when creating a PR it's better not to use your main branch.

Loirooriol added a commit to Asun0204/servo that referenced this pull request Jan 8, 2025
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Loirooriol added a commit to Asun0204/servo that referenced this pull request Jan 8, 2025
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Copy link
Contributor

@Loirooriol Loirooriol left a 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:

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.

@Asun0204
Copy link
Contributor Author

Asun0204 commented Feb 10, 2025

I'm sorry that the code you commit is overwitten by mistake, can you push the code again? @Loirooriol

@Loirooriol
Copy link
Contributor

What code, 83dad25 ?

@Asun0204
Copy link
Contributor Author

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?

@Loirooriol
Copy link
Contributor

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.

Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
Signed-off-by: Asun0204 <asun0204@163.com>
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 pushed a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux", "workflow": "linux", "wpt_layout": "none", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 pushed a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 added a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
{"fail_fast": false, "matrix": [{"name": "Linux (WPT)", "workflow": "linux", "wpt_layout": "2020", "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "wpt_args": ""}]}
Asun0204 pushed a commit to Asun0204/servo that referenced this pull request Feb 11, 2025
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
@Asun0204 Asun0204 force-pushed the main branch 3 times, most recently from 6cf7f42 to 5e04a73 Compare March 4, 2025 09:05
Copy link
Contributor

@Loirooriol Loirooriol left a 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

Copy link
Contributor

@Loirooriol Loirooriol left a 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.

@Asun0204
Copy link
Contributor Author

Asun0204 commented Mar 4, 2025

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.

@Loirooriol
Copy link
Contributor

Remove f588e85

@Asun0204
Copy link
Contributor Author

Asun0204 commented Mar 4, 2025

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.

@Loirooriol
Copy link
Contributor

You need to rebase your changes on top of the latest main (0190fff).

@Asun0204
Copy link
Contributor Author

Asun0204 commented Mar 4, 2025

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

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.

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 push a commit to import app_units pr for compiling it.
It's ok now.

Comment on lines 533 to 537
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)
Copy link
Contributor

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

Suggested change
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
})
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Copy link
Contributor

@Loirooriol Loirooriol left a 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.

Comment on lines 521 to 524
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))
Copy link
Contributor

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:

Suggested change
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)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@Loirooriol Loirooriol left a 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.

@Loirooriol
Copy link
Contributor

You keep using "calcuation" instead of "calculation".
But just avoid this word since it seems to refer to calc() and this is about plain percentages.
Also "float of percentage" is confusing.

@Loirooriol Loirooriol changed the title change conversion to appunit from float of percentage calcuation Use truncation instead of rounding to resolve percentages into app units Mar 11, 2025
@Loirooriol Loirooriol added this pull request to the merge queue Mar 11, 2025
Merged via the queue into servo:main with commit 4add86f Mar 11, 2025
3 checks passed
Loirooriol added a commit to Asun0204/servo that referenced this pull request Mar 11, 2025
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 <obrufau@igalia.com>
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Mar 11, 2025
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 <obrufau@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
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.

2 participants