| 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 RasterizerDelegate; | 28 class RasterizerDelegate; |
| 30 class ResourceProvider; | 29 class ResourceProvider; |
| 31 | 30 |
| 32 class CC_EXPORT TileManagerClient { | 31 class CC_EXPORT TileManagerClient { |
| 33 public: | 32 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 PairedPictureLayer(); | 56 PairedPictureLayer(); |
| 58 ~PairedPictureLayer(); | 57 ~PairedPictureLayer(); |
| 59 | 58 |
| 60 PictureLayerImpl* active_layer; | 59 PictureLayerImpl* active_layer; |
| 61 PictureLayerImpl* pending_layer; | 60 PictureLayerImpl* pending_layer; |
| 62 }; | 61 }; |
| 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); |
| 66 RasterTileIterator(const RasterTileIterator& other); |
| 67 ~RasterTileIterator(); | 67 ~RasterTileIterator(); |
| 68 | 68 |
| 69 RasterTileIterator& operator++(); | 69 RasterTileIterator& operator++(); |
| 70 operator bool() const; | 70 operator bool() const; |
| 71 Tile* operator*(); | 71 Tile* operator*(); |
| 72 RasterTileIterator& operator=(const RasterTileIterator& other); |
| 73 |
| 74 bool HasTilesRequiredForActivation() const; |
| 72 | 75 |
| 73 private: | 76 private: |
| 74 struct PairedPictureLayerIterator { | 77 struct PairedPictureLayerIterator { |
| 75 PairedPictureLayerIterator(); | 78 PairedPictureLayerIterator(); |
| 76 ~PairedPictureLayerIterator(); | 79 ~PairedPictureLayerIterator(); |
| 77 | 80 |
| 78 Tile* PeekTile(TreePriority tree_priority); | 81 Tile* PeekTile(TreePriority tree_priority); |
| 79 void PopTile(TreePriority tree_priority); | 82 void PopTile(TreePriority tree_priority); |
| 80 | 83 |
| 81 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> | 84 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 100 | 103 |
| 101 std::vector<PairedPictureLayerIterator> paired_iterators_; | 104 std::vector<PairedPictureLayerIterator> paired_iterators_; |
| 102 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 105 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
| 103 TreePriority tree_priority_; | 106 TreePriority tree_priority_; |
| 104 RasterOrderComparator comparator_; | 107 RasterOrderComparator comparator_; |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 struct CC_EXPORT EvictionTileIterator { | 110 struct CC_EXPORT EvictionTileIterator { |
| 108 public: | 111 public: |
| 109 EvictionTileIterator(); | 112 EvictionTileIterator(); |
| 113 EvictionTileIterator(const EvictionTileIterator& other); |
| 110 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 114 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
| 111 ~EvictionTileIterator(); | 115 ~EvictionTileIterator(); |
| 112 | 116 |
| 113 EvictionTileIterator& operator++(); | 117 EvictionTileIterator& operator++(); |
| 114 operator bool() const; | 118 operator bool(); |
| 115 Tile* operator*(); | 119 Tile* operator*(); |
| 120 EvictionTileIterator& operator=(const EvictionTileIterator& other); |
| 116 | 121 |
| 117 private: | 122 private: |
| 118 struct PairedPictureLayerIterator { | 123 struct PairedPictureLayerIterator { |
| 119 PairedPictureLayerIterator(); | 124 PairedPictureLayerIterator(); |
| 120 ~PairedPictureLayerIterator(); | 125 ~PairedPictureLayerIterator(); |
| 121 | 126 |
| 122 Tile* PeekTile(TreePriority tree_priority); | 127 Tile* PeekTile(TreePriority tree_priority); |
| 123 void PopTile(TreePriority tree_priority); | 128 void PopTile(TreePriority tree_priority); |
| 124 | 129 |
| 125 PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator( | 130 PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator( |
| 126 TreePriority tree_priority); | 131 TreePriority tree_priority); |
| 127 | 132 |
| 128 PictureLayerImpl::LayerEvictionTileIterator active_iterator; | 133 PictureLayerImpl::LayerEvictionTileIterator active_iterator; |
| 129 PictureLayerImpl::LayerEvictionTileIterator pending_iterator; | 134 PictureLayerImpl::LayerEvictionTileIterator pending_iterator; |
| 130 | 135 |
| 131 std::vector<Tile*> returned_shared_tiles; | 136 std::vector<Tile*> returned_shared_tiles; |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 class EvictionOrderComparator { | 139 class EvictionOrderComparator { |
| 135 public: | 140 public: |
| 136 explicit EvictionOrderComparator(TreePriority tree_priority); | 141 explicit EvictionOrderComparator(TreePriority tree_priority); |
| 137 | 142 |
| 138 bool operator()(PairedPictureLayerIterator* a, | 143 bool operator()(PairedPictureLayerIterator* a, |
| 139 PairedPictureLayerIterator* b) const; | 144 PairedPictureLayerIterator* b) const; |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 TreePriority tree_priority_; | 147 TreePriority tree_priority_; |
| 143 }; | 148 }; |
| 144 | 149 |
| 150 void Initialize(); |
| 151 |
| 152 bool initialized_; |
| 153 TileManager* tile_manager_; |
| 145 std::vector<PairedPictureLayerIterator> paired_iterators_; | 154 std::vector<PairedPictureLayerIterator> paired_iterators_; |
| 146 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 155 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
| 147 TreePriority tree_priority_; | 156 TreePriority tree_priority_; |
| 148 EvictionOrderComparator comparator_; | 157 EvictionOrderComparator comparator_; |
| 149 }; | 158 }; |
| 150 | 159 |
| 151 static scoped_ptr<TileManager> Create( | 160 static scoped_ptr<TileManager> Create( |
| 152 TileManagerClient* client, | 161 TileManagerClient* client, |
| 153 ResourcePool* resource_pool, | 162 ResourcePool* resource_pool, |
| 154 Rasterizer* rasterizer, | 163 Rasterizer* rasterizer, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 216 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 208 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 217 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 209 } | 218 } |
| 210 } | 219 } |
| 211 } | 220 } |
| 212 | 221 |
| 213 void SetGlobalStateForTesting( | 222 void SetGlobalStateForTesting( |
| 214 const GlobalStateThatImpactsTilePriority& state) { | 223 const GlobalStateThatImpactsTilePriority& state) { |
| 215 // Soft limit is used for resource pool such that | 224 // Soft limit is used for resource pool such that |
| 216 // memory returns to soft limit after going over. | 225 // memory returns to soft limit after going over. |
| 217 if (state != global_state_) { | 226 global_state_ = state; |
| 218 global_state_ = state; | |
| 219 prioritized_tiles_dirty_ = true; | |
| 220 } | |
| 221 } | 227 } |
| 222 | 228 |
| 223 protected: | 229 protected: |
| 224 TileManager(TileManagerClient* client, | 230 TileManager(TileManagerClient* client, |
| 225 ResourcePool* resource_pool, | 231 ResourcePool* resource_pool, |
| 226 Rasterizer* rasterizer, | 232 Rasterizer* rasterizer, |
| 227 Rasterizer* gpu_rasterizer, | 233 Rasterizer* gpu_rasterizer, |
| 228 size_t max_raster_usage_bytes, | 234 size_t max_raster_usage_bytes, |
| 229 bool use_rasterize_on_demand, | 235 bool use_rasterize_on_demand, |
| 230 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 236 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 231 | 237 |
| 232 // Methods called by Tile | |
| 233 friend class Tile; | |
| 234 void DidChangeTilePriority(Tile* tile); | |
| 235 | |
| 236 void CleanUpReleasedTiles(); | 238 void CleanUpReleasedTiles(); |
| 237 | 239 |
| 238 // Overriden from RefCountedManager<Tile>: | 240 // Overriden from RefCountedManager<Tile>: |
| 241 friend class Tile; |
| 239 virtual void Release(Tile* tile) OVERRIDE; | 242 virtual void Release(Tile* tile) OVERRIDE; |
| 240 | 243 |
| 241 // Overriden from RasterizerClient: | 244 // Overriden from RasterizerClient: |
| 242 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 245 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
| 243 virtual void DidFinishRunningTasks() OVERRIDE; | 246 virtual void DidFinishRunningTasks() OVERRIDE; |
| 244 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 247 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
| 245 | 248 |
| 246 typedef std::vector<Tile*> TileVector; | 249 typedef std::vector<Tile*> TileVector; |
| 247 typedef std::set<Tile*> TileSet; | 250 typedef std::set<Tile*> TileSet; |
| 248 | 251 |
| 249 // Virtual for test | 252 // Virtual for test |
| 250 virtual void ScheduleTasks( | 253 virtual void ScheduleTasks( |
| 251 const TileVector& tiles_that_need_to_be_rasterized); | 254 const TileVector& tiles_that_need_to_be_rasterized); |
| 252 | 255 |
| 253 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 256 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
| 254 TileVector* tiles_that_need_to_be_rasterized); | |
| 255 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
| 256 | 257 |
| 257 private: | 258 private: |
| 258 enum RasterizerType { | 259 enum RasterizerType { |
| 259 RASTERIZER_TYPE_DEFAULT, | 260 RASTERIZER_TYPE_DEFAULT, |
| 260 RASTERIZER_TYPE_GPU, | 261 RASTERIZER_TYPE_GPU, |
| 261 NUM_RASTERIZER_TYPES | 262 NUM_RASTERIZER_TYPES |
| 262 }; | 263 }; |
| 263 | 264 |
| 264 void OnImageDecodeTaskCompleted(int layer_id, | 265 void OnImageDecodeTaskCompleted(int layer_id, |
| 265 SkPixelRef* pixel_ref, | 266 SkPixelRef* pixel_ref, |
| 266 bool was_canceled); | 267 bool was_canceled); |
| 267 void OnRasterTaskCompleted(Tile::Id tile, | 268 void OnRasterTaskCompleted(Tile::Id tile, |
| 268 scoped_ptr<ScopedResource> resource, | 269 scoped_ptr<ScopedResource> resource, |
| 269 RasterMode raster_mode, | 270 RasterMode raster_mode, |
| 270 const PicturePileImpl::Analysis& analysis, | 271 const PicturePileImpl::Analysis& analysis, |
| 271 bool was_canceled); | 272 bool was_canceled); |
| 272 | 273 |
| 273 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 274 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
| 274 return Resource::MemorySizeBytes(tile->size(), | 275 return Resource::MemorySizeBytes(tile->size(), |
| 275 resource_pool_->resource_format()); | 276 resource_pool_->resource_format()); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void FreeResourceForTile(Tile* tile, RasterMode mode); | 279 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 279 void FreeResourcesForTile(Tile* tile); | 280 void FreeResourcesForTile(Tile* tile); |
| 280 void FreeUnusedResourcesForTile(Tile* tile); | 281 void FreeUnusedResourcesForTile(Tile* tile); |
| 281 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 282 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 282 SkPixelRef* pixel_ref); | 283 SkPixelRef* pixel_ref); |
| 283 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 284 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 284 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 285 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
| 285 void UpdatePrioritizedTileSetIfNeeded(); | |
| 286 | 286 |
| 287 TileManagerClient* client_; | 287 TileManagerClient* client_; |
| 288 ResourcePool* resource_pool_; | 288 ResourcePool* resource_pool_; |
| 289 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; | 289 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; |
| 290 GlobalStateThatImpactsTilePriority global_state_; | 290 GlobalStateThatImpactsTilePriority global_state_; |
| 291 | 291 |
| 292 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 292 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 293 TileMap tiles_; | 293 TileMap tiles_; |
| 294 | 294 |
| 295 PrioritizedTileSet prioritized_tiles_; | |
| 296 bool prioritized_tiles_dirty_; | |
| 297 | |
| 298 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 295 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
| 299 bool all_tiles_required_for_activation_have_memory_; | 296 bool all_tiles_required_for_activation_have_memory_; |
| 300 | 297 |
| 301 size_t memory_required_bytes_; | |
| 302 size_t memory_nice_to_have_bytes_; | |
| 303 | |
| 304 size_t bytes_releasable_; | 298 size_t bytes_releasable_; |
| 305 size_t resources_releasable_; | 299 size_t resources_releasable_; |
| 306 size_t max_raster_usage_bytes_; | 300 size_t max_raster_usage_bytes_; |
| 307 | 301 |
| 308 bool ever_exceeded_memory_budget_; | 302 bool ever_exceeded_memory_budget_; |
| 309 MemoryHistory::Entry memory_stats_from_last_assign_; | 303 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 310 | 304 |
| 311 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 305 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 312 | 306 |
| 313 bool did_initialize_visible_tile_; | 307 bool did_initialize_visible_tile_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 335 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 329 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
| 336 | 330 |
| 337 std::vector<PictureLayerImpl*> layers_; | 331 std::vector<PictureLayerImpl*> layers_; |
| 338 | 332 |
| 339 DISALLOW_COPY_AND_ASSIGN(TileManager); | 333 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 340 }; | 334 }; |
| 341 | 335 |
| 342 } // namespace cc | 336 } // namespace cc |
| 343 | 337 |
| 344 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 338 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |