Skip to content

Commit 7b7ffcb

Browse files
achan00webkit-commit-queue
authored andcommitted
Initial implementation of WebChromeClient::enumerateImmersiveXRDevices() and XRDeviceProxy
https://bugs.webkit.org/show_bug.cgi?id=224353 Patch by Ada Chan <ada.chan@apple.com> 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): Canonical link: https://commits.webkit.org/236404@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275835 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ecc7ee3 commit 7b7ffcb

28 files changed

Lines changed: 1092 additions & 42 deletions

Source/WebCore/ChangeLog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2021-04-12 Ada Chan <ada.chan@apple.com>
2+
3+
Initial implementation of WebChromeClient::enumerateImmersiveXRDevices() and XRDeviceProxy
4+
https://bugs.webkit.org/show_bug.cgi?id=224353
5+
6+
Reviewed by Dean Jackson.
7+
8+
Remove PlatformXRDeviceCocoa as WebKit::XRDeviceProxy will be implementing PlatformXR::Device.
9+
Implement the encode/decode methods to enable PlatformXR::Device::FrameData to
10+
be sent over IPC.
11+
12+
* platform/xr/PlatformXR.h:
13+
(PlatformXR::Device::trackingAndRenderingClient const):
14+
(PlatformXR::Device::FrameData::FloatQuaternion::encode const):
15+
(PlatformXR::Device::FrameData::FloatQuaternion::decode):
16+
(PlatformXR::Device::FrameData::Pose::encode const):
17+
(PlatformXR::Device::FrameData::Pose::decode):
18+
(PlatformXR::Device::FrameData::Fov::encode const):
19+
(PlatformXR::Device::FrameData::Fov::decode):
20+
(PlatformXR::Device::FrameData::View::encode const):
21+
(PlatformXR::Device::FrameData::View::decode):
22+
(PlatformXR::Device::FrameData::StageParameters::encode const):
23+
(PlatformXR::Device::FrameData::StageParameters::decode):
24+
(PlatformXR::Device::FrameData::LayerData::encode const):
25+
(PlatformXR::Device::FrameData::LayerData::decode):
26+
(PlatformXR::Device::FrameData::encode const):
27+
(PlatformXR::Device::FrameData::decode):
28+
* platform/xr/cocoa/PlatformXRCocoa.h:
29+
(): Deleted.
30+
131
2021-04-12 Antoine Quint <graouts@webkit.org>
232

333
border-image-width computed values should be a calc() value if it contains a percentage

Source/WebCore/platform/xr/PlatformXR.h

Lines changed: 241 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Device : public ThreadSafeRefCounted<Device>, public CanMakeWeakPtr<Device
9595

9696
virtual void initializeTrackingAndRendering(SessionMode) = 0;
9797
virtual void shutDownTrackingAndRendering() = 0;
98+
TrackingAndRenderingClient* trackingAndRenderingClient() const { return m_trackingAndRenderingClient.get(); }
9899
void setTrackingAndRenderingClient(WeakPtr<TrackingAndRenderingClient>&& client) { m_trackingAndRenderingClient = WTFMove(client); }
99100

100101
// If this method returns true, that means the device will notify TrackingAndRenderingClient
@@ -110,11 +111,17 @@ class Device : public ThreadSafeRefCounted<Device>, public CanMakeWeakPtr<Device
110111
float y { 0.0f };
111112
float z { 0.0f };
112113
float w { 1.0f };
114+
115+
template<class Encoder> void encode(Encoder&) const;
116+
template<class Decoder> static Optional<FloatQuaternion> decode(Decoder&);
113117
};
114118

115119
struct Pose {
116120
WebCore::FloatPoint3D position;
117121
FloatQuaternion orientation;
122+
123+
template<class Encoder> void encode(Encoder&) const;
124+
template<class Decoder> static Optional<Pose> decode(Decoder&);
118125
};
119126

120127
struct Fov {
@@ -123,22 +130,37 @@ class Device : public ThreadSafeRefCounted<Device>, public CanMakeWeakPtr<Device
123130
float down { 0.0f };
124131
float left { 0.0f };
125132
float right { 0.0f };
133+
134+
template<class Encoder> void encode(Encoder&) const;
135+
template<class Decoder> static Optional<Fov> decode(Decoder&);
126136
};
127137

128-
using Projection = Variant<Fov, std::array<float, 16>, std::nullptr_t>;
138+
static constexpr size_t projectionMatrixSize = 16;
139+
typedef std::array<float, projectionMatrixSize> ProjectionMatrix;
140+
141+
using Projection = Variant<Fov, ProjectionMatrix, std::nullptr_t>;
129142

130143
struct View {
131144
Pose offset;
132145
Projection projection = { nullptr };
146+
147+
template<class Encoder> void encode(Encoder&) const;
148+
template<class Decoder> static Optional<View> decode(Decoder&);
133149
};
134150

135151
struct StageParameters {
136152
int id { 0 };
137153
Vector<WebCore::FloatPoint> bounds;
154+
155+
template<class Encoder> void encode(Encoder&) const;
156+
template<class Decoder> static Optional<StageParameters> decode(Decoder&);
138157
};
139158

