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..59978455fd6e736674d07d78011c0c739c3324a5 | 
| --- /dev/null | 
| +++ b/cc/scheduler/frame_source.h | 
| @@ -0,0 +1,202 @@ | 
| +// 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 <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/gfx/frame_time.h" | 
| + | 
| +namespace cc { | 
| + | 
| +class CC_EXPORT FrameSink { | 
| 
 
brianderson
2014/05/07 17:20:16
Please rename this BeginFrameSink so we have consi
 
mithro-old
2014/05/07 23:42:28
Done.
 
 | 
| + public: | 
| + virtual void BeginFrame(const BeginFrameArgs& args) = 0; | 
| +}; | 
| + | 
| +class CC_EXPORT FrameSource { | 
| 
 
brianderson
2014/05/07 17:20:16
Please rename this BeginFrameSource.
 
mithro-old
2014/05/07 23:42:28
Done.
 
 | 
| + public: | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) = 0; | 
| + virtual void SetSink(FrameSink* sink) = 0; | 
| + virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | 
| + base::TimeDelta interval) = 0; | 
| + | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const = 0; | 
| + virtual inline std::string FrameSourceType() const = 0; | 
| 
 
brianderson
2014/05/07 17:20:16
Is this for testing purposes? Can it be removed in
 
mithro-old
2014/05/07 22:02:32
Having which frame source is in use as part of the
 
 | 
| + virtual ~FrameSource() {} | 
| +}; | 
| + | 
| +class CC_EXPORT BaseFrameSource : public FrameSource { | 
| 
 
brianderson
2014/05/07 17:20:16
I need to think about this a bit. But can you prov
 
mithro-old
2014/05/07 23:42:28
The code BaseFrameSource saves is a relatively sma
 
 | 
| + public: | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) = 0; | 
| + virtual void SetSink(FrameSink* sink) OVERRIDE; | 
| + virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | 
| + base::TimeDelta interval) OVERRIDE; | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | 
| + | 
| + virtual inline std::string FrameSourceType() const = 0; | 
| + | 
| + virtual ~BaseFrameSource() {} | 
| + | 
| + protected: | 
| + base::TimeDelta interval_; | 
| + | 
| + scoped_ptr<base::DictionaryValue> BaseFrameSourceAsValue() const; | 
| + virtual void SendBeginFrame(const BeginFrameArgs& args); | 
| + | 
| + explicit BaseFrameSource(FrameSink* sink); | 
| + | 
| + private: | 
| + FrameSink* frame_sink_; | 
| +}; | 
| + | 
| +/** | 
| + * A frame source which proxies to / from a frame source we don't take | 
| + * ownership of. | 
| + */ | 
| +class CC_EXPORT ProxyFrameSource : public BaseFrameSource, public FrameSink { | 
| 
 
brianderson
2014/05/07 17:20:16
This is getting a bit confusing for me to follow.
 
mithro-old
2014/05/07 22:02:32
The sole reason that ProxyFrameSource exists at th
 
brianderson
2014/05/08 00:55:58
I feel like there must be a solution to this probl
 
mithro-old
2014/05/09 02:45:58
This seems like mostly a style question? 
I guess
 
 | 
| + public: | 
| + // FIXME(mithro): This should probably be a weakptr to the frame source | 
| + // rather then a raw pointer. | 
| + ProxyFrameSource(FrameSink* sink, FrameSource* source); | 
| + | 
| + // FrameSource | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | 
| + virtual std::string FrameSourceType() const OVERRIDE; | 
| + virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | 
| + base::TimeDelta interval) OVERRIDE; | 
| + | 
| + // FrameSink | 
| + virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | 
| + | 
| + private: | 
| + FrameSource* source_; | 
| +}; | 
| + | 
| +/** | 
| + * A frame source which throttles down another begin frame source. | 
| + */ | 
| +class CC_EXPORT ThrottledFrameSource : public BaseFrameSource, | 
| 
 
brianderson
2014/05/07 17:20:16
I was thinking about this more and think a wrapper
 
mithro-old
2014/05/07 23:42:28
I'm going to leave the ThrottledFrameSource here f
 
 | 
