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
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/begin_frame_observer_proxy.h"
9 BeginFrameObserverProxy::BeginFrameObserverProxy(
10 BeginFrameObserverProxyClient
* client
)
11 : needs_begin_frames_(false),
13 compositor_(nullptr) {
16 BeginFrameObserverProxy::~BeginFrameObserverProxy() {
20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames
) {
21 if (needs_begin_frames_
== needs_begin_frames
)
24 needs_begin_frames_
= needs_begin_frames
;
26 // In some cases, BeginFrame message is requested before |client_|'s window is
27 // added in the root window hierarchy.
31 if (needs_begin_frames
)
32 StartObservingBeginFrames();
34 StopObservingBeginFrames();
37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor
* compositor
) {
41 compositor_
= compositor
;
42 compositor_
->AddObserver(this);
43 if (needs_begin_frames_
)
44 StartObservingBeginFrames();
47 void BeginFrameObserverProxy::ResetCompositor() {
50 compositor_
->RemoveObserver(this);
52 if (needs_begin_frames_
)
53 StopObservingBeginFrames();
54 compositor_
= nullptr;
57 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs
& args
) {
58 if (last_sent_begin_frame_args_
.frame_time
!= args
.frame_time
)
59 client_
->SendBeginFrame(args
);
60 last_sent_begin_frame_args_
= args
;
63 void BeginFrameObserverProxy::OnCompositingShuttingDown(
64 ui::Compositor
* compositor
) {
68 void BeginFrameObserverProxy::StartObservingBeginFrames() {
70 compositor_
->AddBeginFrameObserver(this);
73 void BeginFrameObserverProxy::StopObservingBeginFrames() {
75 compositor_
->RemoveBeginFrameObserver(this);
78 } // namespace content