Title: [275835] trunk/Source
Revision
275835
Author
[email protected]
Date
2021-04-12 12:38:34 -0700 (Mon, 12 Apr 2021)

Log Message

Initial implementation of WebChromeClient::enumerateImmersiveXRDevices() and XRDeviceProxy
https://bugs.webkit.org/show_bug.cgi?id=224353

Patch by Ada Chan <[email protected]> on 2021-04-12
Source/WebCore:

Reviewed by Dean Jackson.

Remove PlatformXRDeviceCocoa as WebKit::XRDeviceProxy will be implementing PlatformXR::Device.
Implement the encode/decode methods to enable PlatformXR::Device::FrameData to
be sent over IPC.

* platform/xr/PlatformXR.h:
(PlatformXR::Device::trackingAndRenderingClient const):
(PlatformXR::Device::FrameData::FloatQuaternion::encode const):
(PlatformXR::Device::FrameData::FloatQuaternion::decode):
(PlatformXR::Device::FrameData::Pose::encode const):
(PlatformXR::Device::FrameData::Pose::decode):
(PlatformXR::Device::FrameData::Fov::encode const):
(PlatformXR::Device::FrameData::Fov::decode):
(PlatformXR::Device::FrameData::View::encode const):
(PlatformXR::Device::FrameData::View::decode):
(PlatformXR::Device::FrameData::StageParameters::encode const):
(PlatformXR::Device::FrameData::StageParameters::decode):
(PlatformXR::Device::FrameData::LayerData::encode const):
(PlatformXR::Device::FrameData::LayerData::decode):
(PlatformXR::Device::FrameData::encode const):
(PlatformXR::Device::FrameData::decode):
* platform/xr/cocoa/PlatformXRCocoa.h:
(): Deleted.

Source/WebKit:

Reviewed by Dean Jackson

- Add XRDeviceProxy which implements PlatformXR::Device.
- Implement WebChromeClient::enumerateImmersiveXRDevices(), which calls PlatformXRSystemProxy
to get the list of XRDeviceProxy.
- XRDeviceProxy goes through PlatformXRSystemProxy to handle its operations.
PlatformXRSystemProxy sends messages over IPC to PlatformXRSystem on the UI process side,
which handles XR device discovery and manages sessions via the PlatformXRCoordinator interface.
PlatformXRSystem::xrCoordinator() returns null for now and will be handled in a later patch.

* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Platform/Logging.h:
* Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
(headers_for_type):
* Shared/Cocoa/XRDeviceProxy.h: Added.
* Shared/Cocoa/XRDeviceProxy.mm: Added.
(WebKit::XRDeviceProxy::create):
(WebKit::XRDeviceProxy::XRDeviceProxy):
Initialize its data members based on the XRDeviceInfo passed in.
Keep a weak pointer to PlatformXRSystemProxy (as PlatformXRSystemProxy has
strong references to its list of XRDeviceProxy).
(WebKit::XRDeviceProxy::sessionDidEnd):
Notify the TrackingAndRenderingClient that the session has ended.
(WebKit::XRDeviceProxy::initializeTrackingAndRendering):
(WebKit::XRDeviceProxy::shutDownTrackingAndRendering):
(WebKit::XRDeviceProxy::views const):
Return left and right views if the device supports stereo rendering.
Otherwise return just one view.
(WebKit::XRDeviceProxy::requestFrame):
* Shared/WebCoreArgumentCoders.h:
* SourcesCocoa.txt:
* UIProcess/Cocoa/PlatformXRCoordinator.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
Initial interface for communicating with the platform regarding XR devices and sessions.
For now, the interface covers session creation and termination, and scheduling frame updates.
* UIProcess/Cocoa/PlatformXRSystem.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
* UIProcess/Cocoa/PlatformXRSystem.messages.in: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
* UIProcess/Cocoa/PlatformXRSystem.mm: Added.
(WebKit::PlatformXRSystem::PlatformXRSystem):
(WebKit::PlatformXRSystem::~PlatformXRSystem):
(WebKit::PlatformXRSystem::invalidate):
End any existing session on invalidation.
(WebKit::PlatformXRSystem::enumerateImmersiveXRDevices):
(WebKit::PlatformXRSystem::initializeTrackingAndRendering):
(WebKit::PlatformXRSystem::shutDownTrackingAndRendering):
(WebKit::PlatformXRSystem::requestFrame):
(WebKit::PlatformXRSystem::xrCoordinator):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didAttachToRunningProcess):
Set up the PlatformXRSystem held by the WebPageProxy.
(WebKit::WebPageProxy::resetState):
Invalidate m_xrSystem so existing session is ended properly.
* UIProcess/WebPageProxy.h:
* UIProcess/mac/HighPerformanceGPUManager.h:
Include WeakHashSet.h due to recent type change of m_processesRequiringHighPerformance
from HashSet to WeakHashSet.
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::enumerateImmersiveXRDevices):
Get the list of XRDeviceInfo that represents the immersive devices returned
from PlatformXRSystem. Reuse any existing XRDeviceProxy instances that have the same
XRDeviceIdentifier. Otherwise, create new ones.
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::xrSystemProxy):
* WebProcess/WebPage/WebPage.h:
* WebProcess/cocoa/PlatformXRSystemProxy.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
* WebProcess/cocoa/PlatformXRSystemProxy.messages.in: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
* WebProcess/cocoa/PlatformXRSystemProxy.mm: Added.
(WebKit::PlatformXRSystemProxy::PlatformXRSystemProxy):
(WebKit::PlatformXRSystemProxy::~PlatformXRSystemProxy):
(WebKit::PlatformXRSystemProxy::enumerateImmersiveXRDevices):
(WebKit::PlatformXRSystemProxy::initializeTrackingAndRendering):
(WebKit::PlatformXRSystemProxy::shutDownTrackingAndRendering):
(WebKit::PlatformXRSystemProxy::requestFrame):
(WebKit::PlatformXRSystemProxy::sessionDidEnd):
(WebKit::PlatformXRSystemProxy::deviceByIdentifier):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275834 => 275835)


--- trunk/Source/WebCore/ChangeLog	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebCore/ChangeLog	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1,3 +1,33 @@
+2021-04-12  Ada Chan  <[email protected]>
+
+        Initial implementation of WebChromeClient::enumerateImmersiveXRDevices() and XRDeviceProxy
+        https://bugs.webkit.org/show_bug.cgi?id=224353
+
+        Reviewed by Dean Jackson.
+
+        Remove PlatformXRDeviceCocoa as WebKit::XRDeviceProxy will be implementing PlatformXR::Device.
+        Implement the encode/decode methods to enable PlatformXR::Device::FrameData to
+        be sent over IPC.
+
+        * platform/xr/PlatformXR.h:
+        (PlatformXR::Device::trackingAndRenderingClient const):
+        (PlatformXR::Device::FrameData::FloatQuaternion::encode const):
+        (PlatformXR::Device::FrameData::FloatQuaternion::decode):
+        (PlatformXR::Device::FrameData::Pose::encode const):
+        (PlatformXR::Device::FrameData::Pose::decode):
+        (PlatformXR::Device::FrameData::Fov::encode const):
+        (PlatformXR::Device::FrameData::Fov::decode):
+        (PlatformXR::Device::FrameData::View::encode const):
+        (PlatformXR::Device::FrameData::View::decode):
+        (PlatformXR::Device::FrameData::StageParameters::encode const):
+        (PlatformXR::Device::FrameData::StageParameters::decode):
+        (PlatformXR::Device::FrameData::LayerData::encode const):
+        (PlatformXR::Device::FrameData::LayerData::decode):
+        (PlatformXR::Device::FrameData::encode const):
+        (PlatformXR::Device::FrameData::decode):
+        * platform/xr/cocoa/PlatformXRCocoa.h:
+        (): Deleted.
+
 2021-04-12  Antoine Quint  <[email protected]>
 
         border-image-width computed values should be a calc() value if it contains a percentage

Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (275834 => 275835)


--- trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -95,6 +95,7 @@
 
     virtual void initializeTrackingAndRendering(SessionMode) = 0;
     virtual void shutDownTrackingAndRendering() = 0;
+    TrackingAndRenderingClient* trackingAndRenderingClient() const { return m_trackingAndRenderingClient.get(); }
     void setTrackingAndRenderingClient(WeakPtr<TrackingAndRenderingClient>&& client) { m_trackingAndRenderingClient = WTFMove(client); }
 
     // If this method returns true, that means the device will notify TrackingAndRenderingClient
@@ -110,11 +111,17 @@
             float y { 0.0f };
             float z { 0.0f };
             float w { 1.0f };
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<FloatQuaternion> decode(Decoder&);
         };
 
         struct Pose {
             WebCore::FloatPoint3D position;
             FloatQuaternion orientation;
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<Pose> decode(Decoder&);
         };
 
         struct Fov {
@@ -123,22 +130,37 @@
             float down { 0.0f };
             float left { 0.0f };
             float right { 0.0f };
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<Fov> decode(Decoder&);
         };
 
-        using Projection = Variant<Fov, std::array<float, 16>, std::nullptr_t>;
+        static constexpr size_t projectionMatrixSize = 16;
+        typedef std::array<float, projectionMatrixSize> ProjectionMatrix;
 
+        using Projection = Variant<Fov, ProjectionMatrix, std::nullptr_t>;
+
         struct View {
             Pose offset;
             Projection projection = { nullptr };
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<View> decode(Decoder&);
         };
 
         struct StageParameters {
             int id { 0 };
             Vector<WebCore::FloatPoint> bounds;
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<StageParameters> decode(Decoder&);
         };
 
         struct LayerData {
             PlatformGLObject opaqueTexture { 0 };
+
+            template<class Encoder> void encode(Encoder&) const;
+            template<class Decoder> static Optional<LayerData> decode(Decoder&);
         };
 
         bool isTrackingValid { false };
@@ -151,6 +173,9 @@
         StageParameters stageParameters;
         Vector<View> views;
         HashMap<LayerHandle, LayerData> layers;
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<FrameData> decode(Decoder&);
     };
 
     struct LayerView {
@@ -207,6 +232,221 @@
     DeviceList m_immersiveXRDevices;
 };
 
+template<class Encoder>
+void Device::FrameData::FloatQuaternion::encode(Encoder& encoder) const
+{
+    encoder << x << y << z << w;
+}
+
+template<class Decoder>
+Optional<Device::FrameData::FloatQuaternion> Device::FrameData::FloatQuaternion::decode(Decoder& decoder)
+{
+    Device::FrameData::FloatQuaternion floatQuaternion;
+    if (!decoder.decode(floatQuaternion.x))
+        return WTF::nullopt;
+    if (!decoder.decode(floatQuaternion.y))
+        return WTF::nullopt;
+    if (!decoder.decode(floatQuaternion.z))
+        return WTF::nullopt;
+    if (!decoder.decode(floatQuaternion.w))
+        return WTF::nullopt;
+    return floatQuaternion;
+}
+
+template<class Encoder>
+void Device::FrameData::Pose::encode(Encoder& encoder) const
+{
+    encoder << position << orientation;
+}
+
+template<class Decoder>
+Optional<Device::FrameData::Pose> Device::FrameData::Pose::decode(Decoder& decoder)
+{
+    Device::FrameData::Pose pose;
+    if (!decoder.decode(pose.position))
+        return WTF::nullopt;
+    if (!decoder.decode(pose.orientation))
+        return WTF::nullopt;
+    return pose;
+}
+
+template<class Encoder>
+void Device::FrameData::Fov::encode(Encoder& encoder) const
+{
+    encoder << up << down << left << right;
+}
+
+template<class Decoder>
+Optional<Device::FrameData::Fov> Device::FrameData::Fov::decode(Decoder& decoder)
+{
+    Device::FrameData::Fov fov;
+    if (!decoder.decode(fov.up))
+        return WTF::nullopt;
+    if (!decoder.decode(fov.down))
+        return WTF::nullopt;
+    if (!decoder.decode(fov.left))
+        return WTF::nullopt;
+    if (!decoder.decode(fov.right))
+        return WTF::nullopt;
+    return fov;
+}
+
+template<class Encoder>
+void Device::FrameData::View::encode(Encoder& encoder) const
+{
+    encoder << offset;
+
+    bool hasFov = WTF::holds_alternative<PlatformXR::Device::FrameData::Fov>(projection);
+    encoder << hasFov;
+    if (hasFov) {
+        encoder << WTF::get<PlatformXR::Device::FrameData::Fov>(projection);
+        return;
+    }
+
+    bool hasProjectionMatrix = WTF::holds_alternative<PlatformXR::Device::FrameData::ProjectionMatrix>(projection);
+    encoder << hasProjectionMatrix;
+    if (hasProjectionMatrix) {
+        for (float f : WTF::get<PlatformXR::Device::FrameData::ProjectionMatrix>(projection))
+            encoder << f;
+        return;
+    }
+
+    ASSERT(WTF::holds_alternative<std::nullptr_t>(projection));
+}
+
+template<class Decoder>
+Optional<Device::FrameData::View> Device::FrameData::View::decode(Decoder& decoder)
+{
+    PlatformXR::Device::FrameData::View view;
+    if (!decoder.decode(view.offset))
+        return WTF::nullopt;
+
+    bool hasFov;
+    if (!decoder.decode(hasFov))
+        return WTF::nullopt;
+
+    if (hasFov) {
+        PlatformXR::Device::FrameData::Fov fov;
+        if (!decoder.decode(fov))
+            return WTF::nullopt;
+        view.projection = { WTFMove(fov) };
+        return view;
+    }
+
+    bool hasProjectionMatrix;
+    if (!decoder.decode(hasProjectionMatrix))
+        return WTF::nullopt;
+
+    if (hasProjectionMatrix) {
+        PlatformXR::Device::FrameData::ProjectionMatrix projectionMatrix;
+        for (size_t i = 0; i < PlatformXR::Device::FrameData::projectionMatrixSize; ++i) {
+            float f;
+            if (!decoder.decode(f))
+                return WTF::nullopt;
+            projectionMatrix[i] = f;
+        }
+        view.projection = { WTFMove(projectionMatrix) };
+        return view;
+    }
+
+    view.projection = { nullptr };
+    return view;
+}
+
+template<class Encoder>
+void Device::FrameData::StageParameters::encode(Encoder& encoder) const
+{
+    encoder << id;
+    encoder << bounds;
+}
+
+template<class Decoder>
+Optional<Device::FrameData::StageParameters> Device::FrameData::StageParameters::decode(Decoder& decoder)
+{
+    PlatformXR::Device::FrameData::StageParameters stageParameters;
+    if (!decoder.decode(stageParameters.id))
+        return WTF::nullopt;
+    if (!decoder.decode(stageParameters.bounds))
+        return WTF::nullopt;
+    return stageParameters;
+}
+
+template<class Encoder>
+void Device::FrameData::LayerData::encode(Encoder& encoder) const
+{
+    encoder << opaqueTexture;
+}
+
+template<class Decoder>
+Optional<Device::FrameData::LayerData> Device::FrameData::LayerData::decode(Decoder& decoder)
+{
+    PlatformXR::Device::FrameData::LayerData layerData;
+    if (!decoder.decode(layerData.opaqueTexture))
+        return WTF::nullopt;
+    return layerData;
+}
+
+template<class Encoder>
+void Device::FrameData::encode(Encoder& encoder) const
+{
+    encoder << isTrackingValid;
+    encoder << isPositionValid;
+    encoder << isPositionEmulated;
+    encoder << shouldRender;
+    encoder << predictedDisplayTime;
+    encoder << origin;
+    encoder << floorTransform;
+    encoder << stageParameters;
+    encoder << views;
+    encoder << layers;
+}
+
+template<class Decoder>
+Optional<Device::FrameData> Device::FrameData::decode(Decoder& decoder)
+{
+    PlatformXR::Device::FrameData frameData;
+    if (!decoder.decode(frameData.isTrackingValid))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.isPositionValid))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.isPositionEmulated))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.shouldRender))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.predictedDisplayTime))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.origin))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.floorTransform))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.stageParameters))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.views))
+        return WTF::nullopt;
+    if (!decoder.decode(frameData.layers))
+        return WTF::nullopt;
+    return frameData;
+}
+
 #endif // ENABLE(WEBXR)
 
 } // namespace PlatformXR
+
+#if ENABLE(WEBXR)
+
+namespace WTF {
+
+template<> struct EnumTraits<PlatformXR::ReferenceSpaceType> {
+    using values = EnumValues<
+        PlatformXR::ReferenceSpaceType,
+        PlatformXR::ReferenceSpaceType::Viewer,
+        PlatformXR::ReferenceSpaceType::Local,
+        PlatformXR::ReferenceSpaceType::LocalFloor,
+        PlatformXR::ReferenceSpaceType::BoundedFloor,
+        PlatformXR::ReferenceSpaceType::Unbounded
+    >;
+};
+
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h (275834 => 275835)


--- trunk/Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -27,22 +27,5 @@
 
 #if ENABLE(WEBXR) && PLATFORM(COCOA)
 #include "PlatformXR.h"
-
-namespace PlatformXR {
-
-class PlatformXRDeviceCocoa : public Device {
-public:
-    void initializeTrackingAndRendering(SessionMode) override { }
-    void shutDownTrackingAndRendering() override { }
-    void initializeReferenceSpace(ReferenceSpaceType) override { }
-    Vector<ViewData> views(SessionMode) const override { return { }; }
-    void requestFrame(RequestFrameCallback&&) override { }
-    Optional<LayerHandle> createLayerProjection(uint32_t, uint32_t, bool) override { return WTF::nullopt; };
-    void deleteLayer(LayerHandle) override { };
-};
-
-}
-
 #include <WebKitAdditions/PlatformXRAdditions.h>
-
 #endif

Modified: trunk/Source/WebKit/ChangeLog (275834 => 275835)


--- trunk/Source/WebKit/ChangeLog	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/ChangeLog	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1,3 +1,88 @@
+2021-04-12  Ada Chan  <[email protected]>
+
+        Initial implementation of WebChromeClient::enumerateImmersiveXRDevices() and XRDeviceProxy
+        https://bugs.webkit.org/show_bug.cgi?id=224353
+
+        Reviewed by Dean Jackson
+
+        - Add XRDeviceProxy which implements PlatformXR::Device.
+        - Implement WebChromeClient::enumerateImmersiveXRDevices(), which calls PlatformXRSystemProxy
+        to get the list of XRDeviceProxy.
+        - XRDeviceProxy goes through PlatformXRSystemProxy to handle its operations.
+        PlatformXRSystemProxy sends messages over IPC to PlatformXRSystem on the UI process side,
+        which handles XR device discovery and manages sessions via the PlatformXRCoordinator interface.
+        PlatformXRSystem::xrCoordinator() returns null for now and will be handled in a later patch.
+
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Platform/Logging.h:
+        * Scripts/webkit/messages.py:
+        (types_that_cannot_be_forward_declared):
+        (headers_for_type):
+        * Shared/Cocoa/XRDeviceProxy.h: Added.
+        * Shared/Cocoa/XRDeviceProxy.mm: Added.
+        (WebKit::XRDeviceProxy::create):
+        (WebKit::XRDeviceProxy::XRDeviceProxy):
+        Initialize its data members based on the XRDeviceInfo passed in.
+        Keep a weak pointer to PlatformXRSystemProxy (as PlatformXRSystemProxy has
+        strong references to its list of XRDeviceProxy).
+        (WebKit::XRDeviceProxy::sessionDidEnd):
+        Notify the TrackingAndRenderingClient that the session has ended.
+        (WebKit::XRDeviceProxy::initializeTrackingAndRendering):
+        (WebKit::XRDeviceProxy::shutDownTrackingAndRendering):
+        (WebKit::XRDeviceProxy::views const):
+        Return left and right views if the device supports stereo rendering.
+        Otherwise return just one view.
+        (WebKit::XRDeviceProxy::requestFrame):
+        * Shared/WebCoreArgumentCoders.h:
+        * SourcesCocoa.txt:
+        * UIProcess/Cocoa/PlatformXRCoordinator.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
+        Initial interface for communicating with the platform regarding XR devices and sessions.
+        For now, the interface covers session creation and termination, and scheduling frame updates.
+        * UIProcess/Cocoa/PlatformXRSystem.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
+        * UIProcess/Cocoa/PlatformXRSystem.messages.in: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
+        * UIProcess/Cocoa/PlatformXRSystem.mm: Added.
+        (WebKit::PlatformXRSystem::PlatformXRSystem):
+        (WebKit::PlatformXRSystem::~PlatformXRSystem):
+        (WebKit::PlatformXRSystem::invalidate):
+        End any existing session on invalidation.
+        (WebKit::PlatformXRSystem::enumerateImmersiveXRDevices):
+        (WebKit::PlatformXRSystem::initializeTrackingAndRendering):
+        (WebKit::PlatformXRSystem::shutDownTrackingAndRendering):
+        (WebKit::PlatformXRSystem::requestFrame):
+        (WebKit::PlatformXRSystem::xrCoordinator):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didAttachToRunningProcess):
+        Set up the PlatformXRSystem held by the WebPageProxy.
+        (WebKit::WebPageProxy::resetState):
+        Invalidate m_xrSystem so existing session is ended properly.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/HighPerformanceGPUManager.h:
+        Include WeakHashSet.h due to recent type change of m_processesRequiringHighPerformance
+        from HashSet to WeakHashSet.
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::enumerateImmersiveXRDevices):
+        Get the list of XRDeviceInfo that represents the immersive devices returned
+        from PlatformXRSystem. Reuse any existing XRDeviceProxy instances that have the same
+        XRDeviceIdentifier. Otherwise, create new ones.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::xrSystemProxy):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/cocoa/PlatformXRSystemProxy.h: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
+        * WebProcess/cocoa/PlatformXRSystemProxy.messages.in: Copied from Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h.
+        * WebProcess/cocoa/PlatformXRSystemProxy.mm: Added.
+        (WebKit::PlatformXRSystemProxy::PlatformXRSystemProxy):
+        (WebKit::PlatformXRSystemProxy::~PlatformXRSystemProxy):
+        (WebKit::PlatformXRSystemProxy::enumerateImmersiveXRDevices):
+        (WebKit::PlatformXRSystemProxy::initializeTrackingAndRendering):
+        (WebKit::PlatformXRSystemProxy::shutDownTrackingAndRendering):
+        (WebKit::PlatformXRSystemProxy::requestFrame):
+        (WebKit::PlatformXRSystemProxy::sessionDidEnd):
+        (WebKit::PlatformXRSystemProxy::deviceByIdentifier):
+
 2021-04-12  Adrian Perez de Castro  <[email protected]>
 
         [WPE][GTK] Use g_object_notify_by_pspec() whenever possible

Modified: trunk/Source/WebKit/DerivedSources-input.xcfilelist (275834 => 275835)


--- trunk/Source/WebKit/DerivedSources-input.xcfilelist	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/DerivedSources-input.xcfilelist	2021-04-12 19:38:34 UTC (rev 275835)
@@ -98,6 +98,7 @@
 $(PROJECT_DIR)/Shared/WebConnection.messages.in
 $(PROJECT_DIR)/UIProcess/Automation/Automation.json
 $(PROJECT_DIR)/UIProcess/Automation/WebAutomationSession.messages.in
+$(PROJECT_DIR)/UIProcess/Cocoa/PlatformXRSystem.messages.in
 $(PROJECT_DIR)/UIProcess/Cocoa/PlaybackSessionManagerProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in
@@ -105,8 +106,8 @@
 $(PROJECT_DIR)/UIProcess/DrawingAreaProxy.messages.in
 $(PROJECT_DIR)/UIProcess/GPU/GPUProcessProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Inspector/RemoteWebInspectorUIProxy.messages.in
+$(PROJECT_DIR)/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Inspector/WebInspectorUIProxy.messages.in
-$(PROJECT_DIR)/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Media/AudioSessionRoutingArbitratorProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Media/RemoteMediaSessionCoordinatorProxy.messages.in
 $(PROJECT_DIR)/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.messages.in
@@ -198,6 +199,7 @@
 $(PROJECT_DIR)/WebProcess/WebProcess.messages.in
 $(PROJECT_DIR)/WebProcess/WebStorage/StorageAreaMap.messages.in
 $(PROJECT_DIR)/WebProcess/cocoa/AudioCaptureSampleManager.messages.in
+$(PROJECT_DIR)/WebProcess/cocoa/PlatformXRSystemProxy.messages.in
 $(PROJECT_DIR)/WebProcess/cocoa/PlaybackSessionManager.messages.in
 $(PROJECT_DIR)/WebProcess/cocoa/RemoteCaptureSampleManager.messages.in
 $(PROJECT_DIR)/WebProcess/cocoa/UserMediaCaptureManager.messages.in

Modified: trunk/Source/WebKit/DerivedSources-output.xcfilelist (275834 => 275835)


--- trunk/Source/WebKit/DerivedSources-output.xcfilelist	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/DerivedSources-output.xcfilelist	2021-04-12 19:38:34 UTC (rev 275835)
@@ -109,6 +109,12 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/NetworkSocketStreamMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/NetworkSocketStreamMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/NetworkSocketStreamMessagesReplies.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemMessageReceiver.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemMessages.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemMessagesReplies.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemProxyMessageReceiver.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemProxyMessages.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlatformXRSystemProxyMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlaybackSessionManagerMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlaybackSessionManagerMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/PlaybackSessionManagerMessagesReplies.h
@@ -288,12 +294,12 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteVideoTrackProxyMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteVideoTrackProxyMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteVideoTrackProxyMessagesReplies.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessageReceiver.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessages.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIProxyMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIProxyMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIProxyMessagesReplies.h
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessageReceiver.cpp
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessages.h
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/RemoteWebInspectorUIMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/SampleBufferDisplayLayerMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/SampleBufferDisplayLayerMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/SampleBufferDisplayLayerMessagesReplies.h
@@ -418,9 +424,6 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorMessagesReplies.h
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessageReceiver.cpp
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessages.h
-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIExtensionControllerMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIExtensionControllerMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIExtensionControllerMessagesReplies.h
@@ -430,6 +433,9 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIMessagesReplies.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessageReceiver.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessages.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebInspectorUIProxyMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebMDNSRegisterMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebMDNSRegisterMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2/WebMDNSRegisterMessagesReplies.h

Modified: trunk/Source/WebKit/DerivedSources.make (275834 => 275835)


--- trunk/Source/WebKit/DerivedSources.make	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/DerivedSources.make	2021-04-12 19:38:34 UTC (rev 275835)
@@ -161,6 +161,7 @@
 	UIProcess/ios/SmartMagnificationController \
 	UIProcess/mac/SecItemShimProxy \
 	UIProcess/WebGeolocationManagerProxy \
+	UIProcess/Cocoa/PlatformXRSystem \
 	UIProcess/Cocoa/PlaybackSessionManagerProxy \
 	UIProcess/Cocoa/UserMediaCaptureManagerProxy \
 	UIProcess/Cocoa/VideoFullscreenManagerProxy \
@@ -218,6 +219,7 @@
 	WebProcess/Storage/WebSWContextManagerConnection \
 	WebProcess/Storage/WebSWClientConnection \
 	WebProcess/WebProcess \
+	WebProcess/cocoa/PlatformXRSystemProxy \
 	WebProcess/cocoa/PlaybackSessionManager \
 	WebProcess/cocoa/RemoteCaptureSampleManager \
 	WebProcess/cocoa/UserMediaCaptureManager \

Modified: trunk/Source/WebKit/Platform/Logging.h (275834 => 275835)


--- trunk/Source/WebKit/Platform/Logging.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/Platform/Logging.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -104,6 +104,7 @@
     M(WebGL) \
     M(WebRTC) \
     M(WheelEvents) \
+    M(XR) \
 
 WEBKIT2_LOG_CHANNELS(DECLARE_LOG_CHANNEL)
 

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (275834 => 275835)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2021-04-12 19:38:34 UTC (rev 275835)
@@ -343,6 +343,7 @@
         'WebKit::TransactionID',
         'WebKit::UserContentControllerIdentifier',
         'WebKit::WebPageProxyIdentifier',
+        'WebKit::XRDeviceIdentifier',
     ])
 
 
@@ -777,6 +778,7 @@
         'struct WebKit::WebUserStyleSheetData': ['"WebUserContentControllerDataTypes.h"'],
         'struct WebKit::WebScriptMessageHandlerData': ['"WebUserContentControllerDataTypes.h"'],
         'webrtc::WebKitEncodedFrameInfo': ['<webrtc/sdk/WebKit/WebKitEncoder.h>', '<WebCore/LibWebRTCEnumTraits.h>'],
+        'PlatformXR::Device::FrameData': ['<WebCore/PlatformXR.h>'],
     }
 
     headers = []

Copied: trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.h (from rev 275834, trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h) (0 => 275835)


--- trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBXR)
+
+#include "XRDeviceIdentifier.h"
+#include <WebCore/PlatformXR.h>
+#include <wtf/Optional.h>
+#include <wtf/Ref.h>
+#include <wtf/Vector.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebKit {
+
+class PlatformXRSystemProxy;
+
+struct XRDeviceInfo;
+
+class XRDeviceProxy final : public PlatformXR::Device {
+public:
+    static Ref<XRDeviceProxy> create(XRDeviceInfo&&, PlatformXRSystemProxy&);
+    XRDeviceIdentifier identifier() const { return m_identifier; }
+
+    void sessionDidEnd();
+
+private:
+    XRDeviceProxy(XRDeviceInfo&&, PlatformXRSystemProxy&);
+
+    void initializeTrackingAndRendering(PlatformXR::SessionMode) final;
+    void shutDownTrackingAndRendering() final;
+    bool supportsSessionShutdownNotification() const final { return true; }
+    void initializeReferenceSpace(PlatformXR::ReferenceSpaceType) final { }
+    Vector<PlatformXR::Device::ViewData> views(PlatformXR::SessionMode) const final;
+    void requestFrame(PlatformXR::Device::RequestFrameCallback&&) final;
+    Optional<PlatformXR::LayerHandle> createLayerProjection(uint32_t, uint32_t, bool) override { return WTF::nullopt; };
+    void deleteLayer(PlatformXR::LayerHandle) override { };
+
+    XRDeviceIdentifier m_identifier;
+    WeakPtr<PlatformXRSystemProxy> m_xrSystem;
+    bool m_supportsStereoRendering { false };
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(WEBXR)

Added: trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.mm (0 => 275835)


--- trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.mm	                        (rev 0)
+++ trunk/Source/WebKit/Shared/Cocoa/XRDeviceProxy.mm	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "XRDeviceProxy.h"
+
+#if ENABLE(WEBXR)
+
+#import "PlatformXRSystemProxy.h"
+#import "XRDeviceInfo.h"
+
+using namespace PlatformXR;
+
+namespace WebKit {
+
+Ref<XRDeviceProxy> XRDeviceProxy::create(XRDeviceInfo&& deviceInfo, PlatformXRSystemProxy& xrSystem)
+{
+    return adoptRef(*new XRDeviceProxy(WTFMove(deviceInfo), xrSystem));
+}
+
+XRDeviceProxy::XRDeviceProxy(XRDeviceInfo&& deviceInfo, PlatformXRSystemProxy& xrSystem)
+    : m_xrSystem(makeWeakPtr(xrSystem))
+{
+    m_identifier = deviceInfo.identifier;
+    m_supportsStereoRendering = deviceInfo.supportsStereoRendering;
+    m_supportsOrientationTracking = deviceInfo.supportsOrientationTracking;
+    if (!deviceInfo.features.isEmpty())
+        setEnabledFeatures(SessionMode::ImmersiveVr, deviceInfo.features);
+}
+
+void XRDeviceProxy::sessionDidEnd()
+{
+    if (trackingAndRenderingClient())
+        trackingAndRenderingClient()->sessionDidEnd();
+}
+
+void XRDeviceProxy::initializeTrackingAndRendering(PlatformXR::SessionMode sessionMode)
+{
+    if (sessionMode != PlatformXR::SessionMode::ImmersiveVr)
+        return;
+
+    if (m_xrSystem)
+        m_xrSystem->initializeTrackingAndRendering();
+}
+
+void XRDeviceProxy::shutDownTrackingAndRendering()
+{
+    if (m_xrSystem)
+        m_xrSystem->shutDownTrackingAndRendering();
+}
+
+Vector<PlatformXR::Device::ViewData> XRDeviceProxy::views(SessionMode mode) const
+{
+    Vector<Device::ViewData> views;
+    if (m_supportsStereoRendering && mode == SessionMode::ImmersiveVr) {
+        views.append({ .active = true, Eye::Left });
+        views.append({ .active = true, Eye::Right });
+    } else
+        views.append({ .active = true, Eye::None });
+    return views;
+}
+
+void XRDeviceProxy::requestFrame(PlatformXR::Device::RequestFrameCallback&& callback)
+{
+    if (m_xrSystem)
+        m_xrSystem->requestFrame(WTFMove(callback));
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(WEBXR)

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (275834 => 275835)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1039,19 +1039,4 @@
 };
 #endif
 
-#if ENABLE(WEBXR)
-
-template<> struct EnumTraits<PlatformXR::ReferenceSpaceType> {
-    using values = EnumValues<
-        PlatformXR::ReferenceSpaceType,
-        PlatformXR::ReferenceSpaceType::Viewer,
-        PlatformXR::ReferenceSpaceType::Local,
-        PlatformXR::ReferenceSpaceType::LocalFloor,
-        PlatformXR::ReferenceSpaceType::BoundedFloor,
-        PlatformXR::ReferenceSpaceType::Unbounded
-    >;
-};
-
-#endif
-
 } // namespace WTF

Modified: trunk/Source/WebKit/SourcesCocoa.txt (275834 => 275835)


--- trunk/Source/WebKit/SourcesCocoa.txt	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2021-04-12 19:38:34 UTC (rev 275835)
@@ -181,6 +181,7 @@
 Shared/Cocoa/WKObject.mm
 Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm
 Shared/Cocoa/XRDeviceInfo.mm
+Shared/Cocoa/XRDeviceProxy.mm
 
 Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm
 Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm
@@ -395,6 +396,7 @@
 UIProcess/Cocoa/MediaPermissionUtilities.mm
 UIProcess/Cocoa/NavigationState.mm
 UIProcess/Cocoa/PageClientImplCocoa.mm
+UIProcess/Cocoa/PlatformXRSystem.mm
 UIProcess/Cocoa/PlaybackSessionManagerProxy.mm
 UIProcess/Cocoa/ResourceLoadDelegate.mm
 UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm
@@ -586,6 +588,7 @@
 
 WebProcess/ApplePay/cocoa/WebPaymentCoordinatorCocoa.mm
 
+WebProcess/cocoa/PlatformXRSystemProxy.mm
 WebProcess/cocoa/PlaybackSessionManager.mm
 WebProcess/cocoa/RemoteCaptureSampleManager.cpp
 WebProcess/cocoa/RemoteRealtimeAudioSource.cpp
@@ -701,6 +704,8 @@
 LibWebRTCCodecsProxyMessageReceiver.cpp
 LibWebRTCCodecsMessageReceiver.cpp
 MessageNames.cpp
+PlatformXRSystemMessageReceiver.cpp
+PlatformXRSystemProxyMessageReceiver.cpp
 RemoteAudioDestinationManagerMessageReceiver.cpp
 RemoteAudioHardwareListenerMessageReceiver.cpp
 RemoteAudioSessionMessageReceiver.cpp

Copied: trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRCoordinator.h (from rev 275834, trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h) (0 => 275835)


--- trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRCoordinator.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRCoordinator.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBXR)
+
+#include "XRDeviceIdentifier.h"
+#include "XRDeviceInfo.h"
+#include <WebCore/PlatformXR.h>
+#include <wtf/Function.h>
+#include <wtf/Optional.h>
+
+namespace WebKit {
+
+class WebPageProxy;
+
+class PlatformXRCoordinator {
+public:
+    virtual ~PlatformXRCoordinator() = default;
+
+    using DeviceInfoCallback = Function<void(Optional<XRDeviceInfo>)>;
+    virtual void getPrimaryDeviceInfo(DeviceInfoCallback&&) = 0;
+
+    // Session creation/termination.
+    using _OnSessionEndCallback_ = Function<void(XRDeviceIdentifier)>;
+    virtual void startSession(WebPageProxy&, OnSessionEndCallback&&) = 0;
+    virtual void endSessionIfExists(WebPageProxy&) = 0;
+
+    // Session display loop.
+    virtual void scheduleAnimationFrame(WebPageProxy&, PlatformXR::Device::RequestFrameCallback&&) = 0;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(WEBXR)

Copied: trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.h (from rev 275834, trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h) (0 => 275835)


--- trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBXR)
+
+#include "MessageReceiver.h"
+#include <WebCore/PlatformXR.h>
+
+namespace WebKit {
+
+class PlatformXRCoordinator;
+class WebPageProxy;
+
+struct XRDeviceInfo;
+
+class PlatformXRSystem : public IPC::MessageReceiver {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    PlatformXRSystem(WebPageProxy&);
+    virtual ~PlatformXRSystem();
+
+    void invalidate();
+
+private:
+    static PlatformXRCoordinator* xrCoordinator();
+
+    // IPC::MessageReceiver
+    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+
+    // Message handlers
+    void enumerateImmersiveXRDevices(CompletionHandler<void(Vector<XRDeviceInfo>&&)>&&);
+    void initializeTrackingAndRendering();
+    void shutDownTrackingAndRendering();
+    void requestFrame(CompletionHandler<void(PlatformXR::Device::FrameData&&)>&&);
+
+    WebPageProxy& m_page;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(WEBXR)

Copied: trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.messages.in (from rev 275834, trunk/Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h) (0 => 275835)


--- trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.messages.in	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.messages.in	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+#if PLATFORM(COCOA) && ENABLE(WEBXR)
+
+messages -> PlatformXRSystem NotRefCounted {
+    EnumerateImmersiveXRDevices() -> (Vector<WebKit::XRDeviceInfo> devicesInfos) Async
+    InitializeTrackingAndRendering()
+    ShutDownTrackingAndRendering()
+    RequestFrame() -> (struct PlatformXR::Device::FrameData frameData) Async
+}
+
+#endif

Added: trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.mm (0 => 275835)


--- trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PlatformXRSystem.mm	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "PlatformXRSystem.h"
+
+#if ENABLE(WEBXR)
+
+#import "PlatformXRCoordinator.h"
+#import "PlatformXRSystemMessages.h"
+#import "PlatformXRSystemProxyMessages.h"
+#import "WebPageProxy.h"
+#import "WebProcessProxy.h"
+
+namespace WebKit {
+
+PlatformXRSystem::PlatformXRSystem(WebPageProxy& page)
+    : m_page(page)
+{
+    m_page.process().addMessageReceiver(Messages::PlatformXRSystem::messageReceiverName(), m_page.webPageID(), *this);
+}
+
+PlatformXRSystem::~PlatformXRSystem()
+{
+    m_page.process().removeMessageReceiver(Messages::PlatformXRSystem::messageReceiverName(), m_page.webPageID());
+}
+
+void PlatformXRSystem::invalidate()
+{
+    if (xrCoordinator())
+        xrCoordinator()->endSessionIfExists(m_page);
+}
+
+void PlatformXRSystem::enumerateImmersiveXRDevices(CompletionHandler<void(Vector<XRDeviceInfo>&&)>&& completionHandler)
+{
+    auto* xrCoordinator = PlatformXRSystem::xrCoordinator();
+    if (!xrCoordinator) {
+        completionHandler({ });
+        return;
+    }
+
+    xrCoordinator->getPrimaryDeviceInfo([completionHandler = WTFMove(completionHandler)](Optional<XRDeviceInfo> deviceInfo) mutable {
+        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), deviceInfo = WTFMove(deviceInfo)]() mutable {
+            if (!deviceInfo) {
+                completionHandler({ });
+                return;
+            }
+
+            completionHandler({ deviceInfo.value() });
+        });
+    });
+}
+
+void PlatformXRSystem::initializeTrackingAndRendering()
+{
+    auto* xrCoordinator = PlatformXRSystem::xrCoordinator();
+    if (!xrCoordinator)
+        return;
+
+    xrCoordinator->startSession(m_page, [weakThis = makeWeakPtr(*this)](XRDeviceIdentifier deviceIdentifier) {
+        RunLoop::main().dispatch([weakThis, deviceIdentifier]() mutable {
+            if (weakThis)
+                weakThis->m_page.send(Messages::PlatformXRSystemProxy::SessionDidEnd(deviceIdentifier));
+        });
+    });
+}
+
+void PlatformXRSystem::shutDownTrackingAndRendering()
+{
+    if (auto* xrCoordinator = PlatformXRSystem::xrCoordinator())
+        xrCoordinator->endSessionIfExists(m_page);
+}
+
+void PlatformXRSystem::requestFrame(CompletionHandler<void(PlatformXR::Device::FrameData&&)>&& completionHandler)
+{
+    if (auto* xrCoordinator = PlatformXRSystem::xrCoordinator())
+        xrCoordinator->scheduleAnimationFrame(m_page, WTFMove(completionHandler));
+}
+
+PlatformXRCoordinator* PlatformXRSystem::xrCoordinator()
+{
+    // FIXME: Implement this
+    return nullptr;
+}
+
+}
+
+#endif // ENABLE(WEBXR)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (275834 => 275835)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1025,6 +1025,11 @@
     ASSERT(!m_webDeviceOrientationUpdateProviderProxy);
     m_webDeviceOrientationUpdateProviderProxy = makeUnique<WebDeviceOrientationUpdateProviderProxy>(*this);
 #endif
+
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    ASSERT(!m_xrSystem);
+    m_xrSystem = makeUnique<PlatformXRSystem>(*this);
+#endif
 }
 
 RefPtr<API::Navigation> WebPageProxy::launchProcessForReload()
@@ -7588,6 +7593,13 @@
 #endif
 
     m_speechRecognitionPermissionManager = nullptr;
+
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    if (m_xrSystem) {
+        m_xrSystem->invalidate();
+        m_xrSystem = nullptr;
+    }
+#endif
 }
 
 void WebPageProxy::resetStateAfterProcessExited(ProcessTerminationReason terminationReason)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (275834 => 275835)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -183,6 +183,10 @@
 #include <WebCore/MediaSessionIdentifier.h>
 #endif
 
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+#include "PlatformXRSystem.h"
+#endif
+
 #if USE(APPLE_INTERNAL_SDK)
 #import <WebKitAdditions/WebPageProxyAdditionsBefore.h>
 #endif
@@ -2991,6 +2995,10 @@
 
     Optional<WebCore::PrivateClickMeasurement> m_privateClickMeasurement;
 
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    std::unique_ptr<PlatformXRSystem> m_xrSystem;
+#endif
+
 #if USE(APPLE_INTERNAL_SDK)
 #import <WebKitAdditions/WebPageProxyAdditionsAfter.h>
 #endif

Modified: trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h (275834 => 275835)


--- trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -29,8 +29,8 @@
 
 #include <OpenGL/CGLTypes.h>
 #include <WebCore/Timer.h>
-#include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/WeakHashSet.h>
 
 namespace WebKit {
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (275834 => 275835)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1100,6 +1100,10 @@
 		51FD18B61651FBAD00DBE1CE /* NetworkResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */; };
 		525080B1261BDE6C00678AEE /* XRDeviceIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 525080AE261BDE6B00678AEE /* XRDeviceIdentifier.h */; };
 		525080B2261BDE6C00678AEE /* XRDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 525080AF261BDE6C00678AEE /* XRDeviceInfo.h */; };
+		5263E257261E73DF0018D47D /* XRDeviceProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 5263E255261E73DF0018D47D /* XRDeviceProxy.h */; };
+		5263E25A261E93A70018D47D /* PlatformXRCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 5263E24D261E6FB90018D47D /* PlatformXRCoordinator.h */; };
+		5263E25B261E93AB0018D47D /* PlatformXRSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 5263E24F261E72EB0018D47D /* PlatformXRSystem.h */; };
+		5263E25F261E96EF0018D47D /* PlatformXRSystemProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 5263E25D261E96DF0018D47D /* PlatformXRSystemProxy.h */; };
 		5272D4C91E735F0900EB4290 /* WKProtectionSpaceNS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		528C37C1195CBB1A00D8B9CC /* WKBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		52D5A1B01C57495A00DE34A3 /* VideoFullscreenManagerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 52D5A1AA1C57494E00DE34A3 /* VideoFullscreenManagerProxy.h */; };
@@ -4160,6 +4164,15 @@
 		525080AD261BDE6B00678AEE /* XRDeviceInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = XRDeviceInfo.mm; sourceTree = "<group>"; };
 		525080AE261BDE6B00678AEE /* XRDeviceIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XRDeviceIdentifier.h; sourceTree = "<group>"; };
 		525080AF261BDE6C00678AEE /* XRDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XRDeviceInfo.h; sourceTree = "<group>"; };
+		5263E24D261E6FB90018D47D /* PlatformXRCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformXRCoordinator.h; sourceTree = "<group>"; };
+		5263E24E261E72EB0018D47D /* PlatformXRSystem.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformXRSystem.mm; sourceTree = "<group>"; };
+		5263E24F261E72EB0018D47D /* PlatformXRSystem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformXRSystem.h; sourceTree = "<group>"; };
+		5263E250261E72EC0018D47D /* PlatformXRSystem.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = PlatformXRSystem.messages.in; sourceTree = "<group>"; };
+		5263E254261E73DE0018D47D /* XRDeviceProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = XRDeviceProxy.mm; sourceTree = "<group>"; };
+		5263E255261E73DF0018D47D /* XRDeviceProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XRDeviceProxy.h; sourceTree = "<group>"; };
+		5263E25C261E96DF0018D47D /* PlatformXRSystemProxy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformXRSystemProxy.mm; sourceTree = "<group>"; };
+		5263E25D261E96DF0018D47D /* PlatformXRSystemProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformXRSystemProxy.h; sourceTree = "<group>"; };
+		5263E25E261E96E00018D47D /* PlatformXRSystemProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = PlatformXRSystemProxy.messages.in; sourceTree = "<group>"; };
 		5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKProtectionSpaceNS.h; path = mac/WKProtectionSpaceNS.h; sourceTree = "<group>"; };
 		5272D4C81E735F0900EB4290 /* WKProtectionSpaceNS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKProtectionSpaceNS.mm; path = mac/WKProtectionSpaceNS.mm; sourceTree = "<group>"; };
 		52D5A1AA1C57494E00DE34A3 /* VideoFullscreenManagerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenManagerProxy.h; sourceTree = "<group>"; };
@@ -6987,6 +7000,10 @@
 				1ABC3DF31899E437004F0626 /* NavigationState.mm */,
 				5C6CE6D31F59EA350007C6CB /* PageClientImplCocoa.h */,
 				5C6CE6D01F59BC460007C6CB /* PageClientImplCocoa.mm */,
+				5263E24D261E6FB90018D47D /* PlatformXRCoordinator.h */,
+				5263E24F261E72EB0018D47D /* PlatformXRSystem.h */,
+				5263E250261E72EC0018D47D /* PlatformXRSystem.messages.in */,
+				5263E24E261E72EB0018D47D /* PlatformXRSystem.mm */,
 				CDA29A1E1CBEB5FB00901CCF /* PlaybackSessionManagerProxy.h */,
 				CDA29A221CBEB61A00901CCF /* PlaybackSessionManagerProxy.messages.in */,
 				CDA29A1F1CBEB5FB00901CCF /* PlaybackSessionManagerProxy.mm */,
@@ -8251,6 +8268,8 @@
 				525080AE261BDE6B00678AEE /* XRDeviceIdentifier.h */,
 				525080AF261BDE6C00678AEE /* XRDeviceInfo.h */,
 				525080AD261BDE6B00678AEE /* XRDeviceInfo.mm */,
+				5263E255261E73DF0018D47D /* XRDeviceProxy.h */,
+				5263E254261E73DE0018D47D /* XRDeviceProxy.mm */,
 			);
 			name = cocoa;
 			path = Cocoa;
@@ -9241,6 +9260,9 @@
 				C1A152D624E5A29A00978C8B /* HandleXPCEndpointMessages.mm */,
 				C14D37FC24ACDF45007FF014 /* LaunchServicesDatabaseManager.h */,
 				C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */,
+				5263E25D261E96DF0018D47D /* PlatformXRSystemProxy.h */,
+				5263E25E261E96E00018D47D /* PlatformXRSystemProxy.messages.in */,
+				5263E25C261E96DF0018D47D /* PlatformXRSystemProxy.mm */,
 				446DC64B24A2D8AD0061F390 /* PlaybackSessionContextIdentifier.h */,
 				CDA29A191CBDBF4100901CCF /* PlaybackSessionManager.h */,
 				CDA29A1C1CBDBF5B00901CCF /* PlaybackSessionManager.messages.in */,
@@ -12082,6 +12104,9 @@
 				2D8710171828415D0018FA01 /* PlatformCALayerRemoteCustom.h in Headers */,
 				2D8949F1182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h in Headers */,
 				BCC43ABB127B95DC00317F16 /* PlatformPopupMenuData.h in Headers */,
+				5263E25A261E93A70018D47D /* PlatformXRCoordinator.h in Headers */,
+				5263E25B261E93AB0018D47D /* PlatformXRSystem.h in Headers */,
+				5263E25F261E96EF0018D47D /* PlatformXRSystemProxy.h in Headers */,
 				446DC64C24A2D8E50061F390 /* PlaybackSessionContextIdentifier.h in Headers */,
 				CDA29A1B1CBDBF4100901CCF /* PlaybackSessionManager.h in Headers */,
 				CDA29A291CBEB67A00901CCF /* PlaybackSessionManagerMessages.h in Headers */,
@@ -12972,6 +12997,7 @@
 				BCBECDE816B6416800047A1A /* XPCServiceEntryPoint.h in Headers */,
 				525080B1261BDE6C00678AEE /* XRDeviceIdentifier.h in Headers */,
 				525080B2261BDE6C00678AEE /* XRDeviceInfo.h in Headers */,
