Title: [259298] trunk
Revision
259298
Author
[email protected]
Date
2020-03-31 10:35:30 -0700 (Tue, 31 Mar 2020)

Log Message

requestAnimationFrame and cancelAnimationFrame should be present on DedicatedWorkerGlobalScope
https://bugs.webkit.org/show_bug.cgi?id=202525

Reviewed by Simon Fraser.

Source/WebCore:

Implement AnimationFrameProvider on DedicatedWorkerGlobalScope,
This allows use of requestAnimationFrame and cancelAnimationFrame
inside a dedicated worker thread. This is useful to control animation
when using OffscreenCanvas, and this implementation is only enabled
with the OffscreenCanvas build flag and runtime setting.
Specification: https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animation-frames

No new tests. Covered by existing tests.

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:
* dom/RequestAnimationFrameCallback.h:
* workers/DedicatedWorkerGlobalScope.cpp:
(WebCore::DedicatedWorkerGlobalScope::requestAnimationFrame):
(WebCore::DedicatedWorkerGlobalScope::cancelAnimationFrame):
* workers/DedicatedWorkerGlobalScope.h:
* workers/DedicatedWorkerGlobalScope.idl:
* workers/WorkerAnimationController.cpp: Added.
* workers/WorkerAnimationController.h: Added.
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope):
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::requestAnimationFrameEnabled const):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
* workers/WorkerThread.cpp:
(WebCore::WorkerParameters::isolatedCopy const):
* workers/WorkerThread.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::ServiceWorkerThread):

LayoutTests:

Add PASS expectations for DedicatedWorkerGlobalScope.AnimationFrameProvider on platforms where
OffscreenCanvas is enabled.

* platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (259297 => 259298)


--- trunk/LayoutTests/ChangeLog	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/LayoutTests/ChangeLog	2020-03-31 17:35:30 UTC (rev 259298)
@@ -1,3 +1,18 @@
+2020-03-31  Chris Lord  <[email protected]>
+
+        requestAnimationFrame and cancelAnimationFrame should be present on DedicatedWorkerGlobalScope
+        https://bugs.webkit.org/show_bug.cgi?id=202525
+
+        Reviewed by Simon Fraser.
+
+        Add PASS expectations for DedicatedWorkerGlobalScope.AnimationFrameProvider on platforms where
+        OffscreenCanvas is enabled.
+
+        * platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt: Added.
+        * platform/gtk/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt: Added.
+        * platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt: Added.
+        * platform/wpe/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt: Added.
+
 2020-03-31  Zalan Bujtas  <[email protected]>
 
         [Tables] Infinite recursion in RenderTreeBuilder::attach

Modified: trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt (259297 => 259298)


--- trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt	2020-03-31 17:35:30 UTC (rev 259298)
@@ -633,8 +633,8 @@
 PASS DedicatedWorkerGlobalScope interface: operation close() 
 PASS DedicatedWorkerGlobalScope interface: attribute onmessage 
 FAIL DedicatedWorkerGlobalScope interface: attribute onmessageerror assert_own_property: The global object must have a property "onmessageerror" expected property "onmessageerror" missing
-FAIL DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback) assert_own_property: global object missing non-static operation expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long) assert_own_property: global object missing non-static operation expected property "cancelAnimationFrame" missing
+PASS DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback) 
+PASS DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long) 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Object.setPrototypeOf should throw a TypeError 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via __proto__ should throw a TypeError 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Reflect.setPrototypeOf should return false 
@@ -651,10 +651,10 @@
 PASS DedicatedWorkerGlobalScope interface: self must inherit property "close()" with the proper type 
 PASS DedicatedWorkerGlobalScope interface: self must inherit property "onmessage" with the proper type 
 FAIL DedicatedWorkerGlobalScope interface: self must inherit property "onmessageerror" with the proper type assert_own_property: expected property "onmessageerror" missing
