-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebXR] Add WebXR backend to support immersive-ar backed by ARKit
https://bugs.webkit.org/show_bug.cgi?id=262679 rdar://116502210 Reviewed by Dean Jackson. ARKitCoordinator adds just enough support for WebXR page to query support for immersive-ar, allowing the XR immersive-ar-session.html button to show `START AR` instead of `AR NOT FOUND` * Source/WTF/wtf/PlatformHave.h: * Source/WebKit/Configurations/WebKit.xcconfig: * Source/WebKit/Shared/XR/XRDeviceInfo.cpp: (WebKit::XRDeviceInfo::encode const): (WebKit::XRDeviceInfo::decode): * Source/WebKit/Shared/XR/XRDeviceInfo.h: * Source/WebKit/Shared/XR/XRDeviceProxy.cpp: (WebKit::XRDeviceProxy::XRDeviceProxy): * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/UIProcess/XR/ios/PlatformXRARKit.h: Added. * Source/WebKit/UIProcess/XR/ios/PlatformXRARKit.mm: Added. (WebKit::ARKitCoordinator::getPrimaryDeviceInfo): (WebKit::ARKitCoordinator::requestPermissionOnSessionFeatures): (WebKit::ARKitCoordinator::startSession): (WebKit::ARKitCoordinator::endSessionIfExists): (WebKit::ARKitCoordinator::scheduleAnimationFrame): (WebKit::ARKitCoordinator::submitFrame): (WebKit::ARKitCoordinator::connectSessionIfNeeded): * Source/WebKit/UIProcess/XR/ios/PlatformXRSystemIOS.mm: Copied from Source/WebKit/Shared/XR/XRDeviceInfo.h. (WebKit::PlatformXRSystem::xrCoordinator): * Source/WebKit/UIProcess/ios/WebProcessProxyIOS.mm: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/269049@main
- Loading branch information
Showing
18 changed files
with
268 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2023 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) && USE(ARKITXR_IOS) | ||
|
||
#import "PlatformXRCoordinator.h" | ||
|
||
@class ARSession; | ||
|
||
namespace WebKit { | ||
|
||
class ARKitCoordinator final : public PlatformXRCoordinator { | ||
WTF_MAKE_FAST_ALLOCATED; | ||
public: | ||
ARKitCoordinator(); | ||
virtual ~ARKitCoordinator() = default; | ||
|
||
void getPrimaryDeviceInfo(DeviceInfoCallback&&) override; | ||
void requestPermissionOnSessionFeatures(WebPageProxy&, const WebCore::SecurityOriginData&, PlatformXR::SessionMode, const PlatformXR::Device::FeatureList&, const PlatformXR::Device::FeatureList&, const PlatformXR::Device::FeatureList&, const PlatformXR::Device::FeatureList&, const PlatformXR::Device::FeatureList&, FeatureListCallback&&) override; | ||
|
||
void startSession(WebPageProxy&, WeakPtr<SessionEventClient>&&, const WebCore::SecurityOriginData&, PlatformXR::SessionMode, const PlatformXR::Device::FeatureList&) override; | ||
void endSessionIfExists(WebPageProxy&) override; | ||
|
||
void scheduleAnimationFrame(WebPageProxy&, PlatformXR::Device::RequestFrameCallback&&) override; | ||
void submitFrame(WebPageProxy&) override; | ||
|
||
private: | ||
XRDeviceIdentifier m_deviceIdentifier = XRDeviceIdentifier::generate(); | ||
}; | ||
|
||
} // namespace WebKit | ||
|
||
#endif // ENABLE(WEBXR) && USE(ARKITXR_IOS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (C) 2023 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 "PlatformXRARKit.h" | ||
|
||
#import "APIUIClient.h" | ||
#import "WebPageProxy.h" | ||
|
||
#if ENABLE(WEBXR) && USE(ARKITXR_IOS) | ||
|
||
#import <ARKit/ARKit.h> | ||
|
||
namespace WebKit { | ||
|
||
ARKitCoordinator::ARKitCoordinator() | ||
{ | ||
ASSERT(RunLoop::isMain()); | ||
} | ||
|
||
void ARKitCoordinator::getPrimaryDeviceInfo(DeviceInfoCallback&& callback) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::getPrimaryDeviceInfo"); | ||
ASSERT(RunLoop::isMain()); | ||
|
||
if (!ARWorldTrackingConfiguration.isSupported) { | ||
RELEASE_LOG_ERROR(XR, "ARKitCoordinator: WorldTrackingConfiguration is not supported"); | ||
return callback(std::nullopt); | ||
} | ||
|
||
NSArray<ARVideoFormat *> *supportedVideoFormats = ARWorldTrackingConfiguration.supportedVideoFormats; | ||
if (![supportedVideoFormats count]) | ||
return callback(std::nullopt); | ||
|
||
CGSize recommendedResolution = supportedVideoFormats[0].imageResolution; | ||
|
||
ASSERT(m_deviceIdentifier); | ||
XRDeviceInfo deviceInfo; | ||
deviceInfo.identifier = m_deviceIdentifier; | ||
deviceInfo.supportsOrientationTracking = true; | ||
deviceInfo.supportsStereoRendering = false; | ||
deviceInfo.recommendedResolution = WebCore::IntSize(recommendedResolution.width, recommendedResolution.height); | ||
deviceInfo.arFeatures.append(PlatformXR::SessionFeature::ReferenceSpaceTypeUnbounded); | ||
deviceInfo.arFeatures.append(PlatformXR::SessionFeature::ReferenceSpaceTypeLocalFloor); | ||
deviceInfo.arFeatures.append(PlatformXR::SessionFeature::ReferenceSpaceTypeLocal); | ||
deviceInfo.arFeatures.append(PlatformXR::SessionFeature::ReferenceSpaceTypeViewer); | ||
|
||
callback(WTFMove(deviceInfo)); | ||
} | ||
|
||
void ARKitCoordinator::requestPermissionOnSessionFeatures(WebPageProxy& page, const WebCore::SecurityOriginData& securityOriginData, PlatformXR::SessionMode mode, const PlatformXR::Device::FeatureList& granted, const PlatformXR::Device::FeatureList& consentRequired, const PlatformXR::Device::FeatureList& consentOptional, const PlatformXR::Device::FeatureList& requiredFeaturesRequested, const PlatformXR::Device::FeatureList& optionalFeaturesRequested, FeatureListCallback&& callback) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::requestPermissionOnSessionFeatures"); | ||
if (mode == PlatformXR::SessionMode::Inline) { | ||
callback(granted); | ||
return; | ||
} | ||
|
||
page.uiClient().requestPermissionOnXRSessionFeatures(page, securityOriginData, mode, granted, consentRequired, consentOptional, requiredFeaturesRequested, optionalFeaturesRequested, [callback = WTFMove(callback)](std::optional<Vector<PlatformXR::SessionFeature>> userGranted) mutable { | ||
callback(WTFMove(userGranted)); | ||
}); | ||
} | ||
|
||
void ARKitCoordinator::startSession(WebPageProxy&, WeakPtr<SessionEventClient>&&, const WebCore::SecurityOriginData&, PlatformXR::SessionMode, const PlatformXR::Device::FeatureList&) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::startSession"); | ||
} | ||
|
||
void ARKitCoordinator::endSessionIfExists(WebPageProxy&) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::endSessionIfExists"); | ||
} | ||
|
||
void ARKitCoordinator::scheduleAnimationFrame(WebPageProxy&, PlatformXR::Device::RequestFrameCallback&& onFrameUpdateCallback) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::scheduleAnimationFrame"); | ||
onFrameUpdateCallback({ }); | ||
} | ||
|
||
void ARKitCoordinator::submitFrame(WebPageProxy&) | ||
{ | ||
RELEASE_LOG(XR, "ARKitCoordinator::submitFrame"); | ||
} | ||
|
||
} // namespace WebKit | ||
|
||
#endif // ENABLE(WEBXR) && USE(ARKITXR_IOS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 ENABLE(WEBXR) && PLATFORM(IOS) | ||
|
||
#import "config.h" | ||
#import "PlatformXRSystem.h" | ||
|
||
#import "PlatformXRARKit.h" | ||
#import <wtf/NeverDestroyed.h> | ||
|
||
namespace WebKit { | ||
|
||
PlatformXRCoordinator* PlatformXRSystem::xrCoordinator() | ||
{ | ||
#if USE(ARKITXR_IOS) | ||
static LazyNeverDestroyed<ARKitCoordinator> xrCoordinator; | ||
static std::once_flag once; | ||
std::call_once(once, [] { | ||
xrCoordinator.construct(); | ||
}); | ||
return &xrCoordinator.get(); | ||
#else | ||
return nullptr; | ||
#endif // USE(ARKITXR_IOS) | ||
} | ||
|
||
} // namespace WebKit | ||
|
||
#endif // ENABLE(WEBXR) && PLATFORM(IOS) |
Oops, something went wrong.