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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 client_->NotifyTileStateChanged(tile); | 962 client_->NotifyTileStateChanged(tile); |
960 } | 963 } |
961 | 964 |
962 DCHECK(IsReadyToActivate()); | 965 DCHECK(IsReadyToActivate()); |
963 ready_to_activate_check_notifier_.Schedule(); | 966 ready_to_activate_check_notifier_.Schedule(); |
964 } | 967 } |
965 | 968 |
966 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { | 969 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { |
967 } | 970 } |
968 | 971 |
969 TileManager::MemoryUsage::MemoryUsage(int64 memory_bytes, int resource_count) | 972 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, |
970 : memory_bytes_(memory_bytes), resource_count_(resource_count) { | 973 size_t resource_count) |
| 974 : memory_bytes_(static_cast<int64>(memory_bytes)), |
| 975 resource_count_(static_cast<int>(resource_count)) { |
| 976 // MemoryUsage is constructed using size_ts, since it deals with memory and |
| 977 // the inputs are typically size_t. However, during the course of usage (in |
| 978 // particular operator-=) can cause internal values to become negative. Thus, |
| 979 // member variables are signed. |
| 980 DCHECK_LE(memory_bytes, |
| 981 static_cast<size_t>(std::numeric_limits<int64>::max())); |
| 982 DCHECK_LE(resource_count, |
| 983 static_cast<size_t>(std::numeric_limits<int>::max())); |
971 } | 984 } |
972 | 985 |
973 // static | 986 // static |
974 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig( | 987 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig( |
975 const gfx::Size& size, | 988 const gfx::Size& size, |
976 ResourceFormat format) { | 989 ResourceFormat format) { |
977 // We can use UncheckedMemorySizeBytes here since this is used with a tile | 990 // 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). | 991 // size which is determined by the compositor (it's at most max texture size). |
979 return MemoryUsage(Resource::UncheckedMemorySizeBytes(size, format), 1); | 992 return MemoryUsage(Resource::UncheckedMemorySizeBytes(size, format), 1); |
980 } | 993 } |
(...skipping 28 matching lines...) Expand all Loading... |
1009 result -= other; | 1022 result -= other; |
1010 return result; | 1023 return result; |
1011 } | 1024 } |
1012 | 1025 |
1013 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1026 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
1014 return memory_bytes_ > limit.memory_bytes_ || | 1027 return memory_bytes_ > limit.memory_bytes_ || |
1015 resource_count_ > limit.resource_count_; | 1028 resource_count_ > limit.resource_count_; |
1016 } | 1029 } |
1017 | 1030 |
1018 } // namespace cc | 1031 } // namespace cc |
OLD | NEW |