OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #ifndef CC_SCHEDULER_BEGIN_FRAME_MANAGER_H_ |
| 6 #define CC_SCHEDULER_BEGIN_FRAME_MANAGER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/observer_list.h" |
| 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "base/time/time.h" |
| 12 #include "cc/base/cc_export.h" |
| 13 #include "cc/output/begin_frame_args.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 struct BeginFrameArgs; |
| 18 |
| 19 // This class delivers a BeginFrame request from the Compositor to its |
| 20 // observers. It also handles next BeginFrame scheduling via its delegate. |
| 21 // Browser compositor will own this. |
| 22 // This class will be run only on main thread. |
| 23 class CC_EXPORT BeginFrameManager : public base::NonThreadSafe { |
| 24 public: |
| 25 // Subclass should deliver BeginFrame to its client. |
| 26 class Observer { |
| 27 public: |
| 28 virtual void OnSendBeginFrame(const BeginFrameArgs& args) = 0; |
| 29 }; |
| 30 |
| 31 // Subclass(Scheduler) should implement how to schedule next BeginFrame. |
| 32 class Delegate { |
| 33 public: |
| 34 virtual void SetChildrenNeedBeginFrames(bool need_begin_frame) = 0; |
| 35 |
| 36 // The "authoritative" vsync interval, if provided, will override interval |
| 37 // reported from 3D context. This is typically the value reported by a more |
| 38 // reliable source, e.g, the platform display configuration. |
| 39 // In the particular case of ChromeOS -- this is the value queried through |
| 40 // XRandR, which is more reliable than the value queried through the 3D |
| 41 // context. |
| 42 virtual void SetAuthoritativeVSyncInterval(base::TimeDelta interval) = 0; |
| 43 |
| 44 // When we want to use platform provided refresh rate instead of internal |
| 45 // timer, compositor will deliver it by calling this function. |
| 46 virtual void StartBeginFrame(const BeginFrameArgs& args) = 0; |
| 47 }; |
| 48 |
| 49 BeginFrameManager(); |
| 50 ~BeginFrameManager(); |
| 51 |
| 52 void set_delegate(Delegate* delegate) { |
| 53 DCHECK(!delegate_) << |
| 54 "BeginFrameManager::Delegate is allowed to set only once"; |
| 55 delegate_ = delegate; |
| 56 } |
| 57 |
| 58 // Send BeginFrame to observers. |
| 59 void SendBeginFrameToChildren(const BeginFrameArgs& args); |
| 60 |
| 61 // See the comment of Delegate::SetAuthritativeVSyncInterval. |
| 62 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) const; |
| 63 |
| 64 void AddObserver( |
| 65 Observer* observer, |
| 66 const BeginFrameArgs& last_begin_frame_args_sent_to_observer); |
| 67 void RemoveObserver(Observer* observer); |
| 68 |
| 69 private: |
| 70 // Not owned by this class. |
| 71 Delegate* delegate_; |
| 72 |
| 73 // Number of BeginFrameManager's observer. |
| 74 int num_of_observers_; |
| 75 |
| 76 // Used to send to any new observers immediately. |
| 77 BeginFrameArgs last_begin_frame_args_; |
| 78 |
| 79 ObserverList<Observer> observer_list_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(BeginFrameManager); |
| 82 }; |
| 83 |
| 84 } // namespace cc |
| 85 |
| 86 #endif // CC_SCHEDULER_BEGIN_FRAME_MANAGER_H_ |
OLD | NEW |