OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/browser/renderer_host/begin_frame_observer_proxy.h" |
| 6 |
| 7 namespace content { |
| 8 |
| 9 BeginFrameObserverProxy::BeginFrameObserverProxy( |
| 10 BeginFrameObserverProxyClient* client) |
| 11 : needs_begin_frames_(false), |
| 12 client_(client), |
| 13 compositor_(nullptr) { |
| 14 } |
| 15 |
| 16 BeginFrameObserverProxy::~BeginFrameObserverProxy() { |
| 17 } |
| 18 |
| 19 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 20 if (needs_begin_frames_ == needs_begin_frames) |
| 21 return; |
| 22 |
| 23 needs_begin_frames_ = needs_begin_frames; |
| 24 |
| 25 // In some cases, BeginFrame message is requested before |client_|'s window is |
| 26 // added in the root window hierarchy. |
| 27 if (!compositor_) |
| 28 return; |
| 29 |
| 30 if (needs_begin_frames) |
| 31 StartObservingBeginFrames(); |
| 32 else |
| 33 StopObservingBeginFrames(); |
| 34 } |
| 35 |
| 36 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { |
| 37 DCHECK(!compositor_); |
| 38 DCHECK(compositor); |
| 39 |
| 40 compositor_ = compositor; |
| 41 if (needs_begin_frames_) |
| 42 StartObservingBeginFrames(); |
| 43 } |
| 44 |
| 45 void BeginFrameObserverProxy::ResetCompositor() { |
| 46 if (!compositor_) |
| 47 return; |
| 48 |
| 49 if (needs_begin_frames_) |
| 50 StopObservingBeginFrames(); |
| 51 compositor_ = nullptr; |
| 52 } |
| 53 |
| 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; |
| 58 } |
| 59 |
| 60 void BeginFrameObserverProxy::StartObservingBeginFrames() { |
| 61 DCHECK(compositor_); |
| 62 compositor_->AddBeginFrameObserver(this); |
| 63 } |
| 64 |
| 65 void BeginFrameObserverProxy::StopObservingBeginFrames() { |
| 66 DCHECK(compositor_); |
| 67 compositor_->RemoveBeginFrameObserver(this); |
| 68 } |
| 69 |
| 70 } // namespace content |
OLD | NEW |