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_); | |
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 DCHECK(compositor); |
39 | 40 |
40 compositor_ = compositor; | 41 compositor_ = compositor; |
42 compositor_->AddObserver(this); | |
41 if (needs_begin_frames_) | 43 if (needs_begin_frames_) |
42 StartObservingBeginFrames(); | 44 StartObservingBeginFrames(); |
43 } | 45 } |
44 | 46 |
45 void BeginFrameObserverProxy::ResetCompositor() { | 47 void BeginFrameObserverProxy::ResetCompositor() { |
46 if (!compositor_) | 48 if (!compositor_) |
47 return; | 49 return; |
50 compositor_->RemoveObserver(this); | |
danakj
2015/03/27 16:25:24
You need to remove observer on destruction yes? Sh
simonhong
2015/03/27 17:37:54
Right, we need to call ResetCompositor() in dtor.
| |
48 | 51 |
49 if (needs_begin_frames_) | 52 if (needs_begin_frames_) |
50 StopObservingBeginFrames(); | 53 StopObservingBeginFrames(); |
51 compositor_ = nullptr; | 54 compositor_ = nullptr; |
52 } | 55 } |
53 | 56 |
54 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { | 57 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { |
55 if (last_sent_begin_frame_args_.frame_time != args.frame_time) | 58 if (last_sent_begin_frame_args_.frame_time != args.frame_time) |
56 client_->SendBeginFrame(args); | 59 client_->SendBeginFrame(args); |
57 last_sent_begin_frame_args_ = args; | 60 last_sent_begin_frame_args_ = args; |
58 } | 61 } |
59 | 62 |
63 void BeginFrameObserverProxy::OnCompositingShuttingDown( | |
64 ui::Compositor* compositor) { | |
65 ResetCompositor(); | |
66 } | |
67 | |
60 void BeginFrameObserverProxy::StartObservingBeginFrames() { | 68 void BeginFrameObserverProxy::StartObservingBeginFrames() { |
61 DCHECK(compositor_); | 69 DCHECK(compositor_); |
62 compositor_->AddBeginFrameObserver(this); | 70 compositor_->AddBeginFrameObserver(this); |
63 } | 71 } |
64 | 72 |
65 void BeginFrameObserverProxy::StopObservingBeginFrames() { | 73 void BeginFrameObserverProxy::StopObservingBeginFrames() { |
66 DCHECK(compositor_); | 74 DCHECK(compositor_); |
67 compositor_->RemoveBeginFrameObserver(this); | 75 compositor_->RemoveBeginFrameObserver(this); |
68 } | 76 } |
69 | 77 |
70 } // namespace content | 78 } // namespace content |
OLD | NEW |