summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/animation_frame
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 17:21:03 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 16:25:15 +0000
commitc551f43206405019121bd2b2c93714319a0a3300 (patch)
tree1f48c30631c421fd4bbb3c36da20183c8a2ed7d7 /chromium/third_party/blink/renderer/core/animation_frame
parent7961cea6d1041e3e454dae6a1da660b453efd238 (diff)
downloadqtwebengine-chromium-c551f43206405019121bd2b2c93714319a0a3300.tar.gz
BASELINE: Update Chromium to 79.0.3945.139
Change-Id: I336b7182fab9bca80b709682489c07db112eaca5 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/animation_frame')
-rw-r--r--chromium/third_party/blink/renderer/core/animation_frame/BUILD.gn15
-rw-r--r--chromium/third_party/blink/renderer/core/animation_frame/OWNERS4
-rw-r--r--chromium/third_party/blink/renderer/core/animation_frame/README.md3
-rw-r--r--chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.cc91
-rw-r--r--chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h65
5 files changed, 178 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/core/animation_frame/BUILD.gn b/chromium/third_party/blink/renderer/core/animation_frame/BUILD.gn
new file mode 100644
index 00000000000..5d6265cbaec
--- /dev/null
+++ b/chromium/third_party/blink/renderer/core/animation_frame/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2019 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.
+
+import("//third_party/blink/renderer/core/core.gni")
+
+blink_core_sources("animation_frame") {
+ sources = [
+ "worker_animation_frame_provider.cc",
+ "worker_animation_frame_provider.h",
+ ]
+ deps = [
+ "//mojo/public/cpp/bindings:bindings",
+ ]
+}
diff --git a/chromium/third_party/blink/renderer/core/animation_frame/OWNERS b/chromium/third_party/blink/renderer/core/animation_frame/OWNERS
new file mode 100644
index 00000000000..5ef87b1aa3f
--- /dev/null
+++ b/chromium/third_party/blink/renderer/core/animation_frame/OWNERS
@@ -0,0 +1,4 @@
+fserb@chromium.org
+
+# TEAM: paint-dev@chromium.org
+# COMPONENT: Blink>Canvas
diff --git a/chromium/third_party/blink/renderer/core/animation_frame/README.md b/chromium/third_party/blink/renderer/core/animation_frame/README.md
new file mode 100644
index 00000000000..b47c5e0a87d
--- /dev/null
+++ b/chromium/third_party/blink/renderer/core/animation_frame/README.md
@@ -0,0 +1,3 @@
+# animation frame
+
+This directory contains the implementation of the [animation frames](https://html.spec.whatwg.org/C/#animation-frames)
diff --git a/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.cc b/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.cc
new file mode 100644
index 00000000000..6152182b7c0
--- /dev/null
+++ b/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.cc
@@ -0,0 +1,91 @@
+// Copyright 2018 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 "third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h"
+
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/core/timing/worker_global_scope_performance.h"
+#include "third_party/blink/renderer/platform/bindings/microtask.h"
+#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
+
+namespace blink {
+
+WorkerAnimationFrameProvider::WorkerAnimationFrameProvider(
+ ExecutionContext* context,
+ const BeginFrameProviderParams& begin_frame_provider_params)
+ : begin_frame_provider_(
+ std::make_unique<BeginFrameProvider>(begin_frame_provider_params,
+ this)),
+ callback_collection_(context),
+ context_(context) {}
+
+int WorkerAnimationFrameProvider::RegisterCallback(
+ FrameRequestCallbackCollection::FrameCallback* callback) {
+ if (!begin_frame_provider_->IsValidFrameProvider()) {
+ return WorkerAnimationFrameProvider::kInvalidCallbackId;
+ }
+
+ FrameRequestCallbackCollection::CallbackId id =
+ callback_collection_.RegisterFrameCallback(callback);
+ begin_frame_provider_->RequestBeginFrame();
+ return id;
+}
+
+void WorkerAnimationFrameProvider::CancelCallback(int id) {
+ callback_collection_.CancelFrameCallback(id);
+}
+
+void WorkerAnimationFrameProvider::BeginFrame(const viz::BeginFrameArgs& args) {
+ TRACE_EVENT_WITH_FLOW0("blink", "WorkerAnimationFrameProvider::BeginFrame",
+ TRACE_ID_GLOBAL(args.trace_id),
+ TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT);
+
+ Microtask::EnqueueMicrotask(WTF::Bind(
+ [](base::WeakPtr<WorkerAnimationFrameProvider> provider,
+ const viz::BeginFrameArgs& args) {
+ if (!provider)
+ return;
+ TRACE_EVENT_WITH_FLOW0(
+ "blink", "WorkerAnimationFrameProvider::RequestAnimationFrame",
+ TRACE_ID_GLOBAL(args.trace_id), TRACE_EVENT_FLAG_FLOW_IN);
+ {
+ OffscreenCanvas::ScopedInsideWorkerRAF inside_raf_scope(args);
+ for (auto& offscreen_canvas : provider->offscreen_canvases_) {
+ // If one of the OffscreenCanvas has too many pending frames,
+ // we abort the whole process.
+ if (!inside_raf_scope.AddOffscreenCanvas(offscreen_canvas)) {
+ provider->begin_frame_provider_->FinishBeginFrame(args);
+ provider->begin_frame_provider_->RequestBeginFrame();
+ return;
+ }
+ }
+
+ double time = (args.frame_time - base::TimeTicks()).InMillisecondsF();
+ provider->callback_collection_.ExecuteFrameCallbacks(time, time);
+ }
+ provider->begin_frame_provider_->FinishBeginFrame(args);
+ },
+ weak_factory_.GetWeakPtr(), args));
+}
+
+void WorkerAnimationFrameProvider::RegisterOffscreenCanvas(
+ OffscreenCanvas* context) {
+ DCHECK(offscreen_canvases_.Find(context) == kNotFound);
+ offscreen_canvases_.push_back(context);
+}
+
+void WorkerAnimationFrameProvider::DeregisterOffscreenCanvas(
+ OffscreenCanvas* offscreen_canvas) {
+ wtf_size_t pos = offscreen_canvases_.Find(offscreen_canvas);
+ if (pos != kNotFound) {
+ offscreen_canvases_.EraseAt(pos);
+ }
+}
+
+void WorkerAnimationFrameProvider::Trace(blink::Visitor* visitor) {
+ visitor->Trace(callback_collection_);
+ visitor->Trace(context_);
+}
+
+} // namespace blink
diff --git a/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h b/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h
new file mode 100644
index 00000000000..fdb656bd702
--- /dev/null
+++ b/chromium/third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h
@@ -0,0 +1,65 @@
+// Copyright 2018 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.
+
+#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FRAME_WORKER_ANIMATION_FRAME_PROVIDER_H_
+#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FRAME_WORKER_ANIMATION_FRAME_PROVIDER_H_
+
+#include "base/macros.h"
+#include "third_party/blink/renderer/core/core_export.h"
+#include "third_party/blink/renderer/core/dom/frame_request_callback_collection.h"
+#include "third_party/blink/renderer/platform/graphics/begin_frame_provider.h"
+#include "third_party/blink/renderer/platform/heap/handle.h"
+
+namespace blink {
+
+class OffscreenCanvas;
+
+// WorkerAnimationFrameProvider is a member of WorkerGlobalScope and it provides
+// RequestAnimationFrame capabilities to Workers.
+//
+// It's responsible for registering and dealing with callbacks.
+// And maintains a connection with the Display process, through
+// CompositorFrameSink, that is used to v-sync with the display.
+//
+// OffscreenCanvases can notify when there's been a change on any
+// OffscreenCanvas that is connected to a Canvas, and this class signals
+// OffscreenCanvases when it's time to dispatch frames.
+class CORE_EXPORT WorkerAnimationFrameProvider
+ : public GarbageCollected<WorkerAnimationFrameProvider>,
+ public BeginFrameProviderClient {
+ public:
+ WorkerAnimationFrameProvider(
+ ExecutionContext* context,
+ const BeginFrameProviderParams& begin_frame_provider_params);
+
+ int RegisterCallback(FrameRequestCallbackCollection::FrameCallback* callback);
+ void CancelCallback(int id);
+
+ void Trace(blink::Visitor* visitor);
+
+ // BeginFrameProviderClient
+ void BeginFrame(const viz::BeginFrameArgs&) override;
+
+ void RegisterOffscreenCanvas(OffscreenCanvas*);
+ void DeregisterOffscreenCanvas(OffscreenCanvas*);
+
+ static const int kInvalidCallbackId = -1;
+
+ private:
+ const std::unique_ptr<BeginFrameProvider> begin_frame_provider_;
+ DISALLOW_COPY_AND_ASSIGN(WorkerAnimationFrameProvider);
+ FrameRequestCallbackCollection callback_collection_;
+
+ // To avoid leaking OffscreenCanvas objects, the following vector must
+ // not hold strong references.
+ Vector<UntracedMember<OffscreenCanvas>> offscreen_canvases_;
+
+ Member<ExecutionContext> context_;
+
+ base::WeakPtrFactory<WorkerAnimationFrameProvider> weak_factory_{this};
+};
+
+} // namespace blink
+
+#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FRAME_WORKER_ANIMATION_FRAME_PROVIDER_H_