Diff
Modified: trunk/LayoutTests/ChangeLog (271940 => 271941)
--- trunk/LayoutTests/ChangeLog 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/LayoutTests/ChangeLog 2021-01-27 11:04:16 UTC (rev 271941)
@@ -1,3 +1,15 @@
+2021-01-27 Imanol Fernandez <[email protected]>
+
+ Complete WebXRRigidTransform implementation
+ https://bugs.webkit.org/show_bug.cgi?id=220732
+ <rdar://problem/73617302>
+
+ Reviewed by Sergio Villar Senin.
+
+ Enable XRRigidTransform WebXR tests.
+
+ * platform/wpe/TestExpectations:
+
2021-01-27 Youenn Fablet <[email protected]>
[MacOS] Enable NSURLSession WebSocket code path in WebKitTestRunner
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (271940 => 271941)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-27 11:04:16 UTC (rev 271941)
@@ -1,3 +1,16 @@
+2021-01-27 Imanol Fernandez <[email protected]>
+
+ Complete WebXRRigidTransform implementation
+ https://bugs.webkit.org/show_bug.cgi?id=220732
+ <rdar://problem/73617302>
+
+ Reviewed by Sergio Villar Senin.
+
+ Enable XRRigidTransform WebXR tests.
+
+ * web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt: Added.
+ * web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt: Added.
+
2021-01-27 Youenn Fablet <[email protected]>
Add support for RTCRtpParameters.rtcp
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt (0 => 271941)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt 2021-01-27 11:04:16 UTC (rev 271941)
@@ -0,0 +1,3 @@
+
+PASS XRRigidTransform inverse works
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt (0 => 271941)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt 2021-01-27 11:04:16 UTC (rev 271941)
@@ -0,0 +1,3 @@
+
+PASS XRRigidTransform matrix works
+
Modified: trunk/LayoutTests/platform/wpe/TestExpectations (271940 => 271941)
--- trunk/LayoutTests/platform/wpe/TestExpectations 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/LayoutTests/platform/wpe/TestExpectations 2021-01-27 11:04:16 UTC (rev 271941)
@@ -640,6 +640,8 @@
imported/w3c/web-platform-tests/webxr/navigator_xr_sameObject.https.html [ Pass ]
imported/w3c/web-platform-tests/webxr/xrFrame_session_sameObject.https.html [ Pass ]
imported/w3c/web-platform-tests/webxr/xrRigidTransform_constructor.https.html [ Pass ]
+imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https.html [ Pass ]
+imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https.html [ Pass ]
imported/w3c/web-platform-tests/webxr/xrSession_prevent_multiple_exclusive.https.html [ Pass ]
imported/w3c/web-platform-tests/webxr/render_state_vertical_fov_immersive.https.html [ Pass ]
imported/w3c/web-platform-tests/webxr/render_state_update.https.html [ Pass ]
Modified: trunk/Source/WebCore/ChangeLog (271940 => 271941)
--- trunk/Source/WebCore/ChangeLog 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/Source/WebCore/ChangeLog 2021-01-27 11:04:16 UTC (rev 271941)
@@ -1,3 +1,31 @@
+2021-01-27 Imanol Fernandez <[email protected]>
+
+ Complete WebXRRigidTransform implementation
+ https://bugs.webkit.org/show_bug.cgi?id=220732
+ <rdar://problem/73617302>
+
+ Reviewed by Sergio Villar Senin.
+
+ - 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:
+
2021-01-27 Andy Estes <[email protected]>
[Mac] MediaSampleCursor::stepInOrderedMap can hang when stepping to the end of a track that hasn't been fully parsed
Modified: trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp (271940 => 271941)
--- trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp 2021-01-27 11:04:16 UTC (rev 271941)
@@ -35,6 +35,18 @@
namespace WebCore {
+static bool normalizeQuaternion(DOMPointInit& q)
+{
+ const double length = std::sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
+ if (WTF::areEssentiallyEqual<double>(length, 0))
+ return false;
+ q.x /= length;
+ q.y /= length;
+ q.z /= length;
+ q.w /= length;
+ return true;
+}
+
WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRRigidTransform);
Ref<WebXRRigidTransform> WebXRRigidTransform::create()
@@ -42,6 +54,12 @@
return adoptRef(*new WebXRRigidTransform({ }, { }));
}
+Ref<WebXRRigidTransform> WebXRRigidTransform::create(const TransformationMatrix& transform)
+{
+ return adoptRef(*new WebXRRigidTransform(transform));
+}
+
+
ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPointInit& position, const DOMPointInit& orientation)
{
// The XRRigidTransform(position, orientation) constructor MUST perform the following steps when invoked:
@@ -58,18 +76,9 @@
// 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.
// 7. Normalize x, y, z, and w components of transform’s orientation.
DOMPointInit orientationInit { orientation.x, orientation.y, orientation.z, orientation.w };
- {
- double length = std::sqrt(orientationInit.x * orientationInit.x + orientationInit.y * orientationInit.y
- + orientationInit.z * orientationInit.z + orientationInit.w * orientationInit.w);
- if (WTF::areEssentiallyEqual<double>(length, 0))
- return Exception { InvalidStateError };
+ if (!normalizeQuaternion(orientationInit))
+ return Exception { InvalidStateError };
- orientationInit= {
- orientationInit.x / length, orientationInit.y / length,
- orientationInit.z / length, orientationInit.w / length,
- };
- }
-
// 8. Return transform.
return adoptRef(*new WebXRRigidTransform(positionInit, orientationInit));
}
@@ -78,12 +87,33 @@
: m_position(DOMPointReadOnly::create(position))
, m_orientation(DOMPointReadOnly::create(orientation))
{
- // FIXME: implement properly, per spec.
- TransformationMatrix matrix;
- auto matrixData = matrix.toColumnMajorFloatArray();
- m_matrix = Float32Array::create(matrixData.data(), matrixData.size());
+ TransformationMatrix translation;
+ translation.translate3d(position.x, position.y, position.z);
+ auto rotation = TransformationMatrix::fromQuaternion(orientation.x, orientation.y, orientation.z, orientation.w);
+ m_rawTransform = translation * rotation;
}
+WebXRRigidTransform::WebXRRigidTransform(const TransformationMatrix& transform)
+ : m_position(DOMPointReadOnly::create({ }))
+ , m_orientation(DOMPointReadOnly::create({ }))
+ , m_rawTransform(transform)
+{
+ if (transform.isIdentity()) {
+ // TransformationMatrix::decompose returns a empty quaternion instead of unit quaternion for Identity.
+ // WebXR tests expect a unit quaternion for this case.
+ return;
+ }
+
+ TransformationMatrix::Decomposed4Type decomp = { };
+ transform.decompose4(decomp);
+
+ m_position = DOMPointReadOnly::create(decomp.translateX, decomp.translateY, decomp.translateZ, 1.0f);
+
+ DOMPointInit orientationInit { -decomp.quaternionX, -decomp.quaternionY, -decomp.quaternionZ, decomp.quaternionW };
+ normalizeQuaternion(orientationInit);
+ m_orientation = DOMPointReadOnly::create(orientationInit);
+}
+
WebXRRigidTransform::~WebXRRigidTransform() = default;
const DOMPointReadOnly& WebXRRigidTransform::position() const
@@ -96,19 +126,43 @@
return m_orientation;
}
-Ref<Float32Array> WebXRRigidTransform::matrix() const
+const Float32Array& WebXRRigidTransform::matrix()
{
- auto matrix = Float32Array::create(16);
- matrix->zeroFill();
- return matrix;
+ if (m_matrix && !m_matrix->isDetached())
+ return *m_matrix;
+
+ // Lazily create matrix Float32Array.
+ auto matrixData = m_rawTransform.toColumnMajorFloatArray();
+ m_matrix = Float32Array::create(matrixData.data(), matrixData.size());
+
+ return *m_matrix;
}
-Ref<WebXRRigidTransform> WebXRRigidTransform::inverse() const
+const WebXRRigidTransform& WebXRRigidTransform::inverse()
{
- // FIXME: implement properly.
- return WebXRRigidTransform::create();
+ // The inverse of a inverse object should return the original object.
+ if (m_parentInverse)
+ return *m_parentInverse;
+
+ // Inverse should always return the same object.
+ if (m_inverse)
+ return *m_inverse;
+
+ auto inverseTransform = m_rawTransform.inverse();
+ ASSERT(!!inverseTransform);
+
+ m_inverse = WebXRRigidTransform::create(*inverseTransform);
+ // The inverse of a inverse object should return the original object.
+ m_inverse->m_parentInverse = makeWeakPtr(this);
+
+ return *m_inverse;
}
+const TransformationMatrix& WebXRRigidTransform::rawTransform() const
+{
+ return m_rawTransform;
+}
+
} // namespace WebCore
#endif // ENABLE(WEBXR)
Modified: trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.h (271940 => 271941)
--- trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.h 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.h 2021-01-27 11:04:16 UTC (rev 271941)
@@ -28,9 +28,11 @@
#if ENABLE(WEBXR)
#include "ExceptionOr.h"
+#include "TransformationMatrix.h"
#include <_javascript_Core/Float32Array.h>
#include <wtf/IsoMalloc.h>
#include <wtf/RefCounted.h>
+#include <wtf/WeakPtr.h>
namespace WebCore {
@@ -37,24 +39,30 @@
struct DOMPointInit;
class DOMPointReadOnly;
-class WebXRRigidTransform : public RefCounted<WebXRRigidTransform> {
+class WebXRRigidTransform : public RefCounted<WebXRRigidTransform>, public CanMakeWeakPtr<WebXRRigidTransform> {
WTF_MAKE_ISO_ALLOCATED_EXPORT(WebXRRigidTransform, WEBCORE_EXPORT);
public:
static Ref<WebXRRigidTransform> create();
+ static Ref<WebXRRigidTransform> create(const TransformationMatrix&);
WEBCORE_EXPORT static ExceptionOr<Ref<WebXRRigidTransform>> create(const DOMPointInit&, const DOMPointInit&);
WEBCORE_EXPORT ~WebXRRigidTransform();
const DOMPointReadOnly& position() const;
const DOMPointReadOnly& orientation() const;
- Ref<Float32Array> matrix() const;
- Ref<WebXRRigidTransform> inverse() const;
+ const Float32Array& matrix();
+ const WebXRRigidTransform& inverse();
+ const TransformationMatrix& rawTransform() const;
private:
WebXRRigidTransform(const DOMPointInit&, const DOMPointInit&);
+ WebXRRigidTransform(const TransformationMatrix&);
Ref<DOMPointReadOnly> m_position;
Ref<DOMPointReadOnly> m_orientation;
+ TransformationMatrix m_rawTransform;
RefPtr<Float32Array> m_matrix;
+ RefPtr<WebXRRigidTransform> m_inverse;
+ WeakPtr<WebXRRigidTransform> m_parentInverse;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp (271940 => 271941)
--- trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp 2021-01-27 11:04:16 UTC (rev 271941)
@@ -580,6 +580,26 @@
setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f());
}
+
+// FIXME: Once https://bugs.webkit.org/show_bug.cgi?id=220856 is addressed we can reuse this function in TransformationMatrix::recompose4().
+TransformationMatrix TransformationMatrix::fromQuaternion(double qx, double qy, double qz, double qw)
+{
+ const double xx = qx * qx;
+ const double yy = qy * qy;
+ const double zz = qz * qz;
+ const double xz = qx * qz;
+ const double xy = qx * qy;
+ const double yz = qy * qz;
+ const double xw = qw * qx;
+ const double yw = qw * qy;
+ const double zw = qw * qz;
+
+ return TransformationMatrix(1 - 2 * (yy + zz), 2 * (xy + zw), 2 * (xz - yw), 0,
+ 2 * (xy - zw), 1 - 2 * (xx + zz), 2 * (yz + xw), 0,
+ 2 * (xz + yw), 2 * (yz - xw), 1 - 2 * (xx + yy), 0,
+ 0, 0, 0, 1);
+}
+
TransformationMatrix& TransformationMatrix::scale(double s)
{
return scaleNonUniform(s, s);
Modified: trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h (271940 => 271941)
--- trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h 2021-01-27 10:57:21 UTC (rev 271940)
+++ trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h 2021-01-27 11:04:16 UTC (rev 271941)
@@ -119,6 +119,8 @@
WEBCORE_EXPORT TransformationMatrix(const AffineTransform&);
+ static TransformationMatrix fromQuaternion(double qx, double qy, double qz, double qw);
+
static const TransformationMatrix identity;
void setMatrix(double a, double b, double c, double d, double e, double f)