Commit 971c1735 authored by Mario Bianucci's avatar Mario Bianucci Committed by Chromium LUCI CQ

Propagate left button flag to viz to stop Delegated Ink Trail

Part 2 of ensuring that a delegated ink trail stops as quickly as
possible when a user lifts the left mouse button or pen tip, part 1
here[1].

This CL checks the new flag on the RenderFrameMetadata in the browser
process to determine if the left button is expected to be down or not.
It compares that information to if the button is down on the current
point or not, and if they don't match, it informs viz to reset
prediction. Resetting prediction when we know the trail is ending will
help the trail better match the user's expectation of where the ink
should show up.

[1]: https://chromium-review.googlesource.com/c/chromium/src/+/2579704

Bug: 1052145
Change-Id: If2ffcba7dbddf326263bb982fc8b002d5b162221
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2581001Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Reviewed-by: default avatarDaniel Libby <dlibby@microsoft.com>
Commit-Queue: Mario Bianucci <mabian@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#840463}
parent 7cf54392
...@@ -153,6 +153,8 @@ void DelegatedInkPointRendererBase::PredictPoints( ...@@ -153,6 +153,8 @@ void DelegatedInkPointRendererBase::PredictPoints(
void DelegatedInkPointRendererBase::ResetPrediction() { void DelegatedInkPointRendererBase::ResetPrediction() {
predictor_->Reset(); predictor_->Reset();
metrics_handler_.Reset(); metrics_handler_.Reset();
TRACE_EVENT_INSTANT0("viz", "Delegated ink prediction reset.",
TRACE_EVENT_SCOPE_THREAD);
} }
void DelegatedInkPointRendererBase::StoreDelegatedInkPoint( void DelegatedInkPointRendererBase::StoreDelegatedInkPoint(
......
...@@ -66,7 +66,7 @@ class VIZ_SERVICE_EXPORT DelegatedInkPointRendererBase ...@@ -66,7 +66,7 @@ class VIZ_SERVICE_EXPORT DelegatedInkPointRendererBase
std::vector<DelegatedInkPoint> FilterPoints(); std::vector<DelegatedInkPoint> FilterPoints();
void PredictPoints(std::vector<DelegatedInkPoint>* ink_points_to_draw); void PredictPoints(std::vector<DelegatedInkPoint>* ink_points_to_draw);
void ResetPrediction(); void ResetPrediction() override;
std::unique_ptr<DelegatedInkMetadata> metadata_; std::unique_ptr<DelegatedInkMetadata> metadata_;
......
...@@ -364,10 +364,13 @@ void RenderWidgetHostViewEventHandler::HandleMouseWheelEvent( ...@@ -364,10 +364,13 @@ void RenderWidgetHostViewEventHandler::HandleMouseWheelEvent(
} }
void RenderWidgetHostViewEventHandler::ForwardDelegatedInkPoint( void RenderWidgetHostViewEventHandler::ForwardDelegatedInkPoint(
ui::LocatedEvent* event) { ui::LocatedEvent* event,
bool hovering) {
const cc::RenderFrameMetadata& last_metadata = const cc::RenderFrameMetadata& last_metadata =
host_->render_frame_metadata_provider()->LastRenderFrameMetadata(); host_->render_frame_metadata_provider()->LastRenderFrameMetadata();
if (last_metadata.delegated_ink_metadata.has_value()) { if (last_metadata.delegated_ink_metadata.has_value() &&
hovering == last_metadata.delegated_ink_metadata.value()
.delegated_ink_is_hovering) {
if (!delegated_ink_point_renderer_.is_bound()) { if (!delegated_ink_point_renderer_.is_bound()) {
ui::Compositor* compositor = window_ && window_->layer() ui::Compositor* compositor = window_ && window_->layer()
? window_->layer()->GetCompositor() ? window_->layer()->GetCompositor()
...@@ -402,6 +405,16 @@ void RenderWidgetHostViewEventHandler::ForwardDelegatedInkPoint( ...@@ -402,6 +405,16 @@ void RenderWidgetHostViewEventHandler::ForwardDelegatedInkPoint(
// DrawAndSwap() is called, allowing more points to be drawn as part of // DrawAndSwap() is called, allowing more points to be drawn as part of
// the delegated ink trail, and thus reducing user perceived latency. // the delegated ink trail, and thus reducing user perceived latency.
delegated_ink_point_renderer_->StoreDelegatedInkPoint(delegated_ink_point); delegated_ink_point_renderer_->StoreDelegatedInkPoint(delegated_ink_point);
ended_delegated_ink_trail_ = false;
} else if (delegated_ink_point_renderer_.is_bound() &&
!ended_delegated_ink_trail_) {
// Let viz know that the most recent point it received from us is probably
// the last point the user is inking, so it shouldn't predict anything
// beyond it.
TRACE_EVENT_INSTANT0("input", "Delegated ink trail ended",
TRACE_EVENT_SCOPE_THREAD);
delegated_ink_point_renderer_->ResetPrediction();
ended_delegated_ink_trail_ = true;
} }
} }
...@@ -448,7 +461,9 @@ void RenderWidgetHostViewEventHandler::OnMouseEvent(ui::MouseEvent* event) { ...@@ -448,7 +461,9 @@ void RenderWidgetHostViewEventHandler::OnMouseEvent(ui::MouseEvent* event) {
bool is_selection_popup = NeedsInputGrab(popup_child_host_view_); bool is_selection_popup = NeedsInputGrab(popup_child_host_view_);
if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) &&
!(event->flags() & ui::EF_FROM_TOUCH)) { !(event->flags() & ui::EF_FROM_TOUCH)) {
ForwardDelegatedInkPoint(event); bool hovering = (event->type() ^ ui::ET_MOUSE_DRAGGED) &&
(event->type() ^ ui::ET_MOUSE_PRESSED);
ForwardDelegatedInkPoint(event, hovering);
// Confirm existing composition text on mouse press, to make sure // Confirm existing composition text on mouse press, to make sure
// the input caret won't be moved with an ongoing composition text. // the input caret won't be moved with an ongoing composition text.
...@@ -573,7 +588,7 @@ void RenderWidgetHostViewEventHandler::OnTouchEvent(ui::TouchEvent* event) { ...@@ -573,7 +588,7 @@ void RenderWidgetHostViewEventHandler::OnTouchEvent(ui::TouchEvent* event) {
if (handled) if (handled)
return; return;
ForwardDelegatedInkPoint(event); ForwardDelegatedInkPoint(event, event->hovering());
if (had_no_pointer) if (had_no_pointer)
delegate_->selection_controller_client()->OnTouchDown(); delegate_->selection_controller_client()->OnTouchDown();
......
...@@ -256,7 +256,7 @@ class CONTENT_EXPORT RenderWidgetHostViewEventHandler ...@@ -256,7 +256,7 @@ class CONTENT_EXPORT RenderWidgetHostViewEventHandler
// Forward the location and timestamp of the event to viz if a delegated ink // Forward the location and timestamp of the event to viz if a delegated ink
// trail is requested. // trail is requested.
void ForwardDelegatedInkPoint(ui::LocatedEvent* event); void ForwardDelegatedInkPoint(ui::LocatedEvent* event, bool hovering);
// Flush the remote for testing purposes. // Flush the remote for testing purposes.
void FlushForTest() { delegated_ink_point_renderer_.FlushForTesting(); } void FlushForTest() { delegated_ink_point_renderer_.FlushForTesting(); }
...@@ -327,6 +327,13 @@ class CONTENT_EXPORT RenderWidgetHostViewEventHandler ...@@ -327,6 +327,13 @@ class CONTENT_EXPORT RenderWidgetHostViewEventHandler
// support the delegated ink trails feature. // support the delegated ink trails feature.
mojo::Remote<viz::mojom::DelegatedInkPointRenderer> mojo::Remote<viz::mojom::DelegatedInkPointRenderer>
delegated_ink_point_renderer_; delegated_ink_point_renderer_;
// Used to know if we have already told viz to reset prediction because the
// final point of the delegated ink trail has been sent. True when prediction
// has already been reset for the most recent trail, false otherwise. This
// flag helps make sure that we don't send more IPCs than necessary to viz to
// reset prediction. Sending extra IPCs wouldn't impact correctness, but can
// impact performance due to the IPC overhead.
bool ended_delegated_ink_trail_ = false;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEventHandler); DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEventHandler);
}; };
......
...@@ -17,9 +17,16 @@ struct DelegatedInkPoint { ...@@ -17,9 +17,16 @@ struct DelegatedInkPoint {
// delegated ink trails. A delegated ink point will be produced in the // delegated ink trails. A delegated ink point will be produced in the
// browser process and sent to viz to be held until DrawAndSwap occurs, at // browser process and sent to viz to be held until DrawAndSwap occurs, at
// which point any delegated ink points that arrived may be used to draw the // which point any delegated ink points that arrived may be used to draw the
// ink trail. // ink trail. When the browser detects the end of the trail, it will call
// ResetPrediction() so that viz does not predict any points further than what
// the user is expecting.
interface DelegatedInkPointRenderer { interface DelegatedInkPointRenderer {
// Used to send the DelegatedInkPoint that was created in the browser process // Used to send the DelegatedInkPoint that was created in the browser process
// to viz in order to be drawn as part of the delegated ink trail. // to viz in order to be drawn as part of the delegated ink trail.
StoreDelegatedInkPoint(DelegatedInkPoint point); StoreDelegatedInkPoint(DelegatedInkPoint point);
// Used to reset prediction and prediction metrics that have been generated
// by previously received points. Used by the browser process when a delegated
// ink trail should end.
ResetPrediction();
}; };
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