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

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

Issue 489293002: cc: Don't infinitely throttle large raster tasks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 struct RasterTaskResult { 100 struct RasterTaskResult {
101 unsigned id; 101 unsigned id;
102 bool canceled; 102 bool canceled;
103 }; 103 };
104 104
105 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector; 105 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector;
106 106
107 RasterWorkerPoolTest() 107 RasterWorkerPoolTest()
108 : context_provider_(TestContextProvider::Create()), 108 : context_provider_(TestContextProvider::Create()),
109 timeout_seconds_(5), 109 timeout_seconds_(5),
110 throttle_bytes_(10000),
110 timed_out_(false) { 111 timed_out_(false) {
111 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); 112 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
112 CHECK(output_surface_->BindToClient(&output_surface_client_)); 113 CHECK(output_surface_->BindToClient(&output_surface_client_));
113 114
114 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); 115 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
115 resource_provider_ = 116 resource_provider_ =
116 ResourceProvider::Create( 117 ResourceProvider::Create(
117 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, 118 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1,
118 false).Pass(); 119 false).Pass();
119 staging_resource_pool_ = ResourcePool::Create( 120 staging_resource_pool_ = ResourcePool::Create(
120 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); 121 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888);
121 122
122 switch (GetParam()) { 123 switch (GetParam()) {
123 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: 124 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER:
124 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( 125 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create(
125 base::MessageLoopProxy::current().get(), 126 base::MessageLoopProxy::current().get(),
126 RasterWorkerPool::GetTaskGraphRunner(), 127 RasterWorkerPool::GetTaskGraphRunner(),
127 context_provider_.get(), 128 context_provider_.get(),
128 resource_provider_.get(), 129 resource_provider_.get(),
129 std::numeric_limits<size_t>::max()); 130 throttle_bytes_);
130 break; 131 break;
131 case RASTER_WORKER_POOL_TYPE_IMAGE: 132 case RASTER_WORKER_POOL_TYPE_IMAGE:
132 raster_worker_pool_ = ImageRasterWorkerPool::Create( 133 raster_worker_pool_ = ImageRasterWorkerPool::Create(
133 base::MessageLoopProxy::current().get(), 134 base::MessageLoopProxy::current().get(),
134 RasterWorkerPool::GetTaskGraphRunner(), 135 RasterWorkerPool::GetTaskGraphRunner(),
135 resource_provider_.get()); 136 resource_provider_.get());
136 break; 137 break;
137 case RASTER_WORKER_POOL_TYPE_IMAGE_COPY: 138 case RASTER_WORKER_POOL_TYPE_IMAGE_COPY:
138 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create( 139 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create(
139 base::MessageLoopProxy::current().get(), 140 base::MessageLoopProxy::current().get(),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 RasterTaskQueue queue; 197 RasterTaskQueue queue;
197 198
198 for (RasterTaskVector::const_iterator it = tasks_.begin(); 199 for (RasterTaskVector::const_iterator it = tasks_.begin();
199 it != tasks_.end(); 200 it != tasks_.end();
200 ++it) 201 ++it)
201 queue.items.push_back(RasterTaskQueue::Item(*it, false)); 202 queue.items.push_back(RasterTaskQueue::Item(*it, false));
202 203
203 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue); 204 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue);
204 } 205 }
205 206
206 void AppendTask(unsigned id) { 207 void AppendTask(unsigned id, gfx::Size size) {
reveman 2014/08/21 01:15:47 nit: const gfx::Size& size
enne (OOO) 2014/08/21 01:34:15 Done.
207 const gfx::Size size(1, 1);
208
209 scoped_ptr<ScopedResource> resource( 208 scoped_ptr<ScopedResource> resource(
210 ScopedResource::Create(resource_provider_.get())); 209 ScopedResource::Create(resource_provider_.get()));
211 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); 210 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
212 const Resource* const_resource = resource.get(); 211 const Resource* const_resource = resource.get();
213 212
214 ImageDecodeTask::Vector empty; 213 ImageDecodeTask::Vector empty;
215 tasks_.push_back(new TestRasterTaskImpl( 214 tasks_.push_back(new TestRasterTaskImpl(
216 const_resource, 215 const_resource,
217 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted, 216 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted,
218 base::Unretained(this), 217 base::Unretained(this),
219 base::Passed(&resource), 218 base::Passed(&resource),
220 id), 219 id),
221 &empty)); 220 &empty));
222 } 221 }
223 222
223 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); }
224
224 void AppendBlockingTask(unsigned id, base::Lock* lock) { 225 void AppendBlockingTask(unsigned id, base::Lock* lock) {
225 const gfx::Size size(1, 1); 226 const gfx::Size size(1, 1);
226 227
227 scoped_ptr<ScopedResource> resource( 228 scoped_ptr<ScopedResource> resource(
228 ScopedResource::Create(resource_provider_.get())); 229 ScopedResource::Create(resource_provider_.get()));
229 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); 230 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
230 const Resource* const_resource = resource.get(); 231 const Resource* const_resource = resource.get();
231 232
232 ImageDecodeTask::Vector empty; 233 ImageDecodeTask::Vector empty;
233 tasks_.push_back(new BlockingTestRasterTaskImpl( 234 tasks_.push_back(new BlockingTestRasterTaskImpl(
(...skipping 29 matching lines...) Expand all
263 protected: 264 protected:
264 scoped_refptr<TestContextProvider> context_provider_; 265 scoped_refptr<TestContextProvider> context_provider_;
265 FakeOutputSurfaceClient output_surface_client_; 266 FakeOutputSurfaceClient output_surface_client_;
266 scoped_ptr<FakeOutputSurface> output_surface_; 267 scoped_ptr<FakeOutputSurface> output_surface_;
267 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; 268 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
268 scoped_ptr<ResourceProvider> resource_provider_; 269 scoped_ptr<ResourceProvider> resource_provider_;
269 scoped_ptr<ResourcePool> staging_resource_pool_; 270 scoped_ptr<ResourcePool> staging_resource_pool_;
270 scoped_ptr<RasterWorkerPool> raster_worker_pool_; 271 scoped_ptr<RasterWorkerPool> raster_worker_pool_;
271 base::CancelableClosure timeout_; 272 base::CancelableClosure timeout_;
272 int timeout_seconds_; 273 int timeout_seconds_;
274 size_t throttle_bytes_;
reveman 2014/08/21 01:15:47 nit: max_transfer_buffer_usage_bytes_ as from this
enne (OOO) 2014/08/21 01:34:16 Done.
273 bool timed_out_; 275 bool timed_out_;
274 RasterTaskVector tasks_; 276 RasterTaskVector tasks_;
275 std::vector<RasterTaskResult> completed_tasks_; 277 std::vector<RasterTaskResult> completed_tasks_;
276 }; 278 };
277 279
278 TEST_P(RasterWorkerPoolTest, Basic) { 280 TEST_P(RasterWorkerPoolTest, Basic) {
279 AppendTask(0u); 281 AppendTask(0u);
280 AppendTask(1u); 282 AppendTask(1u);
281 ScheduleTasks(); 283 ScheduleTasks();
282 284
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 RunMessageLoopUntilAllTasksHaveCompleted(); 326 RunMessageLoopUntilAllTasksHaveCompleted();
325 } 327 }
326 328
327 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, 329 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests,
328 RasterWorkerPoolTest, 330 RasterWorkerPoolTest,
329 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, 331 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER,
330 RASTER_WORKER_POOL_TYPE_IMAGE, 332 RASTER_WORKER_POOL_TYPE_IMAGE,
331 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, 333 RASTER_WORKER_POOL_TYPE_IMAGE_COPY,
332 RASTER_WORKER_POOL_TYPE_GPU)); 334 RASTER_WORKER_POOL_TYPE_GPU));
333 335
336 class PixelBufferRasterWorkerPoolTest : public RasterWorkerPoolTest {};
337
338 TEST_P(PixelBufferRasterWorkerPoolTest, BigTaskThrottling) {
reveman 2014/08/21 01:15:47 How about we call this LargeResources and run it f
enne (OOO) 2014/08/21 01:34:15 Done.
339 gfx::Size size(1000, 1000);
340
341 {
342 // Verify a resource of this size will get throttled.
reveman 2014/08/21 01:15:47 are we missing a "not" here? Maybe just "Verify a
enne (OOO) 2014/08/21 01:34:16 No, but maybe it should be "could get throttled".
343 scoped_ptr<ScopedResource> resource(
344 ScopedResource::Create(resource_provider_.get()));
345 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
346 EXPECT_GE(resource->bytes(), throttle_bytes_);
reveman 2014/08/21 01:15:47 Could you instead compute |size| based on kMaxTran
enne (OOO) 2014/08/21 01:34:15 That's why there's the block of code right here, t
347 }
348
349 AppendTask(0u, size);
350 AppendTask(1u, size);
351 AppendTask(2u, size);
352 ScheduleTasks();
353
354 // This will time out if a resource that is larger than the throttle limit
355 // never gets scheduled.
356 RunMessageLoopUntilAllTasksHaveCompleted();
357 }
358
359 INSTANTIATE_TEST_CASE_P(
360 PixelBufferRasterWorkerPoolTests,
361 PixelBufferRasterWorkerPoolTest,
362 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER));
363
334 } // namespace 364 } // namespace
335 } // namespace cc 365 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698