Title: [286048] trunk/Source
Revision
286048
Author
[email protected]
Date
2021-11-18 23:27:51 -0800 (Thu, 18 Nov 2021)

Log Message

[Model] add support for pausing and resuming animations
https://bugs.webkit.org/show_bug.cgi?id=233319
<rdar://problem/85428464>

Reviewed by Wenson Hsieh.

Source/WebCore:

We add three new promise-based methods to the HTMLModelElement IDL to control the playback state
of the animation built into the USDZ asset: isPlayingAnimation(), playAnimation() and pauseAnimation().
All these methods are promise-based.

* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::isPlayingAnimation):
(WebCore::HTMLModelElement::setAnimationIsPlaying):
(WebCore::HTMLModelElement::playAnimation):
(WebCore::HTMLModelElement::pauseAnimation):
* Modules/model-element/HTMLModelElement.h:
* Modules/model-element/HTMLModelElement.idl:
* Modules/model-element/ModelPlayer.h:
* Modules/model-element/dummy/DummyModelPlayer.cpp:
(WebCore::DummyModelPlayer::isPlayingAnimation):
(WebCore::DummyModelPlayer::setAnimationIsPlaying):
* Modules/model-element/dummy/DummyModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.mm:
(WebCore::SceneKitModelPlayer::isPlayingAnimation):
(WebCore::SceneKitModelPlayer::setAnimationIsPlaying):

Source/WebCore/PAL:

Add the new ARQL SPIs we are using.

* pal/spi/ios/SystemPreviewSPI.h:
* pal/spi/mac/SystemPreviewSPI.h:

Source/WebKit:

Expose new WebPageProxy messages to let the WebProcess message the UIProcess
to call into ASVInlinePreview methods to get and set the animation's playback
state.

* UIProcess/Cocoa/ModelElementControllerCocoa.mm:
(WebKit::previewHasAnimationSupport):
(WebKit::ModelElementController::isPlayingAnimationForModelElement):
(WebKit::ModelElementController::setAnimationIsPlayingForModelElement):
* UIProcess/ModelElementController.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::modelElementIsPlayingAnimation):
(WebKit::WebPageProxy::modelElementSetAnimationIsPlaying):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/Model/ARKitInlinePreviewModelPlayer.h:
* WebProcess/Model/ARKitInlinePreviewModelPlayer.mm:
(WebKit::ARKitInlinePreviewModelPlayer::isPlayingAnimation):
(WebKit::ARKitInlinePreviewModelPlayer::setAnimationIsPlaying):

Source/WTF:

Add a new compile-time flag for the new ARQL SPIs we are using.

* wtf/PlatformEnableCocoa.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (286047 => 286048)


--- trunk/Source/WTF/ChangeLog	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WTF/ChangeLog	2021-11-19 07:27:51 UTC (rev 286048)
@@ -1,5 +1,17 @@
 2021-11-18  Antoine Quint  <[email protected]>
 
+        [Model] add support for pausing and resuming animations
+        https://bugs.webkit.org/show_bug.cgi?id=233319
+        <rdar://problem/85428464>
+
+        Reviewed by Wenson Hsieh.
+
+        Add a new compile-time flag for the new ARQL SPIs we are using.
+
+        * wtf/PlatformEnableCocoa.h:
+
+2021-11-18  Antoine Quint  <[email protected]>
+
         [Model] add support for getting and setting the camera
         https://bugs.webkit.org/show_bug.cgi?id=233265
         <rdar://problem/85426290>

Modified: trunk/Source/WTF/wtf/PlatformEnableCocoa.h (286047 => 286048)


--- trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -746,4 +746,5 @@
 
 #if (ENABLE(ARKIT_INLINE_PREVIEW_MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 120400) || (ENABLE(ARKIT_INLINE_PREVIEW_IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150400)
 #define ENABLE_ARKIT_INLINE_PREVIEW_CAMERA_TRANSFORM 1
+#define ENABLE_ARKIT_INLINE_PREVIEW_ANIMATIONS_CONTROL 1
 #endif

Modified: trunk/Source/WebCore/ChangeLog (286047 => 286048)


--- trunk/Source/WebCore/ChangeLog	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/ChangeLog	2021-11-19 07:27:51 UTC (rev 286048)
@@ -1,3 +1,32 @@
+2021-11-18  Antoine Quint  <[email protected]>
+
+        [Model] add support for pausing and resuming animations
+        https://bugs.webkit.org/show_bug.cgi?id=233319
+        <rdar://problem/85428464>
+
+        Reviewed by Wenson Hsieh.
+
+        We add three new promise-based methods to the HTMLModelElement IDL to control the playback state
+        of the animation built into the USDZ asset: isPlayingAnimation(), playAnimation() and pauseAnimation().
+        All these methods are promise-based.
+
+        * Modules/model-element/HTMLModelElement.cpp:
+        (WebCore::HTMLModelElement::isPlayingAnimation):
+        (WebCore::HTMLModelElement::setAnimationIsPlaying):
+        (WebCore::HTMLModelElement::playAnimation):
+        (WebCore::HTMLModelElement::pauseAnimation):
+        * Modules/model-element/HTMLModelElement.h:
+        * Modules/model-element/HTMLModelElement.idl:
+        * Modules/model-element/ModelPlayer.h:
+        * Modules/model-element/dummy/DummyModelPlayer.cpp:
+        (WebCore::DummyModelPlayer::isPlayingAnimation):
+        (WebCore::DummyModelPlayer::setAnimationIsPlaying):
+        * Modules/model-element/dummy/DummyModelPlayer.h:
+        * Modules/model-element/scenekit/SceneKitModelPlayer.h:
+        * Modules/model-element/scenekit/SceneKitModelPlayer.mm:
+        (WebCore::SceneKitModelPlayer::isPlayingAnimation):
+        (WebCore::SceneKitModelPlayer::setAnimationIsPlaying):
+
 2021-11-18  Fujii Hironori  <[email protected]>
 
         [TextureMapper][GraphicsLayerTextureMapper][GraphicsLayerWC] setBackgroundColor support

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2021-11-19 07:27:51 UTC (rev 286048)
@@ -363,7 +363,7 @@
         m_modelPlayer->handleMouseUp(event.pageLocation(), event.timeStamp());
 }
 
-// MARK: – Camera support.
+// MARK: - Camera support.
 
 void HTMLModelElement::getCamera(CameraPromise&& promise)
 {
@@ -395,6 +395,48 @@
     });
 }
 
+// MARK: - Animations support.
+
+void HTMLModelElement::isPlayingAnimation(IsPlayingAnimationPromise&& promise)
+{
+    if (!m_modelPlayer) {
+        promise.reject();
+        return;
+    }
+
+    m_modelPlayer->isPlayingAnimation([promise = WTFMove(promise)] (std::optional<bool> isPlaying) mutable {
+        if (!isPlaying)
+            promise.reject();
+        else
+            promise.resolve(*isPlaying);
+    });
 }
 
+void HTMLModelElement::setAnimationIsPlaying(bool isPlaying, DOMPromiseDeferred<void>&& promise)
+{
+    if (!m_modelPlayer) {
+        promise.reject();
+        return;
+    }
+
+    m_modelPlayer->setAnimationIsPlaying(isPlaying, [promise = WTFMove(promise)] (bool success) mutable {
+        if (success)
+            promise.resolve();
+        else
+            promise.reject();
+    });
+}
+
+void HTMLModelElement::playAnimation(DOMPromiseDeferred<void>&& promise)
+{
+    setAnimationIsPlaying(true, WTFMove(promise));
+}
+
+void HTMLModelElement::pauseAnimation(DOMPromiseDeferred<void>&& promise)
+{
+    setAnimationIsPlaying(false, WTFMove(promise));
+}
+
+}
+
 #endif // ENABLE(MODEL_ELEMENT)

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -75,6 +75,11 @@
     void getCamera(CameraPromise&&);
     void setCamera(HTMLModelElementCamera, DOMPromiseDeferred<void>&&);
 
+    using IsPlayingAnimationPromise = DOMPromiseDeferred<IDLBoolean>;
+    void isPlayingAnimation(IsPlayingAnimationPromise&&);
+    void playAnimation(DOMPromiseDeferred<void>&&);
+    void pauseAnimation(DOMPromiseDeferred<void>&&);
+
     bool isDraggableIgnoringAttributes() const final { return true; }
 
 private:
@@ -105,6 +110,8 @@
     void dragDidChange(MouseEvent&);
     void dragDidEnd(MouseEvent&);
 
