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