| Index: Source/modules/compositorworker/CompositorWorkerGlobalScope.cpp
|
| diff --git a/Source/modules/compositorworker/CompositorWorkerGlobalScope.cpp b/Source/modules/compositorworker/CompositorWorkerGlobalScope.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..606d83739d470980239a02231bfbf2a99acbca9e
|
| --- /dev/null
|
| +++ b/Source/modules/compositorworker/CompositorWorkerGlobalScope.cpp
|
| @@ -0,0 +1,86 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "modules/compositorworker/CompositorWorkerGlobalScope.h"
|
| +
|
| +#include "core/dom/RequestAnimationFrameCallback.h"
|
| +#include "core/workers/WorkerThreadStartupData.h"
|
| +#include "modules/EventTargetModules.h"
|
| +#include "modules/compositorworker/CompositorWorkerThread.h"
|
| +
|
| +namespace blink {
|
| +
|
| +PassRefPtrWillBeRawPtr<CompositorWorkerGlobalScope> CompositorWorkerGlobalScope::create(CompositorWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData, double timeOrigin)
|
| +{
|
| + RefPtrWillBeRawPtr<CompositorWorkerGlobalScope> context = adoptRefWillBeNoop(new CompositorWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, timeOrigin, startupData->m_starterOrigin, startupData->m_workerClients.release()));
|
| + context->applyContentSecurityPolicyFromString(startupData->m_contentSecurityPolicy, startupData->m_contentSecurityPolicyType);
|
| + return context.release();
|
| +}
|
| +
|
| +CompositorWorkerGlobalScope::CompositorWorkerGlobalScope(const KURL& url, const String& userAgent, CompositorWorkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
|
| + : DedicatedWorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, workerClients)
|
| + , m_nextCallbackId(0)
|
| +{
|
| +}
|
| +
|
| +CompositorWorkerGlobalScope::~CompositorWorkerGlobalScope()
|
| +{
|
| +}
|
| +
|
| +// EventTarget
|
| +const AtomicString& CompositorWorkerGlobalScope::interfaceName() const
|
| +{
|
| + return EventTargetNames::CompositorWorkerGlobalScope;
|
| +}
|
| +
|
| +int CompositorWorkerGlobalScope::requestCompositorFrame(RequestAnimationFrameCallback* callback)
|
| +{
|
| + callback->m_cancelled = false;
|
| + callback->m_id = ++m_nextCallbackId;
|
| + m_callbacks.append(callback);
|
| + return callback->m_id;
|
| +}
|
| +
|
| +void CompositorWorkerGlobalScope::cancelCompositorFrame(int id)
|
| +{
|
| + for (size_t i = 0; i < m_callbacks.size(); ++i) {
|
| + if (m_callbacks[i]->m_id == id) {
|
| + m_callbacks.remove(i);
|
| + return;
|
| + }
|
| + }
|
| + for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
|
| + if (m_callbacksToInvoke[i]->m_id == id) {
|
| + m_callbacksToInvoke[i]->m_cancelled = true;
|
| + // will be removed at the end of executeCallbacks()
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| +void CompositorWorkerGlobalScope::executeCompositorFrameCallbacks(double monotonicTimeNow)
|
| +{
|
| + if (!m_callbacks.size())
|
| + 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.
|
| + ASSERT(m_callbacksToInvoke.isEmpty());
|
| + m_callbacksToInvoke.swap(m_callbacks);
|
| +
|
| + for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
|
| + RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get();
|
| + if (!callback->m_cancelled)
|
| + callback->handleEvent(monotonicTimeNow);
|
| + }
|
| +
|
| + m_callbacksToInvoke.clear();
|
| +}
|
| +
|
| +DEFINE_TRACE(CompositorWorkerGlobalScope)
|
| +{
|
| + DedicatedWorkerGlobalScope::trace(visitor);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|