haikuwebkit/Source/WebCore/workers/WorkerAnimationController.h

84 lines
2.8 KiB
C
Raw Permalink Normal View History

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. Canonical link: https://commits.webkit.org/222733@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-31 17:35:30 +00:00
/*
* 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
Allow conditionally enabling OffscreenCanvas only for non-worker contexts https://bugs.webkit.org/show_bug.cgi?id=225845 Reviewed by Darin Adler. .: * Source/cmake/OptionsGTK.cmake: * Source/cmake/OptionsWPE.cmake: * Source/cmake/WebKitFeatures.cmake: Match current behavior of ENABLE_OFFSCREEN_CANVAS for ENABLE_OFFSCREEN_CANVAS_IN_WORKERS. Source/WebCore: Enable both compile time and runtime conditional enablement of just the non-worker OffscreenCanvas code path. To make this work a new IDL extended attribute was needed, ConditionalForWorker=FOO, which allows specifying an additional macro to check for whether the constructor should be exposed on workers. Ideally this would be generic for any context type, but at the moment, the limited syntax of extended attributes makes that hard. If generalization is needed (or a similar syntax is needed for something else) this can be revisited. To support runtime conditional exposure, the existing EnabledForContext, which calls a static function on the implementation class passing the ScriptExecutationContext is used. If conditional per context type ever becomes a common thing, we should add another extended attribute (and add syntax to support like above) that allows specifying both the context type and the setting name. Other than that, uses of ENABLE_OFFSCREEN_CANVAS that guarded worker specific functionality were replaced by ENABLE_OFFSCREEN_CANVAS_IN_WORKERS. * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneDeserializer::deserialize): (WebCore::CloneDeserializer::CloneDeserializer): (WebCore::CloneDeserializer::readTerminal): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::deserialize): * bindings/js/SerializedScriptValue.h: (WebCore::SerializedScriptValue::SerializedScriptValue): * bindings/scripts/IDLAttributes.json: * bindings/scripts/preprocess-idls.pl: (GenerateConstructorAttributes): * html/HTMLCanvasElement.idl: * html/OffscreenCanvas.cpp: (WebCore::OffscreenCanvas::enabledForContext): * html/OffscreenCanvas.h: * html/OffscreenCanvas.idl: * html/canvas/OffscreenCanvasRenderingContext2D.cpp: (WebCore::OffscreenCanvasRenderingContext2D::enabledForContext): * html/canvas/OffscreenCanvasRenderingContext2D.h: * html/canvas/OffscreenCanvasRenderingContext2D.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setOffscreenCanvasInWorkersEnabled): (WebCore::RuntimeEnabledFeatures::offscreenCanvasInWorkersEnabled const): * workers/DedicatedWorkerGlobalScope.h: * workers/DedicatedWorkerGlobalScope.idl: * workers/WorkerAnimationController.cpp: * workers/WorkerAnimationController.h: Source/WTF: * Scripts/Preferences/WebPreferencesInternal.yaml: Add new OffscreenCanvasInWorkersEnabled preference. * wtf/PlatformEnable.h: Add new ENABLE_OFFSCREEN_CANVAS_IN_WORKERS macro. Tools: * Scripts/webkitperl/FeatureList.pm: * WebKitTestRunner/TestOptions.cpp: (WTR::TestOptions::defaults): Match current behavior of ENABLE_OFFSCREEN_CANVAS and OffscreenCanvasEnabled for ENABLE_OFFSCREEN_CANVAS_IN_WORKERS and OffscreenCanvasInWorkersEnabled. Canonical link: https://commits.webkit.org/237788@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277560 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-16 03:14:57 +00:00
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
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. Canonical link: https://commits.webkit.org/222733@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-31 17:35:30 +00:00
#include "ActiveDOMObject.h"
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. Canonical link: https://commits.webkit.org/222733@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-31 17:35:30 +00:00
#include "DOMHighResTimeStamp.h"
#include "PlatformScreen.h"
#include "Timer.h"
#include <wtf/ThreadSafeRefCounted.h>
namespace WebCore {
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 virtualHasPendingActivity() const final;
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. Canonical link: https://commits.webkit.org/222733@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-31 17:35:30 +00:00
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