| + public FrameSink { | 
| + public: | 
| + ThrottledFrameSource(FrameSink* sink, | 
| + scoped_ptr<FrameSource> source, | 
| + base::TimeDelta interval); | 
| + virtual ~ThrottledFrameSource(); | 
| + | 
| + // FrameSource | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | 
| + virtual std::string FrameSourceType() const OVERRIDE; | 
| + virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | 
| + base::TimeDelta interval) OVERRIDE; | 
| + | 
| + // FrameSink | 
| + virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | 
| + | 
| + private: | 
| + BeginFrameArgs last_frame_args_; | 
| + scoped_ptr<FrameSource> source_; | 
| +}; | 
| + | 
| +/** | 
| + * Frame source which needs a task runner object. | 
| + */ | 
| +class CC_EXPORT TaskRunnerFrameSource : public BaseFrameSource { | 
| 
 
brianderson
2014/05/07 17:20:16
Does this extra level of inheritance buy us much?
 
mithro-old
2014/05/07 23:42:28
Not really - I thought there would be more shared
 
brianderson
2014/05/08 00:55:58
Please remove it unless you find there is a signif
 
mithro-old
2014/05/09 02:45:58
Done.
 
 | 
| + public: | 
| + TaskRunnerFrameSource(FrameSink* sink, | 
| + base::SingleThreadTaskRunner* task_runner); | 
| + | 
| + protected: | 
| + base::SingleThreadTaskRunner* task_runner_; | 
| +}; | 
| + | 
| +/** | 
| + * A frame source which sends a BeginFrame as soon as SetNeedsBeginFrame is | 
| + * requested. | 
| + */ | 
| +class CC_EXPORT BackToBackFrameSource : public TaskRunnerFrameSource { | 
| + public: | 
| + BackToBackFrameSource(FrameSink* sink, | 
| + base::SingleThreadTaskRunner* task_runner); | 
| + | 
| + // FrameSource | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | 
| + virtual std::string FrameSourceType() const OVERRIDE; | 
| + | 
| + // --------------------------------------------------------------------- | 
| + void PostBeginFrame(); | 
| +}; | 
| + | 
| +/** | 
| + * A frame source which is locked an external vsync source and generates | 
| + * BeginFrameArgs for it. | 
| + */ | 
| +class CC_EXPORT SyntheticFrameSource : public TaskRunnerFrameSource, | 
| + public TimeSourceClient { | 
| + public: | 
| + SyntheticFrameSource(FrameSink* sink, | 
| + base::SingleThreadTaskRunner* task_runner, | 
| + base::TimeDelta interval); | 
| + virtual ~SyntheticFrameSource(); | 
| + | 
| + // FrameSource | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | 
| + virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | 
| + base::TimeDelta interval) OVERRIDE; | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | 
| + virtual std::string FrameSourceType() const OVERRIDE; | 
| + | 
| + // --------------------------------------------------------------------- | 
| + | 
| + virtual void OnTimerTick() OVERRIDE; | 
| + | 
| + private: | 
| + scoped_refptr<TimeSource> time_source_; | 
| + | 
| + BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | 
| +}; | 
| + | 
| +/** | 
| + * A virtual frame source which lets you switch between two other frame sources | 
| + * (making sure the BeginFrameArgs stays monotonic). | 
| + */ | 
| +class CC_EXPORT DualFrameSource : public BaseFrameSource, public FrameSink { | 
| 
 
brianderson
2014/05/07 17:20:16
Tim and I talked offline comparing this solution f
 
mithro-old
2014/05/07 23:42:28
We are currently
 
 | 
| + public: | 
| + DualFrameSource(FrameSink* sink, | 
| + scoped_ptr<FrameSource> source_primary, | 
| + scoped_ptr<FrameSource> source_secondary); | 
| + virtual ~DualFrameSource(); | 
| + | 
| + // FrameSource | 
| 
 
brianderson
2014/05/07 17:20:16
I think DualFrameSource needs to override SetTimeb
 
mithro-old
2014/05/07 22:02:32
Yes it does.
At the moment I think we want to for
 
brianderson
2014/05/08 00:55:58
To the primary source only sounds good.
 
mithro-old
2014/05/09 02:45:58
Done.
How do we set / change the interval for the
 
 | 
| + virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | 
| + virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | 
| + virtual std::string FrameSourceType() const OVERRIDE; | 
| + | 
| + // FrameSink | 
| + virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | 
| + | 
| + // --------------------------------------------------------------------- | 
| + | 
| + void SwitchSource(const FrameSource* new_source); | 
| + const FrameSource* SourcePrimary() const; | 
| + const FrameSource* SourceSecondary() const; | 
| 
 
brianderson
2014/05/07 17:20:16
Should we rename these to Foreground and Backgroun
 
mithro-old
2014/05/07 23:42:28
Done.
 
 | 
| + | 
| + private: | 
| + bool needs_begin_frame_; | 
| + BeginFrameArgs last_frame_args_; | 
| + FrameSource* active_source_; | 
| + scoped_ptr<FrameSource> source_primary_; | 
| + scoped_ptr<FrameSource> source_secondary_; | 
| +}; | 
| + | 
| +} // namespace cc | 
| + | 
| +#endif // CC_SCHEDULER_FRAME_SOURCE_H_ |