-FAIL DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type assert_own_property: expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError assert_own_property: expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type assert_own_property: expected property "cancelAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError assert_own_property: expected property "cancelAnimationFrame" missing
+PASS DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type 
+PASS DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError 
+PASS DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type 
+PASS DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError 
 PASS WorkerGlobalScope interface: self must inherit property "self" with the proper type 
 PASS WorkerGlobalScope interface: self must inherit property "location" with the proper type 
 PASS WorkerGlobalScope interface: self must inherit property "navigator" with the proper type 

Added: trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt (0 => 259298)


--- trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt	2020-03-31 17:35:30 UTC (rev 259298)
@@ -0,0 +1,3 @@
+
+PASS WorkerGlobalScope_requestAnimationFrame 
+

Modified: trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt (259297 => 259298)


--- trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.worker-expected.txt	2020-03-31 17:35:30 UTC (rev 259298)
@@ -633,8 +633,8 @@
 PASS DedicatedWorkerGlobalScope interface: operation close() 
 PASS DedicatedWorkerGlobalScope interface: attribute onmessage 
 FAIL DedicatedWorkerGlobalScope interface: attribute onmessageerror assert_own_property: The global object must have a property "onmessageerror" expected property "onmessageerror" missing
-FAIL DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback) assert_own_property: global object missing non-static operation expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long) assert_own_property: global object missing non-static operation expected property "cancelAnimationFrame" missing
+PASS DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback) 
+PASS DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long) 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Object.setPrototypeOf should throw a TypeError 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via __proto__ should throw a TypeError 
 PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Reflect.setPrototypeOf should return false 
@@ -651,10 +651,10 @@
 PASS DedicatedWorkerGlobalScope interface: self must inherit property "close()" with the proper type 
 PASS DedicatedWorkerGlobalScope interface: self must inherit property "onmessage" with the proper type 
 FAIL DedicatedWorkerGlobalScope interface: self must inherit property "onmessageerror" with the proper type assert_own_property: expected property "onmessageerror" missing
-FAIL DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type assert_own_property: expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError assert_own_property: expected property "requestAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type assert_own_property: expected property "cancelAnimationFrame" missing
-FAIL DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError assert_own_property: expected property "cancelAnimationFrame" missing
+PASS DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type 
+PASS DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError 
+PASS DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type 
+PASS DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError 
 PASS WorkerGlobalScope interface: self must inherit property "self" with the proper type 
 PASS WorkerGlobalScope interface: self must inherit property "location" with the proper type 
 PASS WorkerGlobalScope interface: self must inherit property "navigator" with the proper type 

Added: trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt (0 => 259298)


--- trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/workers/WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt	2020-03-31 17:35:30 UTC (rev 259298)
@@ -0,0 +1,3 @@
+
+PASS WorkerGlobalScope_requestAnimationFrame 
+

Modified: trunk/Source/WebCore/ChangeLog (259297 => 259298)


--- trunk/Source/WebCore/ChangeLog	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/ChangeLog	2020-03-31 17:35:30 UTC (rev 259298)
@@ -1,3 +1,43 @@
+2020-03-31  Chris Lord  <[email protected]>
+
+        requestAnimationFrame and cancelAnimationFrame should be present on DedicatedWorkerGlobalScope
+        https://bugs.webkit.org/show_bug.cgi?id=202525
+
+        Reviewed by Simon Fraser.
+
+        Implement AnimationFrameProvider on DedicatedWorkerGlobalScope,
+        This allows use of requestAnimationFrame and cancelAnimationFrame
+        inside a dedicated worker thread. This is useful to control animation
+        when using OffscreenCanvas, and this implementation is only enabled
+        with the OffscreenCanvas build flag and runtime setting.
+        Specification: https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animation-frames
+
+        No new tests. Covered by existing tests.
+
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+        * dom/RequestAnimationFrameCallback.h:
+        * workers/DedicatedWorkerGlobalScope.cpp:
+        (WebCore::DedicatedWorkerGlobalScope::requestAnimationFrame):
+        (WebCore::DedicatedWorkerGlobalScope::cancelAnimationFrame):
+        * workers/DedicatedWorkerGlobalScope.h:
+        * workers/DedicatedWorkerGlobalScope.idl:
+        * workers/WorkerAnimationController.cpp: Added.
+        * workers/WorkerAnimationController.h: Added.
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::WorkerGlobalScope):
+        * workers/WorkerGlobalScope.h:
+        (WebCore::WorkerGlobalScope::requestAnimationFrameEnabled const):
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerParameters::isolatedCopy const):
+        * workers/WorkerThread.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
+
 2020-03-31  Zalan Bujtas  <[email protected]>
 
         [Tables] Infinite recursion in RenderTreeBuilder::attach

Modified: trunk/Source/WebCore/Headers.cmake (259297 => 259298)


--- trunk/Source/WebCore/Headers.cmake	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/Headers.cmake	2020-03-31 17:35:30 UTC (rev 259298)
@@ -1486,6 +1486,7 @@
     testing/MockGamepad.h
     testing/MockGamepadProvider.h
 
+    workers/WorkerAnimationController.h
     workers/WorkerDebuggerProxy.h
     workers/WorkerLoaderProxy.h
     workers/WorkerRunLoop.h

Modified: trunk/Source/WebCore/Sources.txt (259297 => 259298)


--- trunk/Source/WebCore/Sources.txt	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/Sources.txt	2020-03-31 17:35:30 UTC (rev 259298)
@@ -2568,6 +2568,7 @@
 workers/DedicatedWorkerGlobalScope.cpp
 workers/DedicatedWorkerThread.cpp
 workers/Worker.cpp
+workers/WorkerAnimationController.cpp
 workers/WorkerConsoleClient.cpp
 workers/WorkerEventLoop.cpp
 workers/WorkerGlobalScope.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (259297 => 259298)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-31 17:35:30 UTC (rev 259298)
@@ -3117,6 +3117,7 @@
 		A454424B119B3661009BE912 /* HTMLMeterElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A4544249119B3661009BE912 /* HTMLMeterElement.h */; };
 		A454424F119B3687009BE912 /* RenderMeter.h in Headers */ = {isa = PBXBuildFile; fileRef = A454424D119B3687009BE912 /* RenderMeter.h */; };
 		A456FA2711AD4A830020B420 /* LabelsNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A456FA2511AD4A830020B420 /* LabelsNodeList.h */; };
