Index: content/browser/renderer_host/begin_frame_observer_proxy.cc |
diff --git a/content/browser/renderer_host/begin_frame_observer_proxy.cc b/content/browser/renderer_host/begin_frame_observer_proxy.cc |
index 06baa18bd2a128390dd6436cf581077043c0f5fc..5789c02ebd8fc743c1008aba71370b4088bbcdc8 100644 |
--- a/content/browser/renderer_host/begin_frame_observer_proxy.cc |
+++ b/content/browser/renderer_host/begin_frame_observer_proxy.cc |
@@ -9,9 +9,10 @@ namespace content { |
BeginFrameObserverProxy::BeginFrameObserverProxy( |
BeginFrameObserverProxyClient* client) |
: needs_begin_frames_(false), |
+ needs_one_begin_frame_(false), |
+ observing_begin_frames_(false), |
client_(client), |
- compositor_(nullptr) { |
-} |
+ compositor_(nullptr) {} |
BeginFrameObserverProxy::~BeginFrameObserverProxy() { |
DCHECK(!compositor_); |
@@ -22,16 +23,15 @@ void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { |
return; |
needs_begin_frames_ = needs_begin_frames; |
+ UpdateBeginFrameObservation(); |
+} |
- // In some cases, BeginFrame message is requested before |client_|'s window is |
- // added in the root window hierarchy. |
- if (!compositor_) |
+void BeginFrameObserverProxy::SetNeedsOneBeginFrame() { |
+ if (needs_one_begin_frame_) |
return; |
- if (needs_begin_frames) |
- StartObservingBeginFrames(); |
- else |
- StopObservingBeginFrames(); |
+ needs_one_begin_frame_ = true; |
+ UpdateBeginFrameObservation(); |
} |
void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { |
@@ -40,23 +40,26 @@ void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { |
compositor_ = compositor; |
compositor_->AddObserver(this); |
- if (needs_begin_frames_) |
- StartObservingBeginFrames(); |
+ UpdateBeginFrameObservation(); |
} |
void BeginFrameObserverProxy::ResetCompositor() { |
if (!compositor_) |
return; |
compositor_->RemoveObserver(this); |
- |
- if (needs_begin_frames_) |
- StopObservingBeginFrames(); |
+ StopObservingBeginFrames(); |
compositor_ = nullptr; |
} |
void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { |
- if (last_sent_begin_frame_args_.frame_time != args.frame_time) |
+ DCHECK(needs_one_begin_frame_ || needs_begin_frames_); |
+ if (last_sent_begin_frame_args_.frame_time != args.frame_time) { |
+ // Don't immediately unsubscribe in case BeginFrame dispatch triggers |
+ // another request. |
+ needs_one_begin_frame_ = false; |
client_->SendBeginFrame(args); |
+ UpdateBeginFrameObservation(); |
+ } |
last_sent_begin_frame_args_ = args; |
} |
@@ -65,14 +68,34 @@ void BeginFrameObserverProxy::OnCompositingShuttingDown( |
ResetCompositor(); |
} |
+void BeginFrameObserverProxy::UpdateBeginFrameObservation() { |
+ // In some cases, BeginFrame message is requested before |client_|'s window is |
+ // added in the root window hierarchy. |
+ if (!compositor_) { |
+ DCHECK(!observing_begin_frames_); |
+ return; |
+ } |
+ |
+ if (needs_begin_frames_ || needs_one_begin_frame_) |
+ StartObservingBeginFrames(); |
+ else |
+ StopObservingBeginFrames(); |
+} |
+ |
void BeginFrameObserverProxy::StartObservingBeginFrames() { |
DCHECK(compositor_); |
- compositor_->AddBeginFrameObserver(this); |
+ if (!observing_begin_frames_) { |
+ observing_begin_frames_ = true; |
+ compositor_->AddBeginFrameObserver(this); |
+ } |
} |
void BeginFrameObserverProxy::StopObservingBeginFrames() { |
DCHECK(compositor_); |
- compositor_->RemoveBeginFrameObserver(this); |
+ if (observing_begin_frames_) { |
+ observing_begin_frames_ = false; |
+ compositor_->RemoveBeginFrameObserver(this); |
+ } |
} |
} // namespace content |