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

Side by Side Diff: cc/tiles/tile_manager.cc

Issue 1210073020: Reland (2): cc: Make tile manager object persist for the length of LTHI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/trees/layer_tree_host_impl.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/tile_manager.h" 5 #include "cc/tiles/tile_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 base::saturated_cast<int>(stats.completed_count)); 221 base::saturated_cast<int>(stats.completed_count));
222 state->SetInteger("canceled_count", 222 state->SetInteger("canceled_count",
223 base::saturated_cast<int>(stats.canceled_count)); 223 base::saturated_cast<int>(stats.canceled_count));
224 return state; 224 return state;
225 } 225 }
226 226
227 // static 227 // static
228 scoped_ptr<TileManager> TileManager::Create( 228 scoped_ptr<TileManager> TileManager::Create(
229 TileManagerClient* client, 229 TileManagerClient* client,
230 base::SequencedTaskRunner* task_runner, 230 base::SequencedTaskRunner* task_runner,
231 ResourcePool* resource_pool,
232 TileTaskRunner* tile_task_runner,
233 size_t scheduled_raster_task_limit) { 231 size_t scheduled_raster_task_limit) {
234 return make_scoped_ptr(new TileManager(client, task_runner, resource_pool, 232 return make_scoped_ptr(
235 tile_task_runner, 233 new TileManager(client, task_runner, scheduled_raster_task_limit));
236 scheduled_raster_task_limit));
237 } 234 }
238 235
239 TileManager::TileManager( 236 TileManager::TileManager(
240 TileManagerClient* client, 237 TileManagerClient* client,
241 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 238 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
242 ResourcePool* resource_pool,
243 TileTaskRunner* tile_task_runner,
244 size_t scheduled_raster_task_limit) 239 size_t scheduled_raster_task_limit)
245 : client_(client), 240 : client_(client),
246 task_runner_(task_runner), 241 task_runner_(task_runner),
247 resource_pool_(resource_pool), 242 resource_pool_(nullptr),
248 tile_task_runner_(tile_task_runner), 243 tile_task_runner_(nullptr),
249 scheduled_raster_task_limit_(scheduled_raster_task_limit), 244 scheduled_raster_task_limit_(scheduled_raster_task_limit),
250 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), 245 all_tiles_that_need_to_be_rasterized_are_scheduled_(true),
251 did_check_for_completed_tasks_since_last_schedule_tasks_(true), 246 did_check_for_completed_tasks_since_last_schedule_tasks_(true),
252 did_oom_on_last_assign_(false), 247 did_oom_on_last_assign_(false),
253 more_tiles_need_prepare_check_notifier_( 248 more_tiles_need_prepare_check_notifier_(
254 task_runner_.get(), 249 task_runner_.get(),
255 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, 250 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared,
256 base::Unretained(this))), 251 base::Unretained(this))),
257 signals_check_notifier_(task_runner_.get(), 252 signals_check_notifier_(task_runner_.get(),
258 base::Bind(&TileManager::CheckAndIssueSignals, 253 base::Bind(&TileManager::CheckAndIssueSignals,
259 base::Unretained(this))), 254 base::Unretained(this))),
260 has_scheduled_tile_tasks_(false), 255 has_scheduled_tile_tasks_(false),
261 prepare_tiles_count_(0u) { 256 prepare_tiles_count_(0u) {
262 tile_task_runner_->SetClient(this);
263 } 257 }
264 258
265 TileManager::~TileManager() { 259 TileManager::~TileManager() {
266 // Reset global state and manage. This should cause 260 FinishTasksAndCleanUp();
267 // our memory usage to drop to zero. 261 }
262
263 void TileManager::FinishTasksAndCleanUp() {
264 if (!tile_task_runner_)
265 return;
266
268 global_state_ = GlobalStateThatImpactsTilePriority(); 267 global_state_ = GlobalStateThatImpactsTilePriority();
269 268
270 TileTaskQueue empty; 269 TileTaskQueue empty;
271 tile_task_runner_->ScheduleTasks(&empty); 270 tile_task_runner_->ScheduleTasks(&empty);
272 orphan_raster_tasks_.clear(); 271 orphan_raster_tasks_.clear();
273 272
274 // This should finish all pending tasks and release any uninitialized 273 // This should finish all pending tasks and release any uninitialized
275 // resources. 274 // resources.
276 tile_task_runner_->Shutdown(); 275 tile_task_runner_->Shutdown();
277 tile_task_runner_->CheckForCompletedTasks(); 276 tile_task_runner_->CheckForCompletedTasks();
278 277
279 FreeResourcesForReleasedTiles(); 278 FreeResourcesForReleasedTiles();
280 CleanUpReleasedTiles(); 279 CleanUpReleasedTiles();
280
281 tile_task_runner_ = nullptr;
282 resource_pool_ = nullptr;
283 more_tiles_need_prepare_check_notifier_.Cancel();
284 signals_check_notifier_.Cancel();
285 }
286
287 void TileManager::SetResources(ResourcePool* resource_pool,
288 TileTaskRunner* tile_task_runner,
289 size_t scheduled_raster_task_limit) {
290 DCHECK(!tile_task_runner_);
291 DCHECK(tile_task_runner);
292
293 scheduled_raster_task_limit_ = scheduled_raster_task_limit;
294 resource_pool_ = resource_pool;
295 tile_task_runner_ = tile_task_runner;
296 tile_task_runner_->SetClient(this);
281 } 297 }
282 298
283 void TileManager::Release(Tile* tile) { 299 void TileManager::Release(Tile* tile) {
284 released_tiles_.push_back(tile); 300 released_tiles_.push_back(tile);
285 } 301 }
286 302
287 TaskSetCollection TileManager::TasksThatShouldBeForcedToComplete() const { 303 TaskSetCollection TileManager::TasksThatShouldBeForcedToComplete() const {
288 TaskSetCollection tasks_that_should_be_forced_to_complete; 304 TaskSetCollection tasks_that_should_be_forced_to_complete;
289 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) 305 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY)
290 tasks_that_should_be_forced_to_complete[REQUIRED_FOR_ACTIVATION] = true; 306 tasks_that_should_be_forced_to_complete[REQUIRED_FOR_ACTIVATION] = true;
(...skipping 26 matching lines...) Expand all
317 } 333 }
318 334
319 delete tile; 335 delete tile;
320 } 336 }
321 released_tiles_.swap(tiles_to_retain); 337 released_tiles_.swap(tiles_to_retain);
322 } 338 }
323 339
324 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { 340 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) {
325 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", 341 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set",
326 TaskSetName(task_set)); 342 TaskSetName(task_set));
343 DCHECK(resource_pool_);
344 DCHECK(tile_task_runner_);
327 345
328 switch (task_set) { 346 switch (task_set) {
329 case ALL: { 347 case ALL: {
330 has_scheduled_tile_tasks_ = false; 348 has_scheduled_tile_tasks_ = false;
331 349
332 bool memory_usage_above_limit = 350 bool memory_usage_above_limit =
333 resource_pool_->total_memory_usage_bytes() > 351 resource_pool_->total_memory_usage_bytes() >
334 global_state_.soft_memory_limit_in_bytes; 352 global_state_.soft_memory_limit_in_bytes;
335 353
336 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && 354 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ &&
(...skipping 16 matching lines...) Expand all
353 371
354 case REQUIRED_FOR_DRAW: 372 case REQUIRED_FOR_DRAW:
355 signals_.ready_to_draw = true; 373 signals_.ready_to_draw = true;
356 signals_check_notifier_.Schedule(); 374 signals_check_notifier_.Schedule();
357 return; 375 return;
358 } 376 }
359 377
360 NOTREACHED(); 378 NOTREACHED();
361 } 379 }
362 380
363 void TileManager::PrepareTiles( 381 bool TileManager::PrepareTiles(
364 const GlobalStateThatImpactsTilePriority& state) { 382 const GlobalStateThatImpactsTilePriority& state) {
365 ++prepare_tiles_count_; 383 ++prepare_tiles_count_;
366 384
367 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", 385 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id",
368 prepare_tiles_count_); 386 prepare_tiles_count_);
369 387
388 if (!tile_task_runner_) {
389 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted",
390 TRACE_EVENT_SCOPE_THREAD);
391 return false;
392 }
393
370 signals_.reset(); 394 signals_.reset();
371 global_state_ = state; 395 global_state_ = state;
372 396
373 // We need to call CheckForCompletedTasks() once in-between each call 397 // We need to call CheckForCompletedTasks() once in-between each call
374 // to ScheduleTasks() to prevent canceled tasks from being scheduled. 398 // to ScheduleTasks() to prevent canceled tasks from being scheduled.
375 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { 399 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) {
376 tile_task_runner_->CheckForCompletedTasks(); 400 tile_task_runner_->CheckForCompletedTasks();
377 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 401 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
378 } 402 }
379 403
(...skipping 16 matching lines...) Expand all
396 420
397 // Schedule tile tasks. 421 // Schedule tile tasks.
398 ScheduleTasks(tiles_that_need_to_be_rasterized); 422 ScheduleTasks(tiles_that_need_to_be_rasterized);
399 423
400 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, 424 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD,
401 "state", BasicStateAsValue()); 425 "state", BasicStateAsValue());
402 426
403 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, 427 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this,
404 resource_pool_->total_memory_usage_bytes() - 428 resource_pool_->total_memory_usage_bytes() -
405 resource_pool_->acquired_memory_usage_bytes()); 429 resource_pool_->acquired_memory_usage_bytes());
430 return true;
406 } 431 }
407 432
408 void TileManager::Flush() { 433 void TileManager::Flush() {
409 TRACE_EVENT0("cc", "TileManager::Flush"); 434 TRACE_EVENT0("cc", "TileManager::Flush");
410 435
436 if (!tile_task_runner_) {
437 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD);
438 return;
439 }
440
411 tile_task_runner_->CheckForCompletedTasks(); 441 tile_task_runner_->CheckForCompletedTasks();
412 442
413 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 443 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
414 444
415 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats", 445 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats",
416 RasterTaskCompletionStatsAsValue(flush_stats_)); 446 RasterTaskCompletionStatsAsValue(flush_stats_));
417 flush_stats_ = RasterTaskCompletionStats(); 447 flush_stats_ = RasterTaskCompletionStats();
418 } 448 }
419 449
420 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 450 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 NOTREACHED(); 527 NOTREACHED();
498 return true; 528 return true;
499 } 529 }
500 530
501 void TileManager::AssignGpuMemoryToTiles( 531 void TileManager::AssignGpuMemoryToTiles(
502 RasterTilePriorityQueue* raster_priority_queue, 532 RasterTilePriorityQueue* raster_priority_queue,
503 size_t scheduled_raster_task_limit, 533 size_t scheduled_raster_task_limit,
504 PrioritizedTileVector* tiles_that_need_to_be_rasterized) { 534 PrioritizedTileVector* tiles_that_need_to_be_rasterized) {
505 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); 535 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles");
506 536
537 DCHECK(resource_pool_);
538 DCHECK(tile_task_runner_);
539
507 // Maintain the list of released resources that can potentially be re-used 540 // Maintain the list of released resources that can potentially be re-used
508 // or deleted. If this operation becomes expensive too, only do this after 541 // or deleted. If this operation becomes expensive too, only do this after
509 // some resource(s) was returned. Note that in that case, one also need to 542 // some resource(s) was returned. Note that in that case, one also need to
510 // invalidate when releasing some resource from the pool. 543 // invalidate when releasing some resource from the pool.
511 resource_pool_->CheckBusyResources(false); 544 resource_pool_->CheckBusyResources(false);
512 545
513 // Now give memory out to the tiles until we're out, and build 546 // Now give memory out to the tiles until we're out, and build
514 // the needs-to-be-rasterized queue. 547 // the needs-to-be-rasterized queue.
515 unsigned schedule_priority = 1u; 548 unsigned schedule_priority = 1u;
516 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; 549 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 847
815 client_->NotifyTileStateChanged(tile); 848 client_->NotifyTileStateChanged(tile);
816 } 849 }
817 850
818 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, 851 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size,
819 const gfx::Rect& content_rect, 852 const gfx::Rect& content_rect,
820 float contents_scale, 853 float contents_scale,
821 int layer_id, 854 int layer_id,
822 int source_frame_number, 855 int source_frame_number,
823 int flags) { 856 int flags) {
857 // We need to have a tile task worker pool to do anything meaningful with
858 // tiles.
859 DCHECK(tile_task_runner_);
824 ScopedTilePtr tile(new Tile(this, desired_texture_size, content_rect, 860 ScopedTilePtr tile(new Tile(this, desired_texture_size, content_rect,
825 contents_scale, layer_id, source_frame_number, 861 contents_scale, layer_id, source_frame_number,
826 flags)); 862 flags));
827 DCHECK(tiles_.find(tile->id()) == tiles_.end()); 863 DCHECK(tiles_.find(tile->id()) == tiles_.end());
828 864
829 tiles_[tile->id()] = tile.get(); 865 tiles_[tile->id()] = tile.get();
830 used_layer_counts_[tile->layer_id()]++; 866 used_layer_counts_[tile->layer_id()]++;
831 return tile; 867 return tile;
832 } 868 }
833 869
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 void TileManager::Signals::reset() { 1093 void TileManager::Signals::reset() {
1058 ready_to_activate = false; 1094 ready_to_activate = false;
1059 did_notify_ready_to_activate = false; 1095 did_notify_ready_to_activate = false;
1060 ready_to_draw = false; 1096 ready_to_draw = false;
1061 did_notify_ready_to_draw = false; 1097 did_notify_ready_to_draw = false;
1062 all_tile_tasks_completed = false; 1098 all_tile_tasks_completed = false;
1063 did_notify_all_tile_tasks_completed = false; 1099 did_notify_all_tile_tasks_completed = false;
1064 } 1100 }
1065 1101
1066 } // namespace cc 1102 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698