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() {
19 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames
) {
20 if (needs_begin_frames_
== needs_begin_frames
)
23 needs_begin_frames_
= needs_begin_frames
;
25 // In some cases, BeginFrame message is requested before |client_|'s window is
26 // added in the root window hierarchy.
30 if (needs_begin_frames
)
31 StartObservingBeginFrames();
33 StopObservingBeginFrames();
36 void BeginFrameObserverProxy::SetCompositor(ui::Compositor
* compositor
) {
40 compositor_
= compositor
;
41 if (needs_begin_frames_
)
42 StartObservingBeginFrames();
45 void BeginFrameObserverProxy::ResetCompositor() {
49 if (needs_begin_frames_
)
50 StopObservingBeginFrames();
51 compositor_
= nullptr;
54 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs
& args
) {
55 if (last_sent_begin_frame_args_
.frame_time
!= args
.frame_time
)
56 client_
->SendBeginFrame(args
);
57 last_sent_begin_frame_args_
= args
;
60 void BeginFrameObserverProxy::StartObservingBeginFrames() {
62 compositor_
->AddBeginFrameObserver(this);
65 void BeginFrameObserverProxy::StopObservingBeginFrames() {
67 compositor_
->RemoveBeginFrameObserver(this);
70 } // namespace content