| 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/layers/picture_layer_impl.h" | 20 #include "cc/layers/picture_layer_impl.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/rasterizer.h" | 24 #include "cc/resources/rasterizer.h" |
| 26 #include "cc/resources/resource_pool.h" | 25 #include "cc/resources/resource_pool.h" |
| 27 #include "cc/resources/tile.h" | 26 #include "cc/resources/tile.h" |
| 28 | 27 |
| 29 namespace cc { | 28 namespace cc { |
| 30 class ResourceProvider; | 29 class ResourceProvider; |
| 31 | 30 |
| 32 class CC_EXPORT TileManagerClient { | 31 class CC_EXPORT TileManagerClient { |
| 33 public: | 32 public: |
| 34 // Returns the set of layers that the tile manager should consider for raster. | 33 // Returns the set of layers that the tile manager should consider for raster. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); | 116 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 struct CC_EXPORT EvictionTileIterator { | 119 struct CC_EXPORT EvictionTileIterator { |
| 121 public: | 120 public: |
| 122 EvictionTileIterator(); | 121 EvictionTileIterator(); |
| 123 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 122 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
| 124 ~EvictionTileIterator(); | 123 ~EvictionTileIterator(); |
| 125 | 124 |
| 126 EvictionTileIterator& operator++(); | 125 EvictionTileIterator& operator++(); |
| 127 operator bool() const; | 126 operator bool(); |
| 128 Tile* operator*(); | 127 Tile* operator*(); |
| 129 | 128 |
| 130 private: | 129 private: |
| 131 struct PairedPictureLayerIterator { | 130 struct PairedPictureLayerIterator { |
| 132 PairedPictureLayerIterator(); | 131 PairedPictureLayerIterator(); |
| 133 ~PairedPictureLayerIterator(); | 132 ~PairedPictureLayerIterator(); |
| 134 | 133 |
| 135 Tile* PeekTile(TreePriority tree_priority); | 134 Tile* PeekTile(TreePriority tree_priority); |
| 136 void PopTile(TreePriority tree_priority); | 135 void PopTile(TreePriority tree_priority); |
| 137 | 136 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 public: | 147 public: |
| 149 explicit EvictionOrderComparator(TreePriority tree_priority); | 148 explicit EvictionOrderComparator(TreePriority tree_priority); |
| 150 | 149 |
| 151 bool operator()(PairedPictureLayerIterator* a, | 150 bool operator()(PairedPictureLayerIterator* a, |
| 152 PairedPictureLayerIterator* b) const; | 151 PairedPictureLayerIterator* b) const; |
| 153 | 152 |
| 154 private: | 153 private: |
| 155 TreePriority tree_priority_; | 154 TreePriority tree_priority_; |
| 156 }; | 155 }; |
| 157 | 156 |
| 157 void Initialize(); |
| 158 |
| 158 std::vector<PairedPictureLayerIterator> paired_iterators_; | 159 std::vector<PairedPictureLayerIterator> paired_iterators_; |
| 159 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 160 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
| 160 TreePriority tree_priority_; | 161 TreePriority tree_priority_; |
| 161 EvictionOrderComparator comparator_; | 162 EvictionOrderComparator comparator_; |
| 163 TileManager* tile_manager_; |
| 164 bool initialized_; |
| 162 | 165 |
| 163 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); | 166 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); |
| 164 }; | 167 }; |
| 165 | 168 |
| 166 static scoped_ptr<TileManager> Create( | 169 static scoped_ptr<TileManager> Create( |
| 167 TileManagerClient* client, | 170 TileManagerClient* client, |
| 168 base::SequencedTaskRunner* task_runner, | 171 base::SequencedTaskRunner* task_runner, |
| 169 ResourcePool* resource_pool, | 172 ResourcePool* resource_pool, |
| 170 Rasterizer* rasterizer, | 173 Rasterizer* rasterizer, |
| 171 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 174 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 192 } | 195 } |
| 193 | 196 |
| 194 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; | 197 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; |
| 195 | 198 |
| 196 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 199 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 197 for (size_t i = 0; i < tiles.size(); ++i) { | 200 for (size_t i = 0; i < tiles.size(); ++i) { |
| 198 ManagedTileState& mts = tiles[i]->managed_state(); | 201 ManagedTileState& mts = tiles[i]->managed_state(); |
| 199 ManagedTileState::TileVersion& tile_version = | 202 ManagedTileState::TileVersion& tile_version = |
| 200 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; | 203 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; |
| 201 | 204 |
| 202 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 205 tile_version.resource_ = |
| 203 | 206 resource_pool_->AcquireResource(tiles[i]->size()); |
| 204 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | |
| 205 ++resources_releasable_; | |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { | 210 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 210 for (size_t i = 0; i < tiles.size(); ++i) { | 211 for (size_t i = 0; i < tiles.size(); ++i) { |
| 211 Tile* tile = tiles[i]; | 212 Tile* tile = tiles[i]; |
| 212 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 213 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 213 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 214 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 void SetGlobalStateForTesting( | 219 void SetGlobalStateForTesting( |
| 219 const GlobalStateThatImpactsTilePriority& state) { | 220 const GlobalStateThatImpactsTilePriority& state) { |
| 220 // Soft limit is used for resource pool such that | 221 global_state_ = state; |
| 221 // memory returns to soft limit after going over. | |
| 222 if (state != global_state_) { | |
| 223 global_state_ = state; | |
| 224 prioritized_tiles_dirty_ = true; | |
| 225 } | |
| 226 } | 222 } |
| 227 | 223 |
| 228 void SetRasterizerForTesting(Rasterizer* rasterizer); | 224 void SetRasterizerForTesting(Rasterizer* rasterizer); |
| 229 | 225 |
| 230 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } | 226 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } |
| 231 | 227 |
| 232 protected: | 228 protected: |
| 233 TileManager(TileManagerClient* client, | 229 TileManager(TileManagerClient* client, |
| 234 base::SequencedTaskRunner* task_runner, | 230 base::SequencedTaskRunner* task_runner, |
| 235 ResourcePool* resource_pool, | 231 ResourcePool* resource_pool, |
| 236 Rasterizer* rasterizer, | 232 Rasterizer* rasterizer, |
| 237 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 233 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 238 | 234 |
| 239 // Methods called by Tile | |
| 240 friend class Tile; | |
| 241 void DidChangeTilePriority(Tile* tile); | |
| 242 | |
| 243 void CleanUpReleasedTiles(); | 235 void CleanUpReleasedTiles(); |
| 244 | 236 |
| 245 // Overriden from RefCountedManager<Tile>: | 237 // Overriden from RefCountedManager<Tile>: |
| 238 friend class Tile; |
| 246 virtual void Release(Tile* tile) OVERRIDE; | 239 virtual void Release(Tile* tile) OVERRIDE; |
| 247 | 240 |
| 248 // Overriden from RasterizerClient: | 241 // Overriden from RasterizerClient: |
| 249 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 242 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
| 250 virtual void DidFinishRunningTasks() OVERRIDE; | 243 virtual void DidFinishRunningTasks() OVERRIDE; |
| 251 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 244 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
| 252 | 245 |
| 253 typedef std::vector<Tile*> TileVector; | 246 typedef std::vector<Tile*> TileVector; |
| 254 typedef std::set<Tile*> TileSet; | 247 typedef std::set<Tile*> TileSet; |
| 255 | 248 |
| 256 // Virtual for test | 249 // Virtual for test |
| 257 virtual void ScheduleTasks( | 250 virtual void ScheduleTasks( |
| 258 const TileVector& tiles_that_need_to_be_rasterized); | 251 const TileVector& tiles_that_need_to_be_rasterized); |
| 259 | 252 |
| 260 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 253 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
| 261 TileVector* tiles_that_need_to_be_rasterized); | |
| 262 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
| 263 | 254 |
| 264 private: | 255 private: |
| 256 class MemoryUsage { |
| 257 public: |
| 258 MemoryUsage(); |
| 259 MemoryUsage(int64 memory_bytes, int resource_count); |
| 260 |
| 261 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 262 static MemoryUsage FromTile(const Tile* tile); |
| 263 |
| 264 MemoryUsage& operator+=(const MemoryUsage& other); |
| 265 MemoryUsage& operator-=(const MemoryUsage& other); |
| 266 MemoryUsage operator-(const MemoryUsage& other); |
| 267 |
| 268 bool Exceeds(const MemoryUsage& limit) const; |
| 269 |
| 270 int64 memory_bytes() const { return memory_bytes_; } |
| 271 |
| 272 private: |
| 273 int64 memory_bytes_; |
| 274 int resource_count_; |
| 275 }; |
| 276 |
| 265 void OnImageDecodeTaskCompleted(int layer_id, | 277 void OnImageDecodeTaskCompleted(int layer_id, |
| 266 SkPixelRef* pixel_ref, | 278 SkPixelRef* pixel_ref, |
| 267 bool was_canceled); | 279 bool was_canceled); |
| 268 void OnRasterTaskCompleted(Tile::Id tile, | 280 void OnRasterTaskCompleted(Tile::Id tile, |
| 269 scoped_ptr<ScopedResource> resource, | 281 scoped_ptr<ScopedResource> resource, |
| 270 RasterMode raster_mode, | 282 RasterMode raster_mode, |
| 271 const PicturePileImpl::Analysis& analysis, | 283 const PicturePileImpl::Analysis& analysis, |
| 272 bool was_canceled); | 284 bool was_canceled); |
| 273 | 285 |
| 274 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | |
| 275 return Resource::MemorySizeBytes(tile->size(), | |
| 276 resource_pool_->resource_format()); | |
| 277 } | |
| 278 | |
| 279 void FreeResourceForTile(Tile* tile, RasterMode mode); | 286 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 280 void FreeResourcesForTile(Tile* tile); | 287 void FreeResourcesForTile(Tile* tile); |
| 281 void FreeUnusedResourcesForTile(Tile* tile); | 288 void FreeUnusedResourcesForTile(Tile* tile); |
| 282 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 289 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
| 283 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 290 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 284 SkPixelRef* pixel_ref); | 291 SkPixelRef* pixel_ref); |
| 285 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 292 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 286 void UpdatePrioritizedTileSetIfNeeded(); | |
| 287 | 293 |
| 294 bool FreeTileResourcesUntilUsageIsWithinLimit(EvictionTileIterator* iterator, |
| 295 const MemoryUsage& limit, |
| 296 MemoryUsage* usage); |
| 297 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 298 EvictionTileIterator* iterator, |
| 299 const MemoryUsage& limit, |
| 300 const TilePriority& other_priority, |
| 301 MemoryUsage* usage); |
| 302 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
| 288 bool IsReadyToActivate() const; | 303 bool IsReadyToActivate() const; |
| 289 void CheckIfReadyToActivate(); | 304 void CheckIfReadyToActivate(); |
| 290 | 305 |
| 291 TileManagerClient* client_; | 306 TileManagerClient* client_; |
| 292 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 307 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 293 ResourcePool* resource_pool_; | 308 ResourcePool* resource_pool_; |
| 294 Rasterizer* rasterizer_; | 309 Rasterizer* rasterizer_; |
| 295 GlobalStateThatImpactsTilePriority global_state_; | 310 GlobalStateThatImpactsTilePriority global_state_; |
| 296 | 311 |
| 297 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 312 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 298 TileMap tiles_; | 313 TileMap tiles_; |
| 299 | 314 |
| 300 PrioritizedTileSet prioritized_tiles_; | 315 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 301 bool prioritized_tiles_dirty_; | |
| 302 | 316 |
| 303 bool all_tiles_that_need_to_be_rasterized_have_memory_; | |
| 304 bool all_tiles_required_for_activation_have_memory_; | |
| 305 | |
| 306 size_t bytes_releasable_; | |
| 307 size_t resources_releasable_; | |
| 308 | |
| 309 bool ever_exceeded_memory_budget_; | |
| 310 MemoryHistory::Entry memory_stats_from_last_assign_; | 317 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 311 | 318 |
| 312 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 319 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 313 | 320 |
| 314 bool did_initialize_visible_tile_; | 321 bool did_initialize_visible_tile_; |
| 315 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 322 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| 316 | 323 |
| 317 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > | 324 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > |
| 318 PixelRefTaskMap; | 325 PixelRefTaskMap; |
| 319 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 326 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 334 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 341 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
| 335 | 342 |
| 336 UniqueNotifier ready_to_activate_check_notifier_; | 343 UniqueNotifier ready_to_activate_check_notifier_; |
| 337 | 344 |
| 338 DISALLOW_COPY_AND_ASSIGN(TileManager); | 345 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 339 }; | 346 }; |
| 340 | 347 |
| 341 } // namespace cc | 348 } // namespace cc |
| 342 | 349 |
| 343 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 350 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |