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( ...@@ -94,19 +94,17 @@ void WorkletAnimationController::ScrollSourceCompositingStateChanged(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
WorkletAnimationController::EnsureMainThreadMutatorDispatcher( WorkletAnimationController::EnsureMainThreadMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner) { scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner) {
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> mutator_dispatcher; base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> mutator_dispatcher;
if (!mutator_task_runner_) { if (!main_thread_mutator_client_) {
main_thread_mutator_client_ = main_thread_mutator_client_ =
AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient( AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient(
&mutator_dispatcher, &mutator_task_runner_); mutator_dispatcher, std::move(mutator_task_runner));
main_thread_mutator_client_->SetDelegate(this); main_thread_mutator_client_->SetDelegate(this);
} }
DCHECK(main_thread_mutator_client_); DCHECK(main_thread_mutator_client_);
DCHECK(mutator_task_runner_);
DCHECK(mutator_dispatcher); DCHECK(mutator_dispatcher);
*mutator_task_runner = mutator_task_runner_;
return mutator_dispatcher; return mutator_dispatcher;
} }
......
...@@ -54,7 +54,7 @@ class CORE_EXPORT WorkletAnimationController ...@@ -54,7 +54,7 @@ class CORE_EXPORT WorkletAnimationController
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
EnsureMainThreadMutatorDispatcher( EnsureMainThreadMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner); scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner);
void SetMutationUpdate( void SetMutationUpdate(
std::unique_ptr<AnimationWorkletOutput> output) override; std::unique_ptr<AnimationWorkletOutput> output) override;
...@@ -79,7 +79,6 @@ class CORE_EXPORT WorkletAnimationController ...@@ -79,7 +79,6 @@ class CORE_EXPORT WorkletAnimationController
// TODO(crbug.com/1090515): The following proxy is needed for platform/ to // TODO(crbug.com/1090515): The following proxy is needed for platform/ to
// access this class. We should bypass it eventually. // access this class. We should bypass it eventually.
std::unique_ptr<MainThreadMutatorClient> main_thread_mutator_client_; std::unique_ptr<MainThreadMutatorClient> main_thread_mutator_client_;
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner_;
Member<Document> document_; Member<Document> document_;
}; };
......
...@@ -2698,15 +2698,15 @@ void WebFrameWidgetImpl::SetRootLayer(scoped_refptr<cc::Layer> layer) { ...@@ -2698,15 +2698,15 @@ void WebFrameWidgetImpl::SetRootLayer(scoped_refptr<cc::Layer> layer) {
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
WebFrameWidgetImpl::EnsureCompositorMutatorDispatcher( WebFrameWidgetImpl::EnsureCompositorMutatorDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner) { scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner) {
if (!mutator_task_runner_) { if (!mutator_task_runner_) {
mutator_task_runner_ = std::move(mutator_task_runner);
widget_base_->LayerTreeHost()->SetLayerTreeMutator( widget_base_->LayerTreeHost()->SetLayerTreeMutator(
AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient( AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient(
&mutator_dispatcher_, &mutator_task_runner_)); mutator_dispatcher_, mutator_task_runner_));
} }
DCHECK(mutator_task_runner_); DCHECK(mutator_task_runner_);
*mutator_task_runner = mutator_task_runner_;
return mutator_dispatcher_; return mutator_dispatcher_;
} }
......
...@@ -169,7 +169,7 @@ class CORE_EXPORT WebFrameWidgetImpl ...@@ -169,7 +169,7 @@ class CORE_EXPORT WebFrameWidgetImpl
// dereferenced on the output |mutator_task_runner|. // dereferenced on the output |mutator_task_runner|.
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
EnsureCompositorMutatorDispatcher( 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. // TODO: consider merge the input and return value to be one parameter.
// Creates or returns cached paint dispatcher. The returned WeakPtr must only // Creates or returns cached paint dispatcher. The returned WeakPtr must only
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/timer/elapsed_timer.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/animation/worklet_animation_controller.h"
#include "third_party/blink/renderer/core/dom/document.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_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_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/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/graphics/animation_worklet_mutator_dispatcher_impl.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" #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
namespace blink { namespace blink {
...@@ -211,17 +213,25 @@ AnimationWorkletProxyClient* AnimationWorkletProxyClient::FromDocument( ...@@ -211,17 +213,25 @@ AnimationWorkletProxyClient* AnimationWorkletProxyClient::FromDocument(
WebLocalFrameImpl* local_frame = WebLocalFrameImpl* local_frame =
WebLocalFrameImpl::FromFrame(document->GetFrame()); 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> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
compositor_mutator_dispatcher = compositor_mutator_dispatcher =
local_frame->LocalRootFrameWidget() 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> base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
main_thread_mutator_dispatcher = main_thread_mutator_dispatcher =
document->GetWorkletAnimationController() document->GetWorkletAnimationController()
.EnsureMainThreadMutatorDispatcher(&main_thread_host_queue); .EnsureMainThreadMutatorDispatcher(main_thread_host_queue);
return MakeGarbageCollected<AnimationWorkletProxyClient>( return MakeGarbageCollected<AnimationWorkletProxyClient>(
worklet_id, std::move(compositor_mutator_dispatcher), worklet_id, std::move(compositor_mutator_dispatcher),
......
...@@ -44,9 +44,9 @@ class AnimationWorkletProxyClientTest : public RenderingTest { ...@@ -44,9 +44,9 @@ class AnimationWorkletProxyClientTest : public RenderingTest {
void SetUp() override { void SetUp() override {
RenderingTest::SetUp(); RenderingTest::SetUp();
auto mutator =
std::make_unique<AnimationWorkletMutatorDispatcherImpl>(true);
mutator_task_runner_ = base::MakeRefCounted<base::TestSimpleTaskRunner>(); mutator_task_runner_ = base::MakeRefCounted<base::TestSimpleTaskRunner>();
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
mutator_task_runner_);
proxy_client_ = MakeGarbageCollected<AnimationWorkletProxyClient>( proxy_client_ = MakeGarbageCollected<AnimationWorkletProxyClient>(
1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner_); 1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner_);
...@@ -226,9 +226,10 @@ TEST_F(AnimationWorkletProxyClientTest, ...@@ -226,9 +226,10 @@ TEST_F(AnimationWorkletProxyClientTest,
nullptr, nullptr); nullptr, nullptr);
EXPECT_TRUE(proxy_client->mutator_items_.IsEmpty()); EXPECT_TRUE(proxy_client->mutator_items_.IsEmpty());
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(true);
scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner = 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>( proxy_client = MakeGarbageCollected<AnimationWorkletProxyClient>(
1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner); 1, nullptr, nullptr, mutator->GetWeakPtr(), mutator_task_runner);
......
...@@ -66,16 +66,10 @@ struct AnimationWorkletMutatorDispatcherImpl::AsyncMutationRequest { ...@@ -66,16 +66,10 @@ struct AnimationWorkletMutatorDispatcherImpl::AsyncMutationRequest {
}; };
AnimationWorkletMutatorDispatcherImpl::AnimationWorkletMutatorDispatcherImpl( AnimationWorkletMutatorDispatcherImpl::AnimationWorkletMutatorDispatcherImpl(
bool main_thread_task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: client_(nullptr), outputs_(OutputVectorRef::Create()) { : host_queue_(task_runner),
// By default web tests run without threaded compositing. See client_(nullptr),
// https://crbug.com/770028. If threaded compositing is disabled or outputs_(OutputVectorRef::Create()) {
// |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();
tick_clock_ = std::make_unique<base::DefaultTickClock>(); tick_clock_ = std::make_unique<base::DefaultTickClock>();
} }
...@@ -85,15 +79,13 @@ AnimationWorkletMutatorDispatcherImpl:: ...@@ -85,15 +79,13 @@ AnimationWorkletMutatorDispatcherImpl::
// static // static
template <typename ClientType> template <typename ClientType>
std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient( std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue, scoped_refptr<base::SingleThreadTaskRunner> queue) {
bool main_thread_client) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>( auto mutator =
main_thread_client); std::make_unique<AnimationWorkletMutatorDispatcherImpl>(std::move(queue));
// This is allowed since we own the class for the duration of creation. // This is allowed since we own the class for the duration of creation.
*weak_interface = mutator->weak_factory_.GetWeakPtr(); weak_interface = mutator->weak_factory_.GetWeakPtr();
*queue = mutator->GetTaskRunner();
return std::make_unique<ClientType>(std::move(mutator)); return std::make_unique<ClientType>(std::move(mutator));
} }
...@@ -101,17 +93,19 @@ std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient( ...@@ -101,17 +93,19 @@ std::unique_ptr<ClientType> AnimationWorkletMutatorDispatcherImpl::CreateClient(
// static // static
std::unique_ptr<CompositorMutatorClient> std::unique_ptr<CompositorMutatorClient>
AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient( AnimationWorkletMutatorDispatcherImpl::CreateCompositorThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue) { scoped_refptr<base::SingleThreadTaskRunner> queue) {
return CreateClient<CompositorMutatorClient>(weak_interface, queue, false); return CreateClient<CompositorMutatorClient>(weak_interface,
std::move(queue));
} }
// static // static
std::unique_ptr<MainThreadMutatorClient> std::unique_ptr<MainThreadMutatorClient>
AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient( AnimationWorkletMutatorDispatcherImpl::CreateMainThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue) { scoped_refptr<base::SingleThreadTaskRunner> queue) {
return CreateClient<MainThreadMutatorClient>(weak_interface, queue, true); return CreateClient<MainThreadMutatorClient>(weak_interface,
std::move(queue));
} }
void AnimationWorkletMutatorDispatcherImpl::MutateSynchronously( void AnimationWorkletMutatorDispatcherImpl::MutateSynchronously(
......
...@@ -33,19 +33,20 @@ class MainThreadMutatorClient; ...@@ -33,19 +33,20 @@ class MainThreadMutatorClient;
class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
: public AnimationWorkletMutatorDispatcher { : public AnimationWorkletMutatorDispatcher {
public: 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 // 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 // pair for referencing the AnimationWorkletMutatorDispatcherImpl. i.e. Put
// tasks on the TaskRunner using the WeakPtr to get to the methods. // tasks on the TaskRunner using the WeakPtr to get to the methods.
static std::unique_ptr<CompositorMutatorClient> CreateCompositorThreadClient( static std::unique_ptr<CompositorMutatorClient> CreateCompositorThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* mutatee, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& mutatee,
scoped_refptr<base::SingleThreadTaskRunner>* mutatee_runner); scoped_refptr<base::SingleThreadTaskRunner> mutatee_runner);
static std::unique_ptr<MainThreadMutatorClient> CreateMainThreadClient( static std::unique_ptr<MainThreadMutatorClient> CreateMainThreadClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* mutatee, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& mutatee,
scoped_refptr<base::SingleThreadTaskRunner>* mutatee_runner); scoped_refptr<base::SingleThreadTaskRunner> mutatee_runner);
explicit AnimationWorkletMutatorDispatcherImpl(bool main_thread_task_runner); explicit AnimationWorkletMutatorDispatcherImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~AnimationWorkletMutatorDispatcherImpl() override; ~AnimationWorkletMutatorDispatcherImpl() override;
// AnimationWorkletMutatorDispatcher implementation. // AnimationWorkletMutatorDispatcher implementation.
...@@ -74,10 +75,6 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final ...@@ -74,10 +75,6 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
MutatorClient* client() { return client_; } MutatorClient* client() { return client_; }
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() {
return host_queue_;
}
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> GetWeakPtr() { base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
...@@ -129,11 +126,11 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final ...@@ -129,11 +126,11 @@ class PLATFORM_EXPORT AnimationWorkletMutatorDispatcherImpl final
// dictionary. // dictionary.
AnimationWorkletMutatorToTaskRunnerMap mutator_map_; AnimationWorkletMutatorToTaskRunnerMap mutator_map_;
// |weak_interface| argument will be modified (initialized) by this function.
template <typename ClientType> template <typename ClientType>
static std::unique_ptr<ClientType> CreateClient( static std::unique_ptr<ClientType> CreateClient(
base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>* weak_interface, base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>& weak_interface,
scoped_refptr<base::SingleThreadTaskRunner>* queue, scoped_refptr<base::SingleThreadTaskRunner> queue);
bool create_main_thread_client);
scoped_refptr<base::SingleThreadTaskRunner> host_queue_; scoped_refptr<base::SingleThreadTaskRunner> host_queue_;
......
...@@ -100,7 +100,7 @@ class AnimationWorkletMutatorDispatcherImplTest : public ::testing::Test { ...@@ -100,7 +100,7 @@ class AnimationWorkletMutatorDispatcherImplTest : public ::testing::Test {
public: public:
void SetUp() override { void SetUp() override {
auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>( auto mutator = std::make_unique<AnimationWorkletMutatorDispatcherImpl>(
/*main_thread_task_runner=*/true); base::ThreadTaskRunnerHandle::Get());
mutator_ = mutator.get(); mutator_ = mutator.get();
client_ = client_ =
std::make_unique<::testing::StrictMock<MockCompositorMutatorClient>>( 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