+    void setAnimationIsPlaying(bool, DOMPromiseDeferred<void>&&);
+
     URL m_sourceURL;
     CachedResourceHandle<CachedRawResource> m_resource;
     RefPtr<SharedBuffer> m_data;

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl	2021-11-19 07:27:51 UTC (rev 286048)
@@ -36,4 +36,8 @@
 
     Promise<HTMLModelElementCamera> getCamera();
     Promise<undefined> setCamera(HTMLModelElementCamera camera);
+
+    Promise<boolean> isPlayingAnimation();
+    Promise<undefined> playAnimation();
+    Promise<undefined> pauseAnimation();
 };

Modified: trunk/Source/WebCore/Modules/model-element/ModelPlayer.h (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/ModelPlayer.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/ModelPlayer.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -50,7 +50,9 @@
     virtual void handleMouseMove(const LayoutPoint&, MonotonicTime) = 0;
     virtual void handleMouseUp(const LayoutPoint&, MonotonicTime) = 0;
     virtual void getCamera(CompletionHandler<void(std::optional<HTMLModelElementCamera>&&)>&&) = 0;
-    virtual void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) = 0;
+    virtual void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool success)>&&) = 0;
+    virtual void isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&) = 0;
+    virtual void setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&) = 0;
 };
 
 }

Modified: trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp	2021-11-19 07:27:51 UTC (rev 286048)
@@ -74,8 +74,16 @@
 {
 }
 
-void DummyModelPlayer::setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&)
+void DummyModelPlayer::setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool success)>&&)
 {
 }
 
+void DummyModelPlayer::isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&)
+{
 }
+
+void DummyModelPlayer::setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&)
+{
+}
+
+}

Modified: trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -48,7 +48,9 @@
     void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
     void handleMouseUp(const LayoutPoint&, MonotonicTime) override;
     void getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&&) override;
-    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
+    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool success)>&&) override;
+    void isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&) override;
+    void setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&) override;
 
     WeakPtr<ModelPlayerClient> m_client;
 };

Modified: trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -62,7 +62,9 @@
     void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
     void handleMouseUp(const LayoutPoint&, MonotonicTime) override;
     void getCamera(CompletionHandler<void(std::optional<HTMLModelElementCamera>&&)>&&) override;
-    void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
+    void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool success)>&&) override;
+    void isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&) override;
+    void setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&) override;
 
     // SceneKitModelLoaderClient overrides.
     virtual void didFinishLoading(SceneKitModelLoader&, Ref<SceneKitModel>) override;

Modified: trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm (286047 => 286048)


--- trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm	2021-11-19 07:27:51 UTC (rev 286048)
@@ -92,10 +92,18 @@
 {
 }
 
-void SceneKitModelPlayer::setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&)
+void SceneKitModelPlayer::setCamera(HTMLModelElementCamera, CompletionHandler<void(bool success)>&&)
 {
 }
 
+void SceneKitModelPlayer::isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&)
+{
+}
+
+void SceneKitModelPlayer::setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&)
+{
+}
+
 // MARK: - SceneKitModelLoaderClient overrides.
 
 void SceneKitModelPlayer::didFinishLoading(SceneKitModelLoader& loader, Ref<SceneKitModel> model)

Modified: trunk/Source/WebCore/PAL/ChangeLog (286047 => 286048)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-11-19 07:27:51 UTC (rev 286048)
@@ -1,5 +1,18 @@
 2021-11-18  Antoine Quint  <[email protected]>
 
+        [Model] add support for pausing and resuming animations
+        https://bugs.webkit.org/show_bug.cgi?id=233319
+        <rdar://problem/85428464>
+
+        Reviewed by Wenson Hsieh.
+
+        Add the new ARQL SPIs we are using.
+
+        * pal/spi/ios/SystemPreviewSPI.h:
+        * pal/spi/mac/SystemPreviewSPI.h:
+
+2021-11-18  Antoine Quint  <[email protected]>
+
         [Model] add support for getting and setting the camera
         https://bugs.webkit.org/show_bug.cgi?id=233265
         <rdar://problem/85426290>

Modified: trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h (286047 => 286048)


--- trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -108,6 +108,10 @@
 - (void)getCameraTransform:(ASVCameraTransformReplyBlock)reply;
 - (void)setCameraTransform:(simd_float3)transform;
 
