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

Side by Side Diff: components/mus/gles2/command_buffer_task_runner.h

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_MUS_GLES2_COMMAND_BUFFER_TASK_RUNNER_H_
6 #define COMPONENTS_MUS_GLES2_COMMAND_BUFFER_TASK_RUNNER_H_
7
8 #include <deque>
9 #include <map>
10 #include <memory>
11
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/synchronization/condition_variable.h"
17 #include "base/synchronization/lock.h"
18 #include "base/threading/thread_checker.h"
19
20 namespace mus {
21
22 class CommandBufferDriver;
23
24 // This class maintains tasks submitted by |CommandBufferImpl|. Those tasks will
25 // be executed on the main thread. But if the main thread is blocked in
26 // |CommandBufferLocal::OnWaitFenceSync()| by waiting a sync point, the
27 // |CommandBufferTaskRunner::RunOneTask()| could be used for executing a task
28 // from other command buffers which may retire the sync point.
29 class CommandBufferTaskRunner
30 : public base::RefCountedThreadSafe<CommandBufferTaskRunner> {
31 public:
32 CommandBufferTaskRunner();
33
34 // TaskCallback returns true if the task is completed and should be removed
35 // from the task queue, otherwise returns false.
36 typedef base::Callback<bool(void)> TaskCallback;
37 bool PostTask(const CommandBufferDriver* driver,
38 const TaskCallback& task);
39
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
41 return task_runner_;
42 }
43
44 private:
45 friend class base::RefCountedThreadSafe<CommandBufferTaskRunner>;
46
47 ~CommandBufferTaskRunner();
48
49 // Run one command buffer task from a scheduled command buffer.
50 // When there isn't any command buffer task, and if the |block| is false,
51 // this function will return false immediately, otherwise, this function
52 // will be blocked until a task is available for executing.
53 bool RunOneTaskInternalLocked();
54
55 // Post a task to the main thread to execute tasks in |driver_map_|, if it is
56 // necessary.
57 void ScheduleTaskIfNecessaryLocked();
58
59 // The callback function for executing tasks in |driver_map_|.
60 void RunCommandBufferTask();
61
62 base::ThreadChecker thread_checker_;
63 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
64
65 typedef std::deque<TaskCallback> TaskQueue;
66 typedef std::map<const CommandBufferDriver*, TaskQueue> DriverMap;
67 DriverMap driver_map_;
68 bool need_post_task_;
69
70 // The access lock for |driver_map_| and |need_post_task_|.
71 base::Lock lock_;
72
73 DISALLOW_COPY_AND_ASSIGN(CommandBufferTaskRunner);
74 };
75
76 } // namespace mus
77
78 #endif // COMPONENTS_MUS_GLES2_COMMAND_BUFFER_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « components/mus/gles2/command_buffer_local_client.h ('k') | components/mus/gles2/command_buffer_task_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698