Commit 7f2c0374 authored by danakj's avatar danakj Committed by Commit Bot

Pull input initialization out of InitializeLayerTreeView

InitializeLayerTreeView has a weird connection with ScreenInfo which
causes us to require it to exist before doing
SynchronizeVisualProperties. We're going to pull it apart.

Here we pull the input stuff out to get out out of the way.

Use the WebMainThreadScheduler from CompositorDependencies instead of
going through a nullable RenderThreadImpl pointer in tests. Then make
the fake on in unit tests return a task runner for the input handler,
which can be the current (main) thread since these tests don't run a
compositor thread. Drop all the null checks around the input queue.

R=avi@chromium.org

Bug: 419087
Change-Id: I117b28eb157ab7b5dc61cef6b80f7f32243404e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1850416Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704389}
parent fb2d0bae
......@@ -538,8 +538,6 @@ void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) {
DCHECK(!webwidget_);
DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
LayerTreeView* layer_tree_view = InitializeLayerTreeView();
......@@ -550,9 +548,9 @@ void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) {
if (web_widget)
web_widget->SetAnimationHost(layer_tree_view->animation_host());
blink::scheduler::WebThreadScheduler* main_thread_scheduler = nullptr;
if (render_thread_impl)
main_thread_scheduler = render_thread_impl->GetWebMainThreadScheduler();
blink::scheduler::WebThreadScheduler* main_thread_scheduler =
compositor_deps_->GetWebMainThreadScheduler();
blink::scheduler::WebThreadScheduler* compositor_thread_scheduler =
blink::scheduler::WebThreadScheduler::CompositorThreadScheduler();
scoped_refptr<base::SingleThreadTaskRunner> compositor_input_task_runner;
......@@ -564,6 +562,10 @@ void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) {
compositor_thread_scheduler->InputTaskRunner();
}
input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>(
this, main_thread_scheduler->InputTaskRunner(), main_thread_scheduler,
/*allow_raf_aligned_input=*/!compositor_never_visible_);
// We only use an external input handler for frame RenderWidgets because only
// frames use the compositor for input handling. Other kinds of RenderWidgets
// (e.g. popups, plugins) must forward their input directly through
......@@ -1237,7 +1239,7 @@ void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) {
// single-thread mode for testing.
bool record_main_frame_metrics =
!!compositor_deps_->GetCompositorImplThreadTaskRunner();
if (input_event_queue_) {
{
base::Optional<ScopedUkmRafAlignedInputTimer> ukm_timer;
if (record_main_frame_metrics) {
ukm_timer.emplace(GetWebWidget());
......@@ -1968,16 +1970,6 @@ LayerTreeView* RenderWidget::InitializeLayerTreeView() {
if (!is_hidden_ && !is_undead_)
StartStopCompositor();
DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
RenderThreadImpl* render_thread = RenderThreadImpl::current();
if (render_thread) {
input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>(
this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
render_thread->GetWebMainThreadScheduler(),
/*allow_raf_aligned_input=*/!compositor_never_visible_);
}
return layer_tree_view_.get();
}
......@@ -2063,8 +2055,7 @@ void RenderWidget::Close(std::unique_ptr<RenderWidget> widget) {
// Stop handling main thread input events immediately so we don't have them
// running while things are partly shut down.
if (input_event_queue_)
input_event_queue_->ClearClient();
input_event_queue_->ClearClient();
// The |webwidget_| will be null when the main frame RenderWidget is undead.
if (webwidget_)
......@@ -3394,8 +3385,7 @@ cc::ManagedMemoryPolicy RenderWidget::GetGpuMemoryPolicy(
}
void RenderWidget::SetHasPointerRawUpdateEventHandlers(bool has_handlers) {
if (input_event_queue_)
input_event_queue_->HasPointerRawUpdateEventHandlers(has_handlers);
input_event_queue_->HasPointerRawUpdateEventHandlers(has_handlers);
}
void RenderWidget::SetHasTouchEventHandlers(bool has_handlers) {
......@@ -3413,13 +3403,11 @@ void RenderWidget::SetHaveScrollEventHandlers(bool have_handlers) {
}
void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
if (input_event_queue_)
input_event_queue_->SetNeedsLowLatency(needs_low_latency);
input_event_queue_->SetNeedsLowLatency(needs_low_latency);
}
void RenderWidget::SetNeedsUnbufferedInputForDebugger(bool unbuffered) {
if (input_event_queue_)
input_event_queue_->SetNeedsUnbufferedInputForDebugger(unbuffered);
input_event_queue_->SetNeedsUnbufferedInputForDebugger(unbuffered);
}
void RenderWidget::AnimateDoubleTapZoomInMainFrame(
......@@ -3694,8 +3682,7 @@ void RenderWidget::NotifySwapAndPresentationTime(
}
void RenderWidget::RequestUnbufferedInputEvents() {
if (input_event_queue_)
input_event_queue_->RequestUnbufferedInputEvents();
input_event_queue_->RequestUnbufferedInputEvents();
}
void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
......
......@@ -298,6 +298,8 @@ TEST_F(RenderWidgetUnittest, CursorChange) {
widget()->DidChangeCursor(cursor_info);
EXPECT_EQ(widget()->sink()->message_count(), 0U);
EXPECT_CALL(*widget()->mock_webwidget(), HandleInputEvent(_))
.WillOnce(::testing::Return(blink::WebInputEventResult::kNotHandled));
widget()->SendInputEvent(SyntheticWebMouseEventBuilder::Build(
blink::WebInputEvent::Type::kMouseLeave),
HandledEventCallback());
......
......@@ -6,6 +6,7 @@
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
......@@ -33,7 +34,7 @@ WebFakeThreadScheduler::CompositorTaskRunner() {
scoped_refptr<base::SingleThreadTaskRunner>
WebFakeThreadScheduler::InputTaskRunner() {
return nullptr;
return base::ThreadTaskRunnerHandle::Get();
}
scoped_refptr<base::SingleThreadTaskRunner>
......
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