Changeset 271941 in webkit


Ignore:
Timestamp:
Jan 27, 2021 3:04:16 AM (3 years ago)
Author:
commit-queue@webkit.org
Message:

Complete WebXRRigidTransform implementation
https://bugs.webkit.org/show_bug.cgi?id=220732
<rdar://problem/73617302>

Patch by Imanol Fernandez <imanol> on 2021-01-27
Reviewed by Sergio Villar Senin.

LayoutTests/imported/w3c:

Enable XRRigidTransform WebXR tests.

  • web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt: Added.
  • web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt: Added.

Source/WebCore:

  • Implement XRRigidTransform.inverse().
  • Expose raw matrix to be used in other WebXR math calculations (e.g pose composition).
  • Correctly lazily initialize and reuse the Float32Array matrixData.

Tested by the WebXR platform tests.

  • Modules/webxr/WebXRRigidTransform.cpp:

(WebCore::normalizeQuaternion):
(WebCore::WebXRRigidTransform::create):
(WebCore::WebXRRigidTransform::WebXRRigidTransform):
(WebCore::m_orientation):
(WebCore::m_rawTransform):
(WebCore::WebXRRigidTransform::matrix):
(WebCore::WebXRRigidTransform::inverse):
(WebCore::WebXRRigidTransform::rawTransform const):

  • Modules/webxr/WebXRRigidTransform.h:
  • platform/graphics/transforms/TransformationMatrix.cpp:

(WebCore::TransformationMatrix::fromQuaternion):

  • platform/graphics/transforms/TransformationMatrix.h:

LayoutTests:

