Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement matrix decomposition and interpolation #13188
Conversation
highfive
commented
Sep 6, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Sep 6, 2016
| @@ -751,12 +769,236 @@ impl Interpolate for LengthOrNone { | |||
| } | |||
| } else { | |||
| // TODO(gw): Implement matrix decomposition and interpolation | |||
| // TODO(canaltinova): Do I need to interpolate each item of the list? | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| let mut fd_matrix = ComputedMatrix::identity(); | ||
| let mut td_matrix = ComputedMatrix::identity(); | ||
| fd_matrix.m43 = -1. / fd.0 as f32; | ||
| td_matrix.m43 = -1. / _td.0 as f32; |
This comment has been minimized.
This comment has been minimized.
canova
Sep 6, 2016
Author
Member
I had to convert Au value to f32 but I'm not sure if it's correct or not.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -701,8 +703,11 @@ impl Interpolate for LengthOrNone { | |||
| match (from, to) { | |||
| (&TransformOperation::Matrix(from), | |||
| &TransformOperation::Matrix(_to)) => { | |||
| // TODO(gw): Implement matrix decomposition and interpolation | |||
| result.push(TransformOperation::Matrix(from)); | |||
| let decomposed_from = MatrixDecomposed2D::from(from); | |||
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 7, 2016
Member
leave comments that it doesn't yet handle cases where one of the two matrices is not 2D
|
|
||
| let decomposed_f = MatrixDecomposed2D::from(matrix_f); | ||
| let decomposed_t = MatrixDecomposed2D::from(matrix_t); | ||
| let interpolated = decomposed_f.interpolate(&decomposed_t, time).unwrap(); |
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 7, 2016
Member
this code is common (and will get more complicated when we handle 3d interpolation), perhaps we should implement Interpolate for ComputedMatrix?
| result.extend_from_slice(from_list); | ||
| } | ||
|
|
||
| TransformList(Some(result)) | ||
| } | ||
|
|
||
| fn rotate_to_matrix(x: f32, y: f32, z: f32, a: SpecifiedAngle) -> ComputedMatrix { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 7, 2016
•
Member
We could probably just use the same code from layout/display_list_builder.rs?
let theta = 2.0f32 * f32::consts::PI - theta.radians();
Matrix4D::create_rotation(ax, ay, az, Radians::new(theta))
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 7, 2016
Member
Or just leave a spec link to https://drafts.csswg.org/css-transforms/#Rotate3dDefined
| let sq = 1.0 / 2.0 * (1.0 - (rad).cos()); | ||
|
|
||
| ComputedMatrix { | ||
| m11: 1.0 - 2.0 * (y * y + z * z) * sq, m12: 2.0 * (x * y * sq - z * sc), |
This comment has been minimized.
This comment has been minimized.
|
|
||
| #[derive(Clone, Copy, Debug)] | ||
| #[cfg_attr(feature = "servo", derive(HeapSizeOf))] | ||
| pub struct DecomposedMatrix { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
canova
Sep 7, 2016
Author
Member
I tried it but rust is not allowing structs to start with integer value(It's same with MatrixDecomposed2D. I tried 2DMatrixDecomposed but couldn't make it), so I'll change it to InnerMatrix2D, if it's ok.
This comment has been minimized.
This comment has been minimized.
| // Translate matrix. | ||
| computed_matrix.m41 = decomposed.translate.0 * decomposed.matrix.m11 + | ||
| decomposed.translate.1 * decomposed.matrix.m21; | ||
| computed_matrix.m42 = decomposed.translate.0 * decomposed.matrix.m11 + |
This comment has been minimized.
This comment has been minimized.
|
Looks correct aside from a few issues. Once those are fixed, could you test this with various matrices (those which are guaranteed to follow the "is 2d matrix" property in the spec) and ensure the animation matches the one firefox does. (Alternatively, just implement the 3D one too so that it's easier to test) There aren't unit tests in firefox (probably are reftests though). I can maybe generate some test data by logging https://dxr.mozilla.org/mozilla-central/source/layout/style/StyleAnimationValue.cpp#1634, but it's not entirely necessary for now. |
|
Firefox's |
…ations
|
Fixed issues except using |
|
Yeah, ignore my comment about create_rotation, it's fine the way it is. |
For now, don't write unit tests -- just test it manually with simple transitions (https://robots.thoughtbot.com/transitions-and-transforms). Have a div which moves between two matrices or something |
|
It might be better to first implement the 3D interpolation, so that we can test all cases. I'll test this one for you for now. |
|
Ok, thanks! So should I implement 3D interpolation in this pull request too or is it better to make it in another pr? |
|
Same PR is fine. I don't want to merge this unless I'm able to manually test it (or we have unit tests), and it may take a few days for me to get time for that, so you can just append to this PR |
|
Ok, I will work on interpolation of 3D matrices now on. So I have to determine in |
|
Thanks, I'll look at it! |
|
@bors-servo try |
Implement matrix decomposition and interpolation <!-- Please describe your changes on the following line: --> Implement 2D and 3D matrix decomposition and interpolation for animated properties. r? @Manishearth --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13188) <!-- Reviewable:end -->
|
|
|
css build still ongoing |
|
The CSS build passed. |
|
Webkit's 2d recomposition agrees with ours wrt translate. Additionally, webkit (well, safari) doesn't seem to have this bug |
|
Overall https://github.com/WebKit/webkit/blob/284f456f1d22f45d2a68cf6d88bafc49a63ee018/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp is a pretty good bit of code which is close to matching the spec. Or perhaps the spec was written by looking at this code. |
|
Anyway, I'm good with merging this (once I test it out myself on your testcases), could you squash (just the last two commits is fine). Though squashing isn't necessary here, so I might just merge directly -- let me know what you prefer. Thanks! |
|
@bors-servo r+ Everything from your pastebin passes now, except for one. There's a bit of an jump with
however it's a 3D transform and Servo has issues with those anyway. It's also 2D->3D which is broken in other browsers. I'd rather wait for the spec to figure this stuff out before fixing this. I'm not sure if it's even an issue, because the transition keeps flickering so I'm not sure if it's a jump or a flicker. Thanks for sticking with this! Great work! |
|
|
|
@bors-servo r+ |
|
|
Implement matrix decomposition and interpolation <!-- Please describe your changes on the following line: --> Implement 2D and 3D matrix decomposition and interpolation for animated properties. r? @Manishearth --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because there are no tests for it and we manually tested it. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13188) <!-- Reviewable:end -->
|
|
|
|
canova commentedSep 6, 2016
•
edited
Implement 2D and 3D matrix decomposition and interpolation for animated properties.
r? @Manishearth
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is