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

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

Issue 367833003: cc: Start using raster/eviction iterators. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + fix Created 6 years, 3 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/tile_manager.h ('k') | cc/resources/tile_manager_unittest.cc » ('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/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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 skia::RefPtr<SkPixelRef> pixel_ref_; 218 skia::RefPtr<SkPixelRef> pixel_ref_;
219 int layer_id_; 219 int layer_id_;
220 RenderingStatsInstrumentation* rendering_stats_; 220 RenderingStatsInstrumentation* rendering_stats_;
221 const base::Callback<void(bool was_canceled)> reply_; 221 const base::Callback<void(bool was_canceled)> reply_;
222 222
223 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); 223 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl);
224 }; 224 };
225 225
226 const size_t kScheduledRasterTasksLimit = 32u; 226 const size_t kScheduledRasterTasksLimit = 32u;
227 227
228 // Memory limit policy works by mapping some bin states to the NEVER bin.
229 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = {
230 // [ALLOW_NOTHING]
231 {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
232 NEVER_BIN, // [NOW_BIN]
233 NEVER_BIN, // [SOON_BIN]
234 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
235 NEVER_BIN, // [EVENTUALLY_BIN]
236 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN]
237 NEVER_BIN, // [AT_LAST_BIN]
238 NEVER_BIN // [NEVER_BIN]
239 },
240 // [ALLOW_ABSOLUTE_MINIMUM]
241 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
242 NOW_BIN, // [NOW_BIN]
243 NEVER_BIN, // [SOON_BIN]
244 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
245 NEVER_BIN, // [EVENTUALLY_BIN]
246 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN]
247 NEVER_BIN, // [AT_LAST_BIN]
248 NEVER_BIN // [NEVER_BIN]
249 },
250 // [ALLOW_PREPAINT_ONLY]
251 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
252 NOW_BIN, // [NOW_BIN]
253 SOON_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_ANYTHING]
261 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
262 NOW_BIN, // [NOW_BIN]
263 SOON_BIN, // [SOON_BIN]
264 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
265 EVENTUALLY_BIN, // [EVENTUALLY_BIN]
266 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN]
267 AT_LAST_BIN, // [AT_LAST_BIN]
268 NEVER_BIN // [NEVER_BIN]
269 }};
270
271 // Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN.
272 const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = {
273 // Not ready
274 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
275 NOW_BIN, // [NOW_BIN]
276 SOON_BIN, // [SOON_BIN]
277 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
278 EVENTUALLY_BIN, // [EVENTUALLY_BIN]
279 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN]
280 AT_LAST_BIN, // [AT_LAST_BIN]
281 NEVER_BIN // [NEVER_BIN]
282 },
283 // Ready
284 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
285 NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN]
286 SOON_BIN, // [SOON_BIN]
287 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
288 EVENTUALLY_BIN, // [EVENTUALLY_BIN]
289 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN]
290 AT_LAST_BIN, // [AT_LAST_BIN]
291 NEVER_BIN // [NEVER_BIN]
292 }};
293
294 // Active works by mapping some bin stats to equivalent _ACTIVE_BIN state.
295 const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = {
296 // Inactive
297 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
298 NOW_BIN, // [NOW_BIN]
299 SOON_BIN, // [SOON_BIN]
300 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
301 EVENTUALLY_BIN, // [EVENTUALLY_BIN]
302 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN]
303 AT_LAST_BIN, // [AT_LAST_BIN]
304 NEVER_BIN // [NEVER_BIN]
305 },
306 // Active
307 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
308 NOW_BIN, // [NOW_BIN]
309 SOON_BIN, // [SOON_BIN]
310 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
311 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN]
312 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN]
313 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN]
314 NEVER_BIN // [NEVER_BIN]
315 }};
316
317 // Determine bin based on three categories of tiles: things we need now,
318 // things we need soon, and eventually.
319 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) {
320 if (prio.priority_bin == TilePriority::NOW)
321 return NOW_BIN;
322
323 if (prio.priority_bin == TilePriority::SOON)
324 return SOON_BIN;
325
326 if (prio.distance_to_visible == std::numeric_limits<float>::infinity())
327 return NEVER_BIN;
328
329 return EVENTUALLY_BIN;
330 }
331
332 } // namespace 228 } // namespace
333 229
334 RasterTaskCompletionStats::RasterTaskCompletionStats() 230 RasterTaskCompletionStats::RasterTaskCompletionStats()
335 : completed_count(0u), canceled_count(0u) {} 231 : completed_count(0u), canceled_count(0u) {}
336 232
337 scoped_refptr<base::debug::ConvertableToTraceFormat> 233 scoped_refptr<base::debug::ConvertableToTraceFormat>
338 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) { 234 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) {
339 scoped_refptr<base::debug::TracedValue> state = 235 scoped_refptr<base::debug::TracedValue> state =
340 new base::debug::TracedValue(); 236 new base::debug::TracedValue();
341 state->SetInteger("completed_count", stats.completed_count); 237 state->SetInteger("completed_count", stats.completed_count);
(...skipping 18 matching lines...) Expand all
360 TileManager::TileManager( 256 TileManager::TileManager(
361 TileManagerClient* client, 257 TileManagerClient* client,
362 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 258 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
363 ResourcePool* resource_pool, 259 ResourcePool* resource_pool,
364 Rasterizer* rasterizer, 260 Rasterizer* rasterizer,
365 RenderingStatsInstrumentation* rendering_stats_instrumentation) 261 RenderingStatsInstrumentation* rendering_stats_instrumentation)
366 : client_(client), 262 : client_(client),
367 task_runner_(task_runner), 263 task_runner_(task_runner),
368 resource_pool_(resource_pool), 264 resource_pool_(resource_pool),
369 rasterizer_(rasterizer), 265 rasterizer_(rasterizer),
370 prioritized_tiles_dirty_(false), 266 all_tiles_that_need_to_be_rasterized_are_scheduled_(true),
371 all_tiles_that_need_to_be_rasterized_have_memory_(true),
372 all_tiles_required_for_activation_have_memory_(true),
373 bytes_releasable_(0),
374 resources_releasable_(0),
375 ever_exceeded_memory_budget_(false),
376 rendering_stats_instrumentation_(rendering_stats_instrumentation), 267 rendering_stats_instrumentation_(rendering_stats_instrumentation),
377 did_initialize_visible_tile_(false), 268 did_initialize_visible_tile_(false),
378 did_check_for_completed_tasks_since_last_schedule_tasks_(true), 269 did_check_for_completed_tasks_since_last_schedule_tasks_(true),
379 did_oom_on_last_assign_(false), 270 did_oom_on_last_assign_(false),
380 ready_to_activate_check_notifier_( 271 ready_to_activate_check_notifier_(
381 task_runner_.get(), 272 task_runner_.get(),
382 base::Bind(&TileManager::CheckIfReadyToActivate, 273 base::Bind(&TileManager::CheckIfReadyToActivate,
383 base::Unretained(this))) { 274 base::Unretained(this))) {
384 rasterizer_->SetClient(this); 275 rasterizer_->SetClient(this);
385 } 276 }
386 277
387 TileManager::~TileManager() { 278 TileManager::~TileManager() {
388 // Reset global state and manage. This should cause 279 // Reset global state and manage. This should cause
389 // our memory usage to drop to zero. 280 // our memory usage to drop to zero.
390 global_state_ = GlobalStateThatImpactsTilePriority(); 281 global_state_ = GlobalStateThatImpactsTilePriority();
391 282
392 RasterTaskQueue empty; 283 RasterTaskQueue empty;
393 rasterizer_->ScheduleTasks(&empty); 284 rasterizer_->ScheduleTasks(&empty);
394 orphan_raster_tasks_.clear(); 285 orphan_raster_tasks_.clear();
395 286
396 // This should finish all pending tasks and release any uninitialized 287 // This should finish all pending tasks and release any uninitialized
397 // resources. 288 // resources.
398 rasterizer_->Shutdown(); 289 rasterizer_->Shutdown();
399 rasterizer_->CheckForCompletedTasks(); 290 rasterizer_->CheckForCompletedTasks();
400 291
401 prioritized_tiles_.Clear();
402
403 FreeResourcesForReleasedTiles(); 292 FreeResourcesForReleasedTiles();
404 CleanUpReleasedTiles(); 293 CleanUpReleasedTiles();
405
406 DCHECK_EQ(0u, bytes_releasable_);
407 DCHECK_EQ(0u, resources_releasable_);
408 } 294 }
409 295
410 void TileManager::Release(Tile* tile) { 296 void TileManager::Release(Tile* tile) {
411 DCHECK(TilePriority() == tile->combined_priority());
412
413 prioritized_tiles_dirty_ = true;
414 released_tiles_.push_back(tile); 297 released_tiles_.push_back(tile);
415 } 298 }
416 299
417 void TileManager::DidChangeTilePriority(Tile* tile) {
418 prioritized_tiles_dirty_ = true;
419 }
420
421 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { 300 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const {
422 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; 301 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY;
423 } 302 }
424 303
425 void TileManager::FreeResourcesForReleasedTiles() { 304 void TileManager::FreeResourcesForReleasedTiles() {
426 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); 305 for (std::vector<Tile*>::iterator it = released_tiles_.begin();
427 it != released_tiles_.end(); 306 it != released_tiles_.end();
428 ++it) { 307 ++it) {
429 Tile* tile = *it; 308 Tile* tile = *it;
430 FreeResourcesForTile(tile); 309 FreeResourcesForTile(tile);
431 } 310 }
432 } 311 }
433 312
434 void TileManager::CleanUpReleasedTiles() { 313 void TileManager::CleanUpReleasedTiles() {
435 // Make sure |prioritized_tiles_| doesn't contain any of the tiles
436 // we're about to delete.
437 DCHECK(prioritized_tiles_.IsEmpty());
438
439 std::vector<Tile*>::iterator it = released_tiles_.begin(); 314 std::vector<Tile*>::iterator it = released_tiles_.begin();
440 while (it != released_tiles_.end()) { 315 while (it != released_tiles_.end()) {
441 Tile* tile = *it; 316 Tile* tile = *it;
442 317
443 if (tile->HasRasterTask()) { 318 if (tile->HasRasterTask()) {
444 ++it; 319 ++it;
445 continue; 320 continue;
446 } 321 }
447 322
448 DCHECK(!tile->HasResources()); 323 DCHECK(!tile->HasResources());
449 DCHECK(tiles_.find(tile->id()) != tiles_.end()); 324 DCHECK(tiles_.find(tile->id()) != tiles_.end());
450 tiles_.erase(tile->id()); 325 tiles_.erase(tile->id());
451 326
452 LayerCountMap::iterator layer_it = 327 LayerCountMap::iterator layer_it =
453 used_layer_counts_.find(tile->layer_id()); 328 used_layer_counts_.find(tile->layer_id());
454 DCHECK_GT(layer_it->second, 0); 329 DCHECK_GT(layer_it->second, 0);
455 if (--layer_it->second == 0) { 330 if (--layer_it->second == 0) {
456 used_layer_counts_.erase(layer_it); 331 used_layer_counts_.erase(layer_it);
457 image_decode_tasks_.erase(tile->layer_id()); 332 image_decode_tasks_.erase(tile->layer_id());
458 } 333 }
459 334
460 delete tile; 335 delete tile;
461 it = released_tiles_.erase(it); 336 it = released_tiles_.erase(it);
462 } 337 }
463 } 338 }
464 339
465 void TileManager::UpdatePrioritizedTileSetIfNeeded() {
466 if (!prioritized_tiles_dirty_)
467 return;
468
469 prioritized_tiles_.Clear();
470
471 FreeResourcesForReleasedTiles();
472 CleanUpReleasedTiles();
473
474 GetTilesWithAssignedBins(&prioritized_tiles_);
475 prioritized_tiles_dirty_ = false;
476 }
477
478 void TileManager::DidFinishRunningTasks() { 340 void TileManager::DidFinishRunningTasks() {
479 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); 341 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks");
480 342
481 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > 343 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() >
482 global_state_.soft_memory_limit_in_bytes; 344 global_state_.soft_memory_limit_in_bytes;
483 345
484 // When OOM, keep re-assigning memory until we reach a steady state 346 // When OOM, keep re-assigning memory until we reach a steady state
485 // where top-priority tiles are initialized. 347 // where top-priority tiles are initialized.
486 if (all_tiles_that_need_to_be_rasterized_have_memory_ && 348 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ &&
487 !memory_usage_above_limit) 349 !memory_usage_above_limit)
488 return; 350 return;
489 351
490 rasterizer_->CheckForCompletedTasks(); 352 rasterizer_->CheckForCompletedTasks();
491 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 353 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
492 354
493 TileVector tiles_that_need_to_be_rasterized; 355 TileVector tiles_that_need_to_be_rasterized;
494 AssignGpuMemoryToTiles(&prioritized_tiles_, 356 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized);
495 &tiles_that_need_to_be_rasterized);
496 357
497 // |tiles_that_need_to_be_rasterized| will be empty when we reach a 358 // |tiles_that_need_to_be_rasterized| will be empty when we reach a
498 // steady memory state. Keep scheduling tasks until we reach this state. 359 // steady memory state. Keep scheduling tasks until we reach this state.
499 if (!tiles_that_need_to_be_rasterized.empty()) { 360 if (!tiles_that_need_to_be_rasterized.empty()) {
500 ScheduleTasks(tiles_that_need_to_be_rasterized); 361 ScheduleTasks(tiles_that_need_to_be_rasterized);
501 return; 362 return;
502 } 363 }
503 364
504 FreeResourcesForReleasedTiles(); 365 FreeResourcesForReleasedTiles();
505 366
506 resource_pool_->ReduceResourceUsage(); 367 resource_pool_->ReduceResourceUsage();
507 368
508 // We don't reserve memory for required-for-activation tiles during 369 // We don't reserve memory for required-for-activation tiles during
509 // accelerated gestures, so we just postpone activation when we don't 370 // accelerated gestures, so we just postpone activation when we don't
510 // have these tiles, and activate after the accelerated gesture. 371 // have these tiles, and activate after the accelerated gesture.
511 bool allow_rasterize_on_demand = 372 bool allow_rasterize_on_demand =
512 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; 373 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY;
513 374
514 // Use on-demand raster for any required-for-activation tiles that have not 375 // Use on-demand raster for any required-for-activation tiles that have not
515 // been been assigned memory after reaching a steady memory state. This 376 // been been assigned memory after reaching a steady memory state. This
516 // ensures that we activate even when OOM. 377 // ensures that we activate even when OOM. Note that we have to rebuilt the
517 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 378 // queue in case the last AssignGpuMemoryToTiles evicted some tiles that
518 Tile* tile = it->second; 379 // would otherwise not be picked up by the old raster queue.
reveman 2014/09/18 19:47:10 You're call but I think you could reduce this comm
380 raster_priority_queue_.Reset();
381 client_->BuildRasterQueue(&raster_priority_queue_,
382 global_state_.tree_priority);
383 while (!raster_priority_queue_.IsEmpty()) {
vmpstr 2014/09/18 18:35:09 This part had to be changed as well, since we can'
reveman 2014/09/18 19:47:10 Got it. This makes sense.
384 Tile* tile = raster_priority_queue_.Top();
519 ManagedTileState& mts = tile->managed_state(); 385 ManagedTileState& mts = tile->managed_state();
520 ManagedTileState::TileVersion& tile_version = 386 ManagedTileState::TileVersion& tile_version =
521 mts.tile_versions[mts.raster_mode]; 387 mts.tile_versions[mts.raster_mode];
522 388
523 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { 389 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) {
524 // If we can't raster on demand, give up early (and don't activate). 390 // If we can't raster on demand, give up early (and don't activate).
525 if (!allow_rasterize_on_demand) 391 if (!allow_rasterize_on_demand)
526 return; 392 return;
527 393
528 tile_version.set_rasterize_on_demand(); 394 tile_version.set_rasterize_on_demand();
529 client_->NotifyTileStateChanged(tile); 395 client_->NotifyTileStateChanged(tile);
530 } 396 }
397
398 raster_priority_queue_.Pop();
531 } 399 }
532 400
533 DCHECK(IsReadyToActivate()); 401 DCHECK(IsReadyToActivate());
534 ready_to_activate_check_notifier_.Schedule(); 402 ready_to_activate_check_notifier_.Schedule();
535 } 403 }
536 404
537 void TileManager::DidFinishRunningTasksRequiredForActivation() { 405 void TileManager::DidFinishRunningTasksRequiredForActivation() {
538 TRACE_EVENT1("cc", 406 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasksRequiredForActivation");
539 "TileManager::DidFinishRunningTasksRequiredForActivation",
540 "all_tiles_required_for_activation_have_memory",
541 all_tiles_required_for_activation_have_memory_);
542 // This is only a true indication that all tiles required for
543 // activation are initialized when no tiles are OOM. We need to
544 // wait for DidFinishRunningTasks() to be called, try to re-assign
545 // memory and in worst case use on-demand raster when tiles
546 // required for activation are OOM.
547 if (!all_tiles_required_for_activation_have_memory_)
548 return;
549
550 ready_to_activate_check_notifier_.Schedule(); 407 ready_to_activate_check_notifier_.Schedule();
551 } 408 }
552 409
553 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) {
554 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins");
555
556 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy;
557 const TreePriority tree_priority = global_state_.tree_priority;
558
559 // For each tree, bin into different categories of tiles.
560 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
561 Tile* tile = it->second;
562 ManagedTileState& mts = tile->managed_state();
563
564 const ManagedTileState::TileVersion& tile_version =
565 tile->GetTileVersionForDrawing();
566 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw();
567 bool tile_is_active = tile_is_ready_to_draw ||
568 mts.tile_versions[mts.raster_mode].raster_task_.get();
569
570 // Get the active priority and bin.
571 TilePriority active_priority = tile->priority(ACTIVE_TREE);
572 ManagedTileBin active_bin = BinFromTilePriority(active_priority);
573
574 // Get the pending priority and bin.
575 TilePriority pending_priority = tile->priority(PENDING_TREE);
576 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority);
577
578 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION;
579 bool pending_is_non_ideal =
580 pending_priority.resolution == NON_IDEAL_RESOLUTION;
581 bool active_is_non_ideal =
582 active_priority.resolution == NON_IDEAL_RESOLUTION;
583
584 // Adjust bin state based on if ready to draw.
585 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin];
586 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin];
587
588 // Adjust bin state based on if active.
589 active_bin = kBinIsActiveMap[tile_is_active][active_bin];
590 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin];
591
592 // We never want to paint new non-ideal tiles, as we always have
593 // a high-res tile covering that content (paint that instead).
594 if (!tile_is_ready_to_draw && active_is_non_ideal)
595 active_bin = NEVER_BIN;
596 if (!tile_is_ready_to_draw && pending_is_non_ideal)
597 pending_bin = NEVER_BIN;
598
599 ManagedTileBin tree_bin[NUM_TREES];
600 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin];
601 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin];
602
603 // Adjust pending bin state for low res tiles. This prevents pending tree
604 // low-res tiles from being initialized before high-res tiles.
605 if (pending_is_low_res)
606 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN);
607
608 TilePriority tile_priority;
609 switch (tree_priority) {
610 case SAME_PRIORITY_FOR_BOTH_TREES:
611 mts.bin = std::min(tree_bin[ACTIVE_TREE], tree_bin[PENDING_TREE]);
612 tile_priority = tile->combined_priority();
613 break;
614 case SMOOTHNESS_TAKES_PRIORITY:
615 mts.bin = tree_bin[ACTIVE_TREE];
616 tile_priority = active_priority;
617 break;
618 case NEW_CONTENT_TAKES_PRIORITY:
619 mts.bin = tree_bin[PENDING_TREE];
620 tile_priority = pending_priority;
621 break;
622 default:
623 NOTREACHED();
624 }
625
626 // Bump up the priority if we determined it's NEVER_BIN on one tree,
627 // but is still required on the other tree.
628 bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN &&
629 tree_bin[PENDING_TREE] == NEVER_BIN;
630
631 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees)
632 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN;
633
634 mts.resolution = tile_priority.resolution;
635 mts.priority_bin = tile_priority.priority_bin;
636 mts.distance_to_visible = tile_priority.distance_to_visible;
637 mts.required_for_activation = tile_priority.required_for_activation;
638
639 mts.visible_and_ready_to_draw =
640 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN;
641
642 // Tiles that are required for activation shouldn't be in NEVER_BIN unless
643 // smoothness takes priority or memory policy allows nothing to be
644 // initialized.
645 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN ||
646 tree_priority == SMOOTHNESS_TAKES_PRIORITY ||
647 memory_policy == ALLOW_NOTHING);
648
649 // If the tile is in NEVER_BIN and it does not have an active task, then we
650 // can release the resources early. If it does have the task however, we
651 // should keep it in the prioritized tile set to ensure that AssignGpuMemory
652 // can visit it.
653 if (mts.bin == NEVER_BIN &&
654 !mts.tile_versions[mts.raster_mode].raster_task_.get()) {
655 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
656 continue;
657 }
658
659 // Insert the tile into a priority set.
660 tiles->InsertTile(tile, mts.bin);
661 }
662 }
663
664 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { 410 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) {
665 TRACE_EVENT0("cc", "TileManager::ManageTiles"); 411 TRACE_EVENT0("cc", "TileManager::ManageTiles");
666 412
667 // Update internal state. 413 global_state_ = state;
668 if (state != global_state_) {
669 global_state_ = state;
670 prioritized_tiles_dirty_ = true;
671 }
672 414
673 // We need to call CheckForCompletedTasks() once in-between each call 415 // We need to call CheckForCompletedTasks() once in-between each call
674 // to ScheduleTasks() to prevent canceled tasks from being scheduled. 416 // to ScheduleTasks() to prevent canceled tasks from being scheduled.
675 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { 417 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) {
676 rasterizer_->CheckForCompletedTasks(); 418 rasterizer_->CheckForCompletedTasks();
677 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 419 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
678 } 420 }
679 421
680 UpdatePrioritizedTileSetIfNeeded(); 422 FreeResourcesForReleasedTiles();
423 CleanUpReleasedTiles();
681 424
682 TileVector tiles_that_need_to_be_rasterized; 425 TileVector tiles_that_need_to_be_rasterized;
683 AssignGpuMemoryToTiles(&prioritized_tiles_, 426 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized);
684 &tiles_that_need_to_be_rasterized);
685 427
686 // Finally, schedule rasterizer tasks. 428 // Finally, schedule rasterizer tasks.
687 ScheduleTasks(tiles_that_need_to_be_rasterized); 429 ScheduleTasks(tiles_that_need_to_be_rasterized);
688 430
689 TRACE_EVENT_INSTANT1("cc", 431 TRACE_EVENT_INSTANT1("cc",
690 "DidManage", 432 "DidManage",
691 TRACE_EVENT_SCOPE_THREAD, 433 TRACE_EVENT_SCOPE_THREAD,
692 "state", 434 "state",
693 BasicStateAsValue()); 435 BasicStateAsValue());
694 436
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 469 }
728 470
729 void TileManager::BasicStateAsValueInto(base::debug::TracedValue* state) const { 471 void TileManager::BasicStateAsValueInto(base::debug::TracedValue* state) const {
730 state->SetInteger("tile_count", tiles_.size()); 472 state->SetInteger("tile_count", tiles_.size());
731 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_); 473 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_);
732 state->BeginDictionary("global_state"); 474 state->BeginDictionary("global_state");
733 global_state_.AsValueInto(state); 475 global_state_.AsValueInto(state);
734 state->EndDictionary(); 476 state->EndDictionary();
735 } 477 }
736 478
479 void TileManager::RebuildEvictionQueueIfNeeded() {
480 if (eviction_priority_queue_is_up_to_date_)
481 return;
482
483 eviction_priority_queue_.Reset();
484 client_->BuildEvictionQueue(&eviction_priority_queue_,
485 global_state_.tree_priority);
486 eviction_priority_queue_is_up_to_date_ = true;
487 }
488
489 bool TileManager::FreeTileResourcesUntilUsageIsWithinLimit(
490 const MemoryUsage& limit,
491 MemoryUsage* usage) {
492 while (usage->Exceeds(limit)) {
493 RebuildEvictionQueueIfNeeded();
494 if (eviction_priority_queue_.IsEmpty())
495 return false;
496
497 Tile* tile = eviction_priority_queue_.Top();
498 *usage -= MemoryUsage::FromTile(tile);
499 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
500 eviction_priority_queue_.Pop();
501 }
502 return true;
503 }
504
505 bool TileManager::FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit(
506 const MemoryUsage& limit,
507 const TilePriority& other_priority,
508 MemoryUsage* usage) {
509 while (usage->Exceeds(limit)) {
510 RebuildEvictionQueueIfNeeded();
511 if (eviction_priority_queue_.IsEmpty())
512 return false;
513
514 Tile* tile = eviction_priority_queue_.Top();
515 if (!other_priority.IsHigherPriorityThan(
516 tile->priority_for_tree_priority(global_state_.tree_priority))) {
517 return false;
518 }
519
520 *usage -= MemoryUsage::FromTile(tile);
521 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
522 eviction_priority_queue_.Pop();
523 }
524 return true;
525 }
526
527 bool TileManager::TilePriorityViolatesMemoryPolicy(
528 const TilePriority& priority) {
529 switch (global_state_.memory_limit_policy) {
530 case ALLOW_NOTHING:
531 return true;
532 case ALLOW_ABSOLUTE_MINIMUM:
533 return priority.priority_bin > TilePriority::NOW;
534 case ALLOW_PREPAINT_ONLY:
535 return priority.priority_bin > TilePriority::SOON;
536 case ALLOW_ANYTHING:
537 return priority.distance_to_visible ==
538 std::numeric_limits<float>::infinity();
539 }
540 NOTREACHED();
541 return true;
542 }
543
737 void TileManager::AssignGpuMemoryToTiles( 544 void TileManager::AssignGpuMemoryToTiles(
738 PrioritizedTileSet* tiles,
739 TileVector* tiles_that_need_to_be_rasterized) { 545 TileVector* tiles_that_need_to_be_rasterized) {
740 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); 546 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles");
741 547
742 // Maintain the list of released resources that can potentially be re-used 548 // Maintain the list of released resources that can potentially be re-used
743 // or deleted. 549 // or deleted.
744 // If this operation becomes expensive too, only do this after some 550 // If this operation becomes expensive too, only do this after some
745 // resource(s) was returned. Note that in that case, one also need to 551 // resource(s) was returned. Note that in that case, one also need to
746 // invalidate when releasing some resource from the pool. 552 // invalidate when releasing some resource from the pool.
747 resource_pool_->CheckBusyResources(); 553 resource_pool_->CheckBusyResources();
748 554
749 // Now give memory out to the tiles until we're out, and build 555 // Now give memory out to the tiles until we're out, and build
750 // the needs-to-be-rasterized queue. 556 // the needs-to-be-rasterized queue.
751 all_tiles_that_need_to_be_rasterized_have_memory_ = true; 557 unsigned schedule_priority = 1u;
752 all_tiles_required_for_activation_have_memory_ = true; 558 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true;
559 bool had_enough_memory_to_schedule_tiles_needed_now = true;
753 560
754 // Cast to prevent overflow. 561 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes,
755 int64 soft_bytes_available = 562 global_state_.num_resources_limit);
756 static_cast<int64>(bytes_releasable_) + 563 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes,
757 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - 564 global_state_.num_resources_limit);
758 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); 565 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(),
759 int64 hard_bytes_available = 566 resource_pool_->acquired_resource_count());
760 static_cast<int64>(bytes_releasable_) +
761 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) -
762 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes());
763 int resources_available = resources_releasable_ +
764 global_state_.num_resources_limit -
765 resource_pool_->acquired_resource_count();
766 size_t soft_bytes_allocatable =
767 std::max(static_cast<int64>(0), soft_bytes_available);
768 size_t hard_bytes_allocatable =
769 std::max(static_cast<int64>(0), hard_bytes_available);
770 size_t resources_allocatable = std::max(0, resources_available);
771 567
772 size_t bytes_that_exceeded_memory_budget = 0; 568 eviction_priority_queue_is_up_to_date_ = false;
773 size_t soft_bytes_left = soft_bytes_allocatable; 569 raster_priority_queue_.Reset();
774 size_t hard_bytes_left = hard_bytes_allocatable; 570 client_->BuildRasterQueue(&raster_priority_queue_,
571 global_state_.tree_priority);
775 572
776 size_t resources_left = resources_allocatable; 573 while (!raster_priority_queue_.IsEmpty()) {
777 bool oomed_soft = false; 574 Tile* tile = raster_priority_queue_.Top();
778 bool oomed_hard = false; 575 TilePriority priority =
779 bool have_hit_soft_memory = false; // Soft memory comes after hard. 576 tile->priority_for_tree_priority(global_state_.tree_priority);
780 577
781 unsigned schedule_priority = 1u; 578 if (TilePriorityViolatesMemoryPolicy(priority))
782 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { 579 break;
783 Tile* tile = *it; 580
581 // We won't be able to schedule this tile, so break out early.
582 if (tiles_that_need_to_be_rasterized->size() >=
583 kScheduledRasterTasksLimit) {
584 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false;
585 break;
586 }
587
784 ManagedTileState& mts = tile->managed_state(); 588 ManagedTileState& mts = tile->managed_state();
785
786 mts.scheduled_priority = schedule_priority++; 589 mts.scheduled_priority = schedule_priority++;
787
788 mts.raster_mode = tile->DetermineOverallRasterMode(); 590 mts.raster_mode = tile->DetermineOverallRasterMode();
789
790 ManagedTileState::TileVersion& tile_version = 591 ManagedTileState::TileVersion& tile_version =
791 mts.tile_versions[mts.raster_mode]; 592 mts.tile_versions[mts.raster_mode];
792 593
793 // If this tile doesn't need a resource, then nothing to do. 594 DCHECK(tile_version.mode() ==
794 if (!tile_version.requires_resource()) 595 ManagedTileState::TileVersion::PICTURE_PILE_MODE ||
795 continue; 596 !tile_version.IsReadyToDraw());
796 597
797 // If the tile is not needed, free it up. 598 // If the tile already has a raster_task, then the memory used by it is
798 if (mts.bin == NEVER_BIN) { 599 // already accounted for in memory_usage. Otherwise, we'll have to acquire
799 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); 600 // more memory to create a raster task.
800 continue; 601 MemoryUsage memory_required_by_tile_to_be_scheduled;
602 if (!tile_version.raster_task_.get()) {
603 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig(
604 tile->size(), resource_pool_->resource_format());
801 } 605 }
802 606
803 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; 607 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW;
804 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile);
805 const size_t tile_bytes_left =
806 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left;
807 608
808 // Hard-limit is reserved for tiles that would cause a calamity 609 // This is the memory limit that will be used by this tile. Depending on
809 // if they were to go away, so by definition they are the highest 610 // the tile priority, it will be one of hard_memory_limit or
810 // priority memory, and must be at the front of the list. 611 // soft_memory_limit.
811 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); 612 MemoryUsage& tile_memory_limit =
812 have_hit_soft_memory |= !tile_uses_hard_limit; 613 tile_is_needed_now ? hard_memory_limit : soft_memory_limit;
813 614
814 size_t tile_bytes = 0; 615 bool memory_usage_is_within_limit =
815 size_t tile_resources = 0; 616 FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit(
617 tile_memory_limit - memory_required_by_tile_to_be_scheduled,
618 priority,
619 &memory_usage);
816 620
817 // It costs to maintain a resource. 621 // If we couldn't fit the tile into our current memory limit, then we're
818 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 622 // done.
819 if (mts.tile_versions[mode].resource_) { 623 if (!memory_usage_is_within_limit) {
820 tile_bytes += bytes_if_allocated; 624 if (tile_is_needed_now)
821 tile_resources++; 625 had_enough_memory_to_schedule_tiles_needed_now = false;
822 } 626 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false;
627 break;
823 } 628 }
824 629
825 // Allow lower priority tiles with initialized resources to keep 630 memory_usage += memory_required_by_tile_to_be_scheduled;
826 // their memory by only assigning memory to new raster tasks if
827 // they can be scheduled.
828 bool reached_scheduled_raster_tasks_limit =
829 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit;
830 if (!reached_scheduled_raster_tasks_limit) {
831 // If we don't have the required version, and it's not in flight
832 // then we'll have to pay to create a new task.
833 if (!tile_version.resource_ && !tile_version.raster_task_.get()) {
834 tile_bytes += bytes_if_allocated;
835 tile_resources++;
836 }
837 }
838
839 // Tile is OOM.
840 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) {
841 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
842
843 // This tile was already on screen and now its resources have been
844 // released. In order to prevent checkerboarding, set this tile as
845 // rasterize on demand immediately.
846 if (mts.visible_and_ready_to_draw)
847 tile_version.set_rasterize_on_demand();
848
849 oomed_soft = true;
850 if (tile_uses_hard_limit) {
851 oomed_hard = true;
852 bytes_that_exceeded_memory_budget += tile_bytes;
853 }
854 } else {
855 resources_left -= tile_resources;
856 hard_bytes_left -= tile_bytes;
857 soft_bytes_left =
858 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0;
859 if (tile_version.resource_)
860 continue;
861 }
862
863 DCHECK(!tile_version.resource_);
864
865 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized|
866 // has reached it's limit or we've failed to assign gpu memory to this
867 // or any higher priority tile. Preventing tiles that fit into memory
868 // budget to be rasterized when higher priority tile is oom is
869 // important for two reasons:
870 // 1. Tile size should not impact raster priority.
871 // 2. Tiles with existing raster task could otherwise incorrectly
872 // be added as they are not affected by |bytes_allocatable|.
873 bool can_schedule_tile =
874 !oomed_soft && !reached_scheduled_raster_tasks_limit;
875
876 if (!can_schedule_tile) {
877 all_tiles_that_need_to_be_rasterized_have_memory_ = false;
878 if (tile->required_for_activation())
879 all_tiles_required_for_activation_have_memory_ = false;
880 it.DisablePriorityOrdering();
881 continue;
882 }
883
884 tiles_that_need_to_be_rasterized->push_back(tile); 631 tiles_that_need_to_be_rasterized->push_back(tile);
632 raster_priority_queue_.Pop();
885 } 633 }
886 634
887 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. 635 // Note that we should try and further reduce memory in case the above loop
888 ever_exceeded_memory_budget_ |= oomed_hard; 636 // didn't reduce memory. This ensures that we always release as many resources
889 if (ever_exceeded_memory_budget_) { 637 // as possible to stay within the memory limit.
890 TRACE_COUNTER_ID2("cc", 638 FreeTileResourcesUntilUsageIsWithinLimit(hard_memory_limit, &memory_usage);
891 "over_memory_budget", 639
892 this, 640 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget",
893 "budget", 641 !had_enough_memory_to_schedule_tiles_needed_now);
894 global_state_.hard_memory_limit_in_bytes, 642 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now;
895 "over", 643
896 bytes_that_exceeded_memory_budget);
897 }
898 did_oom_on_last_assign_ = oomed_hard;
899 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard);
900 memory_stats_from_last_assign_.total_budget_in_bytes = 644 memory_stats_from_last_assign_.total_budget_in_bytes =
901 global_state_.hard_memory_limit_in_bytes; 645 global_state_.hard_memory_limit_in_bytes;
902 memory_stats_from_last_assign_.bytes_allocated = 646 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes();
903 hard_bytes_allocatable - hard_bytes_left; 647 memory_stats_from_last_assign_.had_enough_memory =
904 memory_stats_from_last_assign_.bytes_unreleasable = 648 had_enough_memory_to_schedule_tiles_needed_now;
905 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_;
906 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget;
907 } 649 }
908 650
909 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { 651 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) {
910 ManagedTileState& mts = tile->managed_state(); 652 ManagedTileState& mts = tile->managed_state();
911 if (mts.tile_versions[mode].resource_) { 653 if (mts.tile_versions[mode].resource_)
912 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); 654 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass());
913
914 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile));
915 DCHECK_GE(resources_releasable_, 1u);
916
917 bytes_releasable_ -= BytesConsumedIfAllocated(tile);
918 --resources_releasable_;
919 }
920 } 655 }
921 656
922 void TileManager::FreeResourcesForTile(Tile* tile) { 657 void TileManager::FreeResourcesForTile(Tile* tile) {
923 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 658 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
924 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); 659 FreeResourceForTile(tile, static_cast<RasterMode>(mode));
925 } 660 }
926 } 661 }
927 662
928 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { 663 void TileManager::FreeUnusedResourcesForTile(Tile* tile) {
929 DCHECK(tile->IsReadyToDraw()); 664 DCHECK(tile->IsReadyToDraw());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 839 }
1105 840
1106 ++update_visible_tiles_stats_.completed_count; 841 ++update_visible_tiles_stats_.completed_count;
1107 842
1108 if (analysis.is_solid_color) { 843 if (analysis.is_solid_color) {
1109 tile_version.set_solid_color(analysis.solid_color); 844 tile_version.set_solid_color(analysis.solid_color);
1110 resource_pool_->ReleaseResource(resource.Pass()); 845 resource_pool_->ReleaseResource(resource.Pass());
1111 } else { 846 } else {
1112 tile_version.set_use_resource(); 847 tile_version.set_use_resource();
1113 tile_version.resource_ = resource.Pass(); 848 tile_version.resource_ = resource.Pass();
1114
1115 bytes_releasable_ += BytesConsumedIfAllocated(tile);
1116 ++resources_releasable_;
1117 } 849 }
1118 850
1119 FreeUnusedResourcesForTile(tile); 851 FreeUnusedResourcesForTile(tile);
1120 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) 852 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f)
1121 did_initialize_visible_tile_ = true; 853 did_initialize_visible_tile_ = true;
1122 854
1123 client_->NotifyTileStateChanged(tile); 855 client_->NotifyTileStateChanged(tile);
1124 } 856 }
1125 857
1126 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, 858 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile,
1127 const gfx::Size& tile_size, 859 const gfx::Size& tile_size,
1128 const gfx::Rect& content_rect, 860 const gfx::Rect& content_rect,
1129 float contents_scale, 861 float contents_scale,
1130 int layer_id, 862 int layer_id,
1131 int source_frame_number, 863 int source_frame_number,
1132 int flags) { 864 int flags) {
1133 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this, 865 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this,
1134 picture_pile, 866 picture_pile,
1135 tile_size, 867 tile_size,
1136 content_rect, 868 content_rect,
1137 contents_scale, 869 contents_scale,
1138 layer_id, 870 layer_id,
1139 source_frame_number, 871 source_frame_number,
1140 flags)); 872 flags));
1141 DCHECK(tiles_.find(tile->id()) == tiles_.end()); 873 DCHECK(tiles_.find(tile->id()) == tiles_.end());
1142 874
1143 tiles_[tile->id()] = tile.get(); 875 tiles_[tile->id()] = tile.get();
1144 used_layer_counts_[tile->layer_id()]++; 876 used_layer_counts_[tile->layer_id()]++;
1145 prioritized_tiles_dirty_ = true;
1146 return tile; 877 return tile;
1147 } 878 }
1148 879
1149 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { 880 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) {
1150 rasterizer_ = rasterizer; 881 rasterizer_ = rasterizer;
1151 rasterizer_->SetClient(this); 882 rasterizer_->SetClient(this);
1152 } 883 }
1153 884
1154 bool TileManager::IsReadyToActivate() const { 885 bool TileManager::IsReadyToActivate() const {
1155 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); 886 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers();
(...skipping 11 matching lines...) Expand all
1167 void TileManager::CheckIfReadyToActivate() { 898 void TileManager::CheckIfReadyToActivate() {
1168 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); 899 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate");
1169 900
1170 rasterizer_->CheckForCompletedTasks(); 901 rasterizer_->CheckForCompletedTasks();
1171 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 902 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
1172 903
1173 if (IsReadyToActivate()) 904 if (IsReadyToActivate())
1174 client_->NotifyReadyToActivate(); 905 client_->NotifyReadyToActivate();
1175 } 906 }
1176 907
908 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) {
909 }
910
911 TileManager::MemoryUsage::MemoryUsage(int64 memory_bytes, int resource_count)
912 : memory_bytes_(memory_bytes), resource_count_(resource_count) {
913 }
914
915 // static
916 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig(
917 const gfx::Size& size,
918 ResourceFormat format) {
919 return MemoryUsage(Resource::MemorySizeBytes(size, format), 1);
920 }
921
922 // static
923 TileManager::MemoryUsage TileManager::MemoryUsage::FromTile(const Tile* tile) {
924 const ManagedTileState& mts = tile->managed_state();
925 MemoryUsage total_usage;
926 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
927 if (mts.tile_versions[mode].resource_) {
928 total_usage += MemoryUsage::FromConfig(
929 tile->size(), mts.tile_versions[mode].resource_->format());
930 }
931 }
932 return total_usage;
933 }
934
935 TileManager::MemoryUsage& TileManager::MemoryUsage::operator+=(
936 const MemoryUsage& other) {
937 memory_bytes_ += other.memory_bytes_;
938 resource_count_ += other.resource_count_;
939 return *this;
940 }
941
942 TileManager::MemoryUsage& TileManager::MemoryUsage::operator-=(
943 const MemoryUsage& other) {
944 memory_bytes_ -= other.memory_bytes_;
945 resource_count_ -= other.resource_count_;
946 return *this;
947 }
948
949 TileManager::MemoryUsage TileManager::MemoryUsage::operator-(
950 const MemoryUsage& other) {
951 MemoryUsage result = *this;
952 result -= other;
953 return result;
954 }
955
956 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const {
957 return memory_bytes_ > limit.memory_bytes_ ||
958 resource_count_ > limit.resource_count_;
959 }
960
1177 } // namespace cc 961 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_manager.h ('k') | cc/resources/tile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698