OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/resources/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 : public testing::TestWithParam<RasterWorkerPoolType>, | 102 : public testing::TestWithParam<RasterWorkerPoolType>, |
103 public RasterizerClient { | 103 public RasterizerClient { |
104 public: | 104 public: |
105 struct RasterTaskResult { | 105 struct RasterTaskResult { |
106 unsigned id; | 106 unsigned id; |
107 bool canceled; | 107 bool canceled; |
108 }; | 108 }; |
109 | 109 |
110 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector; | 110 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector; |
111 | 111 |
| 112 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION = 0, ALL = 1 }; |
| 113 |
112 RasterWorkerPoolTest() | 114 RasterWorkerPoolTest() |
113 : context_provider_(TestContextProvider::Create()), | 115 : context_provider_(TestContextProvider::Create()), |
114 timeout_seconds_(5), | 116 timeout_seconds_(5), |
115 timed_out_(false) { | 117 timed_out_(false) { |
116 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | 118 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); |
117 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 119 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
118 | 120 |
119 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 121 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
120 resource_provider_ = ResourceProvider::Create(output_surface_.get(), | 122 resource_provider_ = ResourceProvider::Create(output_surface_.get(), |
121 shared_bitmap_manager_.get(), | 123 shared_bitmap_manager_.get(), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 resource_provider_.reset(); | 168 resource_provider_.reset(); |
167 } | 169 } |
168 | 170 |
169 // Overridden from testing::Test: | 171 // Overridden from testing::Test: |
170 virtual void TearDown() OVERRIDE { | 172 virtual void TearDown() OVERRIDE { |
171 raster_worker_pool_->AsRasterizer()->Shutdown(); | 173 raster_worker_pool_->AsRasterizer()->Shutdown(); |
172 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 174 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
173 } | 175 } |
174 | 176 |
175 // Overriden from RasterWorkerPoolClient: | 177 // Overriden from RasterWorkerPoolClient: |
176 virtual bool ShouldForceTasksRequiredForActivationToComplete() const | 178 virtual void DidFinishRunningTasks(TaskSet task_set) OVERRIDE { |
177 OVERRIDE { | 179 if (task_set == ALL) { |
178 return false; | 180 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 181 base::MessageLoop::current()->Quit(); |
| 182 } |
179 } | 183 } |
180 virtual void DidFinishRunningTasks() OVERRIDE { | 184 virtual TaskSetCollection TasksThatShouldBeForcedToComplete() const OVERRIDE { |
181 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 185 return TaskSetCollection(); |
182 base::MessageLoop::current()->Quit(); | |
183 } | 186 } |
184 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE {} | |
185 | 187 |
186 void RunMessageLoopUntilAllTasksHaveCompleted() { | 188 void RunMessageLoopUntilAllTasksHaveCompleted() { |
187 if (timeout_seconds_) { | 189 if (timeout_seconds_) { |
188 timeout_.Reset( | 190 timeout_.Reset( |
189 base::Bind(&RasterWorkerPoolTest::OnTimeout, base::Unretained(this))); | 191 base::Bind(&RasterWorkerPoolTest::OnTimeout, base::Unretained(this))); |
190 base::MessageLoopProxy::current()->PostDelayedTask( | 192 base::MessageLoopProxy::current()->PostDelayedTask( |
191 FROM_HERE, | 193 FROM_HERE, |
192 timeout_.callback(), | 194 timeout_.callback(), |
193 base::TimeDelta::FromSeconds(timeout_seconds_)); | 195 base::TimeDelta::FromSeconds(timeout_seconds_)); |
194 } | 196 } |
195 | 197 |
196 base::MessageLoop::current()->Run(); | 198 base::MessageLoop::current()->Run(); |
197 | 199 |
198 timeout_.Cancel(); | 200 timeout_.Cancel(); |
199 | 201 |
200 ASSERT_FALSE(timed_out_) << "Test timed out"; | 202 ASSERT_FALSE(timed_out_) << "Test timed out"; |
201 } | 203 } |
202 | 204 |
203 void ScheduleTasks() { | 205 void ScheduleTasks() { |
204 RasterTaskQueue queue; | 206 RasterTaskQueue queue; |
205 | 207 |
206 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 208 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
207 it != tasks_.end(); | 209 it != tasks_.end(); |
208 ++it) | 210 ++it) { |
209 queue.items.push_back(RasterTaskQueue::Item(it->get(), false)); | 211 TaskSetCollection task_sets; |
| 212 task_sets[ALL] = true; |
| 213 queue.items.push_back(RasterTaskQueue::Item(it->get(), task_sets)); |
| 214 } |
210 | 215 |
211 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue); | 216 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue); |
212 } | 217 } |
213 | 218 |
214 void AppendTask(unsigned id, const gfx::Size& size) { | 219 void AppendTask(unsigned id, const gfx::Size& size) { |
215 scoped_ptr<ScopedResource> resource( | 220 scoped_ptr<ScopedResource> resource( |
216 ScopedResource::Create(resource_provider_.get())); | 221 ScopedResource::Create(resource_provider_.get())); |
217 resource->Allocate(size, ResourceProvider::TextureHintImmutable, RGBA_8888); | 222 resource->Allocate(size, ResourceProvider::TextureHintImmutable, RGBA_8888); |
218 const Resource* const_resource = resource.get(); | 223 const Resource* const_resource = resource.get(); |
219 | 224 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 360 |
356 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 361 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
357 RasterWorkerPoolTest, | 362 RasterWorkerPoolTest, |
358 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 363 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
359 RASTER_WORKER_POOL_TYPE_IMAGE, | 364 RASTER_WORKER_POOL_TYPE_IMAGE, |
360 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, | 365 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
361 RASTER_WORKER_POOL_TYPE_GPU)); | 366 RASTER_WORKER_POOL_TYPE_GPU)); |
362 | 367 |
363 } // namespace | 368 } // namespace |
364 } // namespace cc | 369 } // namespace cc |
OLD | NEW |