| 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_TILES_TILE_MANAGER_H_ | 5 #ifndef CC_TILES_TILE_MANAGER_H_ |
| 6 #define CC_TILES_TILE_MANAGER_H_ | 6 #define CC_TILES_TILE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 // This class manages tiles, deciding which should get rasterized and which | 92 // This class manages tiles, deciding which should get rasterized and which |
| 93 // should no longer have any memory assigned to them. Tile objects are "owned" | 93 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 94 // by layers; they automatically register with the manager when they are | 94 // by layers; they automatically register with the manager when they are |
| 95 // created, and unregister from the manager when they are deleted. | 95 // created, and unregister from the manager when they are deleted. |
| 96 class CC_EXPORT TileManager { | 96 class CC_EXPORT TileManager { |
| 97 public: | 97 public: |
| 98 TileManager(TileManagerClient* client, | 98 TileManager(TileManagerClient* client, |
| 99 base::SequencedTaskRunner* task_runner, | 99 base::SequencedTaskRunner* task_runner, |
| 100 size_t scheduled_raster_task_limit, | 100 size_t scheduled_raster_task_limit, |
| 101 bool use_partial_raster); | 101 bool use_partial_raster, |
| 102 int max_preraster_distance_in_screen_pixels); |
| 102 virtual ~TileManager(); | 103 virtual ~TileManager(); |
| 103 | 104 |
| 104 // Assigns tile memory and schedules work to prepare tiles for drawing. | 105 // Assigns tile memory and schedules work to prepare tiles for drawing. |
| 105 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 106 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
| 106 // activation are prepared, or failed to prepare due to OOM. | 107 // activation are prepared, or failed to prepare due to OOM. |
| 107 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 108 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
| 108 // prepared, or failed to prepare due to OOM. | 109 // prepared, or failed to prepare due to OOM. |
| 109 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 110 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
| 110 | 111 |
| 111 // Synchronously finish any in progress work, cancel the rest, and clean up as | 112 // Synchronously finish any in progress work, cancel the rest, and clean up as |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 202 |
| 202 protected: | 203 protected: |
| 203 void FreeResourcesForReleasedTiles(); | 204 void FreeResourcesForReleasedTiles(); |
| 204 void CleanUpReleasedTiles(); | 205 void CleanUpReleasedTiles(); |
| 205 | 206 |
| 206 friend class Tile; | 207 friend class Tile; |
| 207 // Virtual for testing. | 208 // Virtual for testing. |
| 208 virtual void Release(Tile* tile); | 209 virtual void Release(Tile* tile); |
| 209 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } | 210 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } |
| 210 | 211 |
| 211 // Virtual for test | |
| 212 virtual void ScheduleTasks( | |
| 213 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized); | |
| 214 | |
| 215 private: | 212 private: |
| 216 class MemoryUsage { | 213 class MemoryUsage { |
| 217 public: | 214 public: |
| 218 MemoryUsage(); | 215 MemoryUsage(); |
| 219 MemoryUsage(size_t memory_bytes, size_t resource_count); | 216 MemoryUsage(size_t memory_bytes, size_t resource_count); |
| 220 | 217 |
| 221 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 218 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 222 static MemoryUsage FromTile(const Tile* tile); | 219 static MemoryUsage FromTile(const Tile* tile); |
| 223 | 220 |
| 224 MemoryUsage& operator+=(const MemoryUsage& other); | 221 MemoryUsage& operator+=(const MemoryUsage& other); |
| 225 MemoryUsage& operator-=(const MemoryUsage& other); | 222 MemoryUsage& operator-=(const MemoryUsage& other); |
| 226 MemoryUsage operator-(const MemoryUsage& other); | 223 MemoryUsage operator-(const MemoryUsage& other); |
| 227 | 224 |
| 228 bool Exceeds(const MemoryUsage& limit) const; | 225 bool Exceeds(const MemoryUsage& limit) const; |
| 229 int64_t memory_bytes() const { return memory_bytes_; } | 226 int64_t memory_bytes() const { return memory_bytes_; } |
| 230 | 227 |
| 231 private: | 228 private: |
| 232 int64_t memory_bytes_; | 229 int64_t memory_bytes_; |
| 233 int resource_count_; | 230 int resource_count_; |
| 234 }; | 231 }; |
| 235 | 232 |
| 233 struct Signals { |
| 234 Signals(); |
| 235 |
| 236 void reset(); |
| 237 |
| 238 bool ready_to_activate; |
| 239 bool did_notify_ready_to_activate; |
| 240 bool ready_to_draw; |
| 241 bool did_notify_ready_to_draw; |
| 242 bool all_tile_tasks_completed; |
| 243 bool did_notify_all_tile_tasks_completed; |
| 244 }; |
| 245 |
| 246 struct PrioritizedWorkToSchedule { |
| 247 PrioritizedWorkToSchedule(); |
| 248 PrioritizedWorkToSchedule(PrioritizedWorkToSchedule&& other); |
| 249 ~PrioritizedWorkToSchedule(); |
| 250 |
| 251 std::vector<PrioritizedTile> tiles_to_raster; |
| 252 std::vector<PrioritizedTile> tiles_to_process_for_images; |
| 253 }; |
| 254 |
| 236 void FreeResourcesForTile(Tile* tile); | 255 void FreeResourcesForTile(Tile* tile); |
| 237 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 256 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
| 238 scoped_refptr<TileTask> CreateRasterTask( | 257 scoped_refptr<TileTask> CreateRasterTask( |
| 239 const PrioritizedTile& prioritized_tile); | 258 const PrioritizedTile& prioritized_tile); |
| 240 | 259 |
| 241 std::unique_ptr<EvictionTilePriorityQueue> | 260 std::unique_ptr<EvictionTilePriorityQueue> |
| 242 FreeTileResourcesUntilUsageIsWithinLimit( | 261 FreeTileResourcesUntilUsageIsWithinLimit( |
| 243 std::unique_ptr<EvictionTilePriorityQueue> eviction_priority_queue, | 262 std::unique_ptr<EvictionTilePriorityQueue> eviction_priority_queue, |
| 244 const MemoryUsage& limit, | 263 const MemoryUsage& limit, |
| 245 MemoryUsage* usage); | 264 MemoryUsage* usage); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 258 | 277 |
| 259 ResourceFormat DetermineResourceFormat(const Tile* tile) const; | 278 ResourceFormat DetermineResourceFormat(const Tile* tile) const; |
| 260 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; | 279 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; |
| 261 | 280 |
| 262 void DidFinishRunningTileTasksRequiredForActivation(); | 281 void DidFinishRunningTileTasksRequiredForActivation(); |
| 263 void DidFinishRunningTileTasksRequiredForDraw(); | 282 void DidFinishRunningTileTasksRequiredForDraw(); |
| 264 void DidFinishRunningAllTileTasks(); | 283 void DidFinishRunningAllTileTasks(); |
| 265 | 284 |
| 266 scoped_refptr<TileTask> CreateTaskSetFinishedTask( | 285 scoped_refptr<TileTask> CreateTaskSetFinishedTask( |
| 267 void (TileManager::*callback)()); | 286 void (TileManager::*callback)()); |
| 268 std::vector<PrioritizedTile> AssignGpuMemoryToTiles(); | 287 PrioritizedWorkToSchedule AssignGpuMemoryToTiles(); |
| 288 void ScheduleTasks(const PrioritizedWorkToSchedule& work_to_schedule); |
| 269 | 289 |
| 270 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 290 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 271 ScheduledTasksStateAsValue() const; | 291 ScheduledTasksStateAsValue() const; |
| 272 | 292 |
| 273 TileManagerClient* client_; | 293 TileManagerClient* client_; |
| 274 base::SequencedTaskRunner* task_runner_; | 294 base::SequencedTaskRunner* task_runner_; |
| 275 ResourcePool* resource_pool_; | 295 ResourcePool* resource_pool_; |
| 276 TileTaskManager* tile_task_manager_; | 296 TileTaskManager* tile_task_manager_; |
| 277 GlobalStateThatImpactsTilePriority global_state_; | 297 GlobalStateThatImpactsTilePriority global_state_; |
| 278 size_t scheduled_raster_task_limit_; | 298 size_t scheduled_raster_task_limit_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 295 | 315 |
| 296 std::vector<scoped_refptr<TileTask>> orphan_tasks_; | 316 std::vector<scoped_refptr<TileTask>> orphan_tasks_; |
| 297 | 317 |
| 298 TaskGraph graph_; | 318 TaskGraph graph_; |
| 299 scoped_refptr<TileTask> required_for_activation_done_task_; | 319 scoped_refptr<TileTask> required_for_activation_done_task_; |
| 300 scoped_refptr<TileTask> required_for_draw_done_task_; | 320 scoped_refptr<TileTask> required_for_draw_done_task_; |
| 301 scoped_refptr<TileTask> all_done_task_; | 321 scoped_refptr<TileTask> all_done_task_; |
| 302 | 322 |
| 303 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 323 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
| 304 | 324 |
| 305 struct Signals { | 325 Signals signals_; |
| 306 Signals(); | |
| 307 | |
| 308 void reset(); | |
| 309 | |
| 310 bool ready_to_activate; | |
| 311 bool did_notify_ready_to_activate; | |
| 312 bool ready_to_draw; | |
| 313 bool did_notify_ready_to_draw; | |
| 314 bool all_tile_tasks_completed; | |
| 315 bool did_notify_all_tile_tasks_completed; | |
| 316 } signals_; | |
| 317 | 326 |
| 318 UniqueNotifier signals_check_notifier_; | 327 UniqueNotifier signals_check_notifier_; |
| 319 | 328 |
| 320 bool has_scheduled_tile_tasks_; | 329 bool has_scheduled_tile_tasks_; |
| 321 | 330 |
| 322 uint64_t prepare_tiles_count_; | 331 uint64_t prepare_tiles_count_; |
| 323 uint64_t next_tile_id_; | 332 uint64_t next_tile_id_; |
| 324 | 333 |
| 325 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; | 334 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; |
| 335 const int max_preraster_distance_in_screen_pixels_; |
| 336 std::vector<std::pair<DrawImage, scoped_refptr<TileTask>>> locked_images_; |
| 326 | 337 |
| 327 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; | 338 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; |
| 328 | 339 |
| 329 DISALLOW_COPY_AND_ASSIGN(TileManager); | 340 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 330 }; | 341 }; |
| 331 | 342 |
| 332 } // namespace cc | 343 } // namespace cc |
| 333 | 344 |
| 334 #endif // CC_TILES_TILE_MANAGER_H_ | 345 #endif // CC_TILES_TILE_MANAGER_H_ |
| OLD | NEW |