| 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 DCHECK(!compositor_); | |
| 18 } | |
| 19 | |
| 20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { | |
| 21 if (needs_begin_frames_ == needs_begin_frames) | |
| 22 return; | |
| 23 | |
| 24 needs_begin_frames_ = needs_begin_frames; | |
| 25 | |
| 26 // In some cases, BeginFrame message is requested before |client_|'s window is | |
| 27 // added in the root window hierarchy. | |
| 28 if (!compositor_) | |
| 29 return; | |
| 30 | |
| 31 if (needs_begin_frames) | |
| 32 StartObservingBeginFrames(); | |
| 33 else | |
| 34 StopObservingBeginFrames(); | |
| 35 } | |
| 36 | |
| 37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { | |
| 38 DCHECK(!compositor_); | |
| 39 DCHECK(compositor); | |
| 40 | |
| 41 compositor_ = compositor; | |
| 42 compositor_->AddObserver(this); | |
| 43 if (needs_begin_frames_) | |
| 44 StartObservingBeginFrames(); | |
| 45 } | |
| 46 | |
| 47 void BeginFrameObserverProxy::ResetCompositor() { | |
| 48 if (!compositor_) | |
| 49 return; | |
| 50 compositor_->RemoveObserver(this); | |
| 51 | |
| 52 if (needs_begin_frames_) | |
| 53 StopObservingBeginFrames(); | |
| 54 compositor_ = nullptr; | |
| 55 } | |
| 56 | |
| 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; | |
| 61 } | |
| 62 | |
| 63 void BeginFrameObserverProxy::OnCompositingShuttingDown( | |
| 64 ui::Compositor* compositor) { | |
| 65 ResetCompositor(); | |
| 66 } | |
| 67 | |
| 68 void BeginFrameObserverProxy::StartObservingBeginFrames() { | |
| 69 DCHECK(compositor_); | |
| 70 compositor_->AddBeginFrameObserver(this); | |
| 71 } | |
| 72 | |
| 73 void BeginFrameObserverProxy::StopObservingBeginFrames() { | |
| 74 DCHECK(compositor_); | |
| 75 compositor_->RemoveBeginFrameObserver(this); | |
| 76 } | |
| 77 | |
| 78 } // namespace content | |
| OLD | NEW |