Commit 69f23639 authored by danakj's avatar danakj Committed by Commit Bot

Avoid null check on LayerTreeHost, stop passing stack pointer to heap

The LatencyInfoSwapPromiseMonitors do not need to be heap allocated,
they are destroyed within the same stack frame where they are created
but they are put on the heap because the LayerTreeHost is treated as
being possibly null.

The LayerTreeHost would only be null if the RenderWidget is closing,
and an IPC is received on the handler through some other channel.
Instead, don't call to the handler from RenderWidget::HandleInputEvent
if the RenderWidget is closing. Then no null checks are needed, and
the LatencyInfoSwapPromiseMonitors can be created on the stack.

Also narrow their lifetime to just be around the method call that
they are monitoring, for clarity.

R=avi@chromium.org

Bug: 994926
Change-Id: I47a04f248479a6266fba673ea0a2e98ce1671e66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1812915Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698489}
parent 267bb1f5
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "cc/paint/element_id.h" #include "cc/paint/element_id.h"
#include "cc/trees/latency_info_swap_promise_monitor.h" #include "cc/trees/latency_info_swap_promise_monitor.h"
#include "cc/trees/swap_promise_monitor.h"
#include "components/viz/common/surfaces/frame_sink_id.h" #include "components/viz/common/surfaces/frame_sink_id.h"
#include "content/common/input/input_event_ack.h" #include "content/common/input/input_event_ack.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -365,17 +364,9 @@ void RenderWidgetInputHandler::HandleInputEvent( ...@@ -365,17 +364,9 @@ void RenderWidgetInputHandler::HandleInputEvent(
if (!start_time.is_null()) if (!start_time.is_null())
LogInputEventLatencyUma(input_event, start_time); LogInputEventLatencyUma(input_event, start_time);
std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
ui::LatencyInfo swap_latency_info(latency_info); ui::LatencyInfo swap_latency_info(latency_info);
swap_latency_info.AddLatencyNumber( swap_latency_info.AddLatencyNumber(
ui::LatencyComponentType::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT); ui::LatencyComponentType::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT);
if (widget_->layer_tree_host()) {
latency_info_swap_promise_monitor =
std::make_unique<cc::LatencyInfoSwapPromiseMonitor>(
&swap_latency_info,
widget_->layer_tree_host()->GetSwapPromiseManager(), nullptr);
}
bool prevent_default = false; bool prevent_default = false;
bool show_virtual_keyboard_for_mouse = false; bool show_virtual_keyboard_for_mouse = false;
...@@ -385,7 +376,13 @@ void RenderWidgetInputHandler::HandleInputEvent( ...@@ -385,7 +376,13 @@ void RenderWidgetInputHandler::HandleInputEvent(
TRACE_EVENT2("renderer", "HandleMouseMove", "x", TRACE_EVENT2("renderer", "HandleMouseMove", "x",
mouse_event.PositionInWidget().x, "y", mouse_event.PositionInWidget().x, "y",
mouse_event.PositionInWidget().y); mouse_event.PositionInWidget().y);
prevent_default = delegate_->WillHandleMouseEvent(mouse_event);
{
cc::LatencyInfoSwapPromiseMonitor swap_promise_monitor(
&swap_latency_info,
widget_->layer_tree_host()->GetSwapPromiseManager(), nullptr);
prevent_default = delegate_->WillHandleMouseEvent(mouse_event);
}
// Reset the last known cursor if mouse has left this widget. So next // Reset the last known cursor if mouse has left this widget. So next
// time that the mouse enters we always set the cursor accordingly. // time that the mouse enters we always set the cursor accordingly.
...@@ -667,14 +664,6 @@ void RenderWidgetInputHandler::HandleInjectedScrollGestures( ...@@ -667,14 +664,6 @@ void RenderWidgetInputHandler::HandleInjectedScrollGestures(
} }
} }
std::unique_ptr<cc::SwapPromiseMonitor> swap_promise_monitor;
if (widget_->layer_tree_host()) {
swap_promise_monitor =
std::make_unique<cc::LatencyInfoSwapPromiseMonitor>(
&scrollbar_latency_info,
widget_->layer_tree_host()->GetSwapPromiseManager(), nullptr);
}
std::unique_ptr<WebGestureEvent> gesture_event = std::unique_ptr<WebGestureEvent> gesture_event =
ui::GenerateInjectedScrollGesture( ui::GenerateInjectedScrollGesture(
params.type, input_event.TimeStamp(), params.device, position, params.type, input_event.TimeStamp(), params.device, position,
...@@ -687,8 +676,13 @@ void RenderWidgetInputHandler::HandleInjectedScrollGestures( ...@@ -687,8 +676,13 @@ void RenderWidgetInputHandler::HandleInjectedScrollGestures(
last_injected_gesture_was_begin_ = false; last_injected_gesture_was_begin_ = false;
} }
widget_->GetWebWidget()->HandleInputEvent( {
blink::WebCoalescedInputEvent(*gesture_event.get())); cc::LatencyInfoSwapPromiseMonitor swap_promise_monitor(
&scrollbar_latency_info,
widget_->layer_tree_host()->GetSwapPromiseManager(), nullptr);
widget_->GetWebWidget()->HandleInputEvent(
blink::WebCoalescedInputEvent(*gesture_event.get()));
}
} }
} }
......
...@@ -1078,6 +1078,8 @@ bool RenderWidget::HandleInputEvent( ...@@ -1078,6 +1078,8 @@ bool RenderWidget::HandleInputEvent(
const blink::WebCoalescedInputEvent& input_event, const blink::WebCoalescedInputEvent& input_event,
const ui::LatencyInfo& latency_info, const ui::LatencyInfo& latency_info,
HandledEventCallback callback) { HandledEventCallback callback) {
if (closing_)
return false;
if (IsUndeadOrProvisional()) if (IsUndeadOrProvisional())
return false; return false;
input_handler_->HandleInputEvent(input_event, latency_info, input_handler_->HandleInputEvent(input_event, latency_info,
......
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