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

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

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 #include "components/mus/gles2/command_buffer_task_runner.h"
6
7 #include "base/bind.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "components/mus/gles2/command_buffer_driver.h"
10
11 namespace mus {
12
13 CommandBufferTaskRunner::CommandBufferTaskRunner()
14 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
15 need_post_task_(true) {
16 }
17
18 bool CommandBufferTaskRunner::PostTask(
19 const CommandBufferDriver* driver,
20 const TaskCallback& task) {
21 base::AutoLock locker(lock_);
22 driver_map_[driver].push_back(task);
23 ScheduleTaskIfNecessaryLocked();
24 return true;
25 }
26
27 CommandBufferTaskRunner::~CommandBufferTaskRunner() {}
28
29 bool CommandBufferTaskRunner::RunOneTaskInternalLocked() {
30 DCHECK(thread_checker_.CalledOnValidThread());
31 lock_.AssertAcquired();
32
33 for (auto it = driver_map_.begin(); it != driver_map_.end(); ++it) {
34 if (!it->first->IsScheduled())
35 continue;
36 TaskQueue& task_queue = it->second;
37 DCHECK(!task_queue.empty());
38 const TaskCallback& callback = task_queue.front();
39 bool complete = false;
40 {
41 base::AutoUnlock unlocker(lock_);
42 complete = callback.Run();
43 }
44 if (complete) {
45 // Only remove the task if it is complete.
46 task_queue.pop_front();
47 if (task_queue.empty())
48 driver_map_.erase(it);
49 }
50 return true;
51 }
52 return false;
53 }
54
55 void CommandBufferTaskRunner::ScheduleTaskIfNecessaryLocked() {
56 lock_.AssertAcquired();
57 if (!need_post_task_)
58 return;
59 task_runner()->PostTask(
60 FROM_HERE,
61 base::Bind(&CommandBufferTaskRunner::RunCommandBufferTask, this));
62 need_post_task_ = false;
63 }
64
65 void CommandBufferTaskRunner::RunCommandBufferTask() {
66 DCHECK(thread_checker_.CalledOnValidThread());
67 base::AutoLock locker(lock_);
68
69 // Try executing all tasks in |driver_map_| until |RunOneTaskInternalLock()|
70 // returns false (Returning false means |driver_map_| is empty or all tasks
71 // in it aren't executable currently).
72 while (RunOneTaskInternalLocked())
73 ;
74 need_post_task_ = true;
75 }
76
77 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/gles2/command_buffer_task_runner.h ('k') | components/mus/gles2/gl_surface_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698