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

TransformationMatrix::Recompose() and Decompose() incorrectly transpose rotation. #17162

Merged

Conversation

mattwoodrow
Copy link
Contributor

@mattwoodrow mattwoodrow commented Aug 29, 2023

a959acf

TransformationMatrix::Recompose() and Decompose() incorrectly transpose rotation.
https://bugs.webkit.org/show_bug.cgi?id=220856
<rdar://problem/73747851>

Reviewed by Dean Jackson.

The computation of quaternions during matrix decomposition appeared
to be based off of the matrix transpose. Indexing in the quaternion
calculation is consistent with row-major ordering; however, the "rows"
variable is actually column major order (goes back to the original
implementation of unmatrix in Graphics Gems II).  The rotation matrix
constructed from the quaternions also appeared to be assuming row-major
ordering. These discrepancies were mostly corrected for by flipping the
direction of the quaternion when extracting from the matrix.

This is a (partial) cherry-pick from Blink:
  - https://chromium-review.googlesource.com/c/chromium/src/+/2489727

* Source/WebCore/platform/graphics/transforms/RotateTransformOperation.cpp:
(WebCore::RotateTransformOperation::blend):
* Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp:
(WebCore::decompose4):
(WebCore::slerp):
(WebCore::accumulateQuaternion):
(WebCore::TransformationMatrix::recompose4):

Canonical link: https://commits.webkit.org/267424@main

9a4b128

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 ❌ πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@mattwoodrow mattwoodrow self-assigned this Aug 29, 2023
@mattwoodrow mattwoodrow added the Animations Bugs related to CSS + SVG animations and transitions label Aug 29, 2023
Copy link
Contributor

@smfr smfr left a comment

Choose a reason for hiding this comment

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

This should be testable.

@mattwoodrow
Copy link
Contributor Author

This should be testable.

It shouldn't cause any functional changes, since we computed the backwards quaternion in decompose, but then accumulate/slerp and RotateTransformOperation::blend all took that into account when using it.

This is just cleanup and removal of TODO's, but will make it easier to make future changes (which I have a few of locally).

@mattwoodrow
Copy link
Contributor Author

The larger blink change did this cleanup, but also did extra cleanup to their 'Quaternion' class (which we don't have), and then used all of that to fix some actual bugs with interpolation (covered by WPT).

I intend to add a Quaternion class as a followup, and then finally fix the same bugs.

@mattwoodrow mattwoodrow requested a review from smfr August 29, 2023 02:18
@@ -419,103 +419,131 @@ static bool decompose4(const TransformationMatrix::Matrix4& mat, TransformationM
result.translateZ = localMatrix[3][2];
localMatrix[3][2] = 0;

// Vector4 type and functions need to be added to the common set.
Vector3 row[3], pdum3;
// Note: Deviating from the spec in terms of variable naming. The matrix is
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we file a PR on the spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattwoodrow mattwoodrow added the merge-queue Applied to send a pull request to merge-queue label Aug 29, 2023
…se rotation.

https://bugs.webkit.org/show_bug.cgi?id=220856
<rdar://problem/73747851>

Reviewed by Dean Jackson.

The computation of quaternions during matrix decomposition appeared
to be based off of the matrix transpose. Indexing in the quaternion
calculation is consistent with row-major ordering; however, the "rows"
variable is actually column major order (goes back to the original
implementation of unmatrix in Graphics Gems II).  The rotation matrix
constructed from the quaternions also appeared to be assuming row-major
ordering. These discrepancies were mostly corrected for by flipping the
direction of the quaternion when extracting from the matrix.

This is a (partial) cherry-pick from Blink:
  - https://chromium-review.googlesource.com/c/chromium/src/+/2489727

* Source/WebCore/platform/graphics/transforms/RotateTransformOperation.cpp:
(WebCore::RotateTransformOperation::blend):
* Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp:
(WebCore::decompose4):
(WebCore::slerp):
(WebCore::accumulateQuaternion):
(WebCore::TransformationMatrix::recompose4):

Canonical link: https://commits.webkit.org/267424@main
@webkit-commit-queue
Copy link
Collaborator

Committed 267424@main (a959acf): https://commits.webkit.org/267424@main

Reviewed commits have been landed. Closing PR #17162 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit a959acf into WebKit:main Aug 29, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Animations Bugs related to CSS + SVG animations and transitions
Projects
None yet
5 participants