Index: content/browser/compositor/onscreen_display_client.cc |
diff --git a/content/browser/compositor/onscreen_display_client.cc b/content/browser/compositor/onscreen_display_client.cc |
index da60316490f034c0e8f530e1a0b713dcca816173..2ca7a75bd67dd90545beb10b516f122f47b069a6 100644 |
--- a/content/browser/compositor/onscreen_display_client.cc |
+++ b/content/browser/compositor/onscreen_display_client.cc |
@@ -21,6 +21,8 @@ OnscreenDisplayClient::OnscreenDisplayClient( |
new cc::Display(this, manager, HostSharedBitmapManager::current())), |
task_runner_(task_runner), |
scheduled_draw_(false), |
+ deferred_draw_(false), |
+ pending_frames_(0), |
weak_ptr_factory_(this) { |
} |
@@ -33,9 +35,19 @@ scoped_ptr<cc::OutputSurface> OnscreenDisplayClient::CreateOutputSurface() { |
} |
void OnscreenDisplayClient::DisplayDamaged() { |
- if (scheduled_draw_) |
+ if (scheduled_draw_ || deferred_draw_) |
return; |
TRACE_EVENT0("content", "OnscreenDisplayClient::DisplayDamaged"); |
+ if (pending_frames_ >= display_->GetMaxFramesPending()) { |
+ deferred_draw_ = true; |
+ } else { |
+ ScheduleDraw(); |
+ } |
+} |
+ |
+void OnscreenDisplayClient::ScheduleDraw() { |
+ DCHECK(!deferred_draw_); |
+ DCHECK(!scheduled_draw_); |
scheduled_draw_ = true; |
task_runner_->PostTask( |
FROM_HERE, |
@@ -48,4 +60,16 @@ void OnscreenDisplayClient::Draw() { |
display_->Draw(); |
} |
+void OnscreenDisplayClient::DidSwapBuffers() { |
+ pending_frames_++; |
+} |
+ |
+void OnscreenDisplayClient::DidSwapBuffersComplete() { |
+ pending_frames_--; |
+ if ((pending_frames_ < display_->GetMaxFramesPending()) && deferred_draw_) { |
+ deferred_draw_ = false; |
+ ScheduleDraw(); |
+ } |
+} |
+ |
} // namespace content |