+@property (nonatomic, readonly) BOOL isPlaying;
+typedef void (^ASVSetIsPlayingReplyBlock) (BOOL isPlaying, NSError * _Nullable error);
+- (void)setIsPlaying:(BOOL)isPlaying reply:(ASVSetIsPlayingReplyBlock)reply;
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h (286047 => 286048)


--- trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -58,6 +58,10 @@
 - (void)getCameraTransform:(ASVCameraTransformReplyBlock)reply;
 - (void)setCameraTransform:(simd_float3)transform;
 
+@property (nonatomic, readonly) BOOL isPlaying;
+typedef void (^ASVSetIsPlayingReplyBlock) (BOOL isPlaying, NSError * _Nullable error);
+- (void)setIsPlaying:(BOOL)isPlaying reply:(ASVSetIsPlayingReplyBlock)reply;
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebKit/ChangeLog (286047 => 286048)


--- trunk/Source/WebKit/ChangeLog	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/ChangeLog	2021-11-19 07:27:51 UTC (rev 286048)
@@ -1,3 +1,30 @@
+2021-11-18  Antoine Quint  <[email protected]>
+
+        [Model] add support for pausing and resuming animations
+        https://bugs.webkit.org/show_bug.cgi?id=233319
+        <rdar://problem/85428464>
+
+        Reviewed by Wenson Hsieh.
+
+        Expose new WebPageProxy messages to let the WebProcess message the UIProcess
+        to call into ASVInlinePreview methods to get and set the animation's playback
+        state.
+
+        * UIProcess/Cocoa/ModelElementControllerCocoa.mm:
+        (WebKit::previewHasAnimationSupport):
+        (WebKit::ModelElementController::isPlayingAnimationForModelElement):
+        (WebKit::ModelElementController::setAnimationIsPlayingForModelElement):
+        * UIProcess/ModelElementController.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::modelElementIsPlayingAnimation):
+        (WebKit::WebPageProxy::modelElementSetAnimationIsPlaying):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/Model/ARKitInlinePreviewModelPlayer.h:
+        * WebProcess/Model/ARKitInlinePreviewModelPlayer.mm:
+        (WebKit::ARKitInlinePreviewModelPlayer::isPlayingAnimation):
+        (WebKit::ARKitInlinePreviewModelPlayer::setAnimationIsPlaying):
+
 2021-11-18  Myles C. Maxfield  <[email protected]>
 
         [WebGPU] Add converters from serializable descriptors to interface descriptors

Modified: trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm (286047 => 286048)


--- trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2021-11-19 07:27:51 UTC (rev 286048)
@@ -245,7 +245,7 @@
 void ModelElementController::getCameraForModelElement(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&& completionHandler)
 {
     auto* preview = previewForModelIdentifier(modelIdentifier);
-    if (!preview || !previewHasCameraSupport(preview)) {
+    if (!previewHasCameraSupport(preview)) {
         callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler), error = WebCore::ResourceError { WebCore::ResourceError::Type::General }] () mutable {
             if (weakThis)
                 completionHandler(makeUnexpected(error));
@@ -280,7 +280,7 @@
 void ModelElementController::setCameraForModelElement(ModelIdentifier modelIdentifier, WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool)>&& completionHandler)
 {
     auto* preview = previewForModelIdentifier(modelIdentifier);
-    if (!preview || !previewHasCameraSupport(preview)) {
+    if (!previewHasCameraSupport(preview)) {
         callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
             if (weakThis)
                 completionHandler(false);
@@ -302,8 +302,65 @@
     });
 }
 
+static bool previewHasAnimationSupport(ASVInlinePreview *preview)
+{
+#if ENABLE(ARKIT_INLINE_PREVIEW_ANIMATIONS_CONTROL)
+    return [preview respondsToSelector:@selector(isPlaying)];
+#else
+    return false;
 #endif
+}
 
+void ModelElementController::isPlayingAnimationForModelElement(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<bool, WebCore::ResourceError>)>&& completionHandler)
+{
+    auto* preview = previewForModelIdentifier(modelIdentifier);
+    if (!previewHasAnimationSupport(preview)) {
+        callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler), error = WebCore::ResourceError { WebCore::ResourceError::Type::General }] () mutable {
+            if (weakThis)
+                completionHandler(makeUnexpected(error));
+        });
+        return;
+    }
+
+#if ENABLE(ARKIT_INLINE_PREVIEW_ANIMATIONS_CONTROL)
+    auto isPlaying = [preview isPlaying];
+#else
+    auto isPlaying = false;
+#endif
+    callOnMainRunLoop([isPlaying, weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
+        if (weakThis)
+            completionHandler(isPlaying);
+    });
 }
 
