Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1139)

Unified Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 457913002: Android WebView: flush input events during onVSync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixups Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_android.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index dd65887f78db5d47ad01b2adc5b5da168d243a18..23241dede1f939a52be44abc08d7687821d8926c 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -183,7 +183,6 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
RenderWidgetHostImpl* widget_host,
ContentViewCoreImpl* content_view_core)
: host_(widget_host),
- needs_begin_frame_(false),
is_showing_(!widget_host->is_hidden()),
content_view_core_(NULL),
ime_adapter_android_(this),
@@ -196,14 +195,13 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
gesture_text_selector_(this),
touch_scrolling_(false),
potentially_active_fling_count_(0),
- flush_input_requested_(false),
accelerated_surface_route_id_(0),
using_synchronous_compositor_(SynchronousCompositorImpl::FromID(
widget_host->GetProcess()->GetID(),
widget_host->GetRoutingID()) != NULL),
+ vsync_subscribers_bitmask_(0),
frame_evictor_(new DelegatedFrameEvictor(this)),
- locks_on_frame_count_(0),
- observing_root_window_(false) {
+ locks_on_frame_count_(0) {
host_->SetView(this);
SetContentViewCore(content_view_core);
ImageTransportFactoryAndroid::AddObserver(this);
@@ -259,11 +257,8 @@ void RenderWidgetHostViewAndroid::WasShown() {
host_->WasShown(ui::LatencyInfo());
- if (content_view_core_ && !using_synchronous_compositor_) {
- content_view_core_->GetWindowAndroid()->AddObserver(this);
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
- observing_root_window_ = true;
- }
+ if (content_view_core_ && !using_synchronous_compositor_)
+ SubscribeToVSync(INPUT | BEGIN_FRAME);
}
void RenderWidgetHostViewAndroid::WasHidden() {
@@ -276,10 +271,8 @@ void RenderWidgetHostViewAndroid::WasHidden() {
// utilization.
host_->WasHidden();
- if (content_view_core_ && !using_synchronous_compositor_) {
- content_view_core_->GetWindowAndroid()->RemoveObserver(this);
- observing_root_window_ = false;
- }
+ if (content_view_core_ && !using_synchronous_compositor_)
+ UnsubscribeToVSync(INPUT | BEGIN_FRAME);
}
void RenderWidgetHostViewAndroid::WasResized() {
@@ -551,15 +544,15 @@ void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor(
}
void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame(bool enabled) {
- if (enabled == needs_begin_frame_)
+ if (enabled == IsSubscribedToType(BEGIN_FRAME) || !content_view_core_)
boliu 2014/08/20 20:30:00 No need to check for !content_view_core_ here.
return;
TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame",
"enabled", enabled);
- if (content_view_core_ && enabled)
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
-
- needs_begin_frame_ = enabled;
+ if (enabled)
+ SubscribeToVSync(BEGIN_FRAME);
+ else
+ UnsubscribeToVSync(BEGIN_FRAME);
}
void RenderWidgetHostViewAndroid::OnStartContentIntent(
@@ -811,6 +804,10 @@ void RenderWidgetHostViewAndroid::ShowDisambiguationPopup(
scoped_ptr<SyntheticGestureTarget>
RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() {
+ DCHECK(content_view_core_);
+ if (using_synchronous_compositor_)
+ SubscribeToVSync(INPUT);
+
return scoped_ptr<SyntheticGestureTarget>(new SyntheticGestureTargetAndroid(
host_, content_view_core_->CreateTouchEventSynthesizer()));
}
@@ -1300,11 +1297,11 @@ InputEventAckState RenderWidgetHostViewAndroid::FilterInputEvent(
}
void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() {
- if (flush_input_requested_ || !content_view_core_)
+ if ((IsSubscribedToType(INPUT)) || !content_view_core_)
return;
+
TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput");
boliu 2014/08/20 20:30:00 unrelated side note, this should be an instant eve
- flush_input_requested_ = true;
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
+ SubscribeToVSync(INPUT);
}
BrowserAccessibilityManager*
@@ -1345,9 +1342,8 @@ void RenderWidgetHostViewAndroid::SendTouchEvent(
// This is good enough as long as the first touch event has Begin semantics
// and the actual scroll happens on the next vsync.
// TODO: Is this actually still needed?
- if (content_view_core_) {
boliu 2014/08/20 20:30:00 You need to rebase, I added something here to not
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
- }
+ if (content_view_core_)
+ SubscribeToVSync(BEGIN_FRAME);
boliu 2014/08/20 20:30:00 This is not the same as simply calling RequestVSyn
}
void RenderWidgetHostViewAndroid::SendMouseEvent(
@@ -1440,10 +1436,8 @@ void RenderWidgetHostViewAndroid::DidStopFlinging() {
void RenderWidgetHostViewAndroid::SetContentViewCore(
ContentViewCoreImpl* content_view_core) {
RemoveLayers();
- if (observing_root_window_ && content_view_core_) {
- content_view_core_->GetWindowAndroid()->RemoveObserver(this);
- observing_root_window_ = false;
- }
+ if (vsync_subscribers_bitmask_ && content_view_core_)
+ UnsubscribeToVSync(INPUT | BEGIN_FRAME);
boliu 2014/08/20 20:30:00 I think we need an catch all enum value here.
bool resize = false;
if (content_view_core != content_view_core_) {
@@ -1469,12 +1463,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
if (!content_view_core_)
return;
- if (!using_synchronous_compositor_) {
- content_view_core_->GetWindowAndroid()->AddObserver(this);
- observing_root_window_ = true;
- if (needs_begin_frame_)
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
- }
+ if (!using_synchronous_compositor_)
+ SubscribeToVSync(INPUT | BEGIN_FRAME);
boliu 2014/08/20 20:30:00 Only subscribe to what was subscribed before.
+
if (resize)
WasResized();
@@ -1518,17 +1509,44 @@ void RenderWidgetHostViewAndroid::OnDetachCompositor() {
RunAckCallbacks();
}
+void RenderWidgetHostViewAndroid::SubscribeToVSync(uint32 type) {
+ if (!vsync_subscribers_bitmask_)
+ content_view_core_->GetWindowAndroid()->AddObserver(this);
+
+ vsync_subscribers_bitmask_ |= type;
+
+ content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
+
+ // Synchronous compositor does not request begin frames OnVSync.
+ DCHECK(!using_synchronous_compositor_ || !IsSubscribedToType(BEGIN_FRAME));
+}
+
+void RenderWidgetHostViewAndroid::UnsubscribeToVSync(uint32 type) {
+ vsync_subscribers_bitmask_ &= ~type;
+ if (!vsync_subscribers_bitmask_)
+ content_view_core_->GetWindowAndroid()->RemoveObserver(this);
+}
+
+bool RenderWidgetHostViewAndroid::IsSubscribedToType(uint32 type) {
boliu 2014/08/20 20:30:00 const
+ return !!(vsync_subscribers_bitmask_ & type);
+}
+
void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time,
base::TimeDelta vsync_period) {
TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync");
if (!host_)
return;
- if (flush_input_requested_) {
- flush_input_requested_ = false;
+ if (IsSubscribedToType(INPUT)) {
+ // Need to unsubscribe before host_->FlushInput(), because FlushInput()
+ // could cause RWHVA to subscribe to input again.
+ UnsubscribeToVSync(INPUT);
host_->FlushInput();
}
+ if (!IsSubscribedToType(BEGIN_FRAME))
+ return;
+
TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame");
base::TimeTicks display_time = frame_time + vsync_period;
@@ -1543,8 +1561,7 @@ void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time,
host_->GetRoutingID(),
cc::BeginFrameArgs::Create(frame_time, deadline, vsync_period)));
- if (needs_begin_frame_)
- content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
+ content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
boliu 2014/08/20 20:30:00 This is still called outside of SubscribeToVSync.
}
void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) {

Powered by Google App Engine
This is Rietveld 408576698