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

Unified Diff: mc/scheduler/timer.h

Issue 731893002: Add a simple scheduler for animation frames (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix math Created 6 years, 1 month 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
« no previous file with comments | « mc/scheduler/time_interval.cc ('k') | mc/scheduler/timer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mc/scheduler/timer.h
diff --git a/mc/scheduler/timer.h b/mc/scheduler/timer.h
new file mode 100644
index 0000000000000000000000000000000000000000..d16b567b0a54501aaa508d351a0d39d322a1f519
--- /dev/null
+++ b/mc/scheduler/timer.h
@@ -0,0 +1,51 @@
+// 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 MC_SCHEDULER_TIMER_H_
+#define MC_SCHEDULER_TIMER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "base/time/time.h"
+#include "mc/scheduler/time_interval.h"
+
+namespace mc {
+
+class Timer {
+ public:
+ class Client {
+ public:
+ virtual void OnTimerTick(base::TimeTicks now) = 0;
+
+ protected:
+ virtual ~Client();
+ };
+
+ Timer(Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ ~Timer();
+
+ void SetInterval(const TimeInterval& parameters);
+ void SetEnabled(bool enabled);
+
+ private:
+ base::TimeTicks NextTickTarget(base::TimeTicks now);
+ void ScheduleNextTick(base::TimeTicks now);
+ void PostTickTask(base::TimeTicks now, base::TimeTicks target);
+ void OnTimerFired();
+
+ Client* client_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ TimeInterval interval_;
+ base::TimeTicks last_tick_;
+ base::TimeTicks current_target_;
+
+ bool enabled_;
+
+ base::WeakPtrFactory<Timer> weak_factory_;
+};
+}
+
+#endif // MC_SCHEDULER_TIMER_H_
« no previous file with comments | « mc/scheduler/time_interval.cc ('k') | mc/scheduler/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698