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/tiles/tile_manager.h" | 5 #include "cc/tiles/tile_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/numerics/safe_conversions.h" |
15 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
16 #include "cc/base/histograms.h" | 17 #include "cc/base/histograms.h" |
17 #include "cc/debug/devtools_instrumentation.h" | 18 #include "cc/debug/devtools_instrumentation.h" |
18 #include "cc/debug/frame_viewer_instrumentation.h" | 19 #include "cc/debug/frame_viewer_instrumentation.h" |
19 #include "cc/debug/traced_value.h" | 20 #include "cc/debug/traced_value.h" |
20 #include "cc/layers/picture_layer_impl.h" | 21 #include "cc/layers/picture_layer_impl.h" |
21 #include "cc/raster/raster_buffer.h" | 22 #include "cc/raster/raster_buffer.h" |
22 #include "cc/raster/tile_task_runner.h" | 23 #include "cc/raster/tile_task_runner.h" |
23 #include "cc/tiles/tile.h" | 24 #include "cc/tiles/tile.h" |
24 #include "ui/gfx/geometry/rect_conversions.h" | 25 #include "ui/gfx/geometry/rect_conversions.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 202 |
202 } // namespace | 203 } // namespace |
203 | 204 |
204 RasterTaskCompletionStats::RasterTaskCompletionStats() | 205 RasterTaskCompletionStats::RasterTaskCompletionStats() |
205 : completed_count(0u), canceled_count(0u) {} | 206 : completed_count(0u), canceled_count(0u) {} |
206 | 207 |
207 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 208 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
208 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) { | 209 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) { |
209 scoped_refptr<base::trace_event::TracedValue> state = | 210 scoped_refptr<base::trace_event::TracedValue> state = |
210 new base::trace_event::TracedValue(); | 211 new base::trace_event::TracedValue(); |
211 state->SetInteger("completed_count", stats.completed_count); | 212 state->SetInteger("completed_count", |
212 state->SetInteger("canceled_count", stats.canceled_count); | 213 base::saturated_cast<int>(stats.completed_count)); |
| 214 state->SetInteger("canceled_count", |
| 215 base::saturated_cast<int>(stats.canceled_count)); |
213 return state; | 216 return state; |
214 } | 217 } |
215 | 218 |
216 // static | 219 // static |
217 scoped_ptr<TileManager> TileManager::Create( | 220 scoped_ptr<TileManager> TileManager::Create( |
218 TileManagerClient* client, | 221 TileManagerClient* client, |
219 base::SequencedTaskRunner* task_runner, | 222 base::SequencedTaskRunner* task_runner, |
220 ResourcePool* resource_pool, | 223 ResourcePool* resource_pool, |
221 TileTaskRunner* tile_task_runner, | 224 TileTaskRunner* tile_task_runner, |
222 size_t scheduled_raster_task_limit) { | 225 size_t scheduled_raster_task_limit) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 409 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
407 TileManager::BasicStateAsValue() const { | 410 TileManager::BasicStateAsValue() const { |
408 scoped_refptr<base::trace_event::TracedValue> value = | 411 scoped_refptr<base::trace_event::TracedValue> value = |
409 new base::trace_event::TracedValue(); | 412 new base::trace_event::TracedValue(); |
410 BasicStateAsValueInto(value.get()); | 413 BasicStateAsValueInto(value.get()); |
411 return value; | 414 return value; |
412 } | 415 } |
413 | 416 |
414 void TileManager::BasicStateAsValueInto( | 417 void TileManager::BasicStateAsValueInto( |
415 base::trace_event::TracedValue* state) const { | 418 base::trace_event::TracedValue* state) const { |
416 state->SetInteger("tile_count", tiles_.size()); | 419 state->SetInteger("tile_count", base::saturated_cast<int>(tiles_.size())); |
417 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_); | 420 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_); |
418 state->BeginDictionary("global_state"); | 421 state->BeginDictionary("global_state"); |
419 global_state_.AsValueInto(state); | 422 global_state_.AsValueInto(state); |
420 state->EndDictionary(); | 423 state->EndDictionary(); |
421 } | 424 } |
422 | 425 |
423 scoped_ptr<EvictionTilePriorityQueue> | 426 scoped_ptr<EvictionTilePriorityQueue> |
424 TileManager::FreeTileResourcesUntilUsageIsWithinLimit( | 427 TileManager::FreeTileResourcesUntilUsageIsWithinLimit( |
425 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue, | 428 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue, |
426 const MemoryUsage& limit, | 429 const MemoryUsage& limit, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 eviction_priority_queue = FreeTileResourcesUntilUsageIsWithinLimit( | 582 eviction_priority_queue = FreeTileResourcesUntilUsageIsWithinLimit( |
580 eviction_priority_queue.Pass(), hard_memory_limit, &memory_usage); | 583 eviction_priority_queue.Pass(), hard_memory_limit, &memory_usage); |
581 | 584 |
582 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", | 585 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", |
583 !had_enough_memory_to_schedule_tiles_needed_now); | 586 !had_enough_memory_to_schedule_tiles_needed_now); |
584 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; | 587 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; |
585 | 588 |
586 memory_stats_from_last_assign_.total_budget_in_bytes = | 589 memory_stats_from_last_assign_.total_budget_in_bytes = |
587 global_state_.hard_memory_limit_in_bytes; | 590 global_state_.hard_memory_limit_in_bytes; |
588 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); | 591 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); |
| 592 DCHECK_GE(memory_stats_from_last_assign_.total_bytes_used, 0); |
589 memory_stats_from_last_assign_.had_enough_memory = | 593 memory_stats_from_last_assign_.had_enough_memory = |
590 had_enough_memory_to_schedule_tiles_needed_now; | 594 had_enough_memory_to_schedule_tiles_needed_now; |
591 | 595 |
592 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 596 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
593 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 597 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
594 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 598 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
595 "had_enough_memory_to_schedule_tiles_needed_now", | 599 "had_enough_memory_to_schedule_tiles_needed_now", |
596 had_enough_memory_to_schedule_tiles_needed_now); | 600 had_enough_memory_to_schedule_tiles_needed_now); |
597 } | 601 } |
598 | 602 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 client_->NotifyTileStateChanged(tile); | 963 client_->NotifyTileStateChanged(tile); |
960 } | 964 } |
961 | 965 |
962 DCHECK(IsReadyToActivate()); | 966 DCHECK(IsReadyToActivate()); |
963 ready_to_activate_check_notifier_.Schedule(); | 967 ready_to_activate_check_notifier_.Schedule(); |
964 } | 968 } |
965 | 969 |
966 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { | 970 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { |
967 } | 971 } |
968 | 972 |
969 TileManager::MemoryUsage::MemoryUsage(int64 memory_bytes, int resource_count) | 973 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, |
970 : memory_bytes_(memory_bytes), resource_count_(resource_count) { | 974 size_t resource_count) |
| 975 : memory_bytes_(static_cast<int64>(memory_bytes)), |
| 976 resource_count_(static_cast<int>(resource_count)) { |
| 977 // MemoryUsage is constructed using size_ts, since it deals with memory and |
| 978 // the inputs are typically size_t. However, during the course of usage (in |
| 979 // particular operator-=) can cause internal values to become negative. Thus, |
| 980 // member variables are signed. |
| 981 DCHECK_LE(memory_bytes, |
| 982 static_cast<size_t>(std::numeric_limits<int64>::max())); |
| 983 DCHECK_LE(resource_count, |
| 984 static_cast<size_t>(std::numeric_limits<int>::max())); |
971 } | 985 } |
972 | 986 |
973 // static | 987 // static |
974 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig( | 988 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig( |
975 const gfx::Size& size, | 989 const gfx::Size& size, |
976 ResourceFormat format) { | 990 ResourceFormat format) { |
977 // We can use UncheckedMemorySizeBytes here since this is used with a tile | 991 // We can use UncheckedMemorySizeBytes here since this is used with a tile |
978 // size which is determined by the compositor (it's at most max texture size). | 992 // size which is determined by the compositor (it's at most max texture size). |
979 return MemoryUsage(Resource::UncheckedMemorySizeBytes(size, format), 1); | 993 return MemoryUsage(Resource::UncheckedMemorySizeBytes(size, format), 1); |
980 } | 994 } |
(...skipping 28 matching lines...) Expand all Loading... |
1009 result -= other; | 1023 result -= other; |
1010 return result; | 1024 return result; |
1011 } | 1025 } |
1012 | 1026 |
1013 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1027 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
1014 return memory_bytes_ > limit.memory_bytes_ || | 1028 return memory_bytes_ > limit.memory_bytes_ || |
1015 resource_count_ > limit.resource_count_; | 1029 resource_count_ > limit.resource_count_; |
1016 } | 1030 } |
1017 | 1031 |
1018 } // namespace cc | 1032 } // namespace cc |
OLD | NEW |