140159
struct LayerData {
141160
PlatformGLObject opaqueTexture { 0 };
161+
162+
template<class Encoder> void encode(Encoder&) const;
163+
template<class Decoder> static Optional<LayerData> decode(Decoder&);
142164
};
143165

144166
bool isTrackingValid { false };
@@ -151,6 +173,9 @@ class Device : public ThreadSafeRefCounted<Device>, public CanMakeWeakPtr<Device
151173
StageParameters stageParameters;
152174
Vector<View> views;
153175
HashMap<LayerHandle, LayerData> layers;
176+
177+
template<class Encoder> void encode(Encoder&) const;
178+
template<class Decoder> static Optional<FrameData> decode(Decoder&);
154179
};
155180

156181
struct LayerView {
@@ -207,6 +232,221 @@ class Instance {
207232
DeviceList m_immersiveXRDevices;
208233
};
209234

235+
template<class Encoder>
236+
void Device::FrameData::FloatQuaternion::encode(Encoder& encoder) const
237+
{
238+
encoder << x << y << z << w;
239+
}
240+
241+
template<class Decoder>
242+
Optional<Device::FrameData::FloatQuaternion> Device::FrameData::FloatQuaternion::decode(Decoder& decoder)
243+
{
244+
Device::FrameData::FloatQuaternion floatQuaternion;
245+
if (!decoder.decode(floatQuaternion.x))
246+
return WTF::nullopt;
247+
if (!decoder.decode(floatQuaternion.y))
248+
return WTF::nullopt;
249+
if (!decoder.decode(floatQuaternion.z))
250+
return WTF::nullopt;
251+
if (!decoder.decode(floatQuaternion.w))
252+
return WTF::nullopt;
253+
return floatQuaternion;
254+
}
255+
256+
template<class Encoder>
257+
void Device::FrameData::Pose::encode(Encoder& encoder) const
258+
{
259+
encoder << position << orientation;
260+
}
261+
262+
template<class Decoder>
263+
Optional<Device::FrameData::Pose> Device::FrameData::Pose::decode(Decoder& decoder)
264+
{
265+
Device::FrameData::Pose pose;
266+
if (!decoder.decode(pose.position))
267+
return WTF::nullopt;
268+
if (!decoder.decode(pose.orientation))
269+
return WTF::nullopt;
270+
return pose;
271+
}
272+
273+
template<class Encoder>
274+
void Device::FrameData::Fov::encode(Encoder& encoder) const
275+
{
276+
encoder << up << down << left << right;
277+
}
278+
279+
template<class Decoder>
280+
Optional<Device::FrameData::Fov> Device::FrameData::Fov::decode(Decoder& decoder)
281+
{
282+
Device::FrameData::Fov fov;
283+
if (!decoder.decode(fov.up))
284+
return WTF::nullopt;
285+
if (!decoder.decode(fov.down))
286+
return WTF::nullopt;
287+
if (!decoder.decode(fov.left))
288+
return WTF::nullopt;
289+
if (!decoder.decode(fov.right))
290+
return WTF::nullopt;
291+
return fov;
292+
}
293+
294+
template<class Encoder>
295+
void Device::FrameData::View::encode(Encoder& encoder) const
296+
{
297+
encoder << offset;
298+
299+
bool hasFov = WTF::holds_alternative<PlatformXR::Device::FrameData::Fov>(projection);
300+
encoder << hasFov;
301+
if (hasFov) {
302+
encoder << WTF::get<PlatformXR::Device::FrameData::Fov>(projection);
303+
return;
304+
}
305+
306+
bool hasProjectionMatrix = WTF::holds_alternative<PlatformXR::Device::FrameData::ProjectionMatrix>(projection);
307+
encoder << hasProjectionMatrix;
308+
if (hasProjectionMatrix) {
309+
for (float f : WTF::get<PlatformXR::Device::FrameData::ProjectionMatrix>(projection))
310+
encoder << f;
311+
return;
312+
}
313+
314+
ASSERT(WTF::holds_alternative<std::nullptr_t>(projection));
315+
}
316+
317+
template<class Decoder>
318+
Optional<Device::FrameData::View> Device::FrameData::View::decode(Decoder& decoder)
319+
{
320+
PlatformXR::Device::FrameData::View view;
321+
if (!decoder.decode(view.offset))
322+
return WTF::nullopt;
323+
324+
bool hasFov;
325+
if (!decoder.decode(hasFov))
326+
return WTF::nullopt;
327+
328+
if (hasFov) {
329+
PlatformXR::Device::FrameData::Fov fov;
330+
if (!decoder.decode(fov))
331+
return WTF::nullopt;
332+
view.projection = { WTFMove(fov) };
333+
return view;
334+
}
335+
336+
bool hasProjectionMatrix;
337+
if (!decoder.decode(hasProjectionMatrix))
338+
return WTF::nullopt;
339+
340+
if (hasProjectionMatrix) {
341+
PlatformXR::Device::FrameData::ProjectionMatrix projectionMatrix;
342+
for (size_t i = 0; i < PlatformXR::Device::FrameData::projectionMatrixSize; ++i) {
343+
float f;
344+
if (!decoder.decode(f))
345+
return WTF::nullopt;
346+
projectionMatrix[i] = f;
347+
}
348+
view.projection = { WTFMove(projectionMatrix) };
349+
return view;
350+
}
351+
352+
view.projection = { nullptr };
353+
return view;
354+
}
355+
356+
template<class Encoder>
357+
void Device::FrameData::StageParameters::encode(Encoder& encoder) const
358+
{
359+
encoder << id;
360+
encoder << bounds;
361+
}
362+
363+
template<class Decoder>
364+
Optional<Device::FrameData::StageParameters> Device::FrameData::StageParameters::decode(Decoder& decoder)
365+
{
366+
PlatformXR::Device::FrameData::StageParameters stageParameters;
367+
if (!decoder.decode(stageParameters.id))
368+
return WTF::nullopt;
369+
if (!decoder.decode(stageParameters.bounds))
370+
return WTF::nullopt;
371+
return stageParameters;
372+
}
373+
374+
template<class Encoder>
375+
void Device::FrameData::LayerData::encode(Encoder& encoder) const
376+
{
377+
encoder << opaqueTexture;
378+
}
379+
380+
template<class Decoder>
381+
Optional<Device::FrameData::LayerData> Device::FrameData::LayerData::decode(Decoder& decoder)
382+
{
383+
PlatformXR::Device::FrameData::LayerData layerData;
384+
if (!decoder.decode(layerData.opaqueTexture))
385+
return WTF::nullopt;
386+
return layerData;
387+
}
388+
389+
template<class Encoder>
390+
void Device::FrameData::encode(Encoder& encoder) const
391+
{
392+
encoder << isTrackingValid;
393+
encoder << isPositionValid;
394+
encoder << isPositionEmulated;
395+
encoder << shouldRender;
396+
encoder << predictedDisplayTime;
397+
encoder << origin;
398+
encoder << floorTransform;
399+
encoder << stageParameters;
400+
encoder << views;
401+
encoder << layers;
402+
}
403+
404+
template<class Decoder>
405+
Optional<Device::FrameData> Device::FrameData::decode(Decoder& decoder)
406+
{
407+
PlatformXR::Device::FrameData frameData;
408+
if (!decoder.decode(frameData.isTrackingValid))
409+
return WTF::nullopt;
410+
if (!decoder.decode(frameData.isPositionValid))
411+
return WTF::nullopt;
412+
if (!decoder.decode(frameData.isPositionEmulated))
413+
return WTF::nullopt;
414+
if (!decoder.decode(frameData.shouldRender))
415+
return WTF::nullopt;
416+
if (!decoder.decode(frameData.predictedDisplayTime))
417+
return WTF::nullopt;
418+
if (!decoder.decode(frameData.origin))
419+
return WTF::nullopt;
420+
if (!decoder.decode(frameData.floorTransform))
421+
return WTF::nullopt;
422+
if (!decoder.decode(frameData.stageParameters))
423+
return WTF::nullopt;
424+
if (!decoder.decode(frameData.views))
425+
return WTF::nullopt;
426+
if (!decoder.decode(frameData.layers))
427+
return WTF::nullopt;
428+
return frameData;
429+
}
430+
210431
#endif // ENABLE(WEBXR)
211432

212433
} // namespace PlatformXR
434+
435+
#if ENABLE(WEBXR)
436+
437+
namespace WTF {
438+
439+
template<> struct EnumTraits<PlatformXR::ReferenceSpaceType> {
440+
using values = EnumValues<
441+
PlatformXR::ReferenceSpaceType,
442+
PlatformXR::ReferenceSpaceType::Viewer,
443+
PlatformXR::ReferenceSpaceType::Local,
444+
PlatformXR::ReferenceSpaceType::LocalFloor,
445+
PlatformXR::ReferenceSpaceType::BoundedFloor,
446+
PlatformXR::ReferenceSpaceType::Unbounded
447+
>;
448+
};
449+
450+
}
451+
452+
#endif

Source/WebCore/platform/xr/cocoa/PlatformXRCocoa.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,5 @@
2727

2828
#if ENABLE(WEBXR) && PLATFORM(COCOA)
2929
#include "PlatformXR.h"
30-
31-
namespace PlatformXR {
32-
33-
class PlatformXRDeviceCocoa : public Device {
34-
public:
35-
void initializeTrackingAndRendering(SessionMode) override { }
36-
void shutDownTrackingAndRendering() override { }
37-
void initializeReferenceSpace(ReferenceSpaceType) override { }
38-
Vector<ViewData> views(SessionMode) const override { return { }; }
39-
void requestFrame(RequestFrameCallback&&) override { }
40-
Optional<LayerHandle> createLayerProjection(uint32_t, uint32_t, bool) override { return WTF::nullopt; };
41-
void deleteLayer(LayerHandle) override { };
42-
};
43-
44-
}
45-
4630
#include <WebKitAdditions/PlatformXRAdditions.h>
47-
4831
#endif

0 commit comments

Comments
 (0)