| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/begin_frame_observer_proxy.h" | 5 #include "content/browser/renderer_host/begin_frame_observer_proxy.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace content { |
| 8 | 8 |
| 9 BeginFrameObserverProxy::BeginFrameObserverProxy( | 9 BeginFrameObserverProxy::BeginFrameObserverProxy( |
| 10 BeginFrameObserverProxyClient* client) | 10 BeginFrameObserverProxyClient* client) |
| 11 : needs_begin_frames_(false), | 11 : needs_begin_frames_(false), |
| 12 client_(client), | 12 client_(client), |
| 13 compositor_(nullptr) { | 13 compositor_(nullptr) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 BeginFrameObserverProxy::~BeginFrameObserverProxy() { | 16 BeginFrameObserverProxy::~BeginFrameObserverProxy() { |
| 17 DCHECK(!compositor_); | |
| 18 } | 17 } |
| 19 | 18 |
| 20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { | 19 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 21 if (needs_begin_frames_ == needs_begin_frames) | 20 if (needs_begin_frames_ == needs_begin_frames) |
| 22 return; | 21 return; |
| 23 | 22 |
| 24 needs_begin_frames_ = needs_begin_frames; | 23 needs_begin_frames_ = needs_begin_frames; |
| 25 | 24 |
| 26 // In some cases, BeginFrame message is requested before |client_|'s window is | 25 // In some cases, BeginFrame message is requested before |client_|'s window is |
| 27 // added in the root window hierarchy. | 26 // added in the root window hierarchy. |
| 28 if (!compositor_) | 27 if (!compositor_) |
| 29 return; | 28 return; |
| 30 | 29 |
| 31 if (needs_begin_frames) | 30 if (needs_begin_frames) |
| 32 StartObservingBeginFrames(); | 31 StartObservingBeginFrames(); |
| 33 else | 32 else |
| 34 StopObservingBeginFrames(); | 33 StopObservingBeginFrames(); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { | 36 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { |
| 38 DCHECK(!compositor_); | 37 DCHECK(!compositor_); |
| 39 DCHECK(compositor); | 38 DCHECK(compositor); |
| 40 | 39 |
| 41 compositor_ = compositor; | 40 compositor_ = compositor; |
| 42 compositor_->AddObserver(this); | |
| 43 if (needs_begin_frames_) | 41 if (needs_begin_frames_) |
| 44 StartObservingBeginFrames(); | 42 StartObservingBeginFrames(); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void BeginFrameObserverProxy::ResetCompositor() { | 45 void BeginFrameObserverProxy::ResetCompositor() { |
| 48 if (!compositor_) | 46 if (!compositor_) |
| 49 return; | 47 return; |
| 50 compositor_->RemoveObserver(this); | |
| 51 | 48 |
| 52 if (needs_begin_frames_) | 49 if (needs_begin_frames_) |
| 53 StopObservingBeginFrames(); | 50 StopObservingBeginFrames(); |
| 54 compositor_ = nullptr; | 51 compositor_ = nullptr; |
| 55 } | 52 } |
| 56 | 53 |
| 57 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { | 54 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { |
| 58 if (last_sent_begin_frame_args_.frame_time != args.frame_time) | 55 if (last_sent_begin_frame_args_.frame_time != args.frame_time) |
| 59 client_->SendBeginFrame(args); | 56 client_->SendBeginFrame(args); |
| 60 last_sent_begin_frame_args_ = args; | 57 last_sent_begin_frame_args_ = args; |
| 61 } | 58 } |
| 62 | 59 |
| 63 void BeginFrameObserverProxy::OnCompositingShuttingDown( | |
| 64 ui::Compositor* compositor) { | |
| 65 ResetCompositor(); | |
| 66 } | |
| 67 | |
| 68 void BeginFrameObserverProxy::StartObservingBeginFrames() { | 60 void BeginFrameObserverProxy::StartObservingBeginFrames() { |
| 69 DCHECK(compositor_); | 61 DCHECK(compositor_); |
| 70 compositor_->AddBeginFrameObserver(this); | 62 compositor_->AddBeginFrameObserver(this); |
| 71 } | 63 } |
| 72 | 64 |
| 73 void BeginFrameObserverProxy::StopObservingBeginFrames() { | 65 void BeginFrameObserverProxy::StopObservingBeginFrames() { |
| 74 DCHECK(compositor_); | 66 DCHECK(compositor_); |
| 75 compositor_->RemoveBeginFrameObserver(this); | 67 compositor_->RemoveBeginFrameObserver(this); |
| 76 } | 68 } |
| 77 | 69 |
| 78 } // namespace content | 70 } // namespace content |
| OLD | NEW |