+		A45734CF1D3AFD590190608F /* WorkerAnimationController.h in Headers */ = {isa = PBXBuildFile; fileRef = A45733CF1D3AFD590190608F /* WorkerAnimationController.h */; };
 		A501920E132EBF2E008BFE55 /* Autocapitalize.h in Headers */ = {isa = PBXBuildFile; fileRef = A501920C132EBF2E008BFE55 /* Autocapitalize.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A5071E851C56D0DC009951BE /* ResourceUsageData.h in Headers */ = {isa = PBXBuildFile; fileRef = A5071E821C56D079009951BE /* ResourceUsageData.h */; };
 		A5071E871C56D0E1009951BE /* ResourceUsageThread.h in Headers */ = {isa = PBXBuildFile; fileRef = A5071E841C56D079009951BE /* ResourceUsageThread.h */; };
@@ -11709,6 +11710,8 @@
 		A454424D119B3687009BE912 /* RenderMeter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMeter.h; sourceTree = "<group>"; };
 		A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LabelsNodeList.cpp; sourceTree = "<group>"; };
 		A456FA2511AD4A830020B420 /* LabelsNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelsNodeList.h; sourceTree = "<group>"; };
+		A45732CF1C3AFD590180608F /* WorkerAnimationController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerAnimationController.cpp; sourceTree = "<group>"; };
+		A45733CF1D3AFD590190608F /* WorkerAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerAnimationController.h; sourceTree = "<group>"; };
 		A4A69B8BB91B49D0A804C31D /* JSPromiseRejectionEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseRejectionEventCustom.cpp; sourceTree = "<group>"; };
 		A501920C132EBF2E008BFE55 /* Autocapitalize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Autocapitalize.h; sourceTree = "<group>"; };
 		A5071E821C56D079009951BE /* ResourceUsageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceUsageData.h; sourceTree = "<group>"; };
@@ -18101,6 +18104,8 @@
 				2E4346330F546A8200B0F1BA /* Worker.cpp */,
 				2E4346340F546A8200B0F1BA /* Worker.h */,
 				2E4346350F546A8200B0F1BA /* Worker.idl */,
+				A45732CF1C3AFD590180608F /* WorkerAnimationController.cpp */,
+				A45733CF1D3AFD590190608F /* WorkerAnimationController.h */,
 				A55639CF1C6EFD5900806D8E /* WorkerConsoleClient.cpp */,
 				A55639D01C6EFD5900806D8E /* WorkerConsoleClient.h */,
 				A52B349C1FA416F8008B6246 /* WorkerDebuggerProxy.h */,
@@ -33485,6 +33490,7 @@
 				A14832C6187F668F00DA63A6 /* WKViewPrivate.h in Headers */,
 				379919971200DDF400EA041C /* WOFFFileFormat.h in Headers */,
 				2E4346460F546A8200B0F1BA /* Worker.h in Headers */,
+				A45734CF1D3AFD590190608F /* WorkerAnimationController.h in Headers */,
 				91278D6221DEDAF000B57184 /* WorkerAuditAgent.h in Headers */,
 				41A7D3531F438D16008988DE /* WorkerCacheStorageConnection.h in Headers */,
 				A5B81CCD1FAA44DE0037D1E6 /* WorkerConsoleAgent.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (259297 => 259298)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -264,6 +264,7 @@
     macro(byobRequest) \
     macro(caches) \
     macro(cancel) \
+    macro(cancelAnimationFrame) \
     macro(cancelIdleCallback) \
     macro(cloneArrayBuffer) \
     macro(close) \
@@ -339,6 +340,7 @@
     macro(readableStreamController) \
     macro(reader) \
     macro(readyPromiseCapability) \
+    macro(requestAnimationFrame) \
     macro(requestIdleCallback) \
     macro(response) \
     macro(responseCacheIsValid) \

Modified: trunk/Source/WebCore/dom/RequestAnimationFrameCallback.h (259297 => 259298)


--- trunk/Source/WebCore/dom/RequestAnimationFrameCallback.h	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/dom/RequestAnimationFrameCallback.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -32,7 +32,9 @@
 
 #include "ActiveDOMCallback.h"
 #include "CallbackResult.h"
+#include "DOMHighResTimeStamp.h"
 #include <wtf/RefCounted.h>
+#include <wtf/Seconds.h>
 
 namespace WebCore {
 
@@ -44,6 +46,12 @@
 
     int m_id;
     bool m_firedOrCancelled;
+
+    // Allow a little more than 60fps to make sure we can at least hit that frame rate.
+    static constexpr Seconds fullSpeedAnimationInterval { 15_ms };
+    // Allow a little more than 30fps to make sure we can at least hit that frame rate.
+    static constexpr Seconds halfSpeedThrottlingAnimationInterval { 30_ms };
+    static constexpr Seconds aggressiveThrottlingAnimationInterval { 10_s };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp (259297 => 259298)


--- trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -36,7 +36,11 @@
 #include "DOMWindow.h"
 #include "DedicatedWorkerThread.h"
 #include "MessageEvent.h"
+#include "RequestAnimationFrameCallback.h"
 #include "SecurityOrigin.h"
+#if ENABLE(OFFSCREEN_CANVAS)
+#include "WorkerAnimationController.h"
+#endif
 #include "WorkerObjectProxy.h"
 #include <wtf/IsoMallocInlines.h>
 
@@ -93,4 +97,19 @@
     return static_cast<DedicatedWorkerThread&>(Base::thread());
 }
 
+#if ENABLE(OFFSCREEN_CANVAS)
+CallbackId DedicatedWorkerGlobalScope::requestAnimationFrame(Ref<RequestAnimationFrameCallback>&& callback)
+{
+    if (!m_workerAnimationController)
+        m_workerAnimationController = WorkerAnimationController::create(*this);
+    return m_workerAnimationController->requestAnimationFrame(WTFMove(callback));
+}
+
+void DedicatedWorkerGlobalScope::cancelAnimationFrame(CallbackId callbackId)
+{
+    if (m_workerAnimationController)
+        m_workerAnimationController->cancelAnimationFrame(callbackId);
+}
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.h (259297 => 259298)


--- trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.h	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -45,8 +45,15 @@
 class ContentSecurityPolicyResponseHeaders;
 class DedicatedWorkerThread;
 class MessagePort;
+class RequestAnimationFrameCallback;
 class SerializedScriptValue;
 
+#if ENABLE(OFFSCREEN_CANVAS)
+class WorkerAnimationController;
+
+using CallbackId = int;
+#endif
+
 class DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
     WTF_MAKE_ISO_ALLOCATED(DedicatedWorkerGlobalScope);
 public:
@@ -59,6 +66,11 @@
 
     DedicatedWorkerThread& thread();
 
+#if ENABLE(OFFSCREEN_CANVAS)
+    CallbackId requestAnimationFrame(Ref<RequestAnimationFrameCallback>&&);
+    void cancelAnimationFrame(CallbackId);
+#endif
+
 private:
     using Base = WorkerGlobalScope;
 
@@ -69,6 +81,10 @@
     EventTargetInterface eventTargetInterface() const final;
 
     String m_name;
+
+#if ENABLE(OFFSCREEN_CANVAS)
+    RefPtr<WorkerAnimationController> m_workerAnimationController;
+#endif
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.idl (259297 => 259298)


--- trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.idl	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.idl	2020-03-31 17:35:30 UTC (rev 259298)
@@ -42,6 +42,9 @@
     [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
     [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
 
+    [Conditional=OFFSCREEN_CANVAS, EnabledAtRuntime=OffscreenCanvas] long requestAnimationFrame(RequestAnimationFrameCallback callback); // FIXME: Should return an unsigned long.
+    [Conditional=OFFSCREEN_CANVAS, EnabledAtRuntime=OffscreenCanvas] void cancelAnimationFrame(long handle); // FIXME: handle should be an unsigned long.
+
     void close();
 
     attribute EventHandler onmessage;

Added: trunk/Source/WebCore/workers/WorkerAnimationController.cpp (0 => 259298)


--- trunk/Source/WebCore/workers/WorkerAnimationController.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/WorkerAnimationController.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2011 Google Inc. All Rights Reserved.
+ * Copyright (C) 2020 Metrological Group B.V.
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * 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. ``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
+ * 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.
+ */
+
+#include "config.h"
+#include "WorkerAnimationController.h"
+
+#if ENABLE(OFFSCREEN_CANVAS)
+
+#include "ActiveDOMObject.h"
+#include "Performance.h"
+#include "RequestAnimationFrameCallback.h"
+#include "WorkerGlobalScope.h"
+#include <wtf/Ref.h>
+
+namespace WebCore {
+
+Ref<WorkerAnimationController> WorkerAnimationController::create(WorkerGlobalScope& workerGlobalScope)
+{
+    return adoptRef(*new WorkerAnimationController(workerGlobalScope));
+}
+
+WorkerAnimationController::WorkerAnimationController(WorkerGlobalScope& workerGlobalScope)
+    : ActiveDOMObject(&workerGlobalScope)
+    , m_workerGlobalScope(workerGlobalScope)
+    , m_animationTimer(*this, &WorkerAnimationController::animationTimerFired)
+{
+    suspendIfNeeded();
+}
+
+WorkerAnimationController::~WorkerAnimationController()
+{
+    ASSERT(!hasPendingActivity());
+}
+
+const char* WorkerAnimationController::activeDOMObjectName() const
+{
+    return "WorkerAnimationController";
+}
+
+bool WorkerAnimationController::hasPendingActivity() const
+{
+    return m_animationTimer.isActive();
+}
+
+void WorkerAnimationController::stop()
+{
+    m_animationTimer.stop();
+}
+
+void WorkerAnimationController::suspend(ReasonForSuspension)
+{
+    m_savedIsActive = hasPendingActivity();
+    stop();
+}
+
+void WorkerAnimationController::resume()
+{
+    if (m_savedIsActive) {
+        m_savedIsActive = false;
+        scheduleAnimation();
+    }
+}
+
+CallbackId WorkerAnimationController::requestAnimationFrame(Ref<RequestAnimationFrameCallback>&& callback)
+{
+    // FIXME: There's a lot of missing throttling behaviour that's present on DOMDocument
+    CallbackId callbackId = ++m_nextAnimationCallbackId;
+    callback->m_firedOrCancelled = false;
+    callback->m_id = callbackId;
+    m_animationCallbacks.append(WTFMove(callback));
+
+    scheduleAnimation();
+
+    return callbackId;
+}
+
+void WorkerAnimationController::cancelAnimationFrame(CallbackId callbackId)
+{
+    for (size_t i = 0; i < m_animationCallbacks.size(); ++i) {
+        auto& callback = m_animationCallbacks[i];
+        if (callback->m_id == callbackId) {
+            callback->m_firedOrCancelled = true;
+            m_animationCallbacks.remove(i);
+            return;
+        }
+    }
+}
+
+void WorkerAnimationController::scheduleAnimation()
+{
+    if (!m_workerGlobalScope.requestAnimationFrameEnabled())
+        return;
+
+    if (m_animationTimer.isActive())
+        return;
+
+    Seconds animationInterval = RequestAnimationFrameCallback::fullSpeedAnimationInterval;
+    Seconds scheduleDelay = std::max(animationInterval - Seconds::fromMilliseconds(m_workerGlobalScope.performance().now() - m_lastAnimationFrameTimestamp), 0_s);
+
+    m_animationTimer.startOneShot(scheduleDelay);
+}
+
+void WorkerAnimationController::animationTimerFired()
+{
+    m_lastAnimationFrameTimestamp = m_workerGlobalScope.performance().now();
+    serviceRequestAnimationFrameCallbacks(m_lastAnimationFrameTimestamp);
+}
+
+void WorkerAnimationController::serviceRequestAnimationFrameCallbacks(DOMHighResTimeStamp timestamp)
+{
+    if (!m_animationCallbacks.size() || !m_workerGlobalScope.requestAnimationFrameEnabled())
+        return;
+
+    // First, generate a list of callbacks to consider. Callbacks registered from this point
+    // on are considered only for the "next" frame, not this one.
+    CallbackList callbacks(m_animationCallbacks);
+
+    for (auto& callback : callbacks) {
+        if (callback->m_firedOrCancelled)
+            continue;
+        callback->m_firedOrCancelled = true;
+        callback->handleEvent(timestamp);
+    }
+
+    // Remove any callbacks we fired from the list of pending callbacks.
+    m_animationCallbacks.removeAllMatching([](auto& callback) {
+        return callback->m_firedOrCancelled;
+    });
+
+    if (m_animationCallbacks.size())
+        scheduleAnimation();
+}
+
+} // namespace WebCore
+
+#endif

Added: trunk/Source/WebCore/workers/WorkerAnimationController.h (0 => 259298)


--- trunk/Source/WebCore/workers/WorkerAnimationController.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/WorkerAnimationController.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2011 Google Inc. All Rights Reserved.
+ * Copyright (C) 2020 Metrological Group B.V.
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * 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. ``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
+ * 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(OFFSCREEN_CANVAS)
+
+#include "DOMHighResTimeStamp.h"
+#include "PlatformScreen.h"
+#include "Timer.h"
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class ActiveDOMObject;
+class RequestAnimationFrameCallback;
+class WorkerGlobalScope;
+
+class WorkerAnimationController final : public ThreadSafeRefCounted<WorkerAnimationController>, public ActiveDOMObject {
+public:
+    static Ref<WorkerAnimationController> create(WorkerGlobalScope&);
+    ~WorkerAnimationController();
+
+    int requestAnimationFrame(Ref<RequestAnimationFrameCallback>&&);
+    void cancelAnimationFrame(int);
+
+    using ThreadSafeRefCounted::ref;
+    using ThreadSafeRefCounted::deref;
+
+private:
+    WorkerAnimationController(WorkerGlobalScope&);
+
+    const char* activeDOMObjectName() const final;
+
+    bool hasPendingActivity() const final;
+    void stop() final;
+    void suspend(ReasonForSuspension) final;
+    void resume() final;
+
+    void scheduleAnimation();
+    void animationTimerFired();
+    void serviceRequestAnimationFrameCallbacks(DOMHighResTimeStamp timestamp);
+
+    WorkerGlobalScope& m_workerGlobalScope;
+
+    typedef Vector<RefPtr<RequestAnimationFrameCallback>> CallbackList;
+    CallbackList m_animationCallbacks;
+    typedef int CallbackId;
+    CallbackId m_nextAnimationCallbackId { 0 };
+
+    Timer m_animationTimer;
+    DOMHighResTimeStamp m_lastAnimationFrameTimestamp { 0 };
+
+    bool m_savedIsActive { false };
+};
+
+} // namespace WebCore
+
+#endif

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (259297 => 259298)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -78,6 +78,7 @@
     , m_socketProvider(socketProvider)
     , m_performance(Performance::create(this, params.timeOrigin))
     , m_referrerPolicy(params.referrerPolicy)
+    , m_requestAnimationFrameEnabled(params.requestAnimationFrameEnabled)
 {
 #if !ENABLE(INDEXED_DATABASE)
     UNUSED_PARAM(connectionProxy);

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (259297 => 259298)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.h	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -141,6 +141,8 @@
 
     ReferrerPolicy referrerPolicy() const final;
 
+    bool requestAnimationFrameEnabled() const { return m_requestAnimationFrameEnabled; }
+
 protected:
     WorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, WorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
 
@@ -220,6 +222,7 @@
 #endif
     std::unique_ptr<CSSValuePool> m_cssValuePool;
     ReferrerPolicy m_referrerPolicy;
+    bool m_requestAnimationFrameEnabled;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (259297 => 259298)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -39,6 +39,7 @@
 #include "MessageEvent.h"
 #include "Page.h"
 #include "ScriptExecutionContext.h"
+#include "Settings.h"
 #include "Worker.h"
 #include "WorkerInspectorProxy.h"
 #include <_javascript_Core/ConsoleTypes.h>
@@ -88,7 +89,7 @@
 
     SocketProvider* socketProvider = document.socketProvider();
 
-    WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy };
+    WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy, document.settings().requestAnimationFrameEnabled() };
     auto thread = DedicatedWorkerThread::create(params, sourceCode, *this, *this, *this, startMode, document.topOrigin(), proxy, socketProvider, runtimeFlags);
 
     workerThreadCreated(thread.get());

Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (259297 => 259298)


--- trunk/Source/WebCore/workers/WorkerThread.cpp	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -81,6 +81,7 @@
         shouldBypassMainWorldContentSecurityPolicy,
         timeOrigin,
         referrerPolicy,
+        requestAnimationFrameEnabled,
     };
 }
 

Modified: trunk/Source/WebCore/workers/WorkerThread.h (259297 => 259298)


--- trunk/Source/WebCore/workers/WorkerThread.h	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/WorkerThread.h	2020-03-31 17:35:30 UTC (rev 259298)
@@ -68,6 +68,7 @@
     bool shouldBypassMainWorldContentSecurityPolicy;
     MonotonicTime timeOrigin;
     ReferrerPolicy referrerPolicy;
+    bool requestAnimationFrameEnabled;
 
     WorkerParameters isolatedCopy() const;
 };

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (259297 => 259298)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2020-03-31 17:28:01 UTC (rev 259297)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2020-03-31 17:35:30 UTC (rev 259298)
@@ -73,7 +73,7 @@
 // FIXME: Use valid runtime flags
 
 ServiceWorkerThread::ServiceWorkerThread(const ServiceWorkerContextData& data, String&& userAgent, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider)
-    : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { } }, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
+    : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { }, true }, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
     , m_data(data.isolatedCopy())
     , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
     , m_heartBeatTimeout(SWContextManager::singleton().connection()->shouldUseShortTimeout() ? heartBeatTimeoutForTest : heartBeatTimeout)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to