OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/tiles/image_controller.h" | 5 #include "cc/tiles/image_controller.h" |
| 6 |
| 7 #include <utility> |
| 8 |
6 #include "base/bind.h" | 9 #include "base/bind.h" |
7 #include "base/optional.h" | 10 #include "base/optional.h" |
8 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
9 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
10 #include "base/threading/sequenced_task_runner_handle.h" | 13 #include "base/threading/sequenced_task_runner_handle.h" |
11 #include "base/threading/thread_checker_impl.h" | 14 #include "base/threading/thread_checker_impl.h" |
12 #include "cc/test/skia_common.h" | 15 #include "cc/test/skia_common.h" |
13 #include "cc/tiles/image_decode_cache.h" | 16 #include "cc/tiles/image_decode_cache.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
15 | 18 |
(...skipping 11 matching lines...) Expand all Loading... |
27 { | 30 { |
28 base::AutoLock hold(lock_); | 31 base::AutoLock hold(lock_); |
29 if (shutdown_) | 32 if (shutdown_) |
30 break; | 33 break; |
31 | 34 |
32 if (queue_.empty()) { | 35 if (queue_.empty()) { |
33 condition_.Wait(); | 36 condition_.Wait(); |
34 continue; | 37 continue; |
35 } | 38 } |
36 | 39 |
37 task = queue_.front(); | 40 task = std::move(queue_.front()); |
38 queue_.erase(queue_.begin()); | 41 queue_.erase(queue_.begin()); |
39 } | 42 } |
40 task.Run(); | 43 std::move(task).Run(); |
41 } | 44 } |
42 } | 45 } |
43 | 46 |
44 void Shutdown() { | 47 void Shutdown() { |
45 base::AutoLock hold(lock_); | 48 base::AutoLock hold(lock_); |
46 shutdown_ = true; | 49 shutdown_ = true; |
47 condition_.Signal(); | 50 condition_.Signal(); |
48 } | 51 } |
49 | 52 |
50 void PostTask(const base::Closure& task) { | 53 void PostTask(base::Closure task) { |
51 base::AutoLock hold(lock_); | 54 base::AutoLock hold(lock_); |
52 queue_.push_back(task); | 55 queue_.push_back(std::move(task)); |
53 condition_.Signal(); | 56 condition_.Signal(); |
54 } | 57 } |
55 | 58 |
56 private: | 59 private: |
57 base::Lock lock_; | 60 base::Lock lock_; |
58 base::ConditionVariable condition_; | 61 base::ConditionVariable condition_; |
59 std::vector<base::Closure> queue_; | 62 std::vector<base::Closure> queue_; |
60 bool shutdown_ = false; | 63 bool shutdown_ = false; |
61 }; | 64 }; |
62 | 65 |
63 class WorkerTaskRunner : public base::SequencedTaskRunner { | 66 class WorkerTaskRunner : public base::SequencedTaskRunner { |
64 public: | 67 public: |
65 WorkerTaskRunner() { thread_.Start(); } | 68 WorkerTaskRunner() { thread_.Start(); } |
66 | 69 |
67 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
68 const base::Closure& task, | 71 base::Closure task, |
69 base::TimeDelta delay) override { | 72 base::TimeDelta delay) override { |
70 return PostDelayedTask(from_here, task, delay); | 73 return PostDelayedTask(from_here, std::move(task), delay); |
71 } | 74 } |
72 | 75 |
73 bool PostDelayedTask(const tracked_objects::Location& from_here, | 76 bool PostDelayedTask(const tracked_objects::Location& from_here, |
74 const base::Closure& task, | 77 base::Closure task, |
75 base::TimeDelta delay) override { | 78 base::TimeDelta delay) override { |
76 thread_.PostTask(task); | 79 thread_.PostTask(std::move(task)); |
77 return true; | 80 return true; |
78 } | 81 } |
79 | 82 |
80 bool RunsTasksOnCurrentThread() const override { return false; } | 83 bool RunsTasksOnCurrentThread() const override { return false; } |
81 | 84 |
82 protected: | 85 protected: |
83 ~WorkerTaskRunner() override { | 86 ~WorkerTaskRunner() override { |
84 thread_.Shutdown(); | 87 thread_.Shutdown(); |
85 thread_.Join(); | 88 thread_.Join(); |
86 } | 89 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 134 |
132 private: | 135 private: |
133 int number_of_refs_ = 0; | 136 int number_of_refs_ = 0; |
134 scoped_refptr<TileTask> task_to_use_; | 137 scoped_refptr<TileTask> task_to_use_; |
135 }; | 138 }; |
136 | 139 |
137 // A simple class that can receive decode callbacks. | 140 // A simple class that can receive decode callbacks. |
138 class DecodeClient { | 141 class DecodeClient { |
139 public: | 142 public: |
140 DecodeClient() {} | 143 DecodeClient() {} |
141 void Callback(const base::Closure& quit_closure, | 144 void Callback(base::Closure quit_closure, |
142 ImageController::ImageDecodeRequestId id, | 145 ImageController::ImageDecodeRequestId id, |
143 ImageController::ImageDecodeResult result) { | 146 ImageController::ImageDecodeResult result) { |
144 id_ = id; | 147 id_ = id; |
145 result_ = result; | 148 result_ = result; |
146 quit_closure.Run(); | 149 std::move(quit_closure).Run(); |
147 } | 150 } |
148 | 151 |
149 ImageController::ImageDecodeRequestId id() { return id_; } | 152 ImageController::ImageDecodeRequestId id() { return id_; } |
150 ImageController::ImageDecodeResult result() { return result_; } | 153 ImageController::ImageDecodeResult result() { return result_; } |
151 | 154 |
152 private: | 155 private: |
153 ImageController::ImageDecodeRequestId id_ = 0; | 156 ImageController::ImageDecodeRequestId id_ = 0; |
154 ImageController::ImageDecodeResult result_ = | 157 ImageController::ImageDecodeResult result_ = |
155 ImageController::ImageDecodeResult::FAILURE; | 158 ImageController::ImageDecodeResult::FAILURE; |
156 }; | 159 }; |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 decode_client2.result()); | 586 decode_client2.result()); |
584 | 587 |
585 // Reset the controller since the order of destruction is wrong in this test | 588 // Reset the controller since the order of destruction is wrong in this test |
586 // (|other_cache| should outlive the controller. This is normally done via | 589 // (|other_cache| should outlive the controller. This is normally done via |
587 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.) | 590 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.) |
588 ResetController(); | 591 ResetController(); |
589 } | 592 } |
590 | 593 |
591 } // namespace | 594 } // namespace |
592 } // namespace cc | 595 } // namespace cc |
OLD | NEW |