+				5263E257261E73DF0018D47D /* XRDeviceProxy.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (275834 => 275835)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-04-12 19:38:34 UTC (rev 275835)
@@ -1473,4 +1473,11 @@
 
 #endif // ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)
 
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+void WebChromeClient::enumerateImmersiveXRDevices(CompletionHandler<void(const PlatformXR::Instance::DeviceList&)>&& completionHandler)
+{
+    m_page.xrSystemProxy().enumerateImmersiveXRDevices(WTFMove(completionHandler));
+}
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (275834 => 275835)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -435,6 +435,10 @@
     void showMediaControlsContextMenu(WebCore::FloatRect&&, Vector<WebCore::MediaControlsContextMenuItem>&&, CompletionHandler<void(WebCore::MediaControlsContextMenuItem::ID)>&&) final;
 #endif // ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)
 
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    void enumerateImmersiveXRDevices(CompletionHandler<void(const PlatformXR::Instance::DeviceList&)>&&) final;
+#endif
+
     mutable bool m_cachedMainFrameHasHorizontalScrollbar { false };
     mutable bool m_cachedMainFrameHasVerticalScrollbar { false };
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (275834 => 275835)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2021-04-12 19:38:34 UTC (rev 275835)
@@ -439,6 +439,15 @@
     completionHandler(FloatSize(plugin->pdfDocumentSizeForPrinting()));
 }
 
+#if ENABLE(WEBXR)
+PlatformXRSystemProxy& WebPage::xrSystemProxy()
+{
+    if (!m_xrSystemProxy)
+        m_xrSystemProxy = std::unique_ptr<PlatformXRSystemProxy>(new PlatformXRSystemProxy(*this));
+    return *m_xrSystemProxy;
+}
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(COCOA)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (275834 => 275835)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-12 19:31:19 UTC (rev 275834)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -144,6 +144,10 @@
 #include <WebCore/MediaSessionIdentifier.h>
 #endif
 
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+#include "PlatformXRSystemProxy.h"
+#endif
+
 #if PLATFORM(COCOA)
 #include "DynamicViewportSizeUpdate.h"
 #include <WebCore/VisibleSelection.h>
@@ -1428,7 +1432,11 @@
 #if ENABLE(TEXT_AUTOSIZING)
     void textAutosizingUsesIdempotentModeChanged();
 #endif
-    
+
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    PlatformXRSystemProxy& xrSystemProxy();
+#endif
+
 private:
     WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
 
@@ -2310,6 +2318,10 @@
     Vector<std::pair<WeakPtr<WebCore::HTMLElement>, Vector<CompletionHandler<void(RefPtr<WebCore::Element>&&)>>>> m_elementsPendingImageExtraction;
     WeakHashSet<WebCore::HTMLElement> m_elementsWithExtractedImages;
 #endif
+
+#if ENABLE(WEBXR) && PLATFORM(COCOA)
+    std::unique_ptr<PlatformXRSystemProxy> m_xrSystemProxy;
+#endif
 };
 
 #if !PLATFORM(IOS_FAMILY)

Copied: trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.h (from rev 275834, trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h) (0 => 275835)


--- trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.h	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBXR)
+
+#include "MessageReceiver.h"
+#include "XRDeviceIdentifier.h"
+#include "XRDeviceProxy.h"
+#include <WebCore/PlatformXR.h>
+
+namespace WebKit {
+
+class WebPage;
+
+class PlatformXRSystemProxy : public IPC::MessageReceiver {
+public:
+    PlatformXRSystemProxy(WebPage&);
+    virtual ~PlatformXRSystemProxy();
+
+    void enumerateImmersiveXRDevices(CompletionHandler<void(const PlatformXR::Instance::DeviceList&)>&&);
+    void initializeTrackingAndRendering();
+    void shutDownTrackingAndRendering();
+    void requestFrame(PlatformXR::Device::RequestFrameCallback&&);
+
+private:
+    RefPtr<XRDeviceProxy> deviceByIdentifier(XRDeviceIdentifier);
+
+    // IPC::MessageReceiver
+    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+
+    // Message handlers
+    void sessionDidEnd(XRDeviceIdentifier);
+
+    PlatformXR::Instance::DeviceList m_devices;
+    WebPage& m_page;
+};
+
+}
+
+#endif // ENABLE(WEBXR)

Copied: trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.messages.in (from rev 275834, trunk/Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h) (0 => 275835)


--- trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.messages.in	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.messages.in	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if PLATFORM(COCOA) && ENABLE(WEBXR)
+
+messages -> PlatformXRSystemProxy NotRefCounted {
+    SessionDidEnd(WebKit::XRDeviceIdentifier deviceIdentifier)
+}
+
+#endif

Added: trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.mm (0 => 275835)


--- trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.mm	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/cocoa/PlatformXRSystemProxy.mm	2021-04-12 19:38:34 UTC (rev 275835)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "PlatformXRSystemProxy.h"
+
+#if ENABLE(WEBXR)
+
+#import "PlatformXRSystemMessages.h"
+#import "PlatformXRSystemProxyMessages.h"
+#import "WebPage.h"
+#import "WebProcess.h"
+#import "XRDeviceInfo.h"
+#import <wtf/Vector.h>
+
+using namespace PlatformXR;
+
+namespace WebKit {
+
+PlatformXRSystemProxy::PlatformXRSystemProxy(WebPage& page)
+    : m_page(page)
+{
+    WebProcess::singleton().addMessageReceiver(Messages::PlatformXRSystemProxy::messageReceiverName(), m_page.identifier(), *this);
+}
+
+PlatformXRSystemProxy::~PlatformXRSystemProxy()
+{
+    WebProcess::singleton().removeMessageReceiver(Messages::PlatformXRSystemProxy::messageReceiverName(), m_page.identifier());
+}
+
+void PlatformXRSystemProxy::enumerateImmersiveXRDevices(CompletionHandler<void(const Instance::DeviceList&)>&& completionHandler)
+{
+    m_page.sendWithAsyncReply(Messages::PlatformXRSystem::EnumerateImmersiveXRDevices(), [this, weakThis = makeWeakPtr(this), completionHandler = WTFMove(completionHandler)](Vector<XRDeviceInfo>&& devicesInfos) mutable {
+        if (!weakThis)
+            return;
+
+        PlatformXR::Instance::DeviceList devices;
+        for (auto& deviceInfo : devicesInfos) {
+            if (auto device = deviceByIdentifier(deviceInfo.identifier))
+                devices.append(*device);
+            else
+                devices.append(XRDeviceProxy::create(WTFMove(deviceInfo), *this));
+        }
+        m_devices.swap(devices);
+        completionHandler(m_devices);
+    });
+}
+
+void PlatformXRSystemProxy::initializeTrackingAndRendering()
+{
+    m_page.send(Messages::PlatformXRSystem::InitializeTrackingAndRendering());
+}
+
+void PlatformXRSystemProxy::shutDownTrackingAndRendering()
+{
+    m_page.send(Messages::PlatformXRSystem::ShutDownTrackingAndRendering());
+}
+
+void PlatformXRSystemProxy::requestFrame(PlatformXR::Device::RequestFrameCallback&& callback)
+{
+    m_page.sendWithAsyncReply(Messages::PlatformXRSystem::RequestFrame(), WTFMove(callback));
+}
+
+void PlatformXRSystemProxy::sessionDidEnd(XRDeviceIdentifier deviceIdentifier)
+{
+    if (auto device = deviceByIdentifier(deviceIdentifier))
+        device->sessionDidEnd();
+}
+
+RefPtr<XRDeviceProxy> PlatformXRSystemProxy::deviceByIdentifier(XRDeviceIdentifier identifier)
+{
+    for (auto& device : m_devices) {
+        auto* deviceProxy = static_cast<XRDeviceProxy*>(device.ptr());
+        if (deviceProxy->identifier() == identifier)
+            return deviceProxy;
+    }
+
+    return nullptr;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(WEBXR)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to