Chromium Code Reviews| 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 #ifndef CC_RESOURCES_TILE_MANAGER_H_ | 5 #ifndef CC_RESOURCES_TILE_MANAGER_H_ |
| 6 #define CC_RESOURCES_TILE_MANAGER_H_ | 6 #define CC_RESOURCES_TILE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "cc/base/ref_counted_managed.h" | 17 #include "cc/base/ref_counted_managed.h" |
| 18 #include "cc/base/unique_notifier.h" | 18 #include "cc/base/unique_notifier.h" |
| 19 #include "cc/debug/rendering_stats_instrumentation.h" | 19 #include "cc/debug/rendering_stats_instrumentation.h" |
| 20 #include "cc/resources/eviction_tile_priority_queue.h" | 20 #include "cc/resources/eviction_tile_priority_queue.h" |
| 21 #include "cc/resources/managed_tile_state.h" | 21 #include "cc/resources/managed_tile_state.h" |
| 22 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
| 23 #include "cc/resources/picture_pile_impl.h" | 23 #include "cc/resources/picture_pile_impl.h" |
| 24 #include "cc/resources/prioritized_tile_set.h" | |
| 25 #include "cc/resources/raster_tile_priority_queue.h" | 24 #include "cc/resources/raster_tile_priority_queue.h" |
| 26 #include "cc/resources/rasterizer.h" | 25 #include "cc/resources/rasterizer.h" |
| 27 #include "cc/resources/resource_pool.h" | 26 #include "cc/resources/resource_pool.h" |
| 28 #include "cc/resources/tile.h" | 27 #include "cc/resources/tile.h" |
| 29 | 28 |
| 30 namespace base { | 29 namespace base { |
| 31 namespace debug { | 30 namespace debug { |
| 32 class ConvertableToTraceFormat; | 31 class ConvertableToTraceFormat; |
| 33 class TracedValue; | 32 class TracedValue; |
| 34 } | 33 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 115 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 117 return memory_stats_from_last_assign_; | 116 return memory_stats_from_last_assign_; |
| 118 } | 117 } |
| 119 | 118 |
| 120 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 119 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 121 for (size_t i = 0; i < tiles.size(); ++i) { | 120 for (size_t i = 0; i < tiles.size(); ++i) { |
| 122 ManagedTileState& mts = tiles[i]->managed_state(); | 121 ManagedTileState& mts = tiles[i]->managed_state(); |
| 123 ManagedTileState::TileVersion& tile_version = | 122 ManagedTileState::TileVersion& tile_version = |
| 124 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; | 123 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; |
| 125 | 124 |
| 126 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 125 tile_version.resource_ = |
| 127 | 126 resource_pool_->AcquireResource(tiles[i]->size()); |
| 128 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | |
| 129 ++resources_releasable_; | |
| 130 } | 127 } |
| 131 } | 128 } |
| 132 | 129 |
| 133 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { | 130 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 134 for (size_t i = 0; i < tiles.size(); ++i) { | 131 for (size_t i = 0; i < tiles.size(); ++i) { |
| 135 Tile* tile = tiles[i]; | 132 Tile* tile = tiles[i]; |
| 136 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 133 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 137 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 134 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 138 } | 135 } |
| 139 } | 136 } |
| 140 } | 137 } |
| 141 | 138 |
| 142 void SetGlobalStateForTesting( | 139 void SetGlobalStateForTesting( |
| 143 const GlobalStateThatImpactsTilePriority& state) { | 140 const GlobalStateThatImpactsTilePriority& state) { |
| 144 // Soft limit is used for resource pool such that | 141 global_state_ = state; |
| 145 // memory returns to soft limit after going over. | |
| 146 if (state != global_state_) { | |
| 147 global_state_ = state; | |
| 148 prioritized_tiles_dirty_ = true; | |
| 149 } | |
| 150 } | 142 } |
| 151 | 143 |
| 152 void SetRasterizerForTesting(Rasterizer* rasterizer); | 144 void SetRasterizerForTesting(Rasterizer* rasterizer); |
| 153 | 145 |
| 154 void FreeResourcesAndCleanUpReleasedTilesForTesting() { | 146 void FreeResourcesAndCleanUpReleasedTilesForTesting() { |
| 155 prioritized_tiles_.Clear(); | |
| 156 FreeResourcesForReleasedTiles(); | 147 FreeResourcesForReleasedTiles(); |
| 157 CleanUpReleasedTiles(); | 148 CleanUpReleasedTiles(); |
| 158 } | 149 } |
| 159 | 150 |
| 160 protected: | 151 protected: |
| 161 TileManager(TileManagerClient* client, | 152 TileManager(TileManagerClient* client, |
| 162 base::SequencedTaskRunner* task_runner, | 153 base::SequencedTaskRunner* task_runner, |
| 163 ResourcePool* resource_pool, | 154 ResourcePool* resource_pool, |
| 164 Rasterizer* rasterizer, | 155 Rasterizer* rasterizer, |
| 165 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 156 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 166 | 157 |
| 167 // Methods called by Tile | |
| 168 friend class Tile; | |
| 169 void DidChangeTilePriority(Tile* tile); | |
| 170 | |
| 171 void FreeResourcesForReleasedTiles(); | 158 void FreeResourcesForReleasedTiles(); |
| 172 void CleanUpReleasedTiles(); | 159 void CleanUpReleasedTiles(); |
| 173 | 160 |
| 174 // Overriden from RefCountedManager<Tile>: | 161 // Overriden from RefCountedManager<Tile>: |
| 162 friend class Tile; | |
| 175 virtual void Release(Tile* tile) OVERRIDE; | 163 virtual void Release(Tile* tile) OVERRIDE; |
| 176 | 164 |
| 177 // Overriden from RasterizerClient: | 165 // Overriden from RasterizerClient: |
| 178 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 166 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
| 179 virtual void DidFinishRunningTasks() OVERRIDE; | 167 virtual void DidFinishRunningTasks() OVERRIDE; |
| 180 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 168 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
| 181 | 169 |
| 182 typedef std::vector<Tile*> TileVector; | 170 typedef std::vector<Tile*> TileVector; |
| 183 typedef std::set<Tile*> TileSet; | 171 typedef std::set<Tile*> TileSet; |
| 184 | 172 |
| 185 // Virtual for test | 173 // Virtual for test |
| 186 virtual void ScheduleTasks( | 174 virtual void ScheduleTasks( |
| 187 const TileVector& tiles_that_need_to_be_rasterized); | 175 const TileVector& tiles_that_need_to_be_rasterized); |
| 188 | 176 |
| 189 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 177 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
| 190 TileVector* tiles_that_need_to_be_rasterized); | |
| 191 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
| 192 | 178 |
| 193 private: | 179 private: |
| 180 class MemoryUsage { | |
| 181 public: | |
| 182 MemoryUsage(); | |
| 183 MemoryUsage(int64 memory_bytes, int resource_count); | |
| 184 | |
| 185 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | |
| 186 static MemoryUsage FromTile(const Tile* tile); | |
| 187 | |
| 188 MemoryUsage& operator+=(const MemoryUsage& other); | |
| 189 MemoryUsage& operator-=(const MemoryUsage& other); | |
| 190 MemoryUsage operator-(const MemoryUsage& other); | |
| 191 | |
| 192 bool Exceeds(const MemoryUsage& limit) const; | |
| 193 int64 memory_bytes() const { return memory_bytes_; } | |
| 194 | |
| 195 private: | |
| 196 int64 memory_bytes_; | |
| 197 int resource_count_; | |
| 198 }; | |
| 199 | |
| 194 void OnImageDecodeTaskCompleted(int layer_id, | 200 void OnImageDecodeTaskCompleted(int layer_id, |
| 195 SkPixelRef* pixel_ref, | 201 SkPixelRef* pixel_ref, |
| 196 bool was_canceled); | 202 bool was_canceled); |
| 197 void OnRasterTaskCompleted(Tile::Id tile, | 203 void OnRasterTaskCompleted(Tile::Id tile, |
| 198 scoped_ptr<ScopedResource> resource, | 204 scoped_ptr<ScopedResource> resource, |
| 199 RasterMode raster_mode, | 205 RasterMode raster_mode, |
| 200 const PicturePileImpl::Analysis& analysis, | 206 const PicturePileImpl::Analysis& analysis, |
| 201 bool was_canceled); | 207 bool was_canceled); |
| 202 | 208 |
| 203 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | |
| 204 return Resource::MemorySizeBytes(tile->size(), | |
| 205 resource_pool_->resource_format()); | |
| 206 } | |
| 207 | |
| 208 void FreeResourceForTile(Tile* tile, RasterMode mode); | 209 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 209 void FreeResourcesForTile(Tile* tile); | 210 void FreeResourcesForTile(Tile* tile); |
| 210 void FreeUnusedResourcesForTile(Tile* tile); | 211 void FreeUnusedResourcesForTile(Tile* tile); |
| 211 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 212 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
| 212 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 213 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 213 SkPixelRef* pixel_ref); | 214 SkPixelRef* pixel_ref); |
| 214 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 215 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 215 void UpdatePrioritizedTileSetIfNeeded(); | |
| 216 | 216 |
| 217 void RebuildEvictionQueueIfNeeded(); | |
| 218 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | |
| 219 MemoryUsage* usage); | |
| 220 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | |
| 221 const MemoryUsage& limit, | |
| 222 const TilePriority& oother_priority, | |
| 223 MemoryUsage* usage); | |
| 224 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | |
| 217 bool IsReadyToActivate() const; | 225 bool IsReadyToActivate() const; |
| 218 void CheckIfReadyToActivate(); | 226 void CheckIfReadyToActivate(); |
| 219 | 227 |
| 220 TileManagerClient* client_; | 228 TileManagerClient* client_; |
| 221 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 229 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 222 ResourcePool* resource_pool_; | 230 ResourcePool* resource_pool_; |
| 223 Rasterizer* rasterizer_; | 231 Rasterizer* rasterizer_; |
| 224 GlobalStateThatImpactsTilePriority global_state_; | 232 GlobalStateThatImpactsTilePriority global_state_; |
| 225 | 233 |
| 226 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 234 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 227 TileMap tiles_; | 235 TileMap tiles_; |
| 228 | 236 |
| 229 PrioritizedTileSet prioritized_tiles_; | 237 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 230 bool prioritized_tiles_dirty_; | |
| 231 | |
| 232 bool all_tiles_that_need_to_be_rasterized_have_memory_; | |
| 233 bool all_tiles_required_for_activation_have_memory_; | |
| 234 | |
| 235 size_t bytes_releasable_; | |
| 236 size_t resources_releasable_; | |
| 237 | |
| 238 bool ever_exceeded_memory_budget_; | |
| 239 MemoryHistory::Entry memory_stats_from_last_assign_; | 238 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 240 | 239 |
| 241 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 240 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 242 | 241 |
| 243 bool did_initialize_visible_tile_; | 242 bool did_initialize_visible_tile_; |
| 244 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 243 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| 245 | 244 |
| 246 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > | 245 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > |
| 247 PixelRefTaskMap; | 246 PixelRefTaskMap; |
| 248 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 247 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; |
| 249 LayerPixelRefTaskMap image_decode_tasks_; | 248 LayerPixelRefTaskMap image_decode_tasks_; |
| 250 | 249 |
| 251 typedef base::hash_map<int, int> LayerCountMap; | 250 typedef base::hash_map<int, int> LayerCountMap; |
| 252 LayerCountMap used_layer_counts_; | 251 LayerCountMap used_layer_counts_; |
| 253 | 252 |
| 254 RasterTaskCompletionStats update_visible_tiles_stats_; | 253 RasterTaskCompletionStats update_visible_tiles_stats_; |
| 255 | 254 |
| 256 std::vector<Tile*> released_tiles_; | 255 std::vector<Tile*> released_tiles_; |
| 257 | 256 |
| 258 ResourceFormat resource_format_; | 257 ResourceFormat resource_format_; |
| 259 | 258 |
| 260 // Queue used when scheduling raster tasks. | 259 // Queue used when scheduling raster tasks. |
| 261 RasterTaskQueue raster_queue_; | 260 RasterTaskQueue raster_queue_; |
| 262 | 261 |
| 263 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 262 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
| 264 | 263 |
| 265 UniqueNotifier ready_to_activate_check_notifier_; | 264 UniqueNotifier ready_to_activate_check_notifier_; |
| 266 | 265 |
| 266 RasterTilePriorityQueue raster_priority_queue_; | |
| 267 EvictionTilePriorityQueue eviction_priority_queue_; | |
| 268 bool eviction_priority_queue_is_up_to_date_; | |
|
reveman
2014/08/17 18:26:06
nit: i feel like we usually use the term "dirty" f
| |
| 269 | |
| 267 DISALLOW_COPY_AND_ASSIGN(TileManager); | 270 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 268 }; | 271 }; |
| 269 | 272 |
| 270 } // namespace cc | 273 } // namespace cc |
| 271 | 274 |
| 272 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 275 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |