| Differences between
and this patch
- a/Source/WebCore/ChangeLog +28 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2021-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 NOBODY (OOPS!).
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
1
2021-01-27  Andy Estes  <aestes@apple.com>
29
2021-01-27  Andy Estes  <aestes@apple.com>
2
30
3
        [Mac] MediaSampleCursor::stepInOrderedMap can hang when stepping to the end of a track that hasn't been fully parsed
31
        [Mac] MediaSampleCursor::stepInOrderedMap can hang when stepping to the end of a track that hasn't been fully parsed
- a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp -22 / +76 lines
Lines 35-40 a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp_sec1
35
35
36
namespace WebCore {
36
namespace WebCore {
37
37
38
static 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
38
WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRRigidTransform);
50
WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRRigidTransform);
39
51
40
Ref<WebXRRigidTransform> WebXRRigidTransform::create()
52
Ref<WebXRRigidTransform> WebXRRigidTransform::create()
Lines 42-47 Ref<WebXRRigidTransform> WebXRRigidTransform::create() a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp_sec2
42
    return adoptRef(*new WebXRRigidTransform({ }, { }));
54
    return adoptRef(*new WebXRRigidTransform({ }, { }));
43
}
55
}
44
56
57
Ref<WebXRRigidTransform> WebXRRigidTransform::create(const TransformationMatrix& transform)
58
{
59
    return adoptRef(*new WebXRRigidTransform(transform));
60
}
61
62
45
ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPointInit& position, const DOMPointInit& orientation)
63
ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPointInit& position, const DOMPointInit& orientation)
46
{
64
{
47
    // The XRRigidTransform(position, orientation) constructor MUST perform the following steps when invoked:
65
    // The XRRigidTransform(position, orientation) constructor MUST perform the following steps when invoked:
Lines 58-74 ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPoint a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp_sec3
58
    //   6. Else initialize transform’s orientation’s x value to orientation’s x dictionary member, y value to orientation’s y dictionary member, z value to orientation’s z dictionary member and w value to orientation’s w dictionary member.
76
    //   6. Else initialize transform’s orientation’s x value to orientation’s x dictionary member, y value to orientation’s y dictionary member, z value to orientation’s z dictionary member and w value to orientation’s w dictionary member.
59
    //   7. Normalize x, y, z, and w components of transform’s orientation.
77
    //   7. Normalize x, y, z, and w components of transform’s orientation.
60
    DOMPointInit orientationInit { orientation.x, orientation.y, orientation.z, orientation.w };
78
    DOMPointInit orientationInit { orientation.x, orientation.y, orientation.z, orientation.w };
61
    {
79
    if (!normalizeQuaternion(orientationInit))
62
        double length = std::sqrt(orientationInit.x * orientationInit.x + orientationInit.y * orientationInit.y
80
        return Exception { InvalidStateError };
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
    }
72
81
73
    //   8. Return transform.
82
    //   8. Return transform.
74
    return adoptRef(*new WebXRRigidTransform(positionInit, orientationInit));
83
    return adoptRef(*new WebXRRigidTransform(positionInit, orientationInit));
Lines 78-87 WebXRRigidTransform::WebXRRigidTransform(const DOMPointInit& position, const DOM a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp_sec4
78
    : m_position(DOMPointReadOnly::create(position))
87
    : m_position(DOMPointReadOnly::create(position))
79
    , m_orientation(DOMPointReadOnly::create(orientation))
88
    , m_orientation(DOMPointReadOnly::create(orientation))
80
{
89
{
81
    // FIXME: implement properly, per spec.
90
    TransformationMatrix translation;
82
    TransformationMatrix matrix;
91
    translation.translate3d(position.x, position.y, position.z);
83
    auto matrixData = matrix.toColumnMajorFloatArray();
92
    auto rotation = TransformationMatrix::fromQuaternion(orientation.x, orientation.y, orientation.z, orientation.w);
84
    m_matrix = Float32Array::create(matrixData.data(), matrixData.size());
93
    m_rawTransform = translation * rotation;
94
}
95
96
WebXRRigidTransform::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);
85
}
115
}
86
116
87
WebXRRigidTransform::~WebXRRigidTransform() = default;
117
WebXRRigidTransform::~WebXRRigidTransform() = default;
Lines 96-112 const DOMPointReadOnly& WebXRRigidTransform::orientation() const a/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp_sec5
96
    return m_orientation;
126
    return m_orientation;
97
}
127
}
98
128
99
Ref<Float32Array>  WebXRRigidTransform::matrix() const
129
const Float32Array& WebXRRigidTransform::matrix()
130
{
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;
139
}
140
141
const WebXRRigidTransform& WebXRRigidTransform::inverse()
100
{
142
{
101
    auto matrix = Float32Array::create(16);
143
    // The inverse of a inverse object should return the original object.
102
    matrix->zeroFill();
144
    if (m_parentInverse)
103
    return matrix;
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;
104
}
159
}
105
160
106
Ref<WebXRRigidTransform> WebXRRigidTransform::inverse() const
161
const TransformationMatrix& WebXRRigidTransform::rawTransform() const
107
{
162
{
108
    // FIXME: implement properly.
163
    return m_rawTransform;
109
    return WebXRRigidTransform::create();
110
}
164
}
111
165
112
} // namespace WebCore
166
} // namespace WebCore
- a/Source/WebCore/Modules/webxr/WebXRRigidTransform.h -3 / +11 lines
Lines 28-60 a/Source/WebCore/Modules/webxr/WebXRRigidTransform.h_sec1
28
#if ENABLE(WEBXR)
28
#if ENABLE(WEBXR)
29
29
30
#include "ExceptionOr.h"
30
#include "ExceptionOr.h"
31
#include "TransformationMatrix.h"
31
#include <JavaScriptCore/Float32Array.h>
32
#include <JavaScriptCore/Float32Array.h>
32
#include <wtf/IsoMalloc.h>
33
#include <wtf/IsoMalloc.h>
33
#include <wtf/RefCounted.h>
34
#include <wtf/RefCounted.h>
35
#include <wtf/WeakPtr.h>
34
36
35
namespace WebCore {
37
namespace WebCore {
36
38
37
struct DOMPointInit;
39
struct DOMPointInit;
38
class DOMPointReadOnly;
40
class DOMPointReadOnly;
39
41
40
class WebXRRigidTransform : public RefCounted<WebXRRigidTransform> {
42
class WebXRRigidTransform : public RefCounted<WebXRRigidTransform>, public CanMakeWeakPtr<WebXRRigidTransform> {
41
    WTF_MAKE_ISO_ALLOCATED_EXPORT(WebXRRigidTransform, WEBCORE_EXPORT);
43
    WTF_MAKE_ISO_ALLOCATED_EXPORT(WebXRRigidTransform, WEBCORE_EXPORT);
42
public:
44
public:
43
    static Ref<WebXRRigidTransform> create();
45
    static Ref<WebXRRigidTransform> create();
46
    static Ref<WebXRRigidTransform> create(const TransformationMatrix&);
44
    WEBCORE_EXPORT static ExceptionOr<Ref<WebXRRigidTransform>> create(const DOMPointInit&, const DOMPointInit&);
47
    WEBCORE_EXPORT static ExceptionOr<Ref<WebXRRigidTransform>> create(const DOMPointInit&, const DOMPointInit&);
45
    WEBCORE_EXPORT ~WebXRRigidTransform();
48
    WEBCORE_EXPORT ~WebXRRigidTransform();
46
49
47
    const DOMPointReadOnly& position() const;
50
    const DOMPointReadOnly& position() const;
48
    const DOMPointReadOnly& orientation() const;
51
    const DOMPointReadOnly& orientation() const;
49
    Ref<Float32Array> matrix() const;
52
    const Float32Array& matrix();
50
    Ref<WebXRRigidTransform> inverse() const;
53
    const WebXRRigidTransform& inverse();
54
    const TransformationMatrix& rawTransform() const;
51
55
52
private:
56
private:
53
    WebXRRigidTransform(const DOMPointInit&, const DOMPointInit&);
57
    WebXRRigidTransform(const DOMPointInit&, const DOMPointInit&);
58
    WebXRRigidTransform(const TransformationMatrix&);
54
59
55
    Ref<DOMPointReadOnly> m_position;
60
    Ref<DOMPointReadOnly> m_position;
56
    Ref<DOMPointReadOnly> m_orientation;
61
    Ref<DOMPointReadOnly> m_orientation;
62
    TransformationMatrix m_rawTransform;
57
    RefPtr<Float32Array> m_matrix;
63
    RefPtr<Float32Array> m_matrix;
64
    RefPtr<WebXRRigidTransform> m_inverse;
65
    WeakPtr<WebXRRigidTransform> m_parentInverse;
58
};
66
};
59
67
60
} // namespace WebCore
68
} // namespace WebCore
- a/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp +20 lines
Lines 580-585 TransformationMatrix::TransformationMatrix(const AffineTransform& t) a/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp_sec1
580
    setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f());
