OLD | NEW |
---|---|
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/resources/tile_manager.h" | 5 #include "cc/resources/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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 skia::RefPtr<SkPixelRef> pixel_ref_; | 238 skia::RefPtr<SkPixelRef> pixel_ref_; |
239 int layer_id_; | 239 int layer_id_; |
240 RenderingStatsInstrumentation* rendering_stats_; | 240 RenderingStatsInstrumentation* rendering_stats_; |
241 const base::Callback<void(bool was_canceled)> reply_; | 241 const base::Callback<void(bool was_canceled)> reply_; |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 243 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
244 }; | 244 }; |
245 | 245 |
246 const size_t kScheduledRasterTasksLimit = 32u; | 246 const size_t kScheduledRasterTasksLimit = 32u; |
247 | 247 |
248 // Memory limit policy works by mapping some bin states to the NEVER bin. | |
249 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | |
250 // [ALLOW_NOTHING] | |
251 {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
252 NEVER_BIN, // [NOW_BIN] | |
253 NEVER_BIN, // [SOON_BIN] | |
254 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
255 NEVER_BIN, // [EVENTUALLY_BIN] | |
256 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
257 NEVER_BIN, // [AT_LAST_BIN] | |
258 NEVER_BIN // [NEVER_BIN] | |
259 }, | |
260 // [ALLOW_ABSOLUTE_MINIMUM] | |
261 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
262 NOW_BIN, // [NOW_BIN] | |
263 NEVER_BIN, // [SOON_BIN] | |
264 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
265 NEVER_BIN, // [EVENTUALLY_BIN] | |
266 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
267 NEVER_BIN, // [AT_LAST_BIN] | |
268 NEVER_BIN // [NEVER_BIN] | |
269 }, | |
270 // [ALLOW_PREPAINT_ONLY] | |
271 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
272 NOW_BIN, // [NOW_BIN] | |
273 SOON_BIN, // [SOON_BIN] | |
274 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
275 NEVER_BIN, // [EVENTUALLY_BIN] | |
276 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
277 NEVER_BIN, // [AT_LAST_BIN] | |
278 NEVER_BIN // [NEVER_BIN] | |
279 }, | |
280 // [ALLOW_ANYTHING] | |
281 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
282 NOW_BIN, // [NOW_BIN] | |
283 SOON_BIN, // [SOON_BIN] | |
284 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
285 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
286 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
287 AT_LAST_BIN, // [AT_LAST_BIN] | |
288 NEVER_BIN // [NEVER_BIN] | |
289 }}; | |
290 | |
291 // Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN. | |
292 const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = { | |
293 // Not ready | |
294 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
295 NOW_BIN, // [NOW_BIN] | |
296 SOON_BIN, // [SOON_BIN] | |
297 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
298 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
299 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
300 AT_LAST_BIN, // [AT_LAST_BIN] | |
301 NEVER_BIN // [NEVER_BIN] | |
302 }, | |
303 // Ready | |
304 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
305 NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN] | |
306 SOON_BIN, // [SOON_BIN] | |
307 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
308 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
309 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
310 AT_LAST_BIN, // [AT_LAST_BIN] | |
311 NEVER_BIN // [NEVER_BIN] | |
312 }}; | |
313 | |
314 // Active works by mapping some bin stats to equivalent _ACTIVE_BIN state. | |
315 const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = { | |
316 // Inactive | |
317 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
318 NOW_BIN, // [NOW_BIN] | |
319 SOON_BIN, // [SOON_BIN] | |
320 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
321 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
322 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
323 AT_LAST_BIN, // [AT_LAST_BIN] | |
324 NEVER_BIN // [NEVER_BIN] | |
325 }, | |
326 // Active | |
327 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
328 NOW_BIN, // [NOW_BIN] | |
329 SOON_BIN, // [SOON_BIN] | |
330 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
331 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN] | |
332 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
333 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN] | |
334 NEVER_BIN // [NEVER_BIN] | |
335 }}; | |
336 | |
337 // Determine bin based on three categories of tiles: things we need now, | |
338 // things we need soon, and eventually. | |
339 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) { | |
340 if (prio.priority_bin == TilePriority::NOW) | |
341 return NOW_BIN; | |
342 | |
343 if (prio.priority_bin == TilePriority::SOON) | |
344 return SOON_BIN; | |
345 | |
346 if (prio.distance_to_visible == std::numeric_limits<float>::infinity()) | |
347 return NEVER_BIN; | |
348 | |
349 return EVENTUALLY_BIN; | |
350 } | |
351 | |
352 } // namespace | 248 } // namespace |
353 | 249 |
354 RasterTaskCompletionStats::RasterTaskCompletionStats() | 250 RasterTaskCompletionStats::RasterTaskCompletionStats() |
355 : completed_count(0u), canceled_count(0u) {} | 251 : completed_count(0u), canceled_count(0u) {} |
356 | 252 |
357 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 253 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
358 const RasterTaskCompletionStats& stats) { | 254 const RasterTaskCompletionStats& stats) { |
359 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 255 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
360 state->SetInteger("completed_count", stats.completed_count); | 256 state->SetInteger("completed_count", stats.completed_count); |
361 state->SetInteger("canceled_count", stats.canceled_count); | 257 state->SetInteger("canceled_count", stats.canceled_count); |
(...skipping 17 matching lines...) Expand all Loading... | |
379 TileManager::TileManager( | 275 TileManager::TileManager( |
380 TileManagerClient* client, | 276 TileManagerClient* client, |
381 base::SequencedTaskRunner* task_runner, | 277 base::SequencedTaskRunner* task_runner, |
382 ResourcePool* resource_pool, | 278 ResourcePool* resource_pool, |
383 Rasterizer* rasterizer, | 279 Rasterizer* rasterizer, |
384 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 280 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
385 : client_(client), | 281 : client_(client), |
386 task_runner_(task_runner), | 282 task_runner_(task_runner), |
387 resource_pool_(resource_pool), | 283 resource_pool_(resource_pool), |
388 rasterizer_(rasterizer), | 284 rasterizer_(rasterizer), |
389 prioritized_tiles_dirty_(false), | |
390 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 285 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
391 all_tiles_required_for_activation_have_memory_(true), | |
392 memory_required_bytes_(0), | |
393 memory_nice_to_have_bytes_(0), | |
394 bytes_releasable_(0), | 286 bytes_releasable_(0), |
395 resources_releasable_(0), | 287 resources_releasable_(0), |
288 bytes_required_but_not_allocated_(0), | |
396 ever_exceeded_memory_budget_(false), | 289 ever_exceeded_memory_budget_(false), |
397 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 290 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
398 did_initialize_visible_tile_(false), | 291 did_initialize_visible_tile_(false), |
399 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 292 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
400 check_if_ready_to_activate_pending_(false), | 293 check_if_ready_to_activate_pending_(false), |
401 weak_ptr_factory_(this) { | 294 weak_ptr_factory_(this) { |
402 rasterizer_->SetClient(this); | 295 rasterizer_->SetClient(this); |
403 } | 296 } |
404 | 297 |
405 TileManager::~TileManager() { | 298 TileManager::~TileManager() { |
(...skipping 18 matching lines...) Expand all Loading... | |
424 | 317 |
425 for (std::vector<PictureLayerImpl*>::iterator it = layers_.begin(); | 318 for (std::vector<PictureLayerImpl*>::iterator it = layers_.begin(); |
426 it != layers_.end(); | 319 it != layers_.end(); |
427 ++it) { | 320 ++it) { |
428 (*it)->DidUnregisterLayer(); | 321 (*it)->DidUnregisterLayer(); |
429 } | 322 } |
430 layers_.clear(); | 323 layers_.clear(); |
431 } | 324 } |
432 | 325 |
433 void TileManager::Release(Tile* tile) { | 326 void TileManager::Release(Tile* tile) { |
434 prioritized_tiles_dirty_ = true; | |
435 released_tiles_.push_back(tile); | 327 released_tiles_.push_back(tile); |
436 } | 328 } |
437 | 329 |
438 void TileManager::DidChangeTilePriority(Tile* tile) { | |
439 prioritized_tiles_dirty_ = true; | |
440 } | |
441 | |
442 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 330 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
443 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 331 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
444 } | 332 } |
445 | 333 |
446 void TileManager::CleanUpReleasedTiles() { | 334 void TileManager::CleanUpReleasedTiles() { |
447 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 335 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); |
448 it != released_tiles_.end(); | 336 it != released_tiles_.end(); |
449 ++it) { | 337 ++it) { |
450 Tile* tile = *it; | 338 Tile* tile = *it; |
451 ManagedTileState& mts = tile->managed_state(); | 339 ManagedTileState& mts = tile->managed_state(); |
(...skipping 13 matching lines...) Expand all Loading... | |
465 used_layer_counts_.erase(layer_it); | 353 used_layer_counts_.erase(layer_it); |
466 image_decode_tasks_.erase(tile->layer_id()); | 354 image_decode_tasks_.erase(tile->layer_id()); |
467 } | 355 } |
468 | 356 |
469 delete tile; | 357 delete tile; |
470 } | 358 } |
471 | 359 |
472 released_tiles_.clear(); | 360 released_tiles_.clear(); |
473 } | 361 } |
474 | 362 |
475 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | |
476 if (!prioritized_tiles_dirty_) | |
477 return; | |
478 | |
479 CleanUpReleasedTiles(); | |
480 | |
481 prioritized_tiles_.Clear(); | |
482 GetTilesWithAssignedBins(&prioritized_tiles_); | |
483 prioritized_tiles_dirty_ = false; | |
484 } | |
485 | |
486 void TileManager::DidFinishRunningTasks() { | 363 void TileManager::DidFinishRunningTasks() { |
487 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); | 364 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
488 | 365 |
489 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > | 366 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
490 global_state_.soft_memory_limit_in_bytes; | 367 global_state_.soft_memory_limit_in_bytes; |
491 | 368 |
492 // When OOM, keep re-assigning memory until we reach a steady state | 369 // When OOM, keep re-assigning memory until we reach a steady state |
493 // where top-priority tiles are initialized. | 370 // where top-priority tiles are initialized. |
494 if (all_tiles_that_need_to_be_rasterized_have_memory_ && | 371 if (all_tiles_that_need_to_be_rasterized_have_memory_ && |
495 !memory_usage_above_limit) | 372 !memory_usage_above_limit) |
496 return; | 373 return; |
497 | 374 |
498 rasterizer_->CheckForCompletedTasks(); | 375 rasterizer_->CheckForCompletedTasks(); |
499 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 376 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
500 | 377 |
501 TileVector tiles_that_need_to_be_rasterized; | 378 TileVector tiles_that_need_to_be_rasterized; |
502 AssignGpuMemoryToTiles(&prioritized_tiles_, | 379 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
503 &tiles_that_need_to_be_rasterized); | |
504 | 380 |
505 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 381 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
506 // steady memory state. Keep scheduling tasks until we reach this state. | 382 // steady memory state. Keep scheduling tasks until we reach this state. |
507 if (!tiles_that_need_to_be_rasterized.empty()) { | 383 if (!tiles_that_need_to_be_rasterized.empty()) { |
508 ScheduleTasks(tiles_that_need_to_be_rasterized); | 384 ScheduleTasks(tiles_that_need_to_be_rasterized); |
509 return; | 385 return; |
510 } | 386 } |
511 | 387 |
512 resource_pool_->ReduceResourceUsage(); | 388 resource_pool_->ReduceResourceUsage(); |
513 | 389 |
(...skipping 20 matching lines...) Expand all Loading... | |
534 tile_version.set_rasterize_on_demand(); | 410 tile_version.set_rasterize_on_demand(); |
535 client_->NotifyTileStateChanged(tile); | 411 client_->NotifyTileStateChanged(tile); |
536 } | 412 } |
537 } | 413 } |
538 | 414 |
539 DCHECK(IsReadyToActivate()); | 415 DCHECK(IsReadyToActivate()); |
540 ScheduleCheckIfReadyToActivate(); | 416 ScheduleCheckIfReadyToActivate(); |
541 } | 417 } |
542 | 418 |
543 void TileManager::DidFinishRunningTasksRequiredForActivation() { | 419 void TileManager::DidFinishRunningTasksRequiredForActivation() { |
544 // This is only a true indication that all tiles required for | 420 // TODO(vmpstr): Since we don't know if we have scheduled all the tiles, the |
545 // activation are initialized when no tiles are OOM. We need to | 421 // safest thing to do is schedule a check for activation immediately. In case |
546 // wait for DidFinishRunningTasks() to be called, try to re-assign | 422 // some tiles were not scheduled, this will not do anything. Try and optimize |
547 // memory and in worst case use on-demand raster when tiles | 423 // this to avoid checks in situations where we already know it will fail. |
548 // required for activation are OOM. | |
549 if (!all_tiles_required_for_activation_have_memory_) | |
550 return; | |
551 | |
552 ScheduleCheckIfReadyToActivate(); | 424 ScheduleCheckIfReadyToActivate(); |
553 } | 425 } |
554 | 426 |
555 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | |
556 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | |
557 | |
558 // Compute new stats to be return by GetMemoryStats(). | |
559 memory_required_bytes_ = 0; | |
560 memory_nice_to_have_bytes_ = 0; | |
561 | |
562 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | |
563 const TreePriority tree_priority = global_state_.tree_priority; | |
564 | |
565 // For each tree, bin into different categories of tiles. | |
566 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
567 Tile* tile = it->second; | |
568 ManagedTileState& mts = tile->managed_state(); | |
569 | |
570 const ManagedTileState::TileVersion& tile_version = | |
571 tile->GetTileVersionForDrawing(); | |
572 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | |
573 bool tile_is_active = tile_is_ready_to_draw || | |
574 mts.tile_versions[mts.raster_mode].raster_task_; | |
575 | |
576 // Get the active priority and bin. | |
577 TilePriority active_priority = tile->priority(ACTIVE_TREE); | |
578 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | |
579 | |
580 // Get the pending priority and bin. | |
581 TilePriority pending_priority = tile->priority(PENDING_TREE); | |
582 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | |
583 | |
584 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | |
585 bool pending_is_non_ideal = | |
586 pending_priority.resolution == NON_IDEAL_RESOLUTION; | |
587 bool active_is_non_ideal = | |
588 active_priority.resolution == NON_IDEAL_RESOLUTION; | |
589 | |
590 // Adjust bin state based on if ready to draw. | |
591 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; | |
592 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; | |
593 | |
594 // Adjust bin state based on if active. | |
595 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; | |
596 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; | |
597 | |
598 // We never want to paint new non-ideal tiles, as we always have | |
599 // a high-res tile covering that content (paint that instead). | |
600 if (!tile_is_ready_to_draw && active_is_non_ideal) | |
601 active_bin = NEVER_BIN; | |
602 if (!tile_is_ready_to_draw && pending_is_non_ideal) | |
603 pending_bin = NEVER_BIN; | |
604 | |
605 if (!tile_is_ready_to_draw || tile_version.requires_resource()) { | |
606 // The bin that the tile would have if the GPU memory manager had | |
607 // a maximally permissive policy, send to the GPU memory manager | |
608 // to determine policy. | |
609 ManagedTileBin gpu_memmgr_stats_bin = std::min(active_bin, pending_bin); | |
610 if ((gpu_memmgr_stats_bin == NOW_BIN) || | |
611 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) | |
612 memory_required_bytes_ += BytesConsumedIfAllocated(tile); | |
613 if (gpu_memmgr_stats_bin != NEVER_BIN) | |
614 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); | |
615 } | |
616 | |
617 ManagedTileBin tree_bin[NUM_TREES]; | |
618 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; | |
619 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; | |
620 | |
621 // Adjust pending bin state for low res tiles. This prevents pending tree | |
622 // low-res tiles from being initialized before high-res tiles. | |
623 if (pending_is_low_res) | |
624 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); | |
625 | |
626 TilePriority tile_priority; | |
627 switch (tree_priority) { | |
628 case SAME_PRIORITY_FOR_BOTH_TREES: | |
629 mts.bin = std::min(tree_bin[ACTIVE_TREE], tree_bin[PENDING_TREE]); | |
630 tile_priority = tile->combined_priority(); | |
631 break; | |
632 case SMOOTHNESS_TAKES_PRIORITY: | |
633 mts.bin = tree_bin[ACTIVE_TREE]; | |
634 tile_priority = active_priority; | |
635 break; | |
636 case NEW_CONTENT_TAKES_PRIORITY: | |
637 mts.bin = tree_bin[PENDING_TREE]; | |
638 tile_priority = pending_priority; | |
639 break; | |
640 } | |
641 | |
642 // Bump up the priority if we determined it's NEVER_BIN on one tree, | |
643 // but is still required on the other tree. | |
644 bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN && | |
645 tree_bin[PENDING_TREE] == NEVER_BIN; | |
646 | |
647 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) | |
648 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
649 | |
650 mts.resolution = tile_priority.resolution; | |
651 mts.priority_bin = tile_priority.priority_bin; | |
652 mts.distance_to_visible = tile_priority.distance_to_visible; | |
653 mts.required_for_activation = tile_priority.required_for_activation; | |
654 | |
655 mts.visible_and_ready_to_draw = | |
656 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | |
657 | |
658 // Tiles that are required for activation shouldn't be in NEVER_BIN unless | |
659 // smoothness takes priority or memory policy allows nothing to be | |
660 // initialized. | |
661 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || | |
662 tree_priority == SMOOTHNESS_TAKES_PRIORITY || | |
663 memory_policy == ALLOW_NOTHING); | |
664 | |
665 // If the tile is in NEVER_BIN and it does not have an active task, then we | |
666 // can release the resources early. If it does have the task however, we | |
667 // should keep it in the prioritized tile set to ensure that AssignGpuMemory | |
668 // can visit it. | |
669 if (mts.bin == NEVER_BIN && | |
670 !mts.tile_versions[mts.raster_mode].raster_task_) { | |
671 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
672 continue; | |
673 } | |
674 | |
675 // Insert the tile into a priority set. | |
676 tiles->InsertTile(tile, mts.bin); | |
677 } | |
678 } | |
679 | |
680 void TileManager::CleanUpLayers() { | 427 void TileManager::CleanUpLayers() { |
681 for (size_t i = 0; i < layers_.size(); ++i) { | 428 for (size_t i = 0; i < layers_.size(); ++i) { |
682 if (layers_[i]->IsDrawnRenderSurfaceLayerListMember()) | 429 if (layers_[i]->IsDrawnRenderSurfaceLayerListMember()) |
683 continue; | 430 continue; |
684 | 431 |
685 layers_[i]->DidUnregisterLayer(); | 432 layers_[i]->DidUnregisterLayer(); |
686 std::swap(layers_[i], layers_.back()); | 433 std::swap(layers_[i], layers_.back()); |
687 layers_.pop_back(); | 434 layers_.pop_back(); |
688 --i; | 435 --i; |
689 prioritized_tiles_dirty_ = true; | |
690 } | 436 } |
691 } | 437 } |
692 | 438 |
693 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 439 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
694 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 440 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
695 | 441 |
696 // Update internal state. | 442 // Update internal state. |
697 if (state != global_state_) { | 443 global_state_ = state; |
698 global_state_ = state; | |
699 prioritized_tiles_dirty_ = true; | |
700 } | |
701 | 444 |
702 CleanUpLayers(); | 445 CleanUpLayers(); |
703 | 446 |
447 // TODO(vmpstr): See if we still need to keep tiles alive when layers release | |
448 // them. | |
449 CleanUpReleasedTiles(); | |
450 | |
704 // We need to call CheckForCompletedTasks() once in-between each call | 451 // We need to call CheckForCompletedTasks() once in-between each call |
705 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 452 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
706 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 453 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
707 rasterizer_->CheckForCompletedTasks(); | 454 rasterizer_->CheckForCompletedTasks(); |
708 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 455 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
709 } | 456 } |
710 | 457 |
711 UpdatePrioritizedTileSetIfNeeded(); | |
712 | |
713 TileVector tiles_that_need_to_be_rasterized; | 458 TileVector tiles_that_need_to_be_rasterized; |
714 AssignGpuMemoryToTiles(&prioritized_tiles_, | 459 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
715 &tiles_that_need_to_be_rasterized); | |
716 | 460 |
717 // Finally, schedule rasterizer tasks. | 461 // Finally, schedule rasterizer tasks. |
718 ScheduleTasks(tiles_that_need_to_be_rasterized); | 462 ScheduleTasks(tiles_that_need_to_be_rasterized); |
719 | 463 |
720 TRACE_EVENT_INSTANT1("cc", | 464 TRACE_EVENT_INSTANT1("cc", |
721 "DidManage", | 465 "DidManage", |
722 TRACE_EVENT_SCOPE_THREAD, | 466 TRACE_EVENT_SCOPE_THREAD, |
723 "state", | 467 "state", |
724 TracedValue::FromValue(BasicStateAsValue().release())); | 468 TracedValue::FromValue(BasicStateAsValue().release())); |
725 | 469 |
(...skipping 21 matching lines...) Expand all Loading... | |
747 | 491 |
748 bool did_initialize_visible_tile = did_initialize_visible_tile_; | 492 bool did_initialize_visible_tile = did_initialize_visible_tile_; |
749 did_initialize_visible_tile_ = false; | 493 did_initialize_visible_tile_ = false; |
750 return did_initialize_visible_tile; | 494 return did_initialize_visible_tile; |
751 } | 495 } |
752 | 496 |
753 void TileManager::GetMemoryStats(size_t* memory_required_bytes, | 497 void TileManager::GetMemoryStats(size_t* memory_required_bytes, |
754 size_t* memory_nice_to_have_bytes, | 498 size_t* memory_nice_to_have_bytes, |
755 size_t* memory_allocated_bytes, | 499 size_t* memory_allocated_bytes, |
756 size_t* memory_used_bytes) const { | 500 size_t* memory_used_bytes) const { |
757 *memory_required_bytes = memory_required_bytes_; | 501 *memory_required_bytes = resource_pool_->total_memory_usage_bytes() + |
758 *memory_nice_to_have_bytes = memory_nice_to_have_bytes_; | 502 bytes_required_but_not_allocated_; |
503 *memory_nice_to_have_bytes = resource_pool_->total_memory_usage_bytes() + | |
504 bytes_required_but_not_allocated_; | |
759 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); | 505 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); |
760 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); | 506 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); |
761 } | 507 } |
762 | 508 |
763 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { | 509 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { |
764 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 510 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
765 state->SetInteger("tile_count", tiles_.size()); | 511 state->SetInteger("tile_count", tiles_.size()); |
766 state->Set("global_state", global_state_.AsValue().release()); | 512 state->Set("global_state", global_state_.AsValue().release()); |
767 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | 513 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); |
768 return state.PassAs<base::Value>(); | 514 return state.PassAs<base::Value>(); |
(...skipping 19 matching lines...) Expand all Loading... | |
788 &memory_allocated_bytes, | 534 &memory_allocated_bytes, |
789 &memory_used_bytes); | 535 &memory_used_bytes); |
790 requirements->SetInteger("memory_required_bytes", memory_required_bytes); | 536 requirements->SetInteger("memory_required_bytes", memory_required_bytes); |
791 requirements->SetInteger("memory_nice_to_have_bytes", | 537 requirements->SetInteger("memory_nice_to_have_bytes", |
792 memory_nice_to_have_bytes); | 538 memory_nice_to_have_bytes); |
793 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); | 539 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); |
794 requirements->SetInteger("memory_used_bytes", memory_used_bytes); | 540 requirements->SetInteger("memory_used_bytes", memory_used_bytes); |
795 return requirements.PassAs<base::Value>(); | 541 return requirements.PassAs<base::Value>(); |
796 } | 542 } |
797 | 543 |
544 bool TileManager::FreeTileResourcesUntilUsageIsWithinBudget( | |
545 EvictionTileIterator* eviction_iterator, | |
546 const MemoryBudget& required_budget, | |
547 MemoryBudget* current_budget, | |
548 const TilePriority& max_priority, | |
549 bool evict_unconditionally) { | |
550 bool evicted_tiles_required_for_activation = false; | |
551 while (required_budget.Exceeds(*current_budget)) { | |
552 if (!*eviction_iterator) | |
553 break; | |
554 | |
555 Tile* eviction_tile = **eviction_iterator; | |
556 DCHECK(eviction_tile); | |
557 | |
558 TilePriority eviction_priority = | |
559 eviction_tile->priority_for_tree_priority(global_state_.tree_priority); | |
560 | |
561 if (!evict_unconditionally && | |
562 !max_priority.IsHigherPriorityThan(eviction_priority)) | |
563 break; | |
564 | |
565 size_t eviction_bytes_if_allocated = | |
566 BytesConsumedIfAllocated(eviction_tile); | |
567 ManagedTileState& eviction_mts = eviction_tile->managed_state(); | |
568 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | |
569 if (eviction_mts.tile_versions[mode].resource_) { | |
570 current_budget->hard_memory_bytes += eviction_bytes_if_allocated; | |
571 if (eviction_priority.priority_bin != TilePriority::NOW) | |
572 current_budget->soft_memory_bytes += eviction_bytes_if_allocated; | |
573 current_budget->resource_count++; | |
574 } | |
575 } | |
576 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(eviction_tile); | |
577 ++(*eviction_iterator); | |
578 | |
579 evicted_tiles_required_for_activation |= | |
580 eviction_tile->required_for_activation(); | |
581 } | |
582 return evicted_tiles_required_for_activation; | |
583 } | |
584 | |
585 bool TileManager::TilePriorityViolatesMemoryPolicy( | |
586 const TilePriority& priority) { | |
587 switch (global_state_.memory_limit_policy) { | |
588 case ALLOW_NOTHING: | |
589 return true; | |
590 case ALLOW_ABSOLUTE_MINIMUM: | |
591 return priority.priority_bin > TilePriority::NOW; | |
592 case ALLOW_PREPAINT_ONLY: | |
593 return priority.priority_bin > TilePriority::SOON; | |
594 case ALLOW_ANYTHING: | |
595 return priority.distance_to_visible == | |
596 std::numeric_limits<float>::infinity(); | |
597 case NUM_TILE_MEMORY_LIMIT_POLICIES: | |
598 NOTREACHED(); | |
599 break; | |
600 } | |
601 return true; | |
602 } | |
603 | |
798 void TileManager::AssignGpuMemoryToTiles( | 604 void TileManager::AssignGpuMemoryToTiles( |
799 PrioritizedTileSet* tiles, | |
800 TileVector* tiles_that_need_to_be_rasterized) { | 605 TileVector* tiles_that_need_to_be_rasterized) { |
801 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 606 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
802 | 607 |
803 // Maintain the list of released resources that can potentially be re-used | 608 // Maintain the list of released resources that can potentially be re-used |
804 // or deleted. | 609 // or deleted. |
805 // If this operation becomes expensive too, only do this after some | 610 // If this operation becomes expensive too, only do this after some |
806 // resource(s) was returned. Note that in that case, one also need to | 611 // resource(s) was returned. Note that in that case, one also need to |
807 // invalidate when releasing some resource from the pool. | 612 // invalidate when releasing some resource from the pool. |
808 resource_pool_->CheckBusyResources(); | 613 resource_pool_->CheckBusyResources(); |
809 | 614 |
810 // Now give memory out to the tiles until we're out, and build | 615 // Now give memory out to the tiles until we're out, and build |
811 // the needs-to-be-rasterized queue. | 616 // the needs-to-be-rasterized queue. |
812 all_tiles_that_need_to_be_rasterized_have_memory_ = true; | 617 all_tiles_that_need_to_be_rasterized_have_memory_ = true; |
813 all_tiles_required_for_activation_have_memory_ = true; | |
814 | 618 |
619 MemoryBudget budget; | |
815 // Cast to prevent overflow. | 620 // Cast to prevent overflow. |
816 int64 soft_bytes_available = | 621 budget.soft_memory_bytes = |
817 static_cast<int64>(bytes_releasable_) + | |
818 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - | 622 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - |
819 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 623 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
820 int64 hard_bytes_available = | 624 budget.hard_memory_bytes = |
821 static_cast<int64>(bytes_releasable_) + | |
822 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - | 625 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - |
823 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 626 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
824 int resources_available = resources_releasable_ + | 627 budget.resource_count = global_state_.num_resources_limit - |
825 global_state_.num_resources_limit - | 628 resource_pool_->acquired_resource_count(); |
826 resource_pool_->acquired_resource_count(); | 629 |
827 size_t soft_bytes_allocatable = | 630 MemoryBudget initial_budget = budget; |
828 std::max(static_cast<int64>(0), soft_bytes_available); | 631 |
829 size_t hard_bytes_allocatable = | 632 EvictionTileIterator eviction_it(this, global_state_.tree_priority); |
830 std::max(static_cast<int64>(0), hard_bytes_available); | 633 |
831 size_t resources_allocatable = std::max(0, resources_available); | 634 MemoryBudget required_budget; |
635 required_budget.soft_memory_bytes = 0; | |
636 required_budget.hard_memory_bytes = 0; | |
637 required_budget.resource_count = 0; | |
638 | |
639 bool evicted_tiles_required_for_activation = | |
640 FreeTileResourcesUntilUsageIsWithinBudget( | |
641 &eviction_it, required_budget, &budget, TilePriority(), true); | |
832 | 642 |
833 size_t bytes_that_exceeded_memory_budget = 0; | 643 size_t bytes_that_exceeded_memory_budget = 0; |
834 size_t soft_bytes_left = soft_bytes_allocatable; | |
835 size_t hard_bytes_left = hard_bytes_allocatable; | |
836 | 644 |
837 size_t resources_left = resources_allocatable; | |
838 bool oomed_soft = false; | 645 bool oomed_soft = false; |
839 bool oomed_hard = false; | 646 bool oomed_hard = false; |
840 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 647 bool have_hit_soft_memory = false; // Soft memory comes after hard. |
841 | 648 |
842 unsigned schedule_priority = 1u; | 649 unsigned schedule_priority = 1u; |
843 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 650 RasterTileIterator it(this, global_state_.tree_priority); |
651 for (; it; ++it) { | |
844 Tile* tile = *it; | 652 Tile* tile = *it; |
653 TilePriority priority = | |
654 tile->priority_for_tree_priority(global_state_.tree_priority); | |
655 | |
656 if (TilePriorityViolatesMemoryPolicy(priority)) | |
657 break; | |
658 | |
845 ManagedTileState& mts = tile->managed_state(); | 659 ManagedTileState& mts = tile->managed_state(); |
846 | 660 |
847 mts.scheduled_priority = schedule_priority++; | 661 mts.scheduled_priority = schedule_priority++; |
848 | 662 |
849 mts.raster_mode = tile->DetermineOverallRasterMode(); | 663 mts.raster_mode = tile->DetermineOverallRasterMode(); |
850 | 664 |
851 ManagedTileState::TileVersion& tile_version = | 665 ManagedTileState::TileVersion& tile_version = |
852 mts.tile_versions[mts.raster_mode]; | 666 mts.tile_versions[mts.raster_mode]; |
853 | 667 |
854 // If this tile doesn't need a resource, then nothing to do. | 668 // If this tile version is ready to draw, then nothing to do. |
855 if (!tile_version.requires_resource()) | 669 if (tile_version.IsReadyToDraw()) |
856 continue; | 670 continue; |
857 | 671 |
858 // If the tile is not needed, free it up. | 672 const bool tile_uses_hard_limit = |
859 if (mts.bin == NEVER_BIN) { | 673 priority.priority_bin == TilePriority::NOW; |
860 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
861 continue; | |
862 } | |
863 | |
864 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | |
865 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | 674 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
866 const size_t tile_bytes_left = | |
867 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | |
868 | 675 |
869 // Hard-limit is reserved for tiles that would cause a calamity | 676 // Hard-limit is reserved for tiles that would cause a calamity |
870 // if they were to go away, so by definition they are the highest | 677 // if they were to go away, so by definition they are the highest |
871 // priority memory, and must be at the front of the list. | 678 // priority memory, and must be at the front of the list. |
872 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 679 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
873 have_hit_soft_memory |= !tile_uses_hard_limit; | 680 have_hit_soft_memory |= !tile_uses_hard_limit; |
874 | 681 |
875 size_t tile_bytes = 0; | 682 int64 tile_bytes = 0; |
876 size_t tile_resources = 0; | 683 int tile_resources = 0; |
877 | 684 |
878 // It costs to maintain a resource. | 685 // It costs to maintain a resource. |
879 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 686 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
880 if (mts.tile_versions[mode].resource_) { | 687 if (mts.tile_versions[mode].resource_) { |
881 tile_bytes += bytes_if_allocated; | 688 tile_bytes += bytes_if_allocated; |
882 tile_resources++; | 689 tile_resources++; |
883 } | 690 } |
884 } | 691 } |
885 | 692 |
886 // Allow lower priority tiles with initialized resources to keep | 693 // If we don't have the required version, and it's not in flight |
887 // their memory by only assigning memory to new raster tasks if | 694 // then we'll have to pay to create a new task. |
888 // they can be scheduled. | 695 if (!tile_version.resource_ && !tile_version.raster_task_) { |
889 bool reached_scheduled_raster_tasks_limit = | 696 tile_bytes += bytes_if_allocated; |
890 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; | 697 tile_resources++; |
891 if (!reached_scheduled_raster_tasks_limit) { | |
892 // If we don't have the required version, and it's not in flight | |
893 // then we'll have to pay to create a new task. | |
894 if (!tile_version.resource_ && !tile_version.raster_task_) { | |
895 tile_bytes += bytes_if_allocated; | |
896 tile_resources++; | |
897 } | |
898 } | 698 } |
899 | 699 |
900 // Tile is OOM. | 700 required_budget.soft_memory_bytes = 0; |
901 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 701 required_budget.hard_memory_bytes = 0; |
902 bool was_ready_to_draw = tile->IsReadyToDraw(); | 702 required_budget.resource_count = tile_resources; |
703 if (tile_uses_hard_limit) | |
704 required_budget.hard_memory_bytes = tile_bytes; | |
705 else | |
706 required_budget.soft_memory_bytes = tile_bytes; | |
903 | 707 |
904 FreeResourcesForTile(tile); | 708 // Handle OOM tiles. |
709 evicted_tiles_required_for_activation = | |
710 FreeTileResourcesUntilUsageIsWithinBudget( | |
711 &eviction_it, required_budget, &budget, priority, false) || | |
712 evicted_tiles_required_for_activation; | |
713 | |
714 // Tile is still OOM. | |
715 if (required_budget.Exceeds(budget)) { | |
716 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
905 | 717 |
906 // This tile was already on screen and now its resources have been | 718 // This tile was already on screen and now its resources have been |
907 // released. In order to prevent checkerboarding, set this tile as | 719 // released. In order to prevent checkerboarding, set this tile as |
908 // rasterize on demand immediately. | 720 // rasterize on demand immediately. |
909 if (mts.visible_and_ready_to_draw) | 721 if (mts.visible_and_ready_to_draw) |
910 tile_version.set_rasterize_on_demand(); | 722 tile_version.set_rasterize_on_demand(); |
911 | 723 |
912 if (was_ready_to_draw) | |
913 client_->NotifyTileStateChanged(tile); | |
914 | |
915 oomed_soft = true; | 724 oomed_soft = true; |
916 if (tile_uses_hard_limit) { | 725 if (tile_uses_hard_limit) { |
917 oomed_hard = true; | 726 oomed_hard = true; |
918 bytes_that_exceeded_memory_budget += tile_bytes; | 727 bytes_that_exceeded_memory_budget += tile_bytes; |
919 } | 728 } |
920 } else { | 729 } else { |
921 resources_left -= tile_resources; | 730 budget.resource_count -= tile_resources; |
922 hard_bytes_left -= tile_bytes; | 731 budget.hard_memory_bytes -= tile_bytes; |
923 soft_bytes_left = | 732 budget.soft_memory_bytes = (budget.soft_memory_bytes > tile_bytes) |
924 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; | 733 ? budget.soft_memory_bytes - tile_bytes |
734 : 0; | |
925 if (tile_version.resource_) | 735 if (tile_version.resource_) |
926 continue; | 736 continue; |
927 } | 737 } |
928 | 738 |
929 DCHECK(!tile_version.resource_); | 739 DCHECK(!tile_version.resource_); |
930 | 740 |
931 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| | 741 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| |
932 // has reached it's limit or we've failed to assign gpu memory to this | 742 // has reached it's limit or we've failed to assign gpu memory to this |
933 // or any higher priority tile. Preventing tiles that fit into memory | 743 // or any higher priority tile. Preventing tiles that fit into memory |
934 // budget to be rasterized when higher priority tile is oom is | 744 // budget to be rasterized when higher priority tile is oom is |
935 // important for two reasons: | 745 // important for two reasons: |
936 // 1. Tile size should not impact raster priority. | 746 // 1. Tile size should not impact raster priority. |
937 // 2. Tiles with existing raster task could otherwise incorrectly | 747 // 2. Tiles with existing raster task could otherwise incorrectly |
938 // be added as they are not affected by |bytes_allocatable|. | 748 // be added as they are not affected by |bytes_allocatable|. |
939 bool can_schedule_tile = | 749 bool can_schedule_tile = |
940 !oomed_soft && !reached_scheduled_raster_tasks_limit; | 750 !oomed_soft && |
751 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; | |
941 | 752 |
942 if (!can_schedule_tile) { | 753 if (!can_schedule_tile) { |
943 all_tiles_that_need_to_be_rasterized_have_memory_ = false; | 754 all_tiles_that_need_to_be_rasterized_have_memory_ = false; |
944 if (tile->required_for_activation()) | 755 break; |
945 all_tiles_required_for_activation_have_memory_ = false; | |
946 it.DisablePriorityOrdering(); | |
947 continue; | |
948 } | 756 } |
949 | 757 |
950 tiles_that_need_to_be_rasterized->push_back(tile); | 758 tiles_that_need_to_be_rasterized->push_back(tile); |
951 } | 759 } |
952 | 760 |
761 // Count up the memory that would be required on top of the allocated memory | |
762 // in order to initialize all visible tiles. | |
763 bytes_required_but_not_allocated_ = 0; | |
764 for (; it; ++it) { | |
765 Tile* tile = *it; | |
766 TilePriority priority = | |
767 tile->priority_for_tree_priority(global_state_.tree_priority); | |
768 | |
769 if (TilePriorityViolatesMemoryPolicy(priority) || | |
770 priority.priority_bin != TilePriority::NOW) | |
771 break; | |
772 | |
773 ManagedTileState& mts = tile->managed_state(); | |
774 mts.raster_mode = tile->DetermineOverallRasterMode(); | |
775 | |
776 ManagedTileState::TileVersion& tile_version = | |
777 mts.tile_versions[mts.raster_mode]; | |
778 | |
779 // If this tile version is ready to draw, then nothing to do. | |
780 if (tile_version.IsReadyToDraw()) | |
781 continue; | |
782 | |
783 bytes_required_but_not_allocated_ += BytesConsumedIfAllocated(tile); | |
784 } | |
785 | |
953 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. | 786 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. |
954 ever_exceeded_memory_budget_ |= oomed_hard; | 787 ever_exceeded_memory_budget_ |= oomed_hard; |
955 if (ever_exceeded_memory_budget_) { | 788 if (ever_exceeded_memory_budget_) { |
956 TRACE_COUNTER_ID2("cc", | 789 TRACE_COUNTER_ID2("cc", |
957 "over_memory_budget", | 790 "over_memory_budget", |
958 this, | 791 this, |
959 "budget", | 792 "budget", |
960 global_state_.hard_memory_limit_in_bytes, | 793 global_state_.hard_memory_limit_in_bytes, |
961 "over", | 794 "over", |
962 bytes_that_exceeded_memory_budget); | 795 bytes_that_exceeded_memory_budget); |
963 } | 796 } |
964 memory_stats_from_last_assign_.total_budget_in_bytes = | 797 memory_stats_from_last_assign_.total_budget_in_bytes = |
965 global_state_.hard_memory_limit_in_bytes; | 798 global_state_.hard_memory_limit_in_bytes; |
966 memory_stats_from_last_assign_.bytes_allocated = | 799 memory_stats_from_last_assign_.bytes_allocated = |
967 hard_bytes_allocatable - hard_bytes_left; | 800 initial_budget.hard_memory_bytes - budget.hard_memory_bytes; |
968 memory_stats_from_last_assign_.bytes_unreleasable = | 801 memory_stats_from_last_assign_.bytes_unreleasable = |
969 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; | 802 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; |
970 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; | 803 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; |
971 } | 804 } |
972 | 805 |
973 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { | 806 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { |
974 ManagedTileState& mts = tile->managed_state(); | 807 ManagedTileState& mts = tile->managed_state(); |
975 if (mts.tile_versions[mode].resource_) { | 808 if (mts.tile_versions[mode].resource_) { |
976 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); | 809 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); |
977 | 810 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 content_rect, | 1060 content_rect, |
1228 opaque_rect, | 1061 opaque_rect, |
1229 contents_scale, | 1062 contents_scale, |
1230 layer_id, | 1063 layer_id, |
1231 source_frame_number, | 1064 source_frame_number, |
1232 flags)); | 1065 flags)); |
1233 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 1066 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
1234 | 1067 |
1235 tiles_[tile->id()] = tile; | 1068 tiles_[tile->id()] = tile; |
1236 used_layer_counts_[tile->layer_id()]++; | 1069 used_layer_counts_[tile->layer_id()]++; |
1237 prioritized_tiles_dirty_ = true; | |
1238 return tile; | 1070 return tile; |
1239 } | 1071 } |
1240 | 1072 |
1241 void TileManager::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | 1073 void TileManager::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
1242 DCHECK(std::find(layers_.begin(), layers_.end(), layer) == layers_.end()); | 1074 DCHECK(std::find(layers_.begin(), layers_.end(), layer) == layers_.end()); |
1243 layers_.push_back(layer); | 1075 layers_.push_back(layer); |
1244 } | 1076 } |
1245 | 1077 |
1246 void TileManager::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 1078 void TileManager::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
1247 std::vector<PictureLayerImpl*>::iterator it = | 1079 std::vector<PictureLayerImpl*>::iterator it = |
(...skipping 14 matching lines...) Expand all Loading... | |
1262 PictureLayerImpl* layer = *it; | 1094 PictureLayerImpl* layer = *it; |
1263 | 1095 |
1264 // This is a recycle tree layer, we can safely skip since the tiles on this | 1096 // This is a recycle tree layer, we can safely skip since the tiles on this |
1265 // layer have to be accessible via the active tree. | 1097 // layer have to be accessible via the active tree. |
1266 if (!layer->IsOnActiveOrPendingTree()) | 1098 if (!layer->IsOnActiveOrPendingTree()) |
1267 continue; | 1099 continue; |
1268 | 1100 |
1269 PictureLayerImpl* twin_layer = layer->GetTwinLayer(); | 1101 PictureLayerImpl* twin_layer = layer->GetTwinLayer(); |
1270 | 1102 |
1271 // If the twin layer is recycled, it is not a valid twin. | 1103 // If the twin layer is recycled, it is not a valid twin. |
1272 if (twin_layer && !twin_layer->IsOnActiveOrPendingTree()) | 1104 // Note another case twin is not valid is if it wasn't yet registered in |
1105 // this tile manager. This can happen at the start of a new page when we | |
1106 // only update the pending tree's priority after the first commit. | |
1107 if (twin_layer && (!twin_layer->IsOnActiveOrPendingTree() || | |
1108 !twin_layer->LayerRegisteredInTileManager())) { | |
1273 twin_layer = NULL; | 1109 twin_layer = NULL; |
1110 } | |
1274 | 1111 |
1275 PairedPictureLayer paired_layer; | 1112 PairedPictureLayer paired_layer; |
1276 WhichTree tree = layer->GetTree(); | 1113 WhichTree tree = layer->GetTree(); |
1277 | 1114 |
1278 // If the current tree is ACTIVE_TREE, then always generate a paired_layer. | 1115 // If the current tree is ACTIVE_TREE, then always generate a paired_layer. |
1279 // If current tree is PENDING_TREE, then only generate a paired_layer if | 1116 // If current tree is PENDING_TREE, then only generate a paired_layer if |
1280 // there is no twin layer. | 1117 // there is no twin layer. |
1281 if (tree == ACTIVE_TREE) { | 1118 if (tree == ACTIVE_TREE) { |
1282 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE); | 1119 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE); |
1283 paired_layer.active_layer = layer; | 1120 paired_layer.active_layer = layer; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1458 | 1295 |
1459 Tile* a_tile = **a_pair.first; | 1296 Tile* a_tile = **a_pair.first; |
1460 Tile* b_tile = **b_pair.first; | 1297 Tile* b_tile = **b_pair.first; |
1461 | 1298 |
1462 const TilePriority& a_priority = | 1299 const TilePriority& a_priority = |
1463 a_tile->priority_for_tree_priority(tree_priority_); | 1300 a_tile->priority_for_tree_priority(tree_priority_); |
1464 const TilePriority& b_priority = | 1301 const TilePriority& b_priority = |
1465 b_tile->priority_for_tree_priority(tree_priority_); | 1302 b_tile->priority_for_tree_priority(tree_priority_); |
1466 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | 1303 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
1467 | 1304 |
1468 if (b_priority.resolution != a_priority.resolution) { | 1305 if (b_priority.priority_bin == a_priority.priority_bin && |
reveman
2014/06/02 14:45:27
Can we move all iterator related changes into a se
| |
1306 b_priority.resolution != a_priority.resolution) { | |
1469 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || | 1307 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
1470 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || | 1308 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
1471 (a_priority.resolution == NON_IDEAL_RESOLUTION); | 1309 (a_priority.resolution == NON_IDEAL_RESOLUTION); |
1472 } | 1310 } |
1473 | 1311 |
1474 return b_priority.IsHigherPriorityThan(a_priority); | 1312 return b_priority.IsHigherPriorityThan(a_priority); |
1475 } | 1313 } |
1476 | 1314 |
1477 TileManager::EvictionTileIterator::EvictionTileIterator() | 1315 TileManager::EvictionTileIterator::EvictionTileIterator() |
1478 : comparator_(SAME_PRIORITY_FOR_BOTH_TREES) {} | 1316 : initialized_(true), |
1317 tile_manager_(NULL), | |
1318 comparator_(SAME_PRIORITY_FOR_BOTH_TREES) { | |
1319 } | |
1479 | 1320 |
1480 TileManager::EvictionTileIterator::EvictionTileIterator( | 1321 TileManager::EvictionTileIterator::EvictionTileIterator( |
1481 TileManager* tile_manager, | 1322 TileManager* tile_manager, |
1482 TreePriority tree_priority) | 1323 TreePriority tree_priority) |
1483 : tree_priority_(tree_priority), comparator_(tree_priority) { | 1324 : initialized_(false), |
1325 tile_manager_(tile_manager), | |
1326 tree_priority_(tree_priority), | |
1327 comparator_(tree_priority) { | |
1328 } | |
1329 | |
1330 void TileManager::EvictionTileIterator::Initialize() { | |
1484 std::vector<TileManager::PairedPictureLayer> paired_layers; | 1331 std::vector<TileManager::PairedPictureLayer> paired_layers; |
1485 | 1332 |
1486 tile_manager->GetPairedPictureLayers(&paired_layers); | 1333 tile_manager_->GetPairedPictureLayers(&paired_layers); |
1487 | 1334 |
1488 paired_iterators_.reserve(paired_layers.size()); | 1335 paired_iterators_.reserve(paired_layers.size()); |
1489 iterator_heap_.reserve(paired_layers.size()); | 1336 iterator_heap_.reserve(paired_layers.size()); |
1490 for (std::vector<TileManager::PairedPictureLayer>::iterator it = | 1337 for (std::vector<TileManager::PairedPictureLayer>::iterator it = |
1491 paired_layers.begin(); | 1338 paired_layers.begin(); |
1492 it != paired_layers.end(); | 1339 it != paired_layers.end(); |
1493 ++it) { | 1340 ++it) { |
1494 PairedPictureLayerIterator paired_iterator; | 1341 PairedPictureLayerIterator paired_iterator; |
1495 if (it->active_layer) { | 1342 if (it->active_layer) { |
1496 paired_iterator.active_iterator = | 1343 paired_iterator.active_iterator = |
1497 PictureLayerImpl::LayerEvictionTileIterator(it->active_layer, | 1344 PictureLayerImpl::LayerEvictionTileIterator(it->active_layer, |
1498 tree_priority_); | 1345 tree_priority_); |
1499 } | 1346 } |
1500 | 1347 |
1501 if (it->pending_layer) { | 1348 if (it->pending_layer) { |
1502 paired_iterator.pending_iterator = | 1349 paired_iterator.pending_iterator = |
1503 PictureLayerImpl::LayerEvictionTileIterator(it->pending_layer, | 1350 PictureLayerImpl::LayerEvictionTileIterator(it->pending_layer, |
1504 tree_priority_); | 1351 tree_priority_); |
1505 } | 1352 } |
1506 | 1353 |
1507 if (paired_iterator.PeekTile(tree_priority_) != NULL) { | 1354 if (paired_iterator.PeekTile(tree_priority_) != NULL) { |
1508 paired_iterators_.push_back(paired_iterator); | 1355 paired_iterators_.push_back(paired_iterator); |
1509 iterator_heap_.push_back(&paired_iterators_.back()); | 1356 iterator_heap_.push_back(&paired_iterators_.back()); |
1510 } | 1357 } |
1511 } | 1358 } |
1512 | 1359 |
1513 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | 1360 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); |
1361 initialized_ = true; | |
1514 } | 1362 } |
1515 | 1363 |
1516 TileManager::EvictionTileIterator::~EvictionTileIterator() {} | 1364 TileManager::EvictionTileIterator::~EvictionTileIterator() {} |
1517 | 1365 |
1518 TileManager::EvictionTileIterator& TileManager::EvictionTileIterator:: | 1366 TileManager::EvictionTileIterator& TileManager::EvictionTileIterator:: |
1519 operator++() { | 1367 operator++() { |
1368 DCHECK(initialized_); | |
1369 | |
1520 std::pop_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | 1370 std::pop_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); |
1521 PairedPictureLayerIterator* paired_iterator = iterator_heap_.back(); | 1371 PairedPictureLayerIterator* paired_iterator = iterator_heap_.back(); |
1522 iterator_heap_.pop_back(); | 1372 iterator_heap_.pop_back(); |
1523 | 1373 |
1524 paired_iterator->PopTile(tree_priority_); | 1374 paired_iterator->PopTile(tree_priority_); |
1525 if (paired_iterator->PeekTile(tree_priority_) != NULL) { | 1375 if (paired_iterator->PeekTile(tree_priority_) != NULL) { |
1526 iterator_heap_.push_back(paired_iterator); | 1376 iterator_heap_.push_back(paired_iterator); |
1527 std::push_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | 1377 std::push_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); |
1528 } | 1378 } |
1529 return *this; | 1379 return *this; |
1530 } | 1380 } |
1531 | 1381 |
1532 TileManager::EvictionTileIterator::operator bool() const { | 1382 TileManager::EvictionTileIterator::operator bool() { |
1383 if (!initialized_) | |
1384 Initialize(); | |
1385 | |
1533 return !iterator_heap_.empty(); | 1386 return !iterator_heap_.empty(); |
1534 } | 1387 } |
1535 | 1388 |
1536 Tile* TileManager::EvictionTileIterator::operator*() { | 1389 Tile* TileManager::EvictionTileIterator::operator*() { |
1390 DCHECK(initialized_); | |
1537 DCHECK(*this); | 1391 DCHECK(*this); |
1538 return iterator_heap_.front()->PeekTile(tree_priority_); | 1392 return iterator_heap_.front()->PeekTile(tree_priority_); |
1539 } | 1393 } |
1540 | 1394 |
1541 TileManager::EvictionTileIterator::PairedPictureLayerIterator:: | 1395 TileManager::EvictionTileIterator::PairedPictureLayerIterator:: |
1542 PairedPictureLayerIterator() {} | 1396 PairedPictureLayerIterator() {} |
1543 | 1397 |
1544 TileManager::EvictionTileIterator::PairedPictureLayerIterator:: | 1398 TileManager::EvictionTileIterator::PairedPictureLayerIterator:: |
1545 ~PairedPictureLayerIterator() {} | 1399 ~PairedPictureLayerIterator() {} |
1546 | 1400 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 check_if_ready_to_activate_pending_ = false; | 1526 check_if_ready_to_activate_pending_ = false; |
1673 | 1527 |
1674 rasterizer_->CheckForCompletedTasks(); | 1528 rasterizer_->CheckForCompletedTasks(); |
1675 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1529 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
1676 | 1530 |
1677 if (IsReadyToActivate()) | 1531 if (IsReadyToActivate()) |
1678 client_->NotifyReadyToActivate(); | 1532 client_->NotifyReadyToActivate(); |
1679 } | 1533 } |
1680 | 1534 |
1681 } // namespace cc | 1535 } // namespace cc |
OLD | NEW |