Bug 238968 - [WebXR] Implement the WebXRFrame methods for getting joints' poses and radii
Summary: [WebXR] Implement the WebXRFrame methods for getting joints' poses and radii
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ada Chan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-07 16:12 PDT by Ada Chan
Modified: 2022-04-12 11:54 PDT (History)
7 users (show)

See Also:


Attachments
Patch (79.72 KB, patch)
2022-04-07 17:46 PDT, Ada Chan
dino: review+
Details | Formatted Diff | Diff
Patch for landing (79.72 KB, patch)
2022-04-08 14:31 PDT, Ada Chan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing 2 (80.41 KB, patch)
2022-04-08 19:03 PDT, Ada Chan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing 3 (80.64 KB, patch)
2022-04-09 23:38 PDT, Ada Chan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing 4 (80.63 KB, patch)
2022-04-11 17:13 PDT, Ada Chan
no flags Details | Formatted Diff | Diff
Patch for landing 5 (80.73 KB, patch)
2022-04-12 10:50 PDT, Ada Chan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ada Chan 2022-04-07 16:12:56 PDT
[WebXR] Implement the WebXR Hand Input module
Comment 1 Ada Chan 2022-04-07 17:46:53 PDT
Created attachment 456998 [details]
Patch
Comment 2 Ada Chan 2022-04-08 14:31:40 PDT
Created attachment 457119 [details]
Patch for landing
Comment 3 Ada Chan 2022-04-08 19:03:32 PDT
Created attachment 457134 [details]
Patch for landing 2
Comment 4 Chris Dumez 2022-04-08 19:47:24 PDT
Comment on attachment 457134 [details]
Patch for landing 2

View in context: https://bugs.webkit.org/attachment.cgi?id=457134&action=review

Nothing critical that would prevent committing as is but here is some feedback.

> Source/WebCore/Modules/webxr/WebXRFrame.cpp:282
> +ExceptionOr<bool> WebXRFrame::fillJointRadii(const Vector<RefPtr<WebXRJointSpace>> jointSpaces, Float32Array& radii)

Why is the second array passed as non-const reference?

> Source/WebCore/Modules/webxr/WebXRHand.cpp:52
> +        m_joints.append(WebXRJointSpace::create(*document, *this, static_cast<XRHandJoint>(i)));

It seems the size of m_joint is static. Ideally, it would be a FixedVector instead of a Vector.

> Source/WebCore/Modules/webxr/WebXRHand.cpp:95
> +    const PlatformXR::Device::FrameData::HandJointsVector& handJoints = *(inputSource.handJoints);

that's a long type, I would use auto&

> Source/WebCore/Modules/webxr/WebXRHand.h:50
> +    unsigned size() { return m_joints.size(); }

should be const.

> Source/WebCore/Modules/webxr/WebXRJointSpace.cpp:45
> +WebXRJointSpace::WebXRJointSpace(Document& document, WebXRHand& hand, XRHandJoint jointName, const std::optional<PlatformXR::Device::FrameData::InputSourceHandJoint>& joint)

std::optional<PlatformXR::Device::FrameData::InputSourceHandJoint>&&

> Source/WebCore/Modules/webxr/WebXRJointSpace.cpp:50
> +    updateFromJoint(joint);

m_joint(WTFMove(joint)) in the initializer list?

