Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1030)

Unified Diff: cc/scheduler/frame_source.h

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Major rewrite based on Brian's comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e59dac3537c08267663a22788fd9293e32762c42
--- /dev/null
+++ b/cc/scheduler/frame_source.h
@@ -0,0 +1,241 @@
+// 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 VSyncObserverImpl
brianderson 2014/09/13 01:38:12 Maybe call this VSyncParameterObserver so it's cle
+ : public ui::CompositorVSyncManager::Observer {
+ public:
+ VSyncObserverImpl(base::TimeTicks initial_vsync_timebase,
+ base::TimeDelta initial_vsync_interval);
+ virtual ~VSyncObserverImpl();
+
+ 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;
+};
+
+/* Allows multiple observers to be connected to a single BeginFrameSource.
+class MultiBeginFrameObserver : public BeginFrameObserver {
+ public:
+ void AddObserver(BeginFrameObserver* obs) OVERRIDE {
+ observer_list_.AddObserver(obs);
+ }
+ void RemoveObserver(BeginFrameObserver* obs) OVERRIDE {
+ observer_list_.RemoveObserver(obs);
+ }
+
+ virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE {
+ FOR_EACH_OBSERVER(BeginFrameObserver, observer_list_, OnBeginFrame(args));
+ }
+ private:
+ ObserverList<BeginFrameObserver> observer_list_;
+};
+*/
+
+/**
+ *
+ */
+class CC_EXPORT BeginFrameSource {
brianderson 2014/09/13 01:38:12 Would it make sense to split this into a BeginFram
+ public:
+ virtual ~BeginFrameSource() {}
+
+ // Should the frame source be sending begin frames?
+ virtual bool NeedsBeginFrames() = 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 FinishedFrame(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;
+};
+
+/**
+ * A frame source which throttles down another begin frame source.
+ */
+class CC_EXPORT ThrottledBeginFrameSource : public BeginFrameSource,
brianderson 2014/09/13 01:38:13 Let's keep this class out of this patch and add it
+ public BeginFrameObserver {
+ public:
+ static scoped_ptr<ThrottledBeginFrameSource> Create(base::TimeDelta interval);
+ virtual ~ThrottledBeginFrameSource();
+
+ void SetMinimumInterval(base::TimeDelta new_minimum_interval);
+ virtual void AddSource(BeginFrameSource* new_source);
+ virtual void RemoveSource(BeginFrameSource* new_source);
+
+ // BeginFrameObserver
+ virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE;
+ virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE;
+
+ // BeginFrameSource
+ virtual bool NeedsBeginFrames() OVERRIDE;
+ virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
+ virtual void FinishedFrame(size_t remaining_frames) OVERRIDE;
+
+ // Tracing
+ virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE;
+
+ protected:
+ explicit ThrottledBeginFrameSource(base::TimeDelta interval);
+
+ base::TimeDelta minimum_interval_;
+ BeginFrameSource* source_;
+};
+
+/**
+ * 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() OVERRIDE;
+ virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
+ virtual void FinishedFrame(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 ScheduleSendBeginFrameArgs();
+};
+
+/**
+ * A frame source which is locked an external vsync source and generates
+ * BeginFrameArgs for it.
+ */
+class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource,
+ public VSyncObserverImpl,
+ public TimeSourceClient {
+ public:
+ static scoped_ptr<SyntheticBeginFrameSource> Create(
+ base::SingleThreadTaskRunner* task_runner,
+ base::TimeDelta initial_vsync_interval);
+ virtual ~SyntheticBeginFrameSource();
+
+ // TimeSourceClient
+ virtual void OnTimerTick() OVERRIDE;
+
+ // BeginFrameSource
+ virtual bool NeedsBeginFrames() OVERRIDE;
+ virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
+ virtual void FinishedFrame(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 ThrottledBeginFrameSource {
+ public:
+ static scoped_ptr<BeginFrameSourceMultiplexer> Create();
+ virtual ~BeginFrameSourceMultiplexer();
+
+ void SetActiveSource(BeginFrameSource* new_source);
+ const BeginFrameSource* ActiveSource();
+
+ // ThrottledBeginFrameSource
+ virtual void AddSource(BeginFrameSource* new_source) OVERRIDE;
+ virtual void RemoveSource(BeginFrameSource* existing_source) OVERRIDE;
+
+ // Tracing
+ virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE;
+
+ protected:
+ BeginFrameSourceMultiplexer();
+ explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval);
+
+ private:
+ bool HasSource(BeginFrameSource* source);
+ std::set<BeginFrameSource*> source_list_;
+};
+
+} // namespace cc
+
+#endif // CC_SCHEDULER_FRAME_SOURCE_H_
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/scheduler/frame_source.cc » ('j') | cc/scheduler/frame_source.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698