Chromium Code Reviews| Index: services/gfx/compositor/backend/scheduler.h |
| diff --git a/services/gfx/compositor/backend/scheduler.h b/services/gfx/compositor/backend/scheduler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f57032cd5dd7ac986ce4bba24fe89d99399a6a2d |
| --- /dev/null |
| +++ b/services/gfx/compositor/backend/scheduler.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2015 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 SERVICES_GFX_COMPOSITOR_BACKEND_SCHEDULER_H_ |
| +#define SERVICES_GFX_COMPOSITOR_BACKEND_SCHEDULER_H_ |
| + |
| +#include <limits> |
| +#include <mutex> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h" |
| + |
| +namespace compositor { |
| + |
| +// Determines the behavior of |ScheduleFrame()|. |
| +enum class SchedulingMode { |
|
viettrungluu
2016/01/04 21:08:24
Maybe this should be declared inside Scheduler? (D
jeffbrown
2016/01/16 03:28:31
I went back and forth on this. I'll move it back
|
| + // Schedules a snapshot, at minimum. |
| + kSnapshot, |
|
viettrungluu
2016/01/04 21:08:24
FYI: Typically, we've followed Chromium style, whi
jeffbrown
2016/01/16 03:28:31
Apparently the preferred style is now "kFoo" like
|
| + |
| + // Schedules an update followed by a snapshot, at minimum. |
| + kUpdateAndSnapshot, |
| +}; |
| + |
| +// Interface implemented by schedulers. |
|
viettrungluu
2016/01/04 21:08:24
This comment is almost useless. :) It may be helpf
jeffbrown
2016/01/16 03:28:31
Done.
|
| +class Scheduler { |
| + public: |
| + Scheduler() = default; |
| + virtual ~Scheduler() = default; |
| + |
| + // Schedules work for a frame. |
| + // |
| + // This function ensures that every update is followed by a snapshot |
| + // unless scheduling is suspended in the meantime. |
| + // |
| + // When |scheduling_mode| is |kSnapshot|, if there is time between now |
| + // and the snapshot during which an update can be performed, then an |
| + // update will also be scheduled before the requested snapshot. |
| + // |
| + // When |scheduling_mode| is |kUpdateAndSnapshot|, if there is time |
| + // between now and the update during which a snapshot can be performed, |
| + // then a snapshot will also be scheduled before the requested update |
| + // and the next snapshot. |
| + // |
| + // This design is intended to minimize latency by anticipating that |
| + // snapshots will be needed after updates and by scheduling updates in |
| + // advance if it is known that a snapshot will be needed on the next frame. |
| + virtual void ScheduleFrame(SchedulingMode scheduling_mode) = 0; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| +}; |
| + |
| +// Scheduling callbacks. |
| +struct SchedulerCallbacks { |
|
viettrungluu
2016/01/04 21:08:23
When/where is this used? (It's a bit odd that it's
jeffbrown
2016/01/16 03:28:31
Added docs to make this clearer.
|
| + using FrameCallback = |
| + base::Callback<void(const mojo::gfx::composition::FrameInfo&)>; |
| + |
| + SchedulerCallbacks(const FrameCallback& update_callback, |
| + const FrameCallback& snapshot_callback); |
| + ~SchedulerCallbacks(); |
| + |
| + // Called when it's time for applications to/ update the contents of |
| + // their scenes. |
| + const FrameCallback update_callback; |
| + |
| + // Called when it's time for the compositor to snapshot and submit |
| + // the next frame. |
| + const FrameCallback snapshot_callback; |
| +}; |
| + |
| +} // namespace compositor |
| + |
| +#endif // SERVICES_GFX_COMPOSITOR_BACKEND_SCHEDULER_H_ |