| 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/debug/rendering_stats_instrumentation.h" | 18 #include "cc/debug/rendering_stats_instrumentation.h" |
| 19 #include "cc/layers/picture_layer_impl.h" | 19 #include "cc/layers/picture_layer_impl.h" |
| 20 #include "cc/resources/managed_tile_state.h" | 20 #include "cc/resources/managed_tile_state.h" |
| 21 #include "cc/resources/memory_history.h" | 21 #include "cc/resources/memory_history.h" |
| 22 #include "cc/resources/picture_pile_impl.h" | 22 #include "cc/resources/picture_pile_impl.h" |
| 23 #include "cc/resources/prioritized_tile_set.h" | |
| 24 #include "cc/resources/rasterizer.h" | 23 #include "cc/resources/rasterizer.h" |
| 25 #include "cc/resources/resource_pool.h" | 24 #include "cc/resources/resource_pool.h" |
| 26 #include "cc/resources/tile.h" | 25 #include "cc/resources/tile.h" |
| 27 | 26 |
| 28 namespace cc { | 27 namespace cc { |
| 29 class ResourceProvider; | 28 class ResourceProvider; |
| 30 | 29 |
| 31 class CC_EXPORT TileManagerClient { | 30 class CC_EXPORT TileManagerClient { |
| 32 public: | 31 public: |
| 33 virtual void NotifyReadyToActivate() = 0; | 32 virtual void NotifyReadyToActivate() = 0; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 | 62 |
| 64 class CC_EXPORT RasterTileIterator { | 63 class CC_EXPORT RasterTileIterator { |
| 65 public: | 64 public: |
| 66 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 65 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
| 67 ~RasterTileIterator(); | 66 ~RasterTileIterator(); |
| 68 | 67 |
| 69 RasterTileIterator& operator++(); | 68 RasterTileIterator& operator++(); |
| 70 operator bool() const; | 69 operator bool() const; |
| 71 Tile* operator*(); | 70 Tile* operator*(); |
| 72 | 71 |
| 72 bool HasTilesRequiredForActivation() const; |
| 73 |
| 73 private: | 74 private: |
| 74 struct PairedPictureLayerIterator { | 75 struct PairedPictureLayerIterator { |
| 75 PairedPictureLayerIterator(); | 76 PairedPictureLayerIterator(); |
| 76 ~PairedPictureLayerIterator(); | 77 ~PairedPictureLayerIterator(); |
| 77 | 78 |
| 78 Tile* PeekTile(TreePriority tree_priority); | 79 Tile* PeekTile(TreePriority tree_priority); |
| 79 void PopTile(TreePriority tree_priority); | 80 void PopTile(TreePriority tree_priority); |
| 80 | 81 |
| 81 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> | 82 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> |
| 82 NextTileIterator(TreePriority tree_priority); | 83 NextTileIterator(TreePriority tree_priority); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 106 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); | 107 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 struct CC_EXPORT EvictionTileIterator { | 110 struct CC_EXPORT EvictionTileIterator { |
| 110 public: | 111 public: |
| 111 EvictionTileIterator(); | 112 EvictionTileIterator(); |
| 112 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 113 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
| 113 ~EvictionTileIterator(); | 114 ~EvictionTileIterator(); |
| 114 | 115 |
| 115 EvictionTileIterator& operator++(); | 116 EvictionTileIterator& operator++(); |
| 116 operator bool() const; | 117 operator bool(); |
| 117 Tile* operator*(); | 118 Tile* operator*(); |
| 118 | 119 |
| 119 private: | 120 private: |
| 120 struct PairedPictureLayerIterator { | 121 struct PairedPictureLayerIterator { |
| 121 PairedPictureLayerIterator(); | 122 PairedPictureLayerIterator(); |
| 122 ~PairedPictureLayerIterator(); | 123 ~PairedPictureLayerIterator(); |
| 123 | 124 |
| 124 Tile* PeekTile(TreePriority tree_priority); | 125 Tile* PeekTile(TreePriority tree_priority); |
| 125 void PopTile(TreePriority tree_priority); | 126 void PopTile(TreePriority tree_priority); |
| 126 | 127 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 public: | 138 public: |
| 138 explicit EvictionOrderComparator(TreePriority tree_priority); | 139 explicit EvictionOrderComparator(TreePriority tree_priority); |
| 139 | 140 |
| 140 bool operator()(PairedPictureLayerIterator* a, | 141 bool operator()(PairedPictureLayerIterator* a, |
| 141 PairedPictureLayerIterator* b) const; | 142 PairedPictureLayerIterator* b) const; |
| 142 | 143 |
| 143 private: | 144 private: |
| 144 TreePriority tree_priority_; | 145 TreePriority tree_priority_; |
| 145 }; | 146 }; |
| 146 | 147 |
| 148 void Initialize(); |
| 149 |
| 150 bool initialized_; |
| 151 TileManager* tile_manager_; |
| 147 std::vector<PairedPictureLayerIterator> paired_iterators_; | 152 std::vector<PairedPictureLayerIterator> paired_iterators_; |
| 148 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 153 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
| 149 TreePriority tree_priority_; | 154 TreePriority tree_priority_; |
| 150 EvictionOrderComparator comparator_; | 155 EvictionOrderComparator comparator_; |
| 151 | 156 |
| 152 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); | 157 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); |
| 153 }; | 158 }; |
| 154 | 159 |
| 155 static scoped_ptr<TileManager> Create( | 160 static scoped_ptr<TileManager> Create( |
| 156 TileManagerClient* client, | 161 TileManagerClient* client, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 214 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 210 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 215 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 211 } | 216 } |
| 212 } | 217 } |
| 213 } | 218 } |
| 214 | 219 |
| 215 void SetGlobalStateForTesting( | 220 void SetGlobalStateForTesting( |
| 216 const GlobalStateThatImpactsTilePriority& state) { | 221 const GlobalStateThatImpactsTilePriority& state) { |
| 217 // Soft limit is used for resource pool such that | 222 // Soft limit is used for resource pool such that |
| 218 // memory returns to soft limit after going over. | 223 // memory returns to soft limit after going over. |
| 219 if (state != global_state_) { | 224 global_state_ = state; |
| 220 global_state_ = state; | |
| 221 prioritized_tiles_dirty_ = true; | |
| 222 } | |
| 223 } | 225 } |
| 224 | 226 |
| 225 void SetRasterizerForTesting(Rasterizer* rasterizer); | 227 void SetRasterizerForTesting(Rasterizer* rasterizer); |
| 226 | 228 |
| 227 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } | 229 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } |
| 228 | 230 |
| 229 protected: | 231 protected: |
| 230 TileManager(TileManagerClient* client, | 232 TileManager(TileManagerClient* client, |
| 231 ResourcePool* resource_pool, | 233 ResourcePool* resource_pool, |
| 232 Rasterizer* rasterizer, | 234 Rasterizer* rasterizer, |
| 233 bool use_rasterize_on_demand, | 235 bool use_rasterize_on_demand, |
| 234 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 236 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 235 | 237 |
| 236 // Methods called by Tile | |
| 237 friend class Tile; | |
| 238 void DidChangeTilePriority(Tile* tile); | |
| 239 | |
| 240 void CleanUpReleasedTiles(); | 238 void CleanUpReleasedTiles(); |
| 241 | 239 |
| 242 // Overriden from RefCountedManager<Tile>: | 240 // Overriden from RefCountedManager<Tile>: |
| 241 friend class Tile; |
| 243 virtual void Release(Tile* tile) OVERRIDE; | 242 virtual void Release(Tile* tile) OVERRIDE; |
| 244 | 243 |
| 245 // Overriden from RasterizerClient: | 244 // Overriden from RasterizerClient: |
| 246 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 245 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
| 247 virtual void DidFinishRunningTasks() OVERRIDE; | 246 virtual void DidFinishRunningTasks() OVERRIDE; |
| 248 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 247 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
| 249 | 248 |
| 250 typedef std::vector<Tile*> TileVector; | 249 typedef std::vector<Tile*> TileVector; |
| 251 typedef std::set<Tile*> TileSet; | 250 typedef std::set<Tile*> TileSet; |
| 252 | 251 |
| 253 // Virtual for test | 252 // Virtual for test |
| 254 virtual void ScheduleTasks( | 253 virtual void ScheduleTasks( |
| 255 const TileVector& tiles_that_need_to_be_rasterized); | 254 const TileVector& tiles_that_need_to_be_rasterized); |
| 256 | 255 |
| 257 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 256 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
| 258 TileVector* tiles_that_need_to_be_rasterized); | |
| 259 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
| 260 | 257 |
| 261 private: | 258 private: |
| 259 struct MemoryBudget { |
| 260 int64 soft_memory_bytes; |
| 261 int64 hard_memory_bytes; |
| 262 int resource_count; |
| 263 |
| 264 bool Exceeds(const MemoryBudget& other) const { |
| 265 return soft_memory_bytes > other.soft_memory_bytes || |
| 266 hard_memory_bytes > other.hard_memory_bytes || |
| 267 resource_count > other.resource_count; |
| 268 } |
| 269 }; |
| 270 |
| 262 void OnImageDecodeTaskCompleted(int layer_id, | 271 void OnImageDecodeTaskCompleted(int layer_id, |
| 263 SkPixelRef* pixel_ref, | 272 SkPixelRef* pixel_ref, |
| 264 bool was_canceled); | 273 bool was_canceled); |
| 265 void OnRasterTaskCompleted(Tile::Id tile, | 274 void OnRasterTaskCompleted(Tile::Id tile, |
| 266 scoped_ptr<ScopedResource> resource, | 275 scoped_ptr<ScopedResource> resource, |
| 267 RasterMode raster_mode, | 276 RasterMode raster_mode, |
| 268 const PicturePileImpl::Analysis& analysis, | 277 const PicturePileImpl::Analysis& analysis, |
| 269 bool was_canceled); | 278 bool was_canceled); |
| 270 | 279 |
| 271 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 280 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
| 272 return Resource::MemorySizeBytes(tile->size(), | 281 return Resource::MemorySizeBytes(tile->size(), |
| 273 resource_pool_->resource_format()); | 282 resource_pool_->resource_format()); |
| 274 } | 283 } |
| 275 | 284 |
| 276 void FreeResourceForTile(Tile* tile, RasterMode mode); | 285 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 277 void FreeResourcesForTile(Tile* tile); | 286 void FreeResourcesForTile(Tile* tile); |
| 278 void FreeUnusedResourcesForTile(Tile* tile); | 287 void FreeUnusedResourcesForTile(Tile* tile); |
| 279 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 288 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 280 SkPixelRef* pixel_ref); | 289 SkPixelRef* pixel_ref); |
| 281 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 290 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 282 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 291 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
| 283 void UpdatePrioritizedTileSetIfNeeded(); | 292 bool FreeTileResourcesUntilUsageIsWithinBudget( |
| 293 EvictionTileIterator* eviction_iterator, |
| 294 const MemoryBudget& required_budget, |
| 295 MemoryBudget* current_budget, |
| 296 const TilePriority& max_priority, |
| 297 bool evict_unconditionally); |
| 284 void CleanUpLayers(); | 298 void CleanUpLayers(); |
| 299 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
| 285 | 300 |
| 286 TileManagerClient* client_; | 301 TileManagerClient* client_; |
| 287 ResourcePool* resource_pool_; | 302 ResourcePool* resource_pool_; |
| 288 Rasterizer* rasterizer_; | 303 Rasterizer* rasterizer_; |
| 289 GlobalStateThatImpactsTilePriority global_state_; | 304 GlobalStateThatImpactsTilePriority global_state_; |
| 290 | 305 |
| 291 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 306 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 292 TileMap tiles_; | 307 TileMap tiles_; |
| 293 | 308 |
| 294 PrioritizedTileSet prioritized_tiles_; | |
| 295 bool prioritized_tiles_dirty_; | |
| 296 | |
| 297 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 309 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
| 298 bool all_tiles_required_for_activation_have_memory_; | 310 bool all_tiles_required_for_activation_have_memory_; |
| 299 | 311 |
| 300 size_t memory_required_bytes_; | |
| 301 size_t memory_nice_to_have_bytes_; | |
| 302 | |
| 303 size_t bytes_releasable_; | 312 size_t bytes_releasable_; |
| 304 size_t resources_releasable_; | 313 size_t resources_releasable_; |
| 305 | 314 |
| 306 bool ever_exceeded_memory_budget_; | 315 bool ever_exceeded_memory_budget_; |
| 307 MemoryHistory::Entry memory_stats_from_last_assign_; | 316 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 308 | 317 |
| 309 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 318 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 310 | 319 |
| 311 bool did_initialize_visible_tile_; | 320 bool did_initialize_visible_tile_; |
| 312 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 321 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 333 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 342 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
| 334 | 343 |
| 335 std::vector<PictureLayerImpl*> layers_; | 344 std::vector<PictureLayerImpl*> layers_; |
| 336 | 345 |
| 337 DISALLOW_COPY_AND_ASSIGN(TileManager); | 346 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 338 }; | 347 }; |
| 339 | 348 |
| 340 } // namespace cc | 349 } // namespace cc |
| 341 | 350 |
| 342 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 351 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |