Index: blimp/client/core/compositor/blimp_compositor.cc |
diff --git a/blimp/client/core/compositor/blimp_compositor.cc b/blimp/client/core/compositor/blimp_compositor.cc |
index 91edfe58bc727ee1eed8a4015ba9828108b18f93..02e5c800c566ede27603c5d498a676b517d343d4 100644 |
--- a/blimp/client/core/compositor/blimp_compositor.cc |
+++ b/blimp/client/core/compositor/blimp_compositor.cc |
@@ -68,6 +68,7 @@ BlimpCompositor::BlimpCompositor( |
output_surface_request_pending_(false), |
layer_(cc::Layer::Create()), |
remote_proto_channel_receiver_(nullptr), |
+ outstanding_commits_(0U), |
weak_ptr_factory_(this) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -85,12 +86,17 @@ BlimpCompositor::~BlimpCompositor() { |
GetEmbedderDeps()->GetSurfaceManager()->InvalidateSurfaceClientId( |
surface_id_allocator_->client_id()); |
+ |
+ CheckPendingCommitCounts(true /* flush */); |
} |
void BlimpCompositor::SetVisible(bool visible) { |
host_should_be_visible_ = visible; |
if (host_) |
host_->SetVisible(host_should_be_visible_); |
+ |
+ if (!visible) |
+ CheckPendingCommitCounts(true /* flush */); |
} |
bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
@@ -99,6 +105,16 @@ bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
return false; |
} |
+void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { |
+ if (outstanding_commits_ == 0 || !host_ || !host_should_be_visible_) { |
+ callback.Run(); |
+ return; |
+ } |
+ |
+ pending_commit_trackers_.push_back( |
+ std::make_pair(outstanding_commits_, callback)); |
+} |
+ |
void BlimpCompositor::RequestNewOutputSurface() { |
DCHECK(!surface_factory_); |
DCHECK(!output_surface_request_pending_); |
@@ -115,6 +131,11 @@ void BlimpCompositor::DidInitializeOutputSurface() { |
void BlimpCompositor::DidCommitAndDrawFrame() { |
BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
+ |
+ DCHECK_GT(outstanding_commits_, 0U); |
+ outstanding_commits_--; |
+ |
+ CheckPendingCommitCounts(false /* flush */); |
} |
void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
@@ -132,6 +153,12 @@ void BlimpCompositor::OnCompositorMessageReceived( |
const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl(); |
DCHECK(to_impl_proto.has_message_type()); |
+ |
+ if (to_impl_proto.message_type() == |
+ cc::proto::CompositorMessageToImpl::START_COMMIT) { |
+ outstanding_commits_++; |
+ } |
+ |
switch (to_impl_proto.message_type()) { |
case cc::proto::CompositorMessageToImpl::UNKNOWN: |
NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; |
@@ -329,5 +356,17 @@ void BlimpCompositor::DestroyLayerTreeHost() { |
DCHECK(!remote_proto_channel_receiver_); |
} |
+void BlimpCompositor::CheckPendingCommitCounts(bool flush) { |
+ for (auto it = pending_commit_trackers_.begin(); |
+ it != pending_commit_trackers_.end();) { |
+ if (flush || --it->first == 0) { |
+ it->second.Run(); |
+ it = pending_commit_trackers_.erase(it); |
+ } else { |
+ ++it; |
+ } |
+ } |
+} |
+ |
} // namespace client |
} // namespace blimp |