> Source/WebCore/Modules/webxr/WebXRJointSpace.h:45
>  class WebXRJointSpace : public RefCounted<WebXRJointSpace>, public WebXRSpace {

This class can probably be marked as final.

> Source/WebCore/platform/xr/PlatformXR.h:326
> +        typedef Vector<std::optional<InputSourceHandJoint>> HandJointsVector;

We prefer the modern:
using HandJointsVector = Vector<std::optional<InputSourceHandJoint>>;

> Source/WebCore/platform/xr/PlatformXR.h:651
> +    if (!decoder.decode(handJoint.pose))

This is the old style of decoding, modern code should use:
std::optional<InputSourcePose> pose;
decoder >> pose;
if (!pose)
    return std::nullopt;
std::optional<float> radius;
decoder >> radius;
if (!radius)
    return std::nullopt;
return { { WTFMove(*pose), *radius } };

> Source/WebCore/testing/WebFakeXRInputController.h:91
> +    std::optional<PlatformXR::Device::FrameData::HandJointsVector> m_handJoints;

So we will need to distinguish the vector not being initialized vs the vector being empty and that's why it is optional?
I might have missed it but the patch doesn't seem to rely on that.
Comment 5 Ada Chan 2022-04-09 23:31:12 PDT
(In reply to Chris Dumez from comment #4)

Thanks Chris! I really appreciate your detailed review and feedback.

> Comment on attachment 457134 [details]
> Patch for landing 2
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457134&action=review
> 
> Nothing critical that would prevent committing as is but here is some
> feedback.
> 
> > Source/WebCore/Modules/webxr/WebXRFrame.cpp:282
> > +ExceptionOr<bool> WebXRFrame::fillJointRadii(const Vector<RefPtr<WebXRJointSpace>> jointSpaces, Float32Array& radii)
> 
> Why is the second array passed as non-const reference?

In this method, we'll be filling in that radii array so it can't be a const reference.

> 
> > Source/WebCore/Modules/webxr/WebXRHand.cpp:52
> > +        m_joints.append(WebXRJointSpace::create(*document, *this, static_cast<XRHandJoint>(i)));
> 
> It seems the size of m_joint is static. Ideally, it would be a FixedVector
> instead of a Vector.

Fixed!

> 
> > Source/WebCore/Modules/webxr/WebXRHand.cpp:95
> > +    const PlatformXR::Device::FrameData::HandJointsVector& handJoints = *(inputSource.handJoints);
> 
> that's a long type, I would use auto&

Fixed!

> 
> > Source/WebCore/Modules/webxr/WebXRHand.h:50
> > +    unsigned size() { return m_joints.size(); }
> 
> should be const.

Fixed!

> 
> > Source/WebCore/Modules/webxr/WebXRJointSpace.cpp:45
> > +WebXRJointSpace::WebXRJointSpace(Document& document, WebXRHand& hand, XRHandJoint jointName, const std::optional<PlatformXR::Device::FrameData::InputSourceHandJoint>& joint)
> 
> std::optional<PlatformXR::Device::FrameData::InputSourceHandJoint>&&
> 
> > Source/WebCore/Modules/webxr/WebXRJointSpace.cpp:50
> > +    updateFromJoint(joint);
> 
> m_joint(WTFMove(joint)) in the initializer list?

Fixed!

> 
> > Source/WebCore/Modules/webxr/WebXRJointSpace.h:45
> >  class WebXRJointSpace : public RefCounted<WebXRJointSpace>, public WebXRSpace {
> 
> This class can probably be marked as final.

Fixed!

> 
> > Source/WebCore/platform/xr/PlatformXR.h:326
> > +        typedef Vector<std::optional<InputSourceHandJoint>> HandJointsVector;
> 
> We prefer the modern:
> using HandJointsVector = Vector<std::optional<InputSourceHandJoint>>;

Fixed!

> 
> > Source/WebCore/platform/xr/PlatformXR.h:651
> > +    if (!decoder.decode(handJoint.pose))
> 
> This is the old style of decoding, modern code should use:
> std::optional<InputSourcePose> pose;
> decoder >> pose;
> if (!pose)
>     return std::nullopt;
> std::optional<float> radius;
> decoder >> radius;
> if (!radius)
>     return std::nullopt;
> return { { WTFMove(*pose), *radius } };

Fixed!

> 
> > Source/WebCore/testing/WebFakeXRInputController.h:91
> > +    std::optional<PlatformXR::Device::FrameData::HandJointsVector> m_handJoints;
> 
> So we will need to distinguish the vector not being initialized vs the
> vector being empty and that's why it is optional?
> I might have missed it but the patch doesn't seem to rely on that.

I made it optional to be consistent with how PlatformXR::Device::InputSource's handJoints is also optional. By making it optional, I feel it matches better the semantics that specifying joints is optional. If there's a compelling reason that omitting the optional is better, please let me know!
Comment 6 Ada Chan 2022-04-09 23:38:05 PDT
Created attachment 457192 [details]
Patch for landing 3
Comment 7 EWS 2022-04-11 16:41:30 PDT
ChangeLog entry in LayoutTests/ChangeLog contains OOPS!.
Comment 8 Ada Chan 2022-04-11 17:13:47 PDT
Created attachment 457301 [details]
Patch for landing 4
Comment 9 Chris Dumez 2022-04-12 10:23:02 PDT
Comment on attachment 457301 [details]
Patch for landing 4

View in context: https://bugs.webkit.org/attachment.cgi?id=457301&action=review

> Source/WebCore/Modules/webxr/WebXRHand.cpp:55
> +        joints.append(WebXRJointSpace::create(*document, *this, static_cast<XRHandJoint>(i)));

FYI, you can use uncheckedAppend() here since you called reserveInitialCapacity earlier.
Comment 10 Ada Chan 2022-04-12 10:46:34 PDT
(In reply to Chris Dumez from comment #9)
> Comment on attachment 457301 [details]
> Patch for landing 4
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457301&action=review
> 
> > Source/WebCore/Modules/webxr/WebXRHand.cpp:55
> > +        joints.append(WebXRJointSpace::create(*document, *this, static_cast<XRHandJoint>(i)));
> 
> FYI, you can use uncheckedAppend() here since you called
> reserveInitialCapacity earlier.

OK, will fix!
Comment 11 Ada Chan 2022-04-12 10:50:57 PDT
Created attachment 457345 [details]
Patch for landing 5
Comment 12 EWS 2022-04-12 11:53:41 PDT
Committed r292780 (249564@main): <https://commits.webkit.org/249564@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457345 [details].
Comment 13 Radar WebKit Bug Importer 2022-04-12 11:54:17 PDT
<rdar://problem/91640876>