| 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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 namespace debug { | 29 namespace debug { |
| 30 class ConvertableToTraceFormat; | 30 class ConvertableToTraceFormat; |
| 31 class TracedValue; | 31 class TracedValue; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace cc { | 35 namespace cc { |
| 36 class PictureLayerImpl; | 36 class PictureLayerImpl; |
| 37 class Rasterizer; |
| 37 class ResourceProvider; | 38 class ResourceProvider; |
| 38 | 39 |
| 39 class CC_EXPORT TileManagerClient { | 40 class CC_EXPORT TileManagerClient { |
| 40 public: | 41 public: |
| 41 // Returns the set of layers that the tile manager should consider for raster. | 42 // Returns the set of layers that the tile manager should consider for raster. |
| 42 // TODO(vmpstr): Change the way we determine if we are ready to activate, so | 43 // TODO(vmpstr): Change the way we determine if we are ready to activate, so |
| 43 // that this can be removed. | 44 // that this can be removed. |
| 44 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; | 45 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; |
| 45 | 46 |
| 46 // Called when all tiles marked as required for activation are ready to draw. | 47 // Called when all tiles marked as required for activation are ready to draw. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 public RefCountedManager<Tile> { | 90 public RefCountedManager<Tile> { |
| 90 public: | 91 public: |
| 91 enum NamedTaskSet { | 92 enum NamedTaskSet { |
| 92 ALL, | 93 ALL, |
| 93 REQUIRED_FOR_ACTIVATION, | 94 REQUIRED_FOR_ACTIVATION, |
| 94 REQUIRED_FOR_DRAW | 95 REQUIRED_FOR_DRAW |
| 95 // Adding additional values requires increasing kNumberOfTaskSets in | 96 // Adding additional values requires increasing kNumberOfTaskSets in |
| 96 // rasterizer.h | 97 // rasterizer.h |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 static scoped_ptr<TileManager> Create( | 100 static scoped_ptr<TileManager> Create(TileManagerClient* client, |
| 100 TileManagerClient* client, | 101 base::SequencedTaskRunner* task_runner, |
| 101 base::SequencedTaskRunner* task_runner, | 102 ResourcePool* resource_pool, |
| 102 ResourcePool* resource_pool, | 103 TileTaskRunner* tile_task_runner, |
| 103 TileTaskRunner* tile_task_runner, | 104 Rasterizer* rasterizer, |
| 104 size_t scheduled_raster_task_limit); | 105 size_t scheduled_raster_task_limit); |
| 105 ~TileManager() override; | 106 ~TileManager() override; |
| 106 | 107 |
| 107 // Assigns tile memory and schedules work to prepare tiles for drawing. | 108 // Assigns tile memory and schedules work to prepare tiles for drawing. |
| 108 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 109 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
| 109 // activation are prepared, or failed to prepare due to OOM. | 110 // activation are prepared, or failed to prepare due to OOM. |
| 110 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 111 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
| 111 // prepared, or failed to prepare due to OOM. | 112 // prepared, or failed to prepare due to OOM. |
| 112 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 113 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
| 113 | 114 |
| 114 void UpdateVisibleTiles(); | 115 void UpdateVisibleTiles(const GlobalStateThatImpactsTilePriority& state); |
| 115 | 116 |
| 116 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, | 117 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, |
| 117 const gfx::Size& tile_size, | 118 const gfx::Size& tile_size, |
| 118 const gfx::Rect& content_rect, | 119 const gfx::Rect& content_rect, |
| 119 float contents_scale, | 120 float contents_scale, |
| 120 int layer_id, | 121 int layer_id, |
| 121 int source_frame_number, | 122 int source_frame_number, |
| 122 int flags); | 123 int flags); |
| 123 | 124 |
| 124 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() | 125 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 166 |
| 166 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 167 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
| 167 scheduled_raster_task_limit_ = limit; | 168 scheduled_raster_task_limit_ = limit; |
| 168 } | 169 } |
| 169 | 170 |
| 170 protected: | 171 protected: |
| 171 TileManager(TileManagerClient* client, | 172 TileManager(TileManagerClient* client, |
| 172 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 173 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 173 ResourcePool* resource_pool, | 174 ResourcePool* resource_pool, |
| 174 TileTaskRunner* tile_task_runner, | 175 TileTaskRunner* tile_task_runner, |
| 176 Rasterizer* rasterizer, |
| 175 size_t scheduled_raster_task_limit); | 177 size_t scheduled_raster_task_limit); |
| 176 | 178 |
| 177 void FreeResourcesForReleasedTiles(); | 179 void FreeResourcesForReleasedTiles(); |
| 178 void CleanUpReleasedTiles(); | 180 void CleanUpReleasedTiles(); |
| 179 | 181 |
| 180 // Overriden from RefCountedManager<Tile>: | 182 // Overriden from RefCountedManager<Tile>: |
| 181 friend class Tile; | 183 friend class Tile; |
| 182 void Release(Tile* tile) override; | 184 void Release(Tile* tile) override; |
| 183 | 185 |
| 184 // Overriden from TileTaskRunnerClient: | 186 // Overriden from TileTaskRunnerClient: |
| 185 void DidFinishRunningTileTasks(TaskSet task_set) override; | 187 void DidFinishRunningTileTasks(TaskSet task_set) override; |
| 186 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; | 188 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; |
| 187 | 189 |
| 188 typedef std::vector<Tile*> TileVector; | 190 typedef std::vector<Tile*> TileVector; |
| 189 typedef std::set<Tile*> TileSet; | 191 typedef std::set<Tile*> TileSet; |
| 190 | 192 |
| 191 // Virtual for test | 193 // Virtual for test |
| 192 virtual void ScheduleTasks( | 194 virtual void ScheduleTasks( |
| 193 const TileVector& tiles_that_need_to_be_rasterized); | 195 const TileVector& tiles_that_need_to_be_rasterized); |
| 194 | 196 |
| 195 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); | 197 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized, |
| 198 size_t scheduled_raser_task_limit, |
| 199 bool required_for_draw_only); |
| 200 |
| 201 void SynchronouslyRasterizeTiles( |
| 202 const GlobalStateThatImpactsTilePriority& state); |
| 196 | 203 |
| 197 private: | 204 private: |
| 198 class MemoryUsage { | 205 class MemoryUsage { |
| 199 public: | 206 public: |
| 200 MemoryUsage(); | 207 MemoryUsage(); |
| 201 MemoryUsage(int64 memory_bytes, int resource_count); | 208 MemoryUsage(int64 memory_bytes, int resource_count); |
| 202 | 209 |
| 203 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 210 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 204 static MemoryUsage FromTile(const Tile* tile); | 211 static MemoryUsage FromTile(const Tile* tile); |
| 205 | 212 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 232 void RebuildEvictionQueueIfNeeded(); | 239 void RebuildEvictionQueueIfNeeded(); |
| 233 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 240 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
| 234 MemoryUsage* usage); | 241 MemoryUsage* usage); |
| 235 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 242 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 236 const MemoryUsage& limit, | 243 const MemoryUsage& limit, |
| 237 const TilePriority& oother_priority, | 244 const TilePriority& oother_priority, |
| 238 MemoryUsage* usage); | 245 MemoryUsage* usage); |
| 239 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 246 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
| 240 bool IsReadyToActivate() const; | 247 bool IsReadyToActivate() const; |
| 241 bool IsReadyToDraw() const; | 248 bool IsReadyToDraw() const; |
| 249 void NotifyReadyToActivate(); |
| 250 void NotifyReadyToDraw(); |
| 242 void CheckIfReadyToActivate(); | 251 void CheckIfReadyToActivate(); |
| 243 void CheckIfReadyToDraw(); | 252 void CheckIfReadyToDraw(); |
| 244 | 253 |
| 245 TileManagerClient* client_; | 254 TileManagerClient* client_; |
| 246 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 255 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 247 ResourcePool* resource_pool_; | 256 ResourcePool* resource_pool_; |
| 248 TileTaskRunner* tile_task_runner_; | 257 TileTaskRunner* tile_task_runner_; |
| 258 Rasterizer* rasterizer_; |
| 249 GlobalStateThatImpactsTilePriority global_state_; | 259 GlobalStateThatImpactsTilePriority global_state_; |
| 250 size_t scheduled_raster_task_limit_; | 260 size_t scheduled_raster_task_limit_; |
| 251 | 261 |
| 252 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 262 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 253 TileMap tiles_; | 263 TileMap tiles_; |
| 254 | 264 |
| 255 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 265 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 256 MemoryHistory::Entry memory_stats_from_last_assign_; | 266 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 257 | 267 |
| 258 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 268 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 270 | 280 |
| 271 std::vector<Tile*> released_tiles_; | 281 std::vector<Tile*> released_tiles_; |
| 272 | 282 |
| 273 ResourceFormat resource_format_; | 283 ResourceFormat resource_format_; |
| 274 | 284 |
| 275 // Queue used when scheduling raster tasks. | 285 // Queue used when scheduling raster tasks. |
| 276 TileTaskQueue raster_queue_; | 286 TileTaskQueue raster_queue_; |
| 277 | 287 |
| 278 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 288 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
| 279 | 289 |
| 290 UniqueNotifier ready_to_activate_notifier_; |
| 291 UniqueNotifier ready_to_draw_notifier_; |
| 280 UniqueNotifier ready_to_activate_check_notifier_; | 292 UniqueNotifier ready_to_activate_check_notifier_; |
| 281 UniqueNotifier ready_to_draw_check_notifier_; | 293 UniqueNotifier ready_to_draw_check_notifier_; |
| 282 | 294 |
| 283 RasterTilePriorityQueue raster_priority_queue_; | 295 RasterTilePriorityQueue raster_priority_queue_; |
| 284 EvictionTilePriorityQueue eviction_priority_queue_; | 296 EvictionTilePriorityQueue eviction_priority_queue_; |
| 285 bool eviction_priority_queue_is_up_to_date_; | 297 bool eviction_priority_queue_is_up_to_date_; |
| 286 | 298 |
| 287 bool did_notify_ready_to_activate_; | 299 bool did_notify_ready_to_activate_; |
| 288 bool did_notify_ready_to_draw_; | 300 bool did_notify_ready_to_draw_; |
| 289 | 301 |
| 290 DISALLOW_COPY_AND_ASSIGN(TileManager); | 302 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 291 }; | 303 }; |
| 292 | 304 |
| 293 } // namespace cc | 305 } // namespace cc |
| 294 | 306 |
| 295 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 307 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |