Diff
Modified: trunk/Source/WebCore/ChangeLog (262837 => 262838)
--- trunk/Source/WebCore/ChangeLog 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/ChangeLog 2020-06-10 13:17:30 UTC (rev 262838)
@@ -1,3 +1,33 @@
+2020-06-05 Sergio Villar Senin <[email protected]>
+
+ [WebXR] Refactor OpenXR platform code
+ https://bugs.webkit.org/show_bug.cgi?id=212470
+
+ Reviewed by Youenn Fablet.
+
+ Refactored a bit the platform code because we want to extend the PlatformXR::Device for the OpenXR
+ library. Also we're removing all the device id code because there is no need to expose it.
+
+ The idea from now on is to only define interfaces in PlatformXR.h and then add all the OpenXR specifics
+ in the newly renamed PlatformXROpenXR.[ch] files. We're also renaming PlatformXR.cpp to
+ PlatformXROpenXR.cpp to clearly state that it's the OpenXR implementation and to differentiate it from
+ the implementation agnostic PlatformXR.h file.
+
+ No new tests as there is no change in functionality.
+
+ * Sources.txt: Added renamed files. Removed PlatformXR.cpp.
+ * WebCore.xcodeproj/project.pbxproj: Ditto.
+ * platform/xr/PlatformXR.cpp: Removed.
+ * platform/xr/PlatformXR.h:
+ (PlatformXR::Device::id const): Deleted.
+ (PlatformXR::Device::operator== const): Deleted.
+ * platform/xr/openxr/PlatformXROpenXR.cpp: Renamed from Source/WebCore/platform/xr/openxr/PlatformXR.cpp.
+ (PlatformXR::Instance::Impl::~Impl): Call xrDestroyInstance() on m_instance.
+ (PlatformXR::Instance::Impl::collectSupportedSessionModes): Do not pass XrSystemId as argument
+ as it's stored in the OpenXRDevice object.
+ (PlatformXR::Instance::enumerateImmersiveXRDevices): Create an OpenXRDevice instead of a Device.
+ * platform/xr/openxr/PlatformXROpenXR.h: Added.
+
2020-06-09 Pinki Gyanchandani <[email protected]>
Release Assert @ WebCore::RenderTreeBuilder::RenderTreeBuilder
Modified: trunk/Source/WebCore/Sources.txt (262837 => 262838)
--- trunk/Source/WebCore/Sources.txt 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/Sources.txt 2020-06-10 13:17:30 UTC (rev 262838)
@@ -2147,8 +2147,7 @@
platform/text/TextEncodingDetectorICU.cpp
platform/text/TextEncodingRegistry.cpp
-platform/xr/PlatformXR.cpp @no-unify
-platform/xr/openxr/PlatformXR.cpp @no-unify
+platform/xr/openxr/PlatformXROpenXR.cpp @no-unify
plugins/DOMMimeType.cpp
plugins/DOMMimeTypeArray.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (262837 => 262838)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-06-10 13:17:30 UTC (rev 262838)
@@ -4802,6 +4802,8 @@
E1BA671A1742BEF400C20251 /* WebCoreTestShimLibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1BA67191742BEF400C20251 /* WebCoreTestShimLibrary.cpp */; };
E1BD331A182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */; };
E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */ = {isa = PBXBuildFile; fileRef = E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */; };
+ E1C1A39D2480080800E0AF66 /* PlatformXROpenXR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C1A39B2480080600E0AF66 /* PlatformXROpenXR.cpp */; };
+ E1C1A39E2480080800E0AF66 /* PlatformXROpenXR.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C1A39C2480080700E0AF66 /* PlatformXROpenXR.h */; };
E1C266DF18319F31003F8B33 /* CryptoKeyRSAComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C266DD18319F31003F8B33 /* CryptoKeyRSAComponents.h */; };
E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C362ED0EAF2AA9007410BC /* JSWorkerLocation.h */; };
E1C36C030EB076D6007410BC /* JSDOMGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C36C020EB076D6007410BC /* JSDOMGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4818,8 +4820,6 @@
E1E6EEA80B628DB3005F2F70 /* JSHTMLSelectElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E6EEA70B628DB3005F2F70 /* JSHTMLSelectElement.h */; };
E1EC29A00BB04C6B00EA187B /* XPathNodeSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EC299E0BB04C6B00EA187B /* XPathNodeSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1ED8AC30CC49BE000BFC557 /* CSSPrimitiveValueMappings.h in Headers */ = {isa = PBXBuildFile; fileRef = E1ED8AC20CC49BE000BFC557 /* CSSPrimitiveValueMappings.h */; settings = {ATTRIBUTES = (Private, ); }; };
- E1EE8B702412B2A800E794D6 /* PlatformXR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE8B6C2412B2A700E794D6 /* PlatformXR.cpp */; };
- E1EE8B712412B2A800E794D6 /* PlatformXR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE8B6E2412B2A700E794D6 /* PlatformXR.cpp */; };
E1EE8B722412B2A800E794D6 /* PlatformXR.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE8B6F2412B2A700E794D6 /* PlatformXR.h */; };
E1EE8B762413191F00E794D6 /* WebXRViewerPose.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE8AC72412B16F00E794D6 /* WebXRViewerPose.h */; };
E1EE8B772413191F00E794D6 /* XRReferenceSpaceType.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE8AC92412B17000E794D6 /* XRReferenceSpaceType.h */; };
@@ -15305,6 +15305,8 @@
E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSASSA_PKCS1_v1_5.h; sourceTree = "<group>"; };
E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTUnicodeSort.cpp; sourceTree = "<group>"; };
E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTUnicodeSort.h; sourceTree = "<group>"; };
+ E1C1A39B2480080600E0AF66 /* PlatformXROpenXR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformXROpenXR.cpp; sourceTree = "<group>"; };
+ E1C1A39C2480080700E0AF66 /* PlatformXROpenXR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformXROpenXR.h; sourceTree = "<group>"; };
E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp; sourceTree = "<group>"; };
E1C266DC18319F31003F8B33 /* CryptoKeyRSAComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoKeyRSAComponents.cpp; sourceTree = "<group>"; };
E1C266DD18319F31003F8B33 /* CryptoKeyRSAComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyRSAComponents.h; sourceTree = "<group>"; };
@@ -15417,8 +15419,6 @@
E1EE8B162412B17000E794D6 /* XRPose.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = XRPose.idl; sourceTree = "<group>"; };
E1EE8B172412B17000E794D6 /* WebXRInputSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebXRInputSource.h; sourceTree = "<group>"; };
E1EE8B182412B17000E794D6 /* XRInputSourceArray.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = XRInputSourceArray.idl; sourceTree = "<group>"; };
- E1EE8B6C2412B2A700E794D6 /* PlatformXR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformXR.cpp; sourceTree = "<group>"; };
- E1EE8B6E2412B2A700E794D6 /* PlatformXR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformXR.cpp; sourceTree = "<group>"; };
E1EE8B6F2412B2A700E794D6 /* PlatformXR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformXR.h; sourceTree = "<group>"; };
E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTExtensions.cpp; sourceTree = "<group>"; };
E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTExtensions.h; sourceTree = "<group>"; };
@@ -27553,7 +27553,6 @@
isa = PBXGroup;
children = (
E1EE8B6D2412B2A700E794D6 /* openxr */,
- E1EE8B6C2412B2A700E794D6 /* PlatformXR.cpp */,
E1EE8B6F2412B2A700E794D6 /* PlatformXR.h */,
);
path = xr;
@@ -27562,7 +27561,8 @@
E1EE8B6D2412B2A700E794D6 /* openxr */ = {
isa = PBXGroup;
children = (
- E1EE8B6E2412B2A700E794D6 /* PlatformXR.cpp */,
+ E1C1A39B2480080600E0AF66 /* PlatformXROpenXR.cpp */,
+ E1C1A39C2480080700E0AF66 /* PlatformXROpenXR.h */,
);
path = openxr;
sourceTree = "<group>";
@@ -32502,6 +32502,7 @@
52B0D4BE1C57FD1E0077CE53 /* PlatformView.h in Headers */,
935C476B09AC4D4F00A6AAB4 /* PlatformWheelEvent.h in Headers */,
E1EE8B722412B2A800E794D6 /* PlatformXR.h in Headers */,
+ E1C1A39E2480080800E0AF66 /* PlatformXROpenXR.h in Headers */,
712BE4801FE864A7002031CC /* PlaybackDirection.h in Headers */,
CDA29A321CC01A9500901CCF /* PlaybackSessionInterfaceAVKit.h in Headers */,
CDA29A171CBDA56C00901CCF /* PlaybackSessionInterfaceMac.h in Headers */,
@@ -34400,8 +34401,7 @@
E16982601134636A00894115 /* ObjCRuntimeObject.mm in Sources */,
CEA284662141E84900E407E8 /* PlatformEventFactoryIOS.mm in Sources */,
AA12DF491743DF83004DAFDF /* PlatformSpeechSynthesizerIOS.mm in Sources */,
- E1EE8B712412B2A800E794D6 /* PlatformXR.cpp in Sources */,
- E1EE8B702412B2A800E794D6 /* PlatformXR.cpp in Sources */,
+ E1C1A39D2480080800E0AF66 /* PlatformXROpenXR.cpp in Sources */,
CDA29A301CBF74D400901CCF /* PlaybackSessionInterfaceAVKit.mm in Sources */,
CDA29A161CBDA56C00901CCF /* PlaybackSessionInterfaceMac.mm in Sources */,
419242492127B93E00634FCF /* RealtimeOutgoingVideoSourceCocoa.mm in Sources */,
Modified: trunk/Source/WebCore/platform/Logging.h (262837 => 262838)
--- trunk/Source/WebCore/platform/Logging.h 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/platform/Logging.h 2020-06-10 13:17:30 UTC (rev 262838)
@@ -115,6 +115,7 @@
M(WebGPU) \
M(WebRTC) \
M(WebRTCStats) \
+ M(XR) \
M(WheelEventTestMonitor) \
#undef DECLARE_LOG_CHANNEL
Deleted: trunk/Source/WebCore/platform/xr/PlatformXR.cpp (262837 => 262838)
--- trunk/Source/WebCore/platform/xr/PlatformXR.cpp 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.cpp 2020-06-10 13:17:30 UTC (rev 262838)
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2020 Igalia, S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * aint with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "PlatformXR.h"
-
-namespace PlatformXR {
-
-#if ENABLE(WEBXR)
-
-Device::DeviceId Instance::nextDeviceId()
-{
- static Device::DeviceId s_nextDeviceId { 0 };
- return s_nextDeviceId++;
-}
-
-Device::Device()
- : m_id(Instance::nextDeviceId())
-{
-}
-
-#endif // ENABLE(WEBXR)
-
-} // namespace PlatformXR
Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (262837 => 262838)
--- trunk/Source/WebCore/platform/xr/PlatformXR.h 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h 2020-06-10 13:17:30 UTC (rev 262838)
@@ -45,9 +45,7 @@
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(Device);
public:
- using DeviceId = uint32_t;
- Device();
- DeviceId id() const { return m_id; }
+ virtual ~Device() = default;
using ListOfEnabledFeatures = Vector<ReferenceSpaceType>;
bool supports(SessionMode mode) const { return m_enabledFeaturesMap.contains(mode); }
@@ -54,17 +52,14 @@
void setEnabledFeatures(SessionMode mode, const ListOfEnabledFeatures& features) { m_enabledFeaturesMap.set(mode, features); }
ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
- inline bool operator==(const Device& other) const { return m_id == other.m_id; }
+protected:
+ Device() = default;
-protected:
// https://immersive-web.github.io/webxr/#xr-device-concept
// Each XR device has a list of enabled features for each XRSessionMode in its list of supported modes,
// which is a list of feature descriptors which MUST be initially an empty list.
using EnabledFeaturesPerModeMap = WTF::HashMap<SessionMode, ListOfEnabledFeatures, WTF::IntHash<SessionMode>, WTF::StrongEnumHashTraits<SessionMode>>;
EnabledFeaturesPerModeMap m_enabledFeaturesMap;
-
-private:
- DeviceId m_id;
};
class Instance {
@@ -71,8 +66,6 @@
public:
static Instance& singleton();
- static Device::DeviceId nextDeviceId();
-
void enumerateImmersiveXRDevices();
const Vector<std::unique_ptr<Device>>& immersiveXRDevices() const { return m_immersiveXRDevices; }
private:
Deleted: trunk/Source/WebCore/platform/xr/openxr/PlatformXR.cpp (262837 => 262838)
--- trunk/Source/WebCore/platform/xr/openxr/PlatformXR.cpp 2020-06-10 11:18:27 UTC (rev 262837)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXR.cpp 2020-06-10 13:17:30 UTC (rev 262838)
@@ -1,236 +0,0 @@
-/*
- * Copyright (C) 2020 Igalia, S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * aint with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "PlatformXR.h"
-
-#if ENABLE(WEBXR)
-
-#if USE_OPENXR
-#include <openxr/openxr.h>
-#include <wtf/Optional.h>
-#include <wtf/text/StringConcatenateNumbers.h>
-#include <wtf/text/WTFString.h>
-#endif // USE_OPENXR
-#include <wtf/NeverDestroyed.h>
-
-namespace PlatformXR {
-
-#if USE_OPENXR
-
-template<typename T, XrStructureType StructureType>
-T createStructure()
-{
- T object;
- std::memset(&object, 0, sizeof(T));
- object.type = StructureType;
- object.next = nullptr;
- return object;
-}
-
-String resultToString(XrResult value, XrInstance instance)
-{
- char buffer[XR_MAX_RESULT_STRING_SIZE];
- XrResult result = xrResultToString(instance, value, buffer);
- if (result == XR_SUCCESS)
- return String(buffer);
- return makeString("<unknown ", int(value), ">");
-}
-
-#define RETURN_IF_FAILED(result, call, instance) \
- if (XR_FAILED(result)) { \
- WTFLogAlways("%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
- return; \
- } \
-
-#endif // USE_OPENXR
-
-struct Instance::Impl {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- Impl();
- ~Impl();
-
-#if USE_OPENXR
- Optional<Vector<SessionMode>> collectSupportedSessionModes(Device&, XrSystemId);
- XrInstance m_instance { XR_NULL_HANDLE };
-#endif // USE_OPENXR
-};
-
-Instance::Impl::Impl()
-{
-#if USE_OPENXR
- WTFLogAlways("OpenXR: initializing\n");
-
- [&] {
- uint32_t propertyCountOutput { 0 };
- XrResult result = xrEnumerateApiLayerProperties(0, &propertyCountOutput, nullptr);
- RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
-
- if (!propertyCountOutput) {
- WTFLogAlways("xrEnumerateApiLayerProperties(): no properties\n");
- return;
- }
-
- Vector<XrApiLayerProperties> properties(propertyCountOutput);
- result = xrEnumerateApiLayerProperties(propertyCountOutput, nullptr, properties.data());
- RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
-
- WTFLogAlways("xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
- }();
-
- [&] {
- uint32_t propertyCountOutput { 0 };
- XrResult result = xrEnumerateInstanceExtensionProperties(nullptr, 0, &propertyCountOutput, nullptr);
- RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
-
- if (!propertyCountOutput) {
- WTFLogAlways("xrEnumerateInstanceExtensionProperties(): no properties\n");
- return;
- }
-
- Vector<XrExtensionProperties> properties(propertyCountOutput,
- [] {
- XrExtensionProperties object;
- std::memset(&object, 0, sizeof(XrExtensionProperties));
- object.type = XR_TYPE_EXTENSION_PROPERTIES;
- return object;
- }());
- uint32_t propertyCountWritten { 0 };
- result = xrEnumerateInstanceExtensionProperties(nullptr, propertyCountOutput, &propertyCountWritten, properties.data());
- RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
-
- WTFLogAlways("xrEnumerateInstanceExtensionProperties(): %zu extension properties\n", properties.size());
- for (auto& property : properties) {
- WTFLogAlways(" extension '%s', version %u\n",
- property.extensionName, property.extensionVersion);
- }
- }();
-
- static const char* s_applicationName = "WebXR (WebKit)";
- static const uint32_t s_applicationVersion = 1;
-
- {
- auto createInfo = createStructure<XrInstanceCreateInfo, XR_TYPE_INSTANCE_CREATE_INFO>();
- createInfo.createFlags = 0;
- std::memcpy(createInfo.applicationInfo.applicationName, s_applicationName, XR_MAX_APPLICATION_NAME_SIZE);
- createInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
- createInfo.applicationInfo.applicationVersion = s_applicationVersion;
- createInfo.enabledApiLayerCount = 0;
- createInfo.enabledExtensionCount = 0;
-
- XrInstance instance;
- XrResult result = xrCreateInstance(&createInfo, &instance);
- RETURN_IF_FAILED(result, "xrCreateInstance()", m_instance);
-
- m_instance = instance;
- WTFLogAlways("xrCreateInstance(): using instance %p\n", m_instance);
- }
-#endif // USE_OPENXR
-}
-
-Instance::Impl::~Impl()
-{
-}
-
-#if USE_OPENXR
-
-Optional<Vector<SessionMode>> Instance::Impl::collectSupportedSessionModes(Device& device, XrSystemId systemId)
-{
- uint32_t viewConfigurationCount;
- XrResult result = xrEnumerateViewConfigurations(m_instance, systemId, 0, &viewConfigurationCount, nullptr);
- if (result != XR_SUCCESS) {
- WTFLogAlways("xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
- return WTF::nullopt;
- }
-
- XrViewConfigurationType viewConfigurations[viewConfigurationCount];
- result = xrEnumerateViewConfigurations(m_instance, systemId, viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
- if (result != XR_SUCCESS) {
- WTFLogAlways("xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
- WTFLogAlways("xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
- return WTF::nullopt;
- }
-
- Vector<SessionMode> supportedModes;
- for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
- auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
- result = xrGetViewConfigurationProperties(m_instance, systemId, viewConfigurations[i], &viewConfigurationProperties);
- if (result != XR_SUCCESS) {
- WTFLogAlways("xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
- return WTF::nullopt;
- }
- if (viewConfigurationProperties.viewConfigurationType == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO)
- supportedModes.append(SessionMode::ImmersiveAr);
- else if (viewConfigurationProperties.viewConfigurationType == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO)
- supportedModes.append(SessionMode::ImmersiveVr);
- }
- return supportedModes;
-}
-
-#endif // USE_OPENXR
-
-Instance& Instance::singleton()
-{
- static LazyNeverDestroyed<Instance> s_instance;
- static std::once_flag s_onceFlag;
- std::call_once(s_onceFlag,
- [&] {
- s_instance->m_impl = makeUnique<Impl>();
- });
- return s_instance.get();
-}
-
-Instance::Instance() = default;
-Instance::~Instance() = default;
-
-void Instance::enumerateImmersiveXRDevices()
-{
-#if USE_OPENXR
- if (m_impl->m_instance == XR_NULL_HANDLE) {
- WTFLogAlways("%s Unable to enumerate XR devices. No XrInstance present\n", __FUNCTION__);
- return;
- }
-
- auto systemGetInfo = createStructure<XrSystemGetInfo, XR_TYPE_SYSTEM_GET_INFO>();
- systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
-
- XrSystemId systemId;
- XrResult result = xrGetSystem(m_impl->m_instance, &systemGetInfo, &systemId);
- if (result != XR_SUCCESS) {
- WTFLogAlways("xrGetSystem(): error %s\n", resultToString(result, m_impl->m_instance).utf8().data());
- return;
- }
-
- auto device = makeUnique<Device>();
- auto sessionModes = m_impl->collectSupportedSessionModes(*device, systemId);
- if (sessionModes) {
- for (auto& mode : sessionModes.value()) {
- // TODO: fill in features
- device->setEnabledFeatures(mode, { });
- }
- }
-
- m_immersiveXRDevices.append(WTFMove(device));
-#endif // USE_OPENXR
-}
-
-} // namespace PlatformXR
-
-#endif // ENABLE(WEBXR)
Added: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp (0 => 262838)
--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp (rev 0)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp 2020-06-10 13:17:30 UTC (rev 262838)
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2020 Igalia, S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * aint with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "PlatformXROpenXR.h"
+
+#if ENABLE(WEBXR)
+
+#include "Logging.h"
+#if USE_OPENXR
+#include <wtf/Optional.h>
+#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/WTFString.h>
+#endif // USE_OPENXR
+#include <wtf/NeverDestroyed.h>
+
+namespace PlatformXR {
+
+#if USE_OPENXR
+
+template<typename T, XrStructureType StructureType>
+T createStructure()
+{
+ T object;
+ std::memset(&object, 0, sizeof(T));
+ object.type = StructureType;
+ object.next = nullptr;
+ return object;
+}
+
+String resultToString(XrResult value, XrInstance instance)
+{
+ char buffer[XR_MAX_RESULT_STRING_SIZE];
+ XrResult result = xrResultToString(instance, value, buffer);
+ if (result == XR_SUCCESS)
+ return String(buffer);
+ 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; \
+ } \
+
+#endif // USE_OPENXR
+
+struct Instance::Impl {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ Impl();
+ ~Impl();
+
+#if USE_OPENXR
+ Optional<Vector<SessionMode>> collectSupportedSessionModes(OpenXRDevice&);
+ XrInstance xrInstance() const { return m_instance; }
+#endif
+
+private:
+#if USE_OPENXR
+ void enumerateApiLayerProperties() const;
+ void enumerateInstanceExtensionProperties() const;
+
+ XrInstance m_instance { XR_NULL_HANDLE };
+#endif // USE_OPENXR
+};
+
+void Instance::Impl::enumerateApiLayerProperties() const
+{
+#if USE_OPENXR
+ uint32_t propertyCountOutput { 0 };
+ XrResult result = xrEnumerateApiLayerProperties(0, &propertyCountOutput, nullptr);
+ RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
+
+ if (!propertyCountOutput) {
+ LOG(XR, "xrEnumerateApiLayerProperties(): no properties\n");
+ return;
+ }
+
+ Vector<XrApiLayerProperties> properties(propertyCountOutput);
+ result = xrEnumerateApiLayerProperties(propertyCountOutput, nullptr, properties.data());
+ RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
+ LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
+#endif
+}
+
+void Instance::Impl::enumerateInstanceExtensionProperties() const
+{
+#if USE_OPENXR
+ uint32_t propertyCountOutput { 0 };
+ XrResult result = xrEnumerateInstanceExtensionProperties(nullptr, 0, &propertyCountOutput, nullptr);
+ RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
+ if (!propertyCountOutput) {
+ LOG(XR, "xrEnumerateInstanceExtensionProperties(): no properties\n");
+ return;
+ }
+
+ Vector<XrExtensionProperties> properties(propertyCountOutput,
+ [] {
+ XrExtensionProperties object;
+ std::memset(&object, 0, sizeof(XrExtensionProperties));
+ object.type = XR_TYPE_EXTENSION_PROPERTIES;
+ return object;
+ }());
+
+ uint32_t propertyCountWritten { 0 };
+ result = xrEnumerateInstanceExtensionProperties(nullptr, propertyCountOutput, &propertyCountWritten, properties.data());
+ RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
+ LOG(XR, "xrEnumerateInstanceExtensionProperties(): %zu extension properties\n", properties.size());
+ for (auto& property : properties) {
+ LOG(XR, " extension '%s', version %u\n",
+ property.extensionName, property.extensionVersion);
+ }
+#endif
+}
+
+Instance::Impl::Impl()
+{
+ LOG(XR, "OpenXR: initializing\n");
+
+ enumerateApiLayerProperties();
+ enumerateInstanceExtensionProperties();
+
+ static const char* s_applicationName = "WebXR (WebKit)";
+ static const uint32_t s_applicationVersion = 1;
+
+#if USE_OPENXR
+ auto createInfo = createStructure<XrInstanceCreateInfo, XR_TYPE_INSTANCE_CREATE_INFO>();
+ createInfo.createFlags = 0;
+ std::memcpy(createInfo.applicationInfo.applicationName, s_applicationName, XR_MAX_APPLICATION_NAME_SIZE);
+ createInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
+ createInfo.applicationInfo.applicationVersion = s_applicationVersion;
+ createInfo.enabledApiLayerCount = 0;
+ createInfo.enabledExtensionCount = 0;
+
+ XrInstance instance;
+ XrResult result = xrCreateInstance(&createInfo, &instance);
+ RETURN_IF_FAILED(result, "xrCreateInstance()", m_instance);
+ m_instance = instance;
+ LOG(XR, "xrCreateInstance(): using instance %p\n", m_instance);
+
+#endif // USE_OPENXR
+}
+
+Instance::Impl::~Impl()
+{
+ xrDestroyInstance(m_instance);
+}
+
+#if USE_OPENXR
+
+Optional<Vector<SessionMode>> Instance::Impl::collectSupportedSessionModes(OpenXRDevice& device)
+{
+ uint32_t viewConfigurationCount;
+ auto result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), 0, &viewConfigurationCount, nullptr);
+ if (result != XR_SUCCESS) {
+ LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
+ return WTF::nullopt;
+ }
+
+ XrViewConfigurationType viewConfigurations[viewConfigurationCount];
+ result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
+ if (result != XR_SUCCESS) {
+ LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
+ return WTF::nullopt;
+ }
+
+ Vector<SessionMode> supportedModes;
+ for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
+ auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
+ result = xrGetViewConfigurationProperties(m_instance, device.xrSystemId(), viewConfigurations[i], &viewConfigurationProperties);
+ if (result != XR_SUCCESS) {
+ LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
+ return WTF::nullopt;
+ }
+ switch (viewConfigurationProperties.viewConfigurationType) {
+ case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
+ supportedModes.append(SessionMode::ImmersiveAr);
+ break;
+ case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
+ supportedModes.append(SessionMode::ImmersiveVr);
+ break;
+ default:
+ break;
+ };
+ }
+ return supportedModes;
+}
+
+#endif // USE_OPENXR
+
+Instance& Instance::singleton()
+{
+ static LazyNeverDestroyed<Instance> s_instance;
+ static std::once_flag s_onceFlag;
+ std::call_once(s_onceFlag,
+ [&] {
+ s_instance->m_impl = makeUnique<Impl>();
+ });
+ return s_instance.get();
+}
+
+Instance::Instance() = default;
+Instance::~Instance() = default;
+
+void Instance::enumerateImmersiveXRDevices()
+{
+#if USE_OPENXR
+ if (m_impl->xrInstance() == XR_NULL_HANDLE) {
+ LOG(XR, "%s Unable to enumerate XR devices. No XrInstance present\n", __FUNCTION__);
+ return;
+ }
+
+ auto systemGetInfo = createStructure<XrSystemGetInfo, XR_TYPE_SYSTEM_GET_INFO>();
+ systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
+
+ XrSystemId systemId;
+ XrResult result = xrGetSystem(m_impl->xrInstance(), &systemGetInfo, &systemId);
+ if (result != XR_SUCCESS) {
+ LOG(XR, "xrGetSystem(): error %s\n", resultToString(result, m_impl->xrInstance()).utf8().data());
+ return;
+ }
+
+ auto device = makeUnique<OpenXRDevice>();
+ device->setXrSystemId(systemId);
+ auto sessionModes = m_impl->collectSupportedSessionModes(*device);
+ if (sessionModes) {
+ for (auto& mode : sessionModes.value()) {
+ // TODO: fill in features
+ device->setEnabledFeatures(mode, { });
+ }
+ }
+
+ m_immersiveXRDevices.append(WTFMove(device));
+#endif // USE_OPENXR
+}
+
+} // namespace PlatformXR
+
+#endif // ENABLE(WEBXR)
Property changes on: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp
___________________________________________________________________
Added: svn:eol-style
+LF
\ No newline at end of property
Added: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h (0 => 262838)
--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h (rev 0)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h 2020-06-10 13:17:30 UTC (rev 262838)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2020 Igalia, S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * aint with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#if ENABLE(WEBXR)
+#include "PlatformXR.h"
+
+#if USE_OPENXR
+#include <openxr/openxr.h>
+
+namespace PlatformXR {
+
+// https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#system
+// A system represents a collection of related devices in the runtime, often made up of several individual
+// hardware components working together to enable XR experiences.
+//
+// WebXR talks about XR devices, is a physical unit of hardware that can present imagery to the user, so
+// there is not direct correspondence between an OpenXR system and a WebXR device because the system API
+// is an abstraction for a collection of devices while the WebXR device is mostly one physical unit,
+// usually an HMD or a phone/tablet.
+//
+// It's important also not to try to associate OpenXR system with WebXR's XRSystem because they're totally
+// different concepts. The system in OpenXR was defined above as a collection of related devices. In WebXR,
+// the XRSystem is basically the entry point for the WebXR API available via the Navigator object.
+class OpenXRDevice final : public Device {
+public:
+ void setXrSystemId(XrSystemId id) { m_systemId = id; }
+ XrSystemId xrSystemId() const { return m_systemId; }
+private:
+ XrSystemId m_systemId;
+};
+
+} // namespace PlatformXR
+
+#endif // USE_OPENXR
+#endif // ENABLE(WEBXR)
Property changes on: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h
___________________________________________________________________
Added: svn:eol-style
+LF
\ No newline at end of property