Chromium Code Reviews| 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 ResetCompositor(); | |
| 17 } | 18 } |
| 18 | 19 |
| 19 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { | 20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 20 if (needs_begin_frames_ == needs_begin_frames) | 21 if (needs_begin_frames_ == needs_begin_frames) |
| 21 return; | 22 return; |
| 22 | 23 |
| 23 needs_begin_frames_ = needs_begin_frames; | 24 needs_begin_frames_ = needs_begin_frames; |
| 24 | 25 |
| 25 // In some cases, BeginFrame message is requested before |client_|'s window is | 26 // In some cases, BeginFrame message is requested before |client_|'s window is |
| 26 // added in the root window hierarchy. | 27 // added in the root window hierarchy. |
| 27 if (!compositor_) | 28 if (!compositor_) |
| 28 return; | 29 return; |
| 29 | 30 |
| 30 if (needs_begin_frames) | 31 if (needs_begin_frames) |
| 31 StartObservingBeginFrames(); | 32 StartObservingBeginFrames(); |
| 32 else | 33 else |
| 33 StopObservingBeginFrames(); | 34 StopObservingBeginFrames(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { | 37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { |
| 37 DCHECK(!compositor_); | 38 DCHECK(!compositor_); |
| 38 DCHECK(compositor); | 39 |
| 40 if (!compositor) | |
|
simonhong
2015/03/27 17:37:54
I found that when RWHV is destroyed it calls SetCo
danakj
2015/03/27 17:41:47
I don't think we should have SetCompositor(nullptr
| |
| 41 return; | |
| 39 | 42 |
| 40 compositor_ = compositor; | 43 compositor_ = compositor; |
| 44 compositor_->AddObserver(this); | |
| 41 if (needs_begin_frames_) | 45 if (needs_begin_frames_) |
| 42 StartObservingBeginFrames(); | 46 StartObservingBeginFrames(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 void BeginFrameObserverProxy::ResetCompositor() { | 49 void BeginFrameObserverProxy::ResetCompositor() { |
| 46 if (!compositor_) | 50 if (!compositor_) |
| 47 return; | 51 return; |
| 52 compositor_->RemoveObserver(this); | |
| 48 | 53 |
| 49 if (needs_begin_frames_) | 54 if (needs_begin_frames_) |
| 50 StopObservingBeginFrames(); | 55 StopObservingBeginFrames(); |
| 51 compositor_ = nullptr; | 56 compositor_ = nullptr; |
| 52 } | 57 } |
| 53 | 58 |
| 54 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { | 59 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { |
| 55 if (last_sent_begin_frame_args_.frame_time != args.frame_time) | 60 if (last_sent_begin_frame_args_.frame_time != args.frame_time) |
| 56 client_->SendBeginFrame(args); | 61 client_->SendBeginFrame(args); |
| 57 last_sent_begin_frame_args_ = args; | 62 last_sent_begin_frame_args_ = args; |
| 58 } | 63 } |
| 59 | 64 |
| 65 void BeginFrameObserverProxy::OnCompositingShuttingDown( | |
| 66 ui::Compositor* compositor) { | |
| 67 ResetCompositor(); | |
| 68 } | |
| 69 | |
| 60 void BeginFrameObserverProxy::StartObservingBeginFrames() { | 70 void BeginFrameObserverProxy::StartObservingBeginFrames() { |
| 61 DCHECK(compositor_); | 71 DCHECK(compositor_); |
| 62 compositor_->AddBeginFrameObserver(this); | 72 compositor_->AddBeginFrameObserver(this); |
| 63 } | 73 } |
| 64 | 74 |
| 65 void BeginFrameObserverProxy::StopObservingBeginFrames() { | 75 void BeginFrameObserverProxy::StopObservingBeginFrames() { |
| 66 DCHECK(compositor_); | 76 DCHECK(compositor_); |
| 67 compositor_->RemoveBeginFrameObserver(this); | 77 compositor_->RemoveBeginFrameObserver(this); |
| 68 } | 78 } |
| 69 | 79 |
| 70 } // namespace content | 80 } // namespace content |
| OLD | NEW |