| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 5 #ifndef CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
| 6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // - If the |args| passed to OnBeginFrame is (or *will be*) used, then | 40 // - If the |args| passed to OnBeginFrame is (or *will be*) used, then |
| 41 // LastUsedBeginFrameArgs return value should become the |args| given to | 41 // LastUsedBeginFrameArgs return value should become the |args| given to |
| 42 // OnBeginFrame. | 42 // OnBeginFrame. |
| 43 // | 43 // |
| 44 // - If the |args| passed to OnBeginFrame is dropped, then | 44 // - If the |args| passed to OnBeginFrame is dropped, then |
| 45 // LastUsedBeginFrameArgs return value should *not* change. | 45 // LastUsedBeginFrameArgs return value should *not* change. |
| 46 // | 46 // |
| 47 // These requirements are designed to allow chaining and nesting of | 47 // These requirements are designed to allow chaining and nesting of |
| 48 // BeginFrameObservers which filter the incoming BeginFrame messages while | 48 // BeginFrameObservers which filter the incoming BeginFrame messages while |
| 49 // preventing "double dropping" and other bad side effects. | 49 // preventing "double dropping" and other bad side effects. |
| 50 virtual const BeginFrameArgs LastUsedBeginFrameArgs() const = 0; | 50 virtual const BeginFrameArgs LastUsedBeginFrameArgs() = 0; |
| 51 | 51 |
| 52 // Tracing support | 52 // Tracing support |
| 53 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; | 53 virtual void AsValueInto(base::trace_event::TracedValue* dict) = 0; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Simple mix in which implements a BeginFrameObserver which checks the | 56 // Simple mix in which implements a BeginFrameObserver which checks the |
| 57 // incoming values meet the BeginFrameObserver requirements and implements the | 57 // incoming values meet the BeginFrameObserver requirements and implements the |
| 58 // required LastUsedBeginFrameArgs behaviour. | 58 // required LastUsedBeginFrameArgs behaviour. |
| 59 // | 59 // |
| 60 // Users of this mix in should; | 60 // Users of this mix in should; |
| 61 // - Implement the OnBeginFrameMixInDelegate function. | 61 // - Implement the OnBeginFrameMixInDelegate function. |
| 62 // - Recommended (but not required) to call | 62 // - Recommended (but not required) to call |
| 63 // BeginFrameObserverMixIn::OnValueInto in their overridden OnValueInto | 63 // BeginFrameObserverMixIn::OnValueInto in their overridden OnValueInto |
| 64 // function. | 64 // function. |
| 65 class CC_EXPORT BeginFrameObserverMixIn : public BeginFrameObserver { | 65 class CC_EXPORT BeginFrameObserverMixIn : public BeginFrameObserver { |
| 66 public: | 66 public: |
| 67 BeginFrameObserverMixIn(); | 67 BeginFrameObserverMixIn(); |
| 68 | 68 |
| 69 // BeginFrameObserver | 69 // BeginFrameObserver |
| 70 | 70 |
| 71 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls | 71 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls |
| 72 // OnBeginFrameMixInDelegate and updates the last_begin_frame_args_ value on | 72 // OnBeginFrameMixInDelegate and updates the last_begin_frame_args_ value on |
| 73 // true. | 73 // true. |
| 74 void OnBeginFrame(const BeginFrameArgs& args) override; | 74 void OnBeginFrame(const BeginFrameArgs& args) override; |
| 75 const BeginFrameArgs LastUsedBeginFrameArgs() const override; | 75 const BeginFrameArgs LastUsedBeginFrameArgs() override; |
| 76 | 76 |
| 77 // Outputs last_begin_frame_args_ | 77 // Outputs last_begin_frame_args_ |
| 78 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 78 void AsValueInto(base::trace_event::TracedValue* dict) override; |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 // Subclasses should override this method! | 81 // Subclasses should override this method! |
| 82 // Return true if the given argument is (or will be) used. | 82 // Return true if the given argument is (or will be) used. |
| 83 virtual bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) = 0; | 83 virtual bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) = 0; |
| 84 | 84 |
| 85 BeginFrameArgs last_begin_frame_args_; | 85 BeginFrameArgs last_begin_frame_args_; |
| 86 int64_t dropped_begin_frame_args_; | 86 int64_t dropped_begin_frame_args_; |
| 87 }; | 87 }; |
| 88 | 88 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 115 // in the future this may be extended to allow multiple observers. | 115 // in the future this may be extended to allow multiple observers. |
| 116 // If making this change, please use base::ObserverList to do so. | 116 // If making this change, please use base::ObserverList to do so. |
| 117 virtual void AddObserver(BeginFrameObserver* obs) = 0; | 117 virtual void AddObserver(BeginFrameObserver* obs) = 0; |
| 118 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; | 118 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; |
| 119 | 119 |
| 120 // Tells the Source that client is ready to handle BeginFrames messages. | 120 // Tells the Source that client is ready to handle BeginFrames messages. |
| 121 virtual void SetClientReady() = 0; | 121 virtual void SetClientReady() = 0; |
| 122 | 122 |
| 123 // Tracing support - Recommend (but not required) to call this implementation | 123 // Tracing support - Recommend (but not required) to call this implementation |
| 124 // in any override. | 124 // in any override. |
| 125 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; | 125 virtual void AsValueInto(base::trace_event::TracedValue* dict) = 0; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Simple mix in which implements a BeginFrameSource. | 128 // Simple mix in which implements a BeginFrameSource. |
| 129 // Implementation classes should: | 129 // Implementation classes should: |
| 130 // - Implement the pure virtual (Set)NeedsBeginFrames methods from | 130 // - Implement the pure virtual (Set)NeedsBeginFrames methods from |
| 131 // BeginFrameSource. | 131 // BeginFrameSource. |
| 132 // - Use the CallOnBeginFrame method to call to the observer(s). | 132 // - Use the CallOnBeginFrame method to call to the observer(s). |
| 133 // - Recommended (but not required) to call BeginFrameSourceMixIn::AsValueInto | 133 // - Recommended (but not required) to call BeginFrameSourceMixIn::AsValueInto |
| 134 // in their own AsValueInto implementation. | 134 // in their own AsValueInto implementation. |
| 135 class CC_EXPORT BeginFrameSourceMixIn : public BeginFrameSource { | 135 class CC_EXPORT BeginFrameSourceMixIn : public BeginFrameSource { |
| 136 public: | 136 public: |
| 137 ~BeginFrameSourceMixIn() override {} | 137 ~BeginFrameSourceMixIn() override; |
| 138 | 138 |
| 139 // BeginFrameSource | 139 // BeginFrameSource |
| 140 bool NeedsBeginFrames() const final; | 140 bool NeedsBeginFrames() const final; |
| 141 void SetNeedsBeginFrames(bool needs_begin_frames) final; | 141 void SetNeedsBeginFrames(bool needs_begin_frames) final; |
| 142 void DidFinishFrame(size_t remaining_frames) override {} | 142 void DidFinishFrame(size_t remaining_frames) override {} |
| 143 void AddObserver(BeginFrameObserver* obs) final; | 143 void AddObserver(BeginFrameObserver* obs) final; |
| 144 void RemoveObserver(BeginFrameObserver* obs) final; | 144 void RemoveObserver(BeginFrameObserver* obs) final; |
| 145 void SetClientReady() override {} | 145 void SetClientReady() override {} |
| 146 | 146 |
| 147 // Tracing support - Recommend (but not required) to call this implementation | 147 // Tracing support - Recommend (but not required) to call this implementation |
| 148 // in any override. | 148 // in any override. |
| 149 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 149 void AsValueInto(base::trace_event::TracedValue* dict) override; |
| 150 | 150 |
| 151 protected: | 151 protected: |
| 152 BeginFrameSourceMixIn(); | 152 BeginFrameSourceMixIn(); |
| 153 | 153 |
| 154 // These methods should be used by subclasses to make the call to the | 154 // These methods should be used by subclasses to make the call to the |
| 155 // observers. | 155 // observers. |
| 156 void CallOnBeginFrame(const BeginFrameArgs& args); | 156 void CallOnBeginFrame(const BeginFrameArgs& args); |
| 157 | 157 |
| 158 // This method should be overridden if you want to change some behaviour on | 158 // This method should be overridden if you want to change some behaviour on |
| 159 // needs_begin_frames change. | 159 // needs_begin_frames change. |
| 160 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) {} | 160 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) {} |
| 161 | 161 |
| 162 BeginFrameObserver* observer_; | 162 ObserverList<BeginFrameObserver> observer_list_; |
| 163 bool needs_begin_frames_; | 163 bool needs_begin_frames_; |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 bool inside_as_value_into_; | 166 bool inside_as_value_into_; |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 // A frame source which calls BeginFrame (at the next possible time) as soon as | 169 // A frame source which calls BeginFrame (at the next possible time) as soon as |
| 170 // remaining frames reaches zero. | 170 // remaining frames reaches zero. |
| 171 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceMixIn { | 171 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceMixIn { |
| 172 public: | 172 public: |
| 173 static scoped_ptr<BackToBackBeginFrameSource> Create( | 173 static scoped_ptr<BackToBackBeginFrameSource> Create( |
| 174 base::SingleThreadTaskRunner* task_runner); | 174 base::SingleThreadTaskRunner* task_runner); |
| 175 ~BackToBackBeginFrameSource() override; | 175 ~BackToBackBeginFrameSource() override; |
| 176 | 176 |
| 177 // BeginFrameSource | 177 // BeginFrameSource |
| 178 void DidFinishFrame(size_t remaining_frames) override; | 178 void DidFinishFrame(size_t remaining_frames) override; |
| 179 | 179 |
| 180 // Tracing | 180 // Tracing |
| 181 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 181 void AsValueInto(base::trace_event::TracedValue* dict) override; |
| 182 | 182 |
| 183 protected: | 183 protected: |
| 184 explicit BackToBackBeginFrameSource( | 184 explicit BackToBackBeginFrameSource( |
| 185 base::SingleThreadTaskRunner* task_runner); | 185 base::SingleThreadTaskRunner* task_runner); |
| 186 virtual base::TimeTicks Now(); // Now overridable for testing | 186 virtual base::TimeTicks Now(); // Now overridable for testing |
| 187 | 187 |
| 188 base::SingleThreadTaskRunner* task_runner_; | 188 base::SingleThreadTaskRunner* task_runner_; |
| 189 | 189 |
| 190 bool send_begin_frame_posted_; | 190 bool send_begin_frame_posted_; |
| 191 | 191 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 204 public VSyncParameterObserver, | 204 public VSyncParameterObserver, |
| 205 public TimeSourceClient { | 205 public TimeSourceClient { |
| 206 public: | 206 public: |
| 207 static scoped_ptr<SyntheticBeginFrameSource> Create( | 207 static scoped_ptr<SyntheticBeginFrameSource> Create( |
| 208 base::SingleThreadTaskRunner* task_runner, | 208 base::SingleThreadTaskRunner* task_runner, |
| 209 base::TimeTicks initial_vsync_timebase, | 209 base::TimeTicks initial_vsync_timebase, |
| 210 base::TimeDelta initial_vsync_interval); | 210 base::TimeDelta initial_vsync_interval); |
| 211 ~SyntheticBeginFrameSource() override; | 211 ~SyntheticBeginFrameSource() override; |
| 212 | 212 |
| 213 // Tracing | 213 // Tracing |
| 214 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 214 void AsValueInto(base::trace_event::TracedValue* dict) override; |
| 215 | 215 |
| 216 // VSyncParameterObserver | 216 // VSyncParameterObserver |
| 217 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, | 217 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, |
| 218 base::TimeDelta new_vsync_interval) override; | 218 base::TimeDelta new_vsync_interval) override; |
| 219 | 219 |
| 220 // TimeSourceClient | 220 // TimeSourceClient |
| 221 void OnTimerTick() override; | 221 void OnTimerTick() override; |
| 222 | 222 |
| 223 protected: | 223 protected: |
| 224 explicit SyntheticBeginFrameSource( | 224 explicit SyntheticBeginFrameSource( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 247 void AddSource(BeginFrameSource* new_source); | 247 void AddSource(BeginFrameSource* new_source); |
| 248 void RemoveSource(BeginFrameSource* existing_source); | 248 void RemoveSource(BeginFrameSource* existing_source); |
| 249 void SetActiveSource(BeginFrameSource* new_source); | 249 void SetActiveSource(BeginFrameSource* new_source); |
| 250 const BeginFrameSource* ActiveSource(); | 250 const BeginFrameSource* ActiveSource(); |
| 251 | 251 |
| 252 // BeginFrameObserver | 252 // BeginFrameObserver |
| 253 // The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame | 253 // The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame |
| 254 // calls to preserve the monotonicity of the BeginFrameArgs when switching | 254 // calls to preserve the monotonicity of the BeginFrameArgs when switching |
| 255 // sources. | 255 // sources. |
| 256 void OnBeginFrame(const BeginFrameArgs& args) override; | 256 void OnBeginFrame(const BeginFrameArgs& args) override; |
| 257 const BeginFrameArgs LastUsedBeginFrameArgs() const override; | 257 const BeginFrameArgs LastUsedBeginFrameArgs() override; |
| 258 | 258 |
| 259 // BeginFrameSource | 259 // BeginFrameSource |
| 260 void DidFinishFrame(size_t remaining_frames) override; | 260 void DidFinishFrame(size_t remaining_frames) override; |
| 261 | 261 |
| 262 // BeginFrameSourceMixIn | 262 // BeginFrameSourceMixIn |
| 263 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; | 263 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; |
| 264 | 264 |
| 265 // Tracing | 265 // Tracing |
| 266 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 266 void AsValueInto(base::trace_event::TracedValue* dict) override; |
| 267 | 267 |
| 268 protected: | 268 protected: |
| 269 BeginFrameSourceMultiplexer(); | 269 BeginFrameSourceMultiplexer(); |
| 270 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); | 270 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); |
| 271 | 271 |
| 272 bool HasSource(BeginFrameSource* source); | 272 bool HasSource(BeginFrameSource* source); |
| 273 bool IsIncreasing(const BeginFrameArgs& args); | 273 bool IsIncreasing(const BeginFrameArgs& args); |
| 274 | 274 |
| 275 base::TimeDelta minimum_interval_; | 275 base::TimeDelta minimum_interval_; |
| 276 | 276 |
| 277 BeginFrameSource* active_source_; | 277 BeginFrameSource* active_source_; |
| 278 std::set<BeginFrameSource*> source_list_; | 278 std::set<BeginFrameSource*> source_list_; |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 } // namespace cc | 281 } // namespace cc |
| 282 | 282 |
| 283 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 283 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
| OLD | NEW |