580
    setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f());
581
}
581
}
582
582
583
584
// FIXME: Once https://bugs.webkit.org/show_bug.cgi?id=220856 is addressed we can reuse this function in TransformationMatrix::recompose4().
585
TransformationMatrix 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);
601
}
602
583
TransformationMatrix& TransformationMatrix::scale(double s)
603
TransformationMatrix& TransformationMatrix::scale(double s)
584
{
604
{
585
    return scaleNonUniform(s, s);
605
    return scaleNonUniform(s, s);
- a/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h +2 lines
Lines 119-124 public: a/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h_sec1
119
119
120
    WEBCORE_EXPORT TransformationMatrix(const AffineTransform&);
120
    WEBCORE_EXPORT TransformationMatrix(const AffineTransform&);
121
121
122
    static TransformationMatrix fromQuaternion(double qx, double qy, double qz, double qw);
123
122
    static const TransformationMatrix identity;
124
    static const TransformationMatrix identity;
123
125
124
    void setMatrix(double a, double b, double c, double d, double e, double f)
126
    void setMatrix(double a, double b, double c, double d, double e, double f)
- a/LayoutTests/ChangeLog +12 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2021-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 NOBODY (OOPS!).
8
9
        Enable XRRigidTransform WebXR tests.
10
11
        * platform/wpe/TestExpectations:
12
1
2021-01-27  Andy Estes  <aestes@apple.com>
13
2021-01-27  Andy Estes  <aestes@apple.com>
2
14
3
        [Mac] MediaSampleCursor::stepInOrderedMap can hang when stepping to the end of a track that hasn't been fully parsed
15
        [Mac] MediaSampleCursor::stepInOrderedMap can hang when stepping to the end of a track that hasn't been fully parsed
- a/LayoutTests/imported/w3c/ChangeLog +13 lines
Lines 1-3 a/LayoutTests/imported/w3c/ChangeLog_sec1
1
2021-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 NOBODY (OOPS!).
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
1
2021-01-27  Youenn Fablet  <youenn@apple.com>
14
2021-01-27  Youenn Fablet  <youenn@apple.com>
2
15
3
        Add support for RTCRtpParameters.rtcp
16
        Add support for RTCRtpParameters.rtcp
- a/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt +3 lines
Line 0 a/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt_sec1
1
2
PASS XRRigidTransform inverse works
3
- a/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt +3 lines
Line 0 a/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt_sec1
1
2
PASS XRRigidTransform matrix works
3
- a/LayoutTests/platform/wpe/TestExpectations +2 lines
Lines 640-645 webkit.org/b/209859 imported/w3c/web-platform-tests/webxr/xrWebGLLayer_framebuff a/LayoutTests/platform/wpe/TestExpectations_sec1
640
imported/w3c/web-platform-tests/webxr/navigator_xr_sameObject.https.html [ Pass ]
640
imported/w3c/web-platform-tests/webxr/navigator_xr_sameObject.https.html [ Pass ]
641
imported/w3c/web-platform-tests/webxr/xrFrame_session_sameObject.https.html [ Pass ]
641
imported/w3c/web-platform-tests/webxr/xrFrame_session_sameObject.https.html [ Pass ]
642
imported/w3c/web-platform-tests/webxr/xrRigidTransform_constructor.https.html [ Pass ]
642
imported/w3c/web-platform-tests/webxr/xrRigidTransform_constructor.https.html [ Pass ]
643
imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https.html [ Pass ]
644
imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https.html [ Pass ]
643
imported/w3c/web-platform-tests/webxr/xrSession_prevent_multiple_exclusive.https.html [ Pass ]
645
imported/w3c/web-platform-tests/webxr/xrSession_prevent_multiple_exclusive.https.html [ Pass ]
644
imported/w3c/web-platform-tests/webxr/render_state_vertical_fov_immersive.https.html [ Pass ]
646
imported/w3c/web-platform-tests/webxr/render_state_vertical_fov_immersive.https.html [ Pass ]
645
imported/w3c/web-platform-tests/webxr/render_state_update.https.html [ Pass ]
647
imported/w3c/web-platform-tests/webxr/render_state_update.https.html [ Pass ]

Return to Bug 220732