+void ModelElementController::setAnimationIsPlayingForModelElement(ModelIdentifier modelIdentifier, bool isPlaying, CompletionHandler<void(bool)>&& completionHandler)
+{
+    auto* preview = previewForModelIdentifier(modelIdentifier);
+    if (!previewHasAnimationSupport(preview)) {
+        callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
+            if (weakThis)
+                completionHandler(false);
+        });
+        return;
+    }
+
+#if ENABLE(ARKIT_INLINE_PREVIEW_ANIMATIONS_CONTROL)
+    [preview setIsPlaying:isPlaying reply:makeBlockPtr([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] (BOOL, NSError *error) mutable {
+        callOnMainRunLoop([error, weakThis = WTFMove(weakThis), completionHandler = WTFMove(completionHandler)] () mutable {
+            if (weakThis)
+                completionHandler(!error);
+        });
+    }).get()];
+#else
+    callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
+        if (weakThis)
+            completionHandler(false);
+    });
 #endif
+}
+
+#endif
+
+}
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/ModelElementController.h (286047 => 286048)


--- trunk/Source/WebKit/UIProcess/ModelElementController.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/UIProcess/ModelElementController.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -54,6 +54,8 @@
 #if ENABLE(ARKIT_INLINE_PREVIEW)
     void getCameraForModelElement(ModelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&&);
     void setCameraForModelElement(ModelIdentifier, WebCore::HTMLModelElementCamera, CompletionHandler<void(bool)>&&);
+    void isPlayingAnimationForModelElement(ModelIdentifier, CompletionHandler<void(Expected<bool, WebCore::ResourceError>)>&&);
+    void setAnimationIsPlayingForModelElement(ModelIdentifier, bool, CompletionHandler<void(bool)>&&);
 #endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
     void takeModelElementFullscreen(ModelIdentifier);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286047 => 286048)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-11-19 07:27:51 UTC (rev 286048)
@@ -10833,7 +10833,7 @@
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
-void WebPageProxy::modelElementGetCamera(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&& completionHandler)
+void WebPageProxy::modelElementGetCamera(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, ResourceError>)>&& completionHandler)
 {
     modelElementController()->getCameraForModelElement(modelIdentifier, WTFMove(completionHandler));
 }
@@ -10842,6 +10842,16 @@
 {
     modelElementController()->setCameraForModelElement(modelIdentifier, camera, WTFMove(completionHandler));
 }
+
+void WebPageProxy::modelElementIsPlayingAnimation(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<bool, ResourceError>)>&& completionHandler)
+{
+    modelElementController()->isPlayingAnimationForModelElement(modelIdentifier, WTFMove(completionHandler));
+}
+
+void WebPageProxy::modelElementSetAnimationIsPlaying(ModelIdentifier modelIdentifier, bool isPlaying, CompletionHandler<void(bool)>&& completionHandler)
+{
+    modelElementController()->setAnimationIsPlayingForModelElement(modelIdentifier, isPlaying, WTFMove(completionHandler));
+}
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
@@ -10852,7 +10862,7 @@
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
-void WebPageProxy::modelElementDidCreatePreview(const URL& url, const String& uuid, const FloatSize& size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&& completionHandler)
+void WebPageProxy::modelElementDidCreatePreview(const URL& url, const String& uuid, const FloatSize& size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, ResourceError>)>&& completionHandler)
 {
     modelElementController()->modelElementDidCreatePreview(url, uuid, size, WTFMove(completionHandler));
 }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (286047 => 286048)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -590,6 +590,8 @@
     ModelElementController* modelElementController() { return m_modelElementController.get(); }
     void modelElementGetCamera(ModelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&&);
     void modelElementSetCamera(ModelIdentifier, WebCore::HTMLModelElementCamera, CompletionHandler<void(bool)>&&);
+    void modelElementIsPlayingAnimation(ModelIdentifier, CompletionHandler<void(Expected<bool, WebCore::ResourceError>)>&&);
+    void modelElementSetAnimationIsPlaying(ModelIdentifier, bool, CompletionHandler<void(bool)>&&);
 #endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
     void takeModelElementFullscreen(ModelIdentifier);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (286047 => 286048)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-11-19 07:27:51 UTC (rev 286048)
@@ -597,6 +597,8 @@
 #if ENABLE(ARKIT_INLINE_PREVIEW)
     ModelElementGetCamera(struct WebKit::ModelIdentifier modelIdentifier) -> (Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError> result) Async
     ModelElementSetCamera(struct WebKit::ModelIdentifier modelIdentifier, struct WebCore::HTMLModelElementCamera camera) -> (bool success) Async
+    ModelElementIsPlayingAnimation(struct WebKit::ModelIdentifier modelIdentifier) -> (Expected<bool, WebCore::ResourceError> result) Async
+    ModelElementSetAnimationIsPlaying(struct WebKit::ModelIdentifier modelIdentifier, bool isPlaying) -> (bool success) Async
 #endif
 
     requestPermission(struct WebCore::ClientOrigin origin, struct WebCore::PermissionDescriptor descriptor) -> (enum:uint8_t WebCore::PermissionState state) Async

Modified: trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h (286047 => 286048)


--- trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h	2021-11-19 07:27:51 UTC (rev 286048)
@@ -54,7 +54,9 @@
     PlatformLayer* layer() override;
     void enterFullscreen() override;
     void getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&&) override;
-    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
+    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool success)>&&) override;
+    void isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&&) override;
+    void setAnimationIsPlaying(bool, CompletionHandler<void(bool success)>&&) override;
 
     WeakPtr<WebPage> m_page;
     WeakPtr<WebCore::ModelPlayerClient> m_client;

Modified: trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm (286047 => 286048)


--- trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm	2021-11-19 06:30:55 UTC (rev 286047)
+++ trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm	2021-11-19 07:27:51 UTC (rev 286048)
@@ -81,7 +81,7 @@
     strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementGetCamera(*modelIdentifier), WTFMove(remoteCompletionHandler));
 }
 
-void ARKitInlinePreviewModelPlayer::setCamera(WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool&&)>&& completionHandler)
+void ARKitInlinePreviewModelPlayer::setCamera(WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool success)>&& completionHandler)
 {
     auto modelIdentifier = this->modelIdentifier();
     if (!modelIdentifier) {
@@ -96,12 +96,59 @@
     }
 
     CompletionHandler<void(bool)> remoteCompletionHandler = [completionHandler = WTFMove(completionHandler)] (bool success) mutable {
-        completionHandler(WTFMove(success));
+        completionHandler(success);
     };
 
     strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementSetCamera(*modelIdentifier, camera), WTFMove(remoteCompletionHandler));
 }
 
+void ARKitInlinePreviewModelPlayer::isPlayingAnimation(CompletionHandler<void(std::optional<bool>&&)>&& completionHandler)
+{
+    auto modelIdentifier = this->modelIdentifier();
+    if (!modelIdentifier) {
+        completionHandler(std::nullopt);
+        return;
+    }
+
+    auto* strongPage = m_page.get();
+    if (!strongPage) {
+        completionHandler(std::nullopt);
+        return;
+    }
+
+    CompletionHandler<void(Expected<bool, WebCore::ResourceError>)> remoteCompletionHandler = [completionHandler = WTFMove(completionHandler)] (Expected<bool, WebCore::ResourceError> result) mutable {
+        if (!result) {
+            completionHandler(std::nullopt);
+            return;
+        }
+
+        completionHandler(*result);
+    };
+
+    strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementIsPlayingAnimation(*modelIdentifier), WTFMove(remoteCompletionHandler));
 }
 
+void ARKitInlinePreviewModelPlayer::setAnimationIsPlaying(bool isPlaying, CompletionHandler<void(bool success)>&& completionHandler)
+{
+    auto modelIdentifier = this->modelIdentifier();
+    if (!modelIdentifier) {
+        completionHandler(false);
+        return;
+    }
+
+    auto* strongPage = m_page.get();
+    if (!strongPage) {
+        completionHandler(false);
+        return;
+    }
+
+    CompletionHandler<void(bool)> remoteCompletionHandler = [completionHandler = WTFMove(completionHandler)] (bool success) mutable {
+        completionHandler(success);
+    };
+
+    strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementSetAnimationIsPlaying(*modelIdentifier, isPlaying), WTFMove(remoteCompletionHandler));
+}
+
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to