Commit 5e793640 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Chromium LUCI CQ

[MBI] Migrate AnimationWorkletMutatorDispatcherImpl to use per-ASG CompositorTaskRunner

Before this CL, AnimationWorkletMutatorDispatcherImpl uses per-thread CompositorTaskRunner.

After this CL, AnimationWorkletMutatorDispatcherImpl will use per-ASG CompositorTaskRunner.

Bug: 1105403
Change-Id: Ib65e3a6f25be4455611aff91cb2fe83b86b6f13e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631553Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845018}
parent 9982e3be
......@@ -94,19 +94,17 @@ void WorkletAnimationController::ScrollSourceCompositingStateChanged(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
WorkletAnimationController::EnsureMainThreadMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner) {
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner) {
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> mutator_dispatcher;
if (!mutator_task_runner_) {
if (!main_thread_mutator_client_) {
main_thread_mutator_client_ =
AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient(
&mutator_dispatcher, &mutator_task_runner_);
mutator_dispatcher, std::move(mutator_task_runner));
main_thread_mutator_client_->SetDelegate(this);
}
DCHECK(main_thread_mutator_client_);
DCHECK(mutator_task_runner_);
DCHECK(mutator_dispatcher);
*mutator_task_runner = mutator_task_runner_;
return mutator_dispatcher;
}
......
......@@ -54,7 +54,7 @@ class CORE_EXPORT WorkletAnimationController
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
EnsureMainThreadMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner);
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner);
void SetMutationUpdate(
std::unique_ptr<AnimationWorkletOutput> output) override;
......@@ -79,7 +79,6 @@ class CORE_EXPORT WorkletAnimationController
// TODO(crbug.com/1090515): The following proxy is needed for platform/ to
// access this class. We should bypass it eventually.
std::unique_ptr<MainThreadMutatorClient> main_thread_mutator_client_;
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner_;
Member<Document> document_;
};
......
......@@ -2698,15 +2698,15 @@ void WebFrameWidgetImpl::SetRootLayer(scoped_refptr<cc::Layer> layer) {
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
WebFrameWidgetImpl::EnsureCompositorMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner) {
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner) {
if (!mutator_task_runner_) {
mutator_task_runner_ = std::move(mutator_task_runner);
widget_base_->LayerTreeHost()->SetLayerTreeMutator(
AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient(
&mutator_dispatcher_, &mutator_task_runner_));
mutator_dispatcher_, mutator_task_runner_));
}
DCHECK(mutator_task_runner_);
*mutator_task_runner = mutator_task_runner_;
return mutator_dispatcher_;
}
......
......@@ -169,7 +169,7 @@ class CORE_EXPORT WebFrameWidgetImpl
// dereferenced on the output |mutator_task_runner|.
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
EnsureCompositorMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner);
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner);
// TODO: consider merge the input and return value to be one parameter.
// Creates or returns cached paint dispatcher. The returned WeakPtr must only
......
......@@ -8,12 +8,14 @@
#include "base/metrics/histogram_macros.h"
#include "base/timer/elapsed_timer.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/renderer/core/animation/worklet_animation_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/graphics/animation_worklet_mutator_dispatcher_impl.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
namespace blink {
......@@ -211,17 +213,25 @@ AnimationWorkletProxyClient* AnimationWorkletProxyClient::FromDocument(
WebLocalFrameImpl* local_frame =
WebLocalFrameImpl::FromFrame(document->GetFrame());
scoped_refptr<base::SingleThreadTaskRunner> compositor_host_queue;
// By default web tests run without threaded compositing. See
// https://crbug.com/770028. If threaded compositing is disabled, we
// run on the main thread's compositor task runner otherwise we run
// tasks on the compositor thread's default task runner.
scoped_refptr<base::SingleThreadTaskRunner> compositor_host_queue =
Thread::CompositorThread()
? Thread::CompositorThread()->GetTaskRunner()
: local_frame->GetAgentGroupScheduler()->CompositorTaskRunner();
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
compositor_mutator_dispatcher =
local_frame->LocalRootFrameWidget()
->EnsureCompositorMutatorDispatcher(&compositor_host_queue);
->EnsureCompositorMutatorDispatcher(compositor_host_queue);
scoped_refptr<base::SingleThreadTaskRunner> main_thread_host_queue;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_host_queue =
local_frame->GetAgentGroupScheduler()->CompositorTaskRunner();
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
main_thread_mutator_dispatcher =
document->GetWorkletAnimationController()
.EnsureMainThreadMutatorDispatcher(&main_thread_host_queue);
.EnsureMainThreadMutatorDispatcher(main_thread_host_queue);
return MakeGarbageCollected<AnimationWorkletProxyClient>(
worklet_id, std::move(compositor_mutator_dispatcher),
......
......@@ -44,9 +44,9 @@ class AnimationWorkletProxyClientTest : public RenderingTest {
void SetUp() override {
RenderingTest::SetUp();
auto mutator =
std::make_unique<AnimationWorkletMutatorDispatcherImpl>(true);
mutator_task_runner_ = base::MakeRefCounted<base::TestSimpleTaskRunner>();
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
mutator_task_runner_);
proxy_client_ = MakeGarbageCollected<AnimationWorkletProxyClient>(
1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner_);
......@@ -226,9 +226,10 @@ TEST_F(AnimationWorkletProxyClientTest,
nullptr, nullptr);
EXPECT_TRUE(proxy_client->mutator_items_.IsEmpty());
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(true);
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner =
mutator->GetTaskRunner();
base::ThreadTaskRunnerHandle::Get();
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
mutator_task_runner);
proxy_client = MakeGarbageCollected<AnimationWorkletProxyClient>(
1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner);
......
......@@ -66,16 +66,10 @@ struct AnimationWorkletMutatorDispatcherImpl::AsyncMutationRequest {
};
AnimationWorkletMutatorDispatcherImpl::AnimationWorkletMutatorDispatcherImpl(
bool main_thread_task_runner)
: client_(nullptr), outputs_(OutputVectorRef::Create()) {
// By default web tests run without threaded compositing. See
// https://crbug.com/770028. If threaded compositing is disabled or
// |main_thread_task_runner| is true we run on the main thread's compositor
// task runner otherwise we run tasks on the compositor thread's default
// task runner.
host_queue_ = main_thread_task_runner || !Thread::CompositorThread()
? Thread::MainThread()->Scheduler()->CompositorTaskRunner()
: Thread::CompositorThread()->GetTaskRunner();
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: host_queue_(task_runner),
client_(nullptr),
outputs_(OutputVectorRef::Create()) {
tick_clock_ = std::make_unique<base::DefaultTickClock>();
}
......@@ -85,15 +79,13 @@ AnimationWorkletMutatorDispatcherImpl::
// static
template <typename ClientType>
std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue,
bool main_thread_client) {
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner> queue) {
DCHECK(IsMainThread());
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
main_thread_client);
auto mutator =
std::make_unique<AnimationWorkletMutatorDispatcherImpl>(std::move(queue));
// This is allowed since we own the class for the duration of creation.
*weak_interface = mutator->weak_factory_.GetWeakPtr();
*queue = mutator->GetTaskRunner();
weak_interface = mutator->weak_factory_.GetWeakPtr();
return std::make_unique<ClientType>(std::move(mutator));
}
......@@ -101,17 +93,19 @@ std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient(
// static
std::unique_ptr<CompositorMutatorClient>
AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue) {
return CreateClient<CompositorMutatorClient>(weak_interface, queue, false);
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner> queue) {
return CreateClient<CompositorMutatorClient>(weak_interface,
std::move(queue));
}
// static
std::unique_ptr<MainThreadMutatorClient>
AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue) {
return CreateClient<MainThreadMutatorClient>(weak_interface, queue, true);
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner> queue) {
return CreateClient<MainThreadMutatorClient>(weak_interface,
std::move(queue));
}
void AnimationWorkletMutatorDispatcherImpl::MutateSynchronously(
......
......@@ -33,19 +33,20 @@ class MainThreadMutatorClient;
class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
: public AnimationWorkletMutatorDispatcher {
public:
// There are three outputs for the two interface surfaces of the created
// There are two outputs for the two interface surfaces of the created
// class blob. The returned owning pointer to the Client, which
// also owns the rest of the structure. |mutatee| and |mutatee_runner| form a
// also owns the rest of the structure. |mutatee| form a
// pair for referencing the AnimationWorkletMutatorDispatcherImpl. i.e. Put
// tasks on the TaskRunner using the WeakPtr to get to the methods.
static std::unique_ptr<CompositorMutatorClient> CreateCompositorThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* mutatee,
scoped_refptr<base::SingleThreadTaskRunner>* mutatee_runner);
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& mutatee,
scoped_refptr<base::SingleThreadTaskRunner> mutatee_runner);
static std::unique_ptr<MainThreadMutatorClient> CreateMainThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* mutatee,
scoped_refptr<base::SingleThreadTaskRunner>* mutatee_runner);
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& mutatee,
scoped_refptr<base::SingleThreadTaskRunner> mutatee_runner);
explicit AnimationWorkletMutatorDispatcherImpl(bool main_thread_task_runner);
explicit AnimationWorkletMutatorDispatcherImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~AnimationWorkletMutatorDispatcherImpl() override;
// AnimationWorkletMutatorDispatcher implementation.
......@@ -74,10 +75,6 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
MutatorClient* client() { return client_; }
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() {
return host_queue_;
}
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......@@ -129,11 +126,11 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
// dictionary.
AnimationWorkletMutatorToTaskRunnerMap mutator_map_;
// |weak_interface| argument will be modified (initialized) by this function.
template <typename ClientType>
static std::unique_ptr<ClientType> CreateClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue,
bool create_main_thread_client);
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner> queue);
scoped_refptr<base::SingleThreadTaskRunner> host_queue_;
......
......@@ -100,7 +100,7 @@ class AnimationWorkletMutatorDispatcherImplTest : public ::testing::Test {
public:
void SetUp() override {
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
/*main_thread_task_runner=*/true);
base::ThreadTaskRunnerHandle::Get());
mutator_ = mutator.get();
client_ =
std::make_unique<::testing::StrictMock<MockCompositorMutatorClient>>(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment