| 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..747b8003f16c22df0edb65e253cc937faf2c1727
|
| --- /dev/null
|
| +++ b/cc/scheduler/frame_source.h
|
| @@ -0,0 +1,207 @@
|
| +// 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"
|
| +#include "ui/gfx/frame_time.h"
|
| +
|
| +namespace cc {
|
| +
|
| +/**
|
| + *
|
| + */
|
| +class CC_EXPORT VSyncParameterObserver
|
| + : public ui::CompositorVSyncManager::Observer {
|
| + public:
|
| + VSyncParameterObserver(base::TimeTicks initial_vsync_timebase,
|
| + base::TimeDelta initial_vsync_interval);
|
| + virtual ~VSyncParameterObserver();
|
| +
|
| + virtual void OnUpdateVSyncParameters(
|
| + base::TimeTicks new_vsync_timebase,
|
| + base::TimeDelta new_vsync_interval) OVERRIDE;
|
| +
|
| + virtual base::TimeTicks VSyncTimebase() const;
|
| + virtual base::TimeDelta VSyncInterval() const;
|
| +
|
| + // Tracing support
|
| + virtual void AsValueInto(base::debug::TracedValue* dict) const;
|
| +
|
| + protected:
|
| + virtual void OnTimeBaseAndIntervalChange(
|
| + const base::TimeTicks new_vsync_timebase,
|
| + const base::TimeDelta new_vsync_interval) {}
|
| +
|
| + private:
|
| + base::TimeTicks vsync_timebase_;
|
| + base::TimeDelta vsync_interval_;
|
| +};
|
| +
|
| +/**
|
| + *
|
| + */
|
| +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 then toggling
|
| + // SetGenerateFrames. 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:
|
| + void SendBeginFrame(const BeginFrameArgs& args);
|
| + BeginFrameObserver* observer_ = NULL;
|
| +
|
| + private:
|
| + bool inside_as_value_into_ = false;
|
| +};
|
| +
|
| +/**
|
| + * 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();
|
| +
|
| + virtual void SendBeginFrameArgs();
|
| +
|
| + // 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_ = false;
|
| + bool send_begin_frame_posted_ = false;
|
| +
|
| + void ScheduleSendBeginFrameArgs();
|
| +};
|
| +
|
| +/**
|
| + * A frame source which is locked an external vsync source and generates
|
| + * BeginFrameArgs for it.
|
| + */
|
| +class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource,
|
| + public VSyncParameterObserver,
|
| + public TimeSourceClient {
|
| + public:
|
| + static scoped_ptr<SyntheticBeginFrameSource> Create(
|
| + base::SingleThreadTaskRunner* task_runner,
|
| + base::TimeTicks initial_vsync_timebase,
|
| + base::TimeDelta initial_vsync_interval);
|
| + virtual ~SyntheticBeginFrameSource();
|
| +
|
| + // TimeSourceClient
|
| + virtual void OnTimerTick() 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:
|
| + SyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source,
|
| + base::TimeTicks initial_vsync_timebase,
|
| + base::TimeDelta initial_vsync_interval);
|
| +
|
| + virtual void OnTimeBaseAndIntervalChange(
|
| + const base::TimeTicks new_vsync_timebase,
|
| + const base::TimeDelta new_vsync_interval) OVERRIDE;
|
| +
|
| + 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).
|
| + */
|
| +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_
|
|
|