| Index: gpu/ipc/service/gpu_scheduler.h
|
| diff --git a/gpu/ipc/service/gpu_scheduler.h b/gpu/ipc/service/gpu_scheduler.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6c540b00380621d5bb3134be9be059c2c56acc50
|
| --- /dev/null
|
| +++ b/gpu/ipc/service/gpu_scheduler.h
|
| @@ -0,0 +1,114 @@
|
| +// Copyright (c) 2016 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 GPU_IPC_SERVICE_GPU_SCHEDULER_H_
|
| +#define GPU_IPC_SERVICE_GPU_SCHEDULER_H_
|
| +
|
| +#include <deque>
|
| +#include <set>
|
| +#include <vector>
|
| +
|
| +#include "base/cancelable_callback.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "base/threading/thread_checker.h"
|
| +#include "base/time/time.h"
|
| +#include "gpu/command_buffer/common/preemption_flag.h"
|
| +#include "gpu/gpu_export.h"
|
| +#include "gpu/ipc/common/gpu_stream_constants.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace gpu {
|
| +
|
| +class GpuCommandStream;
|
| +
|
| +struct GPU_EXPORT GpuSchedulerSettings {
|
| + base::TimeDelta min_time_slice;
|
| + base::TimeDelta max_time_slice;
|
| +};
|
| +
|
| +class GPU_EXPORT GpuScheduler {
|
| + public:
|
| + // Create with default settings.
|
| + static std::unique_ptr<GpuScheduler> Create(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
| +
|
| + GpuScheduler(const GpuSchedulerSettings& settings,
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
| +
|
| + virtual ~GpuScheduler();
|
| +
|
| + void AddStream(GpuCommandStream* stream, GpuStreamPriority priority);
|
| + void RemoveStream(GpuCommandStream* stream);
|
| +
|
| + // Returns true if current stream should yield. Called on the main thread.
|
| + bool ShouldYield();
|
| +
|
| + // Called when stream becomes ready.
|
| + void ScheduleStream(GpuCommandStream* stream);
|
| +
|
| + // Called when a stream stops being ready.
|
| + void DescheduleStream(GpuCommandStream* stream);
|
| +
|
| + protected:
|
| + virtual base::TimeTicks Now(); // for testing
|
| +
|
| + private:
|
| + struct StreamInfo {
|
| + GpuCommandStream* stream = nullptr;
|
| + GpuStreamPriority priority = GpuStreamPriority::LAST;
|
| + bool ready = false;
|
| + };
|
| +
|
| + struct ScheduledStream {
|
| + GpuCommandStream* stream = nullptr;
|
| + GpuStreamPriority priority = GpuStreamPriority::LAST;
|
| +
|
| + bool operator<(const ScheduledStream& other) const {
|
| + return std::tie(priority, stream) >
|
| + std::tie(other.priority, other.stream);
|
| + }
|
| + };
|
| +
|
| + std::vector<StreamInfo>::iterator FindStream(GpuCommandStream* stream);
|
| + std::vector<ScheduledStream>::iterator FindScheduledStream(
|
| + GpuCommandStream* stream);
|
| +
|
| + void BuildWorkQueue();
|
| + ScheduledStream GetNextStream();
|
| + void RunNextStream();
|
| +
|
| + const GpuSchedulerSettings settings_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| +
|
| + // The following are protected by |lock_|.
|
| + bool running_ = false;
|
| + // If we need to reschedule
|
| + bool needs_rescheduling_ = false;
|
| + // List of streams and associated information.
|
| + std::vector<StreamInfo> streams_;
|
| + // Priority queue of streams that are scheduled to run.
|
| + std::vector<ScheduledStream> work_queue_;
|
| + // Protects the above variables.
|
| + base::Lock lock_;
|
| +
|
| + // Time when current stream started running.
|
| + base::TimeTicks running_stream_start_time_;
|
| +
|
| + // Used to ensure that methods (except ScheduleStream) are called on the main
|
| + // thread.
|
| + base::ThreadChecker thread_checker_;
|
| +
|
| + base::WeakPtrFactory<GpuScheduler> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(GpuScheduler);
|
| +};
|
| +
|
| +} // namespace gpu
|
| +
|
| +#endif // GPU_IPC_SERVICE_GPU_SCHEDULER_H_
|
|
|