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

Side by Side Diff: cc/resources/raster_worker_pool_unittest.cc

Issue 168083002: cc: Remove RasterWorkerPool::Task. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove RasterTaskQueueIterator Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/raster_worker_pool_perftest.cc ('k') | cc/resources/tile_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 private: 106 private:
107 base::Lock* lock_; 107 base::Lock* lock_;
108 108
109 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterWorkerPoolTaskImpl); 109 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterWorkerPoolTaskImpl);
110 }; 110 };
111 111
112 class RasterWorkerPoolTest 112 class RasterWorkerPoolTest
113 : public testing::TestWithParam<RasterWorkerPoolType>, 113 : public testing::TestWithParam<RasterWorkerPoolType>,
114 public RasterWorkerPoolClient { 114 public RasterWorkerPoolClient {
115 public: 115 public:
116 class RasterTask : public RasterWorkerPool::RasterTask {
117 public:
118 typedef std::vector<RasterTask> Vector;
119
120 static RasterTask Create(const Resource* resource,
121 const TestRasterWorkerPoolTaskImpl::Reply& reply) {
122 internal::WorkerPoolTask::Vector dependencies;
123 return RasterTask(
124 new TestRasterWorkerPoolTaskImpl(resource, reply, &dependencies));
125 }
126
127 static RasterTask CreateBlocking(
128 const Resource* resource,
129 const TestRasterWorkerPoolTaskImpl::Reply& reply,
130 base::Lock* lock) {
131 internal::WorkerPoolTask::Vector dependencies;
132 return RasterTask(new BlockingTestRasterWorkerPoolTaskImpl(
133 resource, reply, lock, &dependencies));
134 }
135
136 private:
137 friend class RasterWorkerPoolTest;
138
139 explicit RasterTask(internal::RasterWorkerPoolTask* task)
140 : RasterWorkerPool::RasterTask(task) {}
141 };
142
143 struct RasterTaskResult { 116 struct RasterTaskResult {
144 unsigned id; 117 unsigned id;
145 bool canceled; 118 bool canceled;
146 RasterThread raster_thread; 119 RasterThread raster_thread;
147 }; 120 };
148 121
122 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> >
123 RasterTaskVector;
124
149 RasterWorkerPoolTest() 125 RasterWorkerPoolTest()
150 : context_provider_(TestContextProvider::Create()), 126 : context_provider_(TestContextProvider::Create()),
151 timeout_seconds_(5), 127 timeout_seconds_(5),
152 timed_out_(false) { 128 timed_out_(false) {
153 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); 129 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
154 CHECK(output_surface_->BindToClient(&output_surface_client_)); 130 CHECK(output_surface_->BindToClient(&output_surface_client_));
155 131
156 resource_provider_ = ResourceProvider::Create( 132 resource_provider_ = ResourceProvider::Create(
157 output_surface_.get(), NULL, 0, false, 1).Pass(); 133 output_surface_.get(), NULL, 0, false, 1).Pass();
158 134
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 181 }
206 182
207 base::MessageLoop::current()->Run(); 183 base::MessageLoop::current()->Run();
208 184
209 timeout_.Cancel(); 185 timeout_.Cancel();
210 186
211 ASSERT_FALSE(timed_out_) << "Test timed out"; 187 ASSERT_FALSE(timed_out_) << "Test timed out";
212 } 188 }
213 189
214 void ScheduleTasks() { 190 void ScheduleTasks() {
215 RasterWorkerPool::RasterTask::Queue queue; 191 RasterTaskQueue queue;
216 192
217 for (RasterTask::Vector::iterator it = tasks_.begin(); it != tasks_.end(); 193 for (RasterTaskVector::const_iterator it = tasks_.begin();
194 it != tasks_.end();
218 ++it) 195 ++it)
219 queue.Append(*it, false); 196 queue.items.push_back(RasterTaskQueue::Item(*it, false));
220 197
221 raster_worker_pool_->ScheduleTasks(&queue); 198 raster_worker_pool_->ScheduleTasks(&queue);
222 } 199 }
223 200
224 void AppendTask(unsigned id) { 201 void AppendTask(unsigned id) {
225 const gfx::Size size(1, 1); 202 const gfx::Size size(1, 1);
226 203
227 scoped_ptr<ScopedResource> resource( 204 scoped_ptr<ScopedResource> resource(
228 ScopedResource::Create(resource_provider_.get())); 205 ScopedResource::Create(resource_provider_.get()));
229 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); 206 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
230 const Resource* const_resource = resource.get(); 207 const Resource* const_resource = resource.get();
231 208
232 tasks_.push_back( 209 internal::WorkerPoolTask::Vector empty;
233 RasterTask::Create(const_resource, 210 tasks_.push_back(new TestRasterWorkerPoolTaskImpl(
234 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted, 211 const_resource,
235 base::Unretained(this), 212 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted,
236 base::Passed(&resource), 213 base::Unretained(this),
237 id))); 214 base::Passed(&resource),
215 id),
216 &empty));
238 } 217 }
239 218
240 void AppendBlockingTask(unsigned id, base::Lock* lock) { 219 void AppendBlockingTask(unsigned id, base::Lock* lock) {
241 const gfx::Size size(1, 1); 220 const gfx::Size size(1, 1);
242 221
243 scoped_ptr<ScopedResource> resource( 222 scoped_ptr<ScopedResource> resource(
244 ScopedResource::Create(resource_provider_.get())); 223 ScopedResource::Create(resource_provider_.get()));
245 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); 224 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
246 const Resource* const_resource = resource.get(); 225 const Resource* const_resource = resource.get();
247 226
248 tasks_.push_back(RasterTask::CreateBlocking( 227 internal::WorkerPoolTask::Vector empty;
228 tasks_.push_back(new BlockingTestRasterWorkerPoolTaskImpl(
249 const_resource, 229 const_resource,
250 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted, 230 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted,
251 base::Unretained(this), 231 base::Unretained(this),
252 base::Passed(&resource), 232 base::Passed(&resource),
253 id), 233 id),
254 lock)); 234 lock,
235 &empty));
255 } 236 }
256 237
257 const std::vector<RasterTaskResult>& completed_tasks() const { 238 const std::vector<RasterTaskResult>& completed_tasks() const {
258 return completed_tasks_; 239 return completed_tasks_;
259 } 240 }
260 241
261 private: 242 private:
262 void OnTaskCompleted(scoped_ptr<ScopedResource> resource, 243 void OnTaskCompleted(scoped_ptr<ScopedResource> resource,
263 unsigned id, 244 unsigned id,
264 const PicturePileImpl::Analysis& analysis, 245 const PicturePileImpl::Analysis& analysis,
(...skipping 13 matching lines...) Expand all
278 259
279 protected: 260 protected:
280 scoped_refptr<TestContextProvider> context_provider_; 261 scoped_refptr<TestContextProvider> context_provider_;
281 FakeOutputSurfaceClient output_surface_client_; 262 FakeOutputSurfaceClient output_surface_client_;
282 scoped_ptr<FakeOutputSurface> output_surface_; 263 scoped_ptr<FakeOutputSurface> output_surface_;
283 scoped_ptr<ResourceProvider> resource_provider_; 264 scoped_ptr<ResourceProvider> resource_provider_;
284 scoped_ptr<RasterWorkerPool> raster_worker_pool_; 265 scoped_ptr<RasterWorkerPool> raster_worker_pool_;
285 base::CancelableClosure timeout_; 266 base::CancelableClosure timeout_;
286 int timeout_seconds_; 267 int timeout_seconds_;
287 bool timed_out_; 268 bool timed_out_;
288 std::vector<RasterTask> tasks_; 269 RasterTaskVector tasks_;
289 std::vector<RasterTaskResult> completed_tasks_; 270 std::vector<RasterTaskResult> completed_tasks_;
290 }; 271 };
291 272
292 TEST_P(RasterWorkerPoolTest, Basic) { 273 TEST_P(RasterWorkerPoolTest, Basic) {
293 AppendTask(0u); 274 AppendTask(0u);
294 AppendTask(1u); 275 AppendTask(1u);
295 ScheduleTasks(); 276 ScheduleTasks();
296 277
297 RunMessageLoopUntilAllTasksHaveCompleted(); 278 RunMessageLoopUntilAllTasksHaveCompleted();
298 279
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 322 }
342 323
343 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, 324 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests,
344 RasterWorkerPoolTest, 325 RasterWorkerPoolTest,
345 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, 326 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER,
346 RASTER_WORKER_POOL_TYPE_IMAGE, 327 RASTER_WORKER_POOL_TYPE_IMAGE,
347 RASTER_WORKER_POOL_TYPE_DIRECT)); 328 RASTER_WORKER_POOL_TYPE_DIRECT));
348 329
349 } // namespace 330 } // namespace
350 } // namespace cc 331 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/raster_worker_pool_perftest.cc ('k') | cc/resources/tile_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698