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

Unified Diff: content/browser/android/in_process/synchronous_compositor_impl.cc

Issue 817603002: cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/android/in_process/synchronous_compositor_impl.cc
diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc
index e76b36b85be6b0e5698c9c5d4e4b12d82f50ad7a..dcbccac9389c5061ea35490f97bf68f0aa09cc85 100644
--- a/content/browser/android/in_process/synchronous_compositor_impl.cc
+++ b/content/browser/android/in_process/synchronous_compositor_impl.cc
@@ -119,8 +119,9 @@ void SynchronousCompositorImpl::DidInitializeRendererObjects(
output_surface_ = output_surface;
begin_frame_source_ = begin_frame_source;
- begin_frame_source_->SetCompositor(this);
- output_surface_->SetBeginFrameSource(begin_frame_source_);
+ output_surface_->SetInvalidateCallback(
+ base::Bind(&SynchronousCompositorImpl::DidInvalidateOutputSurface,
+ weak_ptr_factory_.GetWeakPtr()));
output_surface_->SetTreeActivationCallback(
base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree,
weak_ptr_factory_.GetWeakPtr()));
@@ -133,7 +134,6 @@ void SynchronousCompositorImpl::DidDestroyRendererObjects() {
DCHECK(begin_frame_source_);
begin_frame_source_->SetCompositor(nullptr);
- output_surface_->SetBeginFrameSource(nullptr);
if (compositor_client_)
compositor_client_->DidDestroyCompositor(this);
compositor_client_ = nullptr;
@@ -183,6 +183,12 @@ scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw(
base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
true);
+
+ // This is to handle draws that are not initiated by the platform.
+ // Platform draws happen synchronously after OnVSync is called.
+ if (!begin_frame_source_->InsideBeginFrame())
+ begin_frame_source_->SendBeginFrameNow();
+
scoped_ptr<cc::CompositorFrame> frame =
output_surface_->DemandDrawHw(surface_size,
transform,
@@ -190,12 +196,12 @@ scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw(
clip,
viewport_rect_for_tile_priority,
transform_for_tile_priority);
+
+ DCHECK(!begin_frame_source_->InsideBeginFrame());
+
if (frame.get())
UpdateFrameMetaData(frame->metadata);
- compositor_client_->SetContinuousInvalidate(
- begin_frame_source_->NeedsBeginFrames());
-
return frame.Pass();
}
@@ -214,14 +220,20 @@ bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
true);
+
+ // This is to handle draws that are not initiated by the platform.
+ // Platform draws happen synchronously after OnVSync is called.
+ if (!begin_frame_source_->InsideBeginFrame())
+ begin_frame_source_->SendBeginFrameNow();
+
scoped_ptr<cc::CompositorFrame> frame =
output_surface_->DemandDrawSw(canvas);
+
+ DCHECK(!begin_frame_source_->InsideBeginFrame());
+
if (frame.get())
UpdateFrameMetaData(frame->metadata);
- compositor_client_->SetContinuousInvalidate(
- begin_frame_source_->NeedsBeginFrames());
-
return !!frame.get();
}
@@ -241,11 +253,21 @@ void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
output_surface_->SetMemoryPolicy(bytes_limit);
}
+void SynchronousCompositorImpl::NeedsBeginFramesChanged() const {
+ compositor_client_->SetNeedsVSyncs(begin_frame_source_->NeedsBeginFrames());
+}
+
void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() {
if (input_handler_)
input_handler_->OnRootLayerDelegatedScrollOffsetChanged();
}
+void SynchronousCompositorImpl::OnVSync(base::TimeTicks frame_time,
+ base::TimeDelta vsync_period) {
+ DCHECK(CalledOnValidThread());
+ begin_frame_source_->SendBeginFrame(frame_time, vsync_period);
+}
+
void SynchronousCompositorImpl::SetInputHandler(
cc::InputHandler* input_handler) {
DCHECK(CalledOnValidThread());
@@ -275,18 +297,6 @@ void SynchronousCompositorImpl::DidStopFlinging() {
rwhv->DidStopFlinging();
}
-void SynchronousCompositorImpl::NeedsBeginFramesChanged() const {
- DCHECK(CalledOnValidThread());
- DCHECK(begin_frame_source_);
- if (invoking_composite_)
- return;
-
- if (compositor_client_) {
- compositor_client_->SetContinuousInvalidate(
- begin_frame_source_->NeedsBeginFrames());
- }
-}
-
InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
const blink::WebInputEvent& input_event) {
DCHECK(CalledOnValidThread());
@@ -305,6 +315,12 @@ void SynchronousCompositorImpl::DeliverMessages() {
}
}
+void SynchronousCompositorImpl::DidInvalidateOutputSurface() {
+ // Ignore invalidations while inside a draw.
+ if (compositor_client_ && !invoking_composite_)
+ compositor_client_->PostInvalidate();
+}
+
void SynchronousCompositorImpl::DidActivatePendingTree() {
if (compositor_client_)
compositor_client_->DidUpdateContent();

Powered by Google App Engine
This is Rietveld 408576698