Diff
Modified: trunk/Source/WebCore/ChangeLog (271287 => 271288)
--- trunk/Source/WebCore/ChangeLog 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/ChangeLog 2021-01-08 09:59:25 UTC (rev 271288)
@@ -1,3 +1,29 @@
+2020-09-24 Sergio Villar Senin <[email protected]>
+
+ [WebXR] Initial implemention of device initialization/shutdown with OpenXR
+ https://bugs.webkit.org/show_bug.cgi?id=216925
+
+ Reviewed by Darin Adler.
+
+ Added a very basic initialization and shutdown processes of XR devices using OpenXR. So far we're just creating and destroying
+ the XR session. Follow up patches will add the required machinery to get frame data from OpenXR.
+
+ * Modules/webxr/WebXRSession.cpp:
+ (WebCore::WebXRSession::WebXRSession): Call initializeTrackingAndRendering().
+ (WebCore::WebXRSession::~WebXRSession): Call shutdownTrackingAndRendering().
+ (WebCore::WebXRSession::shutdown): Ditto.
+ * Modules/webxr/WebXRSystem.h:
+ * platform/xr/PlatformXR.h: New virtual methods to initialize/shutdown devices.
+ * platform/xr/openxr/PlatformXROpenXR.cpp:
+ (PlatformXR::OpenXRDevice::OpenXRDevice): Initialize m_session.
+ (PlatformXR::OpenXRDevice::~OpenXRDevice): Call shutdownTrackingAndRendering().
+ (PlatformXR::toXrViewConfigurationType): New method. Translates from SessionMode to XrViewConfigurationType.
+ (PlatformXR::OpenXRDevice::initializeTrackingAndRendering): New method. Creates a session with a given mode.
+ (PlatformXR::OpenXRDevice::resetSession): Destroys session.
+ (PlatformXR::OpenXRDevice::shutdownTrackingAndRendering):
+ * platform/xr/openxr/PlatformXROpenXR.h:
+ * testing/WebFakeXRDevice.h: Added empty implementations for the new virtual methods.
+
2021-01-07 Zalan Bujtas <[email protected]>
paypal.com: text at the bottom of the page is not aligned properly
Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (271287 => 271288)
--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp 2021-01-08 09:59:25 UTC (rev 271288)
@@ -57,12 +57,16 @@
, m_activeRenderState(WebXRRenderState::create(mode))
, m_animationTimer(*this, &WebXRSession::animationTimerFired)
{
- // FIXME: If no other features of the user agent have done so already, perform the necessary platform-specific steps to
- // initialize the device's tracking and rendering capabilities, including showing any necessary instructions to the user.
+ m_device->initializeTrackingAndRendering(mode);
+
suspendIfNeeded();
}
-WebXRSession::~WebXRSession() = default;
+WebXRSession::~WebXRSession()
+{
+ if (!m_ended && m_device)
+ m_device->shutDownTrackingAndRendering();
+}
XREnvironmentBlendMode WebXRSession::environmentBlendMode() const
{
@@ -329,6 +333,9 @@
// 6.1. Releasing exclusive access to the XR device if session is an immersive session.
// 6.2. Deallocating any graphics resources acquired by session for presentation to the XR device.
// 6.3. Putting the XR device in a state such that a different source may be able to initiate a session with the same device if session is an immersive session.
+ if (m_device)
+ m_device->shutDownTrackingAndRendering();
+
// 7. Queue a task that fires an XRSessionEvent named end on session.
auto event = XRSessionEvent::create(eventNames().endEvent, { makeRefPtr(*this) });
queueTaskToDispatchEvent(*this, TaskSource::WebXR, WTFMove(event));
@@ -342,7 +349,8 @@
Ref<WebXRSession> protectedThis(*this);
// 1. Let promise be a new Promise.
// 2. Shut down the target XRSession object.
- shutdown();
+ if (!m_ended)
+ shutdown();
// 3. Queue a task to perform the following steps:
queueTaskKeepingObjectAlive(*this, TaskSource::WebXR, [promise = WTFMove(promise)] () mutable {
Modified: trunk/Source/WebCore/Modules/webxr/WebXRSystem.h (271287 => 271288)
--- trunk/Source/WebCore/Modules/webxr/WebXRSystem.h 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSystem.h 2021-01-08 09:59:25 UTC (rev 271288)
@@ -107,6 +107,10 @@
class DummyInlineDevice final : public PlatformXR::Device {
public:
DummyInlineDevice();
+
+ private:
+ void initializeTrackingAndRendering(PlatformXR::SessionMode) final { }
+ void shutDownTrackingAndRendering() final { }
};
DummyInlineDevice m_defaultInlineDevice;
Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (271287 => 271288)
--- trunk/Source/WebCore/platform/xr/PlatformXR.h 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h 2021-01-08 09:59:25 UTC (rev 271288)
@@ -59,6 +59,9 @@
bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
+ virtual void initializeTrackingAndRendering(SessionMode) = 0;
+ virtual void shutDownTrackingAndRendering() = 0;
+
protected:
Device() = default;
Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp (271287 => 271288)
--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp 2021-01-08 09:59:25 UTC (rev 271288)
@@ -24,11 +24,11 @@
#include "Logging.h"
#include <openxr/openxr_platform.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/Optional.h>
#include <wtf/Scope.h>
#include <wtf/text/StringConcatenateNumbers.h>
#include <wtf/text/WTFString.h>
-#include <wtf/NeverDestroyed.h>
using namespace WebCore;
@@ -53,15 +53,15 @@
return makeString("<unknown ", int(value), ">");
}
-#define RETURN_IF_FAILED(result, call, instance, ...) \
- if (XR_FAILED(result)) { \
- LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
- return __VA_ARGS__; \
- } \
+#define RETURN_IF_FAILED(result, call, instance, ...) \
+ if (XR_FAILED(result)) { \
+ LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
+ return __VA_ARGS__; \
+ }
struct Instance::Impl {
- WTF_MAKE_FAST_ALLOCATED;
-public:
+ WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
Impl();
~Impl();
@@ -260,6 +260,11 @@
});
}
+OpenXRDevice::~OpenXRDevice()
+{
+ shutDownTrackingAndRendering();
+}
+
Device::ListOfEnabledFeatures OpenXRDevice::enumerateReferenceSpaces(XrSession& session) const
{
uint32_t referenceSpacesCount;
@@ -377,6 +382,51 @@
return Device::recommendedResolution(mode);
}
+XrViewConfigurationType toXrViewConfigurationType(SessionMode mode)
+{
+ switch (mode) {
+ case SessionMode::ImmersiveVr:
+ return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
+ case SessionMode::Inline:
+ case SessionMode::ImmersiveAr:
+ return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO;
+ };
+ ASSERT_NOT_REACHED();
+ return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO;
+}
+
+void OpenXRDevice::initializeTrackingAndRendering(SessionMode mode)
+{
+ m_queue.dispatch([this, mode]() {
+ ASSERT(m_instance != XR_NULL_HANDLE);
+ ASSERT(m_session == XR_NULL_HANDLE);
+
+ m_currentViewConfigurationType = toXrViewConfigurationType(mode);
+ ASSERT(m_configurationViews.contains(m_currentViewConfigurationType));
+
+ // Create the session.
+ auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>();
+ sessionCreateInfo.systemId = m_systemId;
+ auto result = xrCreateSession(m_instance, &sessionCreateInfo, &m_session);
+ RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance);
+ });
+}
+
+void OpenXRDevice::resetSession()
+{
+ m_queue.dispatch([this]() {
+ if (m_session == XR_NULL_HANDLE)
+ return;
+ xrDestroySession(m_session);
+ m_session = XR_NULL_HANDLE;
+ });
+}
+
+void OpenXRDevice::shutDownTrackingAndRendering()
+{
+ resetSession();
+}
+
} // namespace PlatformXR
#endif // ENABLE(WEBXR) && USE(OPENXR)
Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h (271287 => 271288)
--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h 2021-01-08 09:59:25 UTC (rev 271288)
@@ -44,6 +44,7 @@
class OpenXRDevice final : public Device {
public:
OpenXRDevice(XrSystemId, XrInstance, WorkQueue&, CompletionHandler<void()>&&);
+ ~OpenXRDevice();
XrSystemId xrSystemId() const { return m_systemId; }
private:
@@ -54,6 +55,11 @@
WebCore::IntSize recommendedResolution(SessionMode) final;
+ void initializeTrackingAndRendering(SessionMode) final;
+ void shutDownTrackingAndRendering() final;
+
+ void resetSession();
+
using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
ViewConfigurationPropertiesMap m_viewConfigurationProperties;
using ViewConfigurationViewsMap = HashMap<XrViewConfigurationType, Vector<XrViewConfigurationView>, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
@@ -61,9 +67,11 @@
XrSystemId m_systemId;
XrInstance m_instance;
- XrSession m_session;
+ XrSession m_session { XR_NULL_HANDLE };
WorkQueue& m_queue;
+
+ XrViewConfigurationType m_currentViewConfigurationType;
};
} // namespace PlatformXR
Modified: trunk/Source/WebCore/testing/WebFakeXRDevice.h (271287 => 271288)
--- trunk/Source/WebCore/testing/WebFakeXRDevice.h 2021-01-08 07:34:45 UTC (rev 271287)
+++ trunk/Source/WebCore/testing/WebFakeXRDevice.h 2021-01-08 09:59:25 UTC (rev 271288)
@@ -70,6 +70,8 @@
void setEmulatedPosition(bool emulated) { m_emulatedPosition = emulated; }
Vector<Ref<FakeXRView>>& views() { return m_views; }
private:
+ void initializeTrackingAndRendering(PlatformXR::SessionMode) final { }
+ void shutDownTrackingAndRendering() final { }
Optional<Vector<FakeXRBoundsPoint>> m_nativeBoundsGeometry;
RefPtr<WebXRRigidTransform> m_viewerOrigin;
RefPtr<WebXRRigidTransform> m_floorOrigin;