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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 Rasterizer* rasterizer, | 232 Rasterizer* rasterizer, |
233 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 233 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
234 size_t scheduled_raster_task_limit) | 234 size_t scheduled_raster_task_limit) |
235 : client_(client), | 235 : client_(client), |
236 task_runner_(task_runner), | 236 task_runner_(task_runner), |
237 resource_pool_(resource_pool), | 237 resource_pool_(resource_pool), |
238 rasterizer_(rasterizer), | 238 rasterizer_(rasterizer), |
239 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 239 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
240 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | 240 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
241 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 241 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
242 did_initialize_visible_tile_(false), | |
243 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 242 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
244 did_oom_on_last_assign_(false), | 243 did_oom_on_last_assign_(false), |
| 244 has_active_visible_tile_scheduled_(false), |
245 ready_to_activate_check_notifier_( | 245 ready_to_activate_check_notifier_( |
246 task_runner_.get(), | 246 task_runner_.get(), |
247 base::Bind(&TileManager::CheckIfReadyToActivate, | 247 base::Bind(&TileManager::CheckIfReadyToActivate, |
248 base::Unretained(this))) { | 248 base::Unretained(this))) { |
249 rasterizer_->SetClient(this); | 249 rasterizer_->SetClient(this); |
250 } | 250 } |
251 | 251 |
252 TileManager::~TileManager() { | 252 TileManager::~TileManager() { |
253 // Reset global state and manage. This should cause | 253 // Reset global state and manage. This should cause |
254 // our memory usage to drop to zero. | 254 // our memory usage to drop to zero. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 delete tile; | 312 delete tile; |
313 it = released_tiles_.erase(it); | 313 it = released_tiles_.erase(it); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 void TileManager::DidFinishRunningTasks(TaskSet task_set) { | 317 void TileManager::DidFinishRunningTasks(TaskSet task_set) { |
318 if (task_set == ALL) { | 318 if (task_set == ALL) { |
319 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTasks", "task_set", "ALL"); | 319 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTasks", "task_set", "ALL"); |
320 | 320 |
| 321 rasterizer_->CheckForCompletedTasks(); |
| 322 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 323 has_active_visible_tile_scheduled_ = false; |
| 324 |
321 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > | 325 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
322 global_state_.soft_memory_limit_in_bytes; | 326 global_state_.soft_memory_limit_in_bytes; |
323 | 327 |
324 // When OOM, keep re-assigning memory until we reach a steady state | 328 // When OOM, keep re-assigning memory until we reach a steady state |
325 // where top-priority tiles are initialized. | 329 // where top-priority tiles are initialized. |
326 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && | 330 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && |
327 !memory_usage_above_limit) | 331 !memory_usage_above_limit) |
328 return; | 332 return; |
329 | 333 |
330 rasterizer_->CheckForCompletedTasks(); | |
331 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | |
332 | |
333 TileVector tiles_that_need_to_be_rasterized; | 334 TileVector tiles_that_need_to_be_rasterized; |
334 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); | 335 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
335 | 336 |
336 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 337 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
337 // steady memory state. Keep scheduling tasks until we reach this state. | 338 // steady memory state. Keep scheduling tasks until we reach this state. |
338 if (!tiles_that_need_to_be_rasterized.empty()) { | 339 if (!tiles_that_need_to_be_rasterized.empty()) { |
339 ScheduleTasks(tiles_that_need_to_be_rasterized); | 340 ScheduleTasks(tiles_that_need_to_be_rasterized); |
340 return; | 341 return; |
341 } | 342 } |
342 | 343 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 "state", | 424 "state", |
424 BasicStateAsValue()); | 425 BasicStateAsValue()); |
425 | 426 |
426 TRACE_COUNTER_ID1("cc", | 427 TRACE_COUNTER_ID1("cc", |
427 "unused_memory_bytes", | 428 "unused_memory_bytes", |
428 this, | 429 this, |
429 resource_pool_->total_memory_usage_bytes() - | 430 resource_pool_->total_memory_usage_bytes() - |
430 resource_pool_->acquired_memory_usage_bytes()); | 431 resource_pool_->acquired_memory_usage_bytes()); |
431 } | 432 } |
432 | 433 |
433 bool TileManager::UpdateVisibleTiles() { | 434 void TileManager::UpdateVisibleTiles() { |
434 TRACE_EVENT0("cc", "TileManager::UpdateVisibleTiles"); | 435 TRACE_EVENT0("cc", "TileManager::UpdateVisibleTiles"); |
435 | 436 |
436 rasterizer_->CheckForCompletedTasks(); | 437 rasterizer_->CheckForCompletedTasks(); |
437 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 438 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
438 | 439 |
439 TRACE_EVENT_INSTANT1( | 440 TRACE_EVENT_INSTANT1( |
440 "cc", | 441 "cc", |
441 "DidUpdateVisibleTiles", | 442 "DidUpdateVisibleTiles", |
442 TRACE_EVENT_SCOPE_THREAD, | 443 TRACE_EVENT_SCOPE_THREAD, |
443 "stats", | 444 "stats", |
444 RasterTaskCompletionStatsAsValue(update_visible_tiles_stats_)); | 445 RasterTaskCompletionStatsAsValue(update_visible_tiles_stats_)); |
445 update_visible_tiles_stats_ = RasterTaskCompletionStats(); | 446 update_visible_tiles_stats_ = RasterTaskCompletionStats(); |
446 | |
447 bool did_initialize_visible_tile = did_initialize_visible_tile_; | |
448 did_initialize_visible_tile_ = false; | |
449 return did_initialize_visible_tile; | |
450 } | 447 } |
451 | 448 |
452 scoped_refptr<base::debug::ConvertableToTraceFormat> | 449 scoped_refptr<base::debug::ConvertableToTraceFormat> |
453 TileManager::BasicStateAsValue() const { | 450 TileManager::BasicStateAsValue() const { |
454 scoped_refptr<base::debug::TracedValue> value = | 451 scoped_refptr<base::debug::TracedValue> value = |
455 new base::debug::TracedValue(); | 452 new base::debug::TracedValue(); |
456 BasicStateAsValueInto(value.get()); | 453 BasicStateAsValueInto(value.get()); |
457 return value; | 454 return value; |
458 } | 455 } |
459 | 456 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 const TileVector& tiles_that_need_to_be_rasterized) { | 663 const TileVector& tiles_that_need_to_be_rasterized) { |
667 TRACE_EVENT1("cc", | 664 TRACE_EVENT1("cc", |
668 "TileManager::ScheduleTasks", | 665 "TileManager::ScheduleTasks", |
669 "count", | 666 "count", |
670 tiles_that_need_to_be_rasterized.size()); | 667 tiles_that_need_to_be_rasterized.size()); |
671 | 668 |
672 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); | 669 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); |
673 | 670 |
674 raster_queue_.Reset(); | 671 raster_queue_.Reset(); |
675 | 672 |
| 673 has_active_visible_tile_scheduled_ = false; |
| 674 |
676 // Build a new task queue containing all task currently needed. Tasks | 675 // Build a new task queue containing all task currently needed. Tasks |
677 // are added in order of priority, highest priority task first. | 676 // are added in order of priority, highest priority task first. |
678 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin(); | 677 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin(); |
679 it != tiles_that_need_to_be_rasterized.end(); | 678 it != tiles_that_need_to_be_rasterized.end(); |
680 ++it) { | 679 ++it) { |
681 Tile* tile = *it; | 680 Tile* tile = *it; |
682 ManagedTileState& mts = tile->managed_state(); | 681 ManagedTileState& mts = tile->managed_state(); |
683 | 682 |
| 683 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) |
| 684 has_active_visible_tile_scheduled_ = true; |
| 685 |
684 DCHECK(mts.draw_info.requires_resource()); | 686 DCHECK(mts.draw_info.requires_resource()); |
685 DCHECK(!mts.draw_info.resource_); | 687 DCHECK(!mts.draw_info.resource_); |
686 | 688 |
687 if (!mts.raster_task.get()) | 689 if (!mts.raster_task.get()) |
688 mts.raster_task = CreateRasterTask(tile); | 690 mts.raster_task = CreateRasterTask(tile); |
689 | 691 |
690 TaskSetCollection task_sets; | 692 TaskSetCollection task_sets; |
691 if (tile->required_for_activation()) | 693 if (tile->required_for_activation()) |
692 task_sets.set(REQUIRED_FOR_ACTIVATION); | 694 task_sets.set(REQUIRED_FOR_ACTIVATION); |
693 task_sets.set(ALL); | 695 task_sets.set(ALL); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 ++update_visible_tiles_stats_.completed_count; | 817 ++update_visible_tiles_stats_.completed_count; |
816 | 818 |
817 if (analysis.is_solid_color) { | 819 if (analysis.is_solid_color) { |
818 mts.draw_info.set_solid_color(analysis.solid_color); | 820 mts.draw_info.set_solid_color(analysis.solid_color); |
819 resource_pool_->ReleaseResource(resource.Pass()); | 821 resource_pool_->ReleaseResource(resource.Pass()); |
820 } else { | 822 } else { |
821 mts.draw_info.set_use_resource(); | 823 mts.draw_info.set_use_resource(); |
822 mts.draw_info.resource_ = resource.Pass(); | 824 mts.draw_info.resource_ = resource.Pass(); |
823 } | 825 } |
824 | 826 |
825 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) | |
826 did_initialize_visible_tile_ = true; | |
827 | |
828 client_->NotifyTileStateChanged(tile); | 827 client_->NotifyTileStateChanged(tile); |
829 } | 828 } |
830 | 829 |
831 scoped_refptr<Tile> TileManager::CreateTile(RasterSource* raster_source, | 830 scoped_refptr<Tile> TileManager::CreateTile(RasterSource* raster_source, |
832 const gfx::Size& tile_size, | 831 const gfx::Size& tile_size, |
833 const gfx::Rect& content_rect, | 832 const gfx::Rect& content_rect, |
834 float contents_scale, | 833 float contents_scale, |
835 int layer_id, | 834 int layer_id, |
836 int source_frame_number, | 835 int source_frame_number, |
837 int flags) { | 836 int flags) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 result -= other; | 921 result -= other; |
923 return result; | 922 return result; |
924 } | 923 } |
925 | 924 |
926 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 925 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
927 return memory_bytes_ > limit.memory_bytes_ || | 926 return memory_bytes_ > limit.memory_bytes_ || |
928 resource_count_ > limit.resource_count_; | 927 resource_count_ > limit.resource_count_; |
929 } | 928 } |
930 | 929 |
931 } // namespace cc | 930 } // namespace cc |
OLD | NEW |