| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 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 "cc/surfaces/primary_begin_frame_source.h" | |
| 6 | |
| 7 namespace cc { | |
| 8 | |
| 9 PrimaryBeginFrameSource::PrimaryBeginFrameSource() | |
| 10 : begin_frame_source_(this) {} | |
| 11 | |
| 12 PrimaryBeginFrameSource::~PrimaryBeginFrameSource() = default; | |
| 13 | |
| 14 void PrimaryBeginFrameSource::OnBeginFrameSourceAdded( | |
| 15 BeginFrameSource* begin_frame_source) { | |
| 16 sources_.insert(begin_frame_source); | |
| 17 | |
| 18 if (current_begin_frame_source_) | |
| 19 return; | |
| 20 | |
| 21 current_begin_frame_source_ = begin_frame_source; | |
| 22 if (needs_begin_frames_ && current_begin_frame_source_) | |
| 23 current_begin_frame_source_->AddObserver(this); | |
| 24 } | |
| 25 | |
| 26 void PrimaryBeginFrameSource::OnBeginFrameSourceRemoved( | |
| 27 BeginFrameSource* begin_frame_source) { | |
| 28 sources_.erase(begin_frame_source); | |
| 29 if (current_begin_frame_source_ != begin_frame_source) | |
| 30 return; | |
| 31 | |
| 32 if (needs_begin_frames_) | |
| 33 current_begin_frame_source_->RemoveObserver(this); | |
| 34 | |
| 35 if (!sources_.empty()) | |
| 36 current_begin_frame_source_ = *sources_.begin(); | |
| 37 else | |
| 38 current_begin_frame_source_ = nullptr; | |
| 39 | |
| 40 if (needs_begin_frames_ && current_begin_frame_source_) | |
| 41 current_begin_frame_source_->AddObserver(this); | |
| 42 } | |
| 43 | |
| 44 void PrimaryBeginFrameSource::OnBeginFrame(const BeginFrameArgs& args) { | |
| 45 begin_frame_source_.OnBeginFrame(args); | |
| 46 last_begin_frame_args_ = args; | |
| 47 } | |
| 48 | |
| 49 const BeginFrameArgs& PrimaryBeginFrameSource::LastUsedBeginFrameArgs() const { | |
| 50 return last_begin_frame_args_; | |
| 51 } | |
| 52 | |
| 53 void PrimaryBeginFrameSource::OnBeginFrameSourcePausedChanged(bool paused) {} | |
| 54 | |
| 55 void PrimaryBeginFrameSource::DidFinishFrame(BeginFrameObserver* obs, | |
| 56 const BeginFrameAck& ack) { | |
| 57 begin_frame_source_.DidFinishFrame(obs, ack); | |
| 58 } | |
| 59 | |
| 60 void PrimaryBeginFrameSource::AddObserver(BeginFrameObserver* obs) { | |
| 61 begin_frame_source_.AddObserver(obs); | |
| 62 } | |
| 63 | |
| 64 void PrimaryBeginFrameSource::RemoveObserver(BeginFrameObserver* obs) { | |
| 65 begin_frame_source_.RemoveObserver(obs); | |
| 66 } | |
| 67 | |
| 68 bool PrimaryBeginFrameSource::IsThrottled() const { | |
| 69 return begin_frame_source_.IsThrottled(); | |
| 70 } | |
| 71 | |
| 72 void PrimaryBeginFrameSource::OnNeedsBeginFrames(bool needs_begin_frames) { | |
| 73 if (needs_begin_frames_ == needs_begin_frames) | |
| 74 return; | |
| 75 | |
| 76 needs_begin_frames_ = needs_begin_frames; | |
| 77 | |
| 78 if (!current_begin_frame_source_) | |
| 79 return; | |
| 80 | |
| 81 if (needs_begin_frames_) | |
| 82 current_begin_frame_source_->AddObserver(this); | |
| 83 else | |
| 84 current_begin_frame_source_->RemoveObserver(this); | |
| 85 } | |
| 86 | |
| 87 } // namespace cc | |
| OLD | NEW |