Chromium Code Reviews| Index: cc/scheduler/frame_source.h |
| diff --git a/cc/scheduler/frame_source.h b/cc/scheduler/frame_source.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a00cdd0e3bf45c534b786f1ce6e113c9761da799 |
| --- /dev/null |
| +++ b/cc/scheduler/frame_source.h |
| @@ -0,0 +1,180 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_SCHEDULER_FRAME_SOURCE_H_ |
| +#define CC_SCHEDULER_FRAME_SOURCE_H_ |
| + |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/debug/trace_event.h" |
| +#include "base/logging.h" |
| +#include "cc/output/begin_frame_args.h" |
| +#include "cc/scheduler/delay_based_time_source.h" |
| +#include "ui/compositor/compositor_vsync_manager.h" |
| + |
| +namespace cc { |
| + |
| +/** |
| + * |
| + */ |
| +class CC_EXPORT BeginFrameObserver { |
| + public: |
| + virtual const BeginFrameArgs& LastBeginFrameArgs() const = 0; |
| + virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; |
| + |
| + // Tracing support |
| + virtual void AsValueInto(base::debug::TracedValue* dict) const = 0; |
| +}; |
| + |
| +/** |
| + * |
| + */ |
| +class CC_EXPORT BeginFrameSource { |
| + public: |
| + virtual ~BeginFrameSource() {} |
| + |
| + // Should the frame source be sending begin frames? |
| + virtual bool NeedsBeginFrames() const = 0; |
| + virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; |
| + // This method provides backpressure to a frame source rather than toggling |
| + // SetNeedsBeginFrames. It is used by systems like the BackToBackFrameSource |
| + // to make sure only one frame is pending at a time. |
| + virtual void DidFinishFrame(size_t remaining_frames) = 0; |
| + |
| + void AddObserver(BeginFrameObserver* obs); |
| + void RemoveObserver(BeginFrameObserver* obs); |
| + |
| + // Tracing support |
| + virtual void AsValueInto(base::debug::TracedValue* dict) const = 0; |
| + |
| + protected: |
| + BeginFrameSource(); |
| + void CallOnBeginFrame(const BeginFrameArgs& args); |
| + BeginFrameObserver* observer_; |
| + |
| + private: |
| + bool inside_as_value_into_; |
| +}; |
| + |
| +/** |
| + * A frame source which sends a BeginFrame as soon as remaining frames reaches |
| + * zero. |
| + */ |
| +class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSource { |
| + public: |
| + static scoped_ptr<BackToBackBeginFrameSource> Create( |
| + base::SingleThreadTaskRunner* task_runner); |
| + virtual ~BackToBackBeginFrameSource(); |
| + |
| + // BeginFrameSource |
| + virtual bool NeedsBeginFrames() const OVERRIDE; |
| + virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; |
| + virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE; |
| + |
| + // Tracing |
| + virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; |
| + |
| + protected: |
| + explicit BackToBackBeginFrameSource( |
| + base::SingleThreadTaskRunner* task_runner); |
| + virtual base::TimeTicks Now(); // Now overridable for testing |
| + |
| + base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; |
| + base::SingleThreadTaskRunner* task_runner_; |
| + |
| + bool needs_begin_frames_; |
| + bool send_begin_frame_posted_; |
| + |
| + void ScheduleBeginFrame(); |
| + void BeginFrame(); |
| +}; |
| + |
| +/** |
| + * A frame source which is locked an external vsync source and generates |
| + * BeginFrameArgs for it. |
| + */ |
| +class CC_EXPORT SyntheticBeginFrameSource |
| + : public BeginFrameSource, |
| + public ui::CompositorVSyncManager::Observer, |
| + public TimeSourceClient { |
| + public: |
| + static scoped_ptr<SyntheticBeginFrameSource> Create( |
| + base::SingleThreadTaskRunner* task_runner, |
| + base::TimeTicks initial_vsync_timebase, |
| + base::TimeDelta initial_vsync_interval); |
| + virtual ~SyntheticBeginFrameSource(); |
| + |
| + // BeginFrameSource |
| + virtual bool NeedsBeginFrames() const OVERRIDE; |
| + virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; |
| + virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE{}; |
| + |
| + // Tracing |
| + virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; |
| + |
| + // ui::CompositorVSyncManager::Observer |
| + virtual void OnUpdateVSyncParameters( |
| + base::TimeTicks new_vsync_timebase, |
| + base::TimeDelta new_vsync_interval) OVERRIDE; |
| + |
| + // TimeSourceClient |
| + virtual void OnTimerTick() OVERRIDE; |
| + |
| + protected: |
| + explicit SyntheticBeginFrameSource( |
| + scoped_refptr<DelayBasedTimeSource> time_source); |
| + |
| + void SendBeginFrameFromTick(base::TimeTicks frame_time); |
| + |
| + scoped_refptr<DelayBasedTimeSource> time_source_; |
| +}; |
| + |
| +/** |
| + * A virtual frame source which lets you switch between multiple other frame |
| + * sources while making sure the BeginFrameArgs stays increasing (possibly |
| + * enforcing minimum boundry between BeginFrameArgs messages). |
| + * |
| + * The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame calls |
| + * to preserves the monoticity of the BeginFrameArgs when switching sources. |
|
brianderson
2014/09/18 21:54:19
to preserve
mithro-old
2014/09/19 02:45:40
Done.
|
| + */ |
| +class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSource, |
| + public BeginFrameObserver { |
| + public: |
| + static scoped_ptr<BeginFrameSourceMultiplexer> Create(); |
| + virtual ~BeginFrameSourceMultiplexer(); |
| + |
| + void SetMinimumInterval(base::TimeDelta new_minimum_interval); |
| + |
| + void AddSource(BeginFrameSource* new_source); |
| + void RemoveSource(BeginFrameSource* existing_source); |
| + void SetActiveSource(BeginFrameSource* new_source); |
| + const BeginFrameSource* ActiveSource(); |
| + |
| + // BeginFrameObserver |
| + virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| + virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; |
| + |
| + // BeginFrameSource |
| + virtual bool NeedsBeginFrames() const OVERRIDE; |
| + virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; |
| + virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE; |
| + |
| + // Tracing |
| + virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; |
| + |
| + protected: |
| + BeginFrameSourceMultiplexer(); |
| + explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); |
| + bool HasSource(BeginFrameSource* source); |
| + |
| + base::TimeDelta minimum_interval_; |
| + |
| + BeginFrameSource* active_source_; |
| + std::set<BeginFrameSource*> source_list_; |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_SCHEDULER_FRAME_SOURCE_H_ |