Enable XRRigidTransform WebXR tests.

  • platform/wpe/TestExpectations:
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r271940 r271941  
     12021-01-27  Imanol Fernandez  <ifernandez@igalia.com>
     2
     3        Complete WebXRRigidTransform implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=220732
     5        <rdar://problem/73617302>
     6
     7        Reviewed by Sergio Villar Senin.
     8
     9        Enable XRRigidTransform WebXR tests.
     10
     11        * platform/wpe/TestExpectations:
     12
    1132021-01-27  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r271936 r271941  
     12021-01-27  Imanol Fernandez  <ifernandez@igalia.com>
     2
     3        Complete WebXRRigidTransform implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=220732
     5        <rdar://problem/73617302>
     6
     7        Reviewed by Sergio Villar Senin.
     8
     9        Enable XRRigidTransform WebXR tests.
     10
     11        * web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt: Added.
     12        * web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt: Added.
     13
    1142021-01-27  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/LayoutTests/platform/wpe/TestExpectations

    r271671 r271941  
    641641imported/w3c/web-platform-tests/webxr/xrFrame_session_sameObject.https.html [ Pass ]
    642642imported/w3c/web-platform-tests/webxr/xrRigidTransform_constructor.https.html [ Pass ]
     643imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https.html [ Pass ]
     644imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https.html [ Pass ]
    643645imported/w3c/web-platform-tests/webxr/xrSession_prevent_multiple_exclusive.https.html [ Pass ]
    644646imported/w3c/web-platform-tests/webxr/render_state_vertical_fov_immersive.https.html [ Pass ]
  • trunk/Source/WebCore/ChangeLog

    r271939 r271941  
     12021-01-27  Imanol Fernandez  <ifernandez@igalia.com>
     2
     3        Complete WebXRRigidTransform implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=220732
     5        <rdar://problem/73617302>
     6
     7        Reviewed by Sergio Villar Senin.
     8
     9        - Implement XRRigidTransform.inverse().
     10        - Expose raw matrix to be used in other WebXR math calculations (e.g pose composition).
     11        - Correctly lazily initialize and reuse the Float32Array matrixData.
     12
     13        Tested by the WebXR platform tests.
     14
     15        * Modules/webxr/WebXRRigidTransform.cpp:
     16        (WebCore::normalizeQuaternion):
     17        (WebCore::WebXRRigidTransform::create):
     18        (WebCore::WebXRRigidTransform::WebXRRigidTransform):
     19        (WebCore::m_orientation):
     20        (WebCore::m_rawTransform):
     21        (WebCore::WebXRRigidTransform::matrix):
     22        (WebCore::WebXRRigidTransform::inverse):
     23        (WebCore::WebXRRigidTransform::rawTransform const):
     24        * Modules/webxr/WebXRRigidTransform.h:
     25        * platform/graphics/transforms/TransformationMatrix.cpp:
     26        (WebCore::TransformationMatrix::fromQuaternion):
     27        * platform/graphics/transforms/TransformationMatrix.h:
     28
    1292021-01-27  Andy Estes  <aestes@apple.com>
    230
  • trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp

    r258498 r271941  
    3636namespace WebCore {
    3737
     38static bool normalizeQuaternion(DOMPointInit& q)
     39{
     40    const double length = std::sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
     41    if (WTF::areEssentiallyEqual<double>(length, 0))
     42        return false;
     43    q.x /= length;
     44    q.y /= length;
     45    q.z /= length;
     46    q.w /= length;
     47    return true;
     48}
     49
    3850WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRRigidTransform);
    3951
     
    4254    return adoptRef(*new WebXRRigidTransform({ }, { }));
    4355}
     56
     57Ref<WebXRRigidTransform> WebXRRigidTransform::create(const TransformationMatrix& transform)
     58{
     59    return adoptRef(*new WebXRRigidTransform(transform));
     60}
     61
    4462
    4563ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPointInit& position, const DOMPointInit& orientation)
     
    5977    //   7. Normalize x, y, z, and w components of transform’s orientation.
    6078    DOMPointInit orientationInit { orientation.x, orientation.y, orientation.z, orientation.w };
    61     {
    62         double length = std::sqrt(orientationInit.x * orientationInit.x + orientationInit.y * orientationInit.y
    63             + orientationInit.z * orientationInit.z + orientationInit.w * orientationInit.w);
    64         if (WTF::areEssentiallyEqual<double>(length, 0))
    65             return Exception { InvalidStateError };
    66 
    67         orientationInit= {
    68             orientationInit.x / length, orientationInit.y / length,
    69             orientationInit.z / length, orientationInit.w / length,
    70         };
    71     }
     79    if (!normalizeQuaternion(orientationInit))
     80        return Exception { InvalidStateError };
    7281
    7382    //   8. Return transform.
     
    7988    , m_orientation(DOMPointReadOnly::create(orientation))
    8089{
    81     // FIXME: implement properly, per spec.
    82     TransformationMatrix matrix;
    83     auto matrixData = matrix.toColumnMajorFloatArray();
    84     m_matrix = Float32Array::create(matrixData.data(), matrixData.size());
     90    TransformationMatrix translation;
     91    translation.translate3d(position.x, position.y, position.z);
     92    auto rotation = TransformationMatrix::fromQuaternion(orientation.x, orientation.y, orientation.z, orientation.w);
     93    m_rawTransform = translation * rotation;
     94}
     95
     96WebXRRigidTransform::WebXRRigidTransform(const TransformationMatrix& transform)
     97    : m_position(DOMPointReadOnly::create({ }))
     98    , m_orientation(DOMPointReadOnly::create({ }))
     99    , m_rawTransform(transform)
     100{
     101    if (transform.isIdentity()) {
     102        // TransformationMatrix::decompose returns a empty quaternion instead of unit quaternion for Identity.
     103        // WebXR tests expect a unit quaternion for this case.
     104        return;
     105    }
     106
     107    TransformationMatrix::Decomposed4Type decomp = { };
     108    transform.decompose4(decomp);
     109
     110    m_position = DOMPointReadOnly::create(decomp.translateX, decomp.translateY, decomp.translateZ, 1.0f);
     111
     112    DOMPointInit orientationInit { -decomp.quaternionX, -decomp.quaternionY, -decomp.quaternionZ, decomp.quaternionW };
     113    normalizeQuaternion(orientationInit);
     114    m_orientation = DOMPointReadOnly::create(orientationInit);
    85115}
    86116
     
    97127}
    98128
    99 Ref<Float32Array>  WebXRRigidTransform::matrix() const
     129const Float32Array& WebXRRigidTransform::matrix()
    100130{
    101     auto matrix = Float32Array::create(16);
    102     matrix->zeroFill();
    103     return matrix;
     131    if (m_matrix && !m_matrix->isDetached())
     132        return *m_matrix;
     133
     134    // Lazily create matrix Float32Array.
     135    auto matrixData = m_rawTransform.toColumnMajorFloatArray();
     136    m_matrix = Float32Array::create(matrixData.data(), matrixData.size());
     137
     138    return *m_matrix;
    104139}
    105140
    106 Ref<WebXRRigidTransform> WebXRRigidTransform::inverse() const
     141const WebXRRigidTransform& WebXRRigidTransform::inverse()
    107142{
    108     // FIXME: implement properly.
    109     return WebXRRigidTransform::create();
     143    // The inverse of a inverse object should return the original object.
     144    if (m_parentInverse)
     145        return *m_parentInverse;
     146
     147    // Inverse should always return the same object.
     148    if (m_inverse)
     149        return *m_inverse;
     150   
     151    auto inverseTransform = m_rawTransform.inverse();
     152    ASSERT(!!inverseTransform);
     153
     154    m_inverse = WebXRRigidTransform::create(*inverseTransform);
     155    // The inverse of a inverse object should return the original object.
     156    m_inverse->m_parentInverse = makeWeakPtr(this);
     157
     158    return *m_inverse;
     159}
     160
     161const TransformationMatrix& WebXRRigidTransform::rawTransform() const
     162{
     163    return m_rawTransform;
    110164}
    111165
  • trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.h

    r270067 r271941  
    2929
    3030#include "ExceptionOr.h"
     31#include "TransformationMatrix.h"
    3132#include <JavaScriptCore/Float32Array.h>
    3233#include <wtf/IsoMalloc.h>
    3334#include <wtf/RefCounted.h>
     35#include <wtf/WeakPtr.h>
    3436
    3537namespace WebCore {
     
    3840class DOMPointReadOnly;
    3941
    40 class WebXRRigidTransform : public RefCounted<WebXRRigidTransform> {
     42class WebXRRigidTransform : public RefCounted<WebXRRigidTransform>, public CanMakeWeakPtr<WebXRRigidTransform> {
    4143    WTF_MAKE_ISO_ALLOCATED_EXPORT(WebXRRigidTransform, WEBCORE_EXPORT);
    4244public:
    4345    static Ref<WebXRRigidTransform> create();
     46    static Ref<WebXRRigidTransform> create(const TransformationMatrix&);
    4447    WEBCORE_EXPORT static ExceptionOr<Ref<WebXRRigidTransform>> create(const DOMPointInit&, const DOMPointInit&);
    4548    WEBCORE_EXPORT ~WebXRRigidTransform();
     
    4750    const DOMPointReadOnly& position() const;
    4851    const DOMPointReadOnly& orientation() const;
    49     Ref<Float32Array> matrix() const;
    50     Ref<WebXRRigidTransform> inverse() const;
     52    const Float32Array& matrix();
     53    const WebXRRigidTransform& inverse();
     54    const TransformationMatrix& rawTransform() const;
    5155
    5256private:
    5357    WebXRRigidTransform(const DOMPointInit&, const DOMPointInit&);
     58    WebXRRigidTransform(const TransformationMatrix&);
    5459
    5560    Ref<DOMPointReadOnly> m_position;
    5661    Ref<DOMPointReadOnly> m_orientation;
     62    TransformationMatrix m_rawTransform;
    5763    RefPtr<Float32Array> m_matrix;
     64    RefPtr<WebXRRigidTransform> m_inverse;
     65    WeakPtr<WebXRRigidTransform> m_parentInverse;
    5866};
    5967
  • trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp

    r270801 r271941  
    579579{
    580580    setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f());
     581}
     582
     583
     584// FIXME: Once https://bugs.webkit.org/show_bug.cgi?id=220856 is addressed we can reuse this function in TransformationMatrix::recompose4().
     585TransformationMatrix TransformationMatrix::fromQuaternion(double qx, double qy, double qz, double qw)
     586{
     587    const double xx = qx * qx;
     588    const double yy = qy * qy;
     589    const double zz = qz * qz;
     590    const double xz = qx * qz;
     591    const double xy = qx * qy;
     592    const double yz = qy * qz;
     593    const double xw = qw * qx;
     594    const double yw = qw * qy;
     595    const double zw = qw * qz;
     596
     597    return TransformationMatrix(1 - 2 * (yy + zz), 2 * (xy + zw), 2 * (xz - yw), 0,
     598        2 * (xy - zw), 1 - 2 * (xx + zz), 2 * (yz + xw), 0,
     599        2 * (xz + yw), 2 * (yz - xw), 1 - 2 * (xx + yy), 0,
     600        0, 0, 0, 1);
    581601}
    582602
  • trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h

    r266513 r271941  
    119119
    120120    WEBCORE_EXPORT TransformationMatrix(const AffineTransform&);
     121
     122    static TransformationMatrix fromQuaternion(double qx, double qy, double qz, double qw);
    121123
    122124    static const TransformationMatrix identity;
Note: See TracChangeset for help on using the changeset viewer.