| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); | 83 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); |
| 83 | 84 |
| 84 // This class manages tiles, deciding which should get rasterized and which | 85 // This class manages tiles, deciding which should get rasterized and which |
| 85 // should no longer have any memory assigned to them. Tile objects are "owned" | 86 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 86 // by layers; they automatically register with the manager when they are | 87 // by layers; they automatically register with the manager when they are |
| 87 // created, and unregister from the manager when they are deleted. | 88 // created, and unregister from the manager when they are deleted. |
| 88 class CC_EXPORT TileManager : public TileTaskRunnerClient, | 89 class CC_EXPORT TileManager : public TileTaskRunnerClient, |
| 89 public RefCountedManager<Tile> { | 90 public RefCountedManager<Tile> { |
| 90 public: | 91 public: |
| 91 enum NamedTaskSet { | 92 enum NamedTaskSet { |
| 92 ALL, | |
| 93 REQUIRED_FOR_ACTIVATION, | 93 REQUIRED_FOR_ACTIVATION, |
| 94 REQUIRED_FOR_DRAW | 94 REQUIRED_FOR_DRAW, |
| 95 // PixelBufferTileTaskWorkerPool depends on ALL being last. |
| 96 ALL |
| 95 // Adding additional values requires increasing kNumberOfTaskSets in | 97 // Adding additional values requires increasing kNumberOfTaskSets in |
| 96 // rasterizer.h | 98 // rasterizer.h |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 static scoped_ptr<TileManager> Create( | 101 COMPILE_ASSERT(NamedTaskSet::ALL == (kNumberOfTaskSets - 1), |
| 100 TileManagerClient* client, | 102 NamedTaskSet_ALL_not_kNumberOfTaskSets_minus_1); |
| 101 base::SequencedTaskRunner* task_runner, | 103 |
| 102 ResourcePool* resource_pool, | 104 static scoped_ptr<TileManager> Create(TileManagerClient* client, |
| 103 TileTaskRunner* tile_task_runner, | 105 base::SequencedTaskRunner* task_runner, |
| 104 size_t scheduled_raster_task_limit); | 106 ResourcePool* resource_pool, |
| 107 TileTaskRunner* tile_task_runner, |
| 108 Rasterizer* rasterizer, |
| 109 size_t scheduled_raster_task_limit); |
| 105 ~TileManager() override; | 110 ~TileManager() override; |
| 106 | 111 |
| 107 // Assigns tile memory and schedules work to prepare tiles for drawing. | 112 // Assigns tile memory and schedules work to prepare tiles for drawing. |
| 108 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 113 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
| 109 // activation are prepared, or failed to prepare due to OOM. | 114 // activation are prepared, or failed to prepare due to OOM. |
| 110 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 115 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
| 111 // prepared, or failed to prepare due to OOM. | 116 // prepared, or failed to prepare due to OOM. |
| 112 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 117 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
| 113 | 118 |
| 114 void UpdateVisibleTiles(); | 119 void UpdateVisibleTiles(const GlobalStateThatImpactsTilePriority& state); |
| 115 | 120 |
| 116 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, | 121 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, |
| 117 const gfx::Size& tile_size, | 122 const gfx::Size& desired_texture_size, |
| 118 const gfx::Rect& content_rect, | 123 const gfx::Rect& content_rect, |
| 119 float contents_scale, | 124 float contents_scale, |
| 120 int layer_id, | 125 int layer_id, |
| 121 int source_frame_number, | 126 int source_frame_number, |
| 122 int flags); | 127 int flags); |
| 123 | 128 |
| 124 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() | 129 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() |
| 125 const; | 130 const; |
| 126 void BasicStateAsValueInto(base::debug::TracedValue* dict) const; | 131 void BasicStateAsValueInto(base::debug::TracedValue* dict) const; |
| 127 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 132 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 128 return memory_stats_from_last_assign_; | 133 return memory_stats_from_last_assign_; |
| 129 } | 134 } |
| 130 | 135 |
| 131 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 136 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 132 for (size_t i = 0; i < tiles.size(); ++i) { | 137 for (size_t i = 0; i < tiles.size(); ++i) { |
| 133 TileDrawInfo& draw_info = tiles[i]->draw_info(); | 138 TileDrawInfo& draw_info = tiles[i]->draw_info(); |
| 134 draw_info.resource_ = resource_pool_->AcquireResource(tiles[i]->size()); | 139 draw_info.resource_ = |
| 140 resource_pool_->AcquireResource(tiles[i]->desired_texture_size()); |
| 135 } | 141 } |
| 136 } | 142 } |
| 137 | 143 |
| 138 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { | 144 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 139 for (size_t i = 0; i < tiles.size(); ++i) { | 145 for (size_t i = 0; i < tiles.size(); ++i) { |
| 140 Tile* tile = tiles[i]; | 146 Tile* tile = tiles[i]; |
| 141 FreeResourcesForTile(tile); | 147 FreeResourcesForTile(tile); |
| 142 } | 148 } |
| 143 } | 149 } |
| 144 | 150 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 165 | 171 |
| 166 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 172 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
| 167 scheduled_raster_task_limit_ = limit; | 173 scheduled_raster_task_limit_ = limit; |
| 168 } | 174 } |
| 169 | 175 |
| 170 protected: | 176 protected: |
| 171 TileManager(TileManagerClient* client, | 177 TileManager(TileManagerClient* client, |
| 172 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 178 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 173 ResourcePool* resource_pool, | 179 ResourcePool* resource_pool, |
| 174 TileTaskRunner* tile_task_runner, | 180 TileTaskRunner* tile_task_runner, |
| 181 Rasterizer* rasterizer, |
| 175 size_t scheduled_raster_task_limit); | 182 size_t scheduled_raster_task_limit); |
| 176 | 183 |
| 177 void FreeResourcesForReleasedTiles(); | 184 void FreeResourcesForReleasedTiles(); |
| 178 void CleanUpReleasedTiles(); | 185 void CleanUpReleasedTiles(); |
| 179 | 186 |
| 180 // Overriden from RefCountedManager<Tile>: | 187 // Overriden from RefCountedManager<Tile>: |
| 181 friend class Tile; | 188 friend class Tile; |
| 182 void Release(Tile* tile) override; | 189 void Release(Tile* tile) override; |
| 183 | 190 |
| 184 // Overriden from TileTaskRunnerClient: | 191 // Overriden from TileTaskRunnerClient: |
| 185 void DidFinishRunningTileTasks(TaskSet task_set) override; | 192 void DidFinishRunningTileTasks(TaskSet task_set) override; |
| 186 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; | 193 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; |
| 187 | 194 |
| 188 typedef std::vector<Tile*> TileVector; | 195 typedef std::vector<Tile*> TileVector; |
| 189 typedef std::set<Tile*> TileSet; | 196 typedef std::set<Tile*> TileSet; |
| 190 | 197 |
| 191 // Virtual for test | 198 // Virtual for test |
| 192 virtual void ScheduleTasks( | 199 virtual void ScheduleTasks( |
| 193 const TileVector& tiles_that_need_to_be_rasterized); | 200 const TileVector& tiles_that_need_to_be_rasterized); |
| 194 | 201 |
| 195 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); | 202 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized, |
| 203 size_t scheduled_raser_task_limit, |
| 204 bool required_for_draw_only); |
| 205 |
| 206 void SynchronouslyRasterizeTiles( |
| 207 const GlobalStateThatImpactsTilePriority& state); |
| 196 | 208 |
| 197 private: | 209 private: |
| 198 class MemoryUsage { | 210 class MemoryUsage { |
| 199 public: | 211 public: |
| 200 MemoryUsage(); | 212 MemoryUsage(); |
| 201 MemoryUsage(int64 memory_bytes, int resource_count); | 213 MemoryUsage(int64 memory_bytes, int resource_count); |
| 202 | 214 |
| 203 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 215 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 204 static MemoryUsage FromTile(const Tile* tile); | 216 static MemoryUsage FromTile(const Tile* tile); |
| 205 | 217 |
| 206 MemoryUsage& operator+=(const MemoryUsage& other); | 218 MemoryUsage& operator+=(const MemoryUsage& other); |
| 207 MemoryUsage& operator-=(const MemoryUsage& other); | 219 MemoryUsage& operator-=(const MemoryUsage& other); |
| 208 MemoryUsage operator-(const MemoryUsage& other); | 220 MemoryUsage operator-(const MemoryUsage& other); |
| 209 | 221 |
| 210 bool Exceeds(const MemoryUsage& limit) const; | 222 bool Exceeds(const MemoryUsage& limit) const; |
| 211 int64 memory_bytes() const { return memory_bytes_; } | 223 int64 memory_bytes() const { return memory_bytes_; } |
| 212 | 224 |
| 213 private: | 225 private: |
| 214 int64 memory_bytes_; | 226 int64 memory_bytes_; |
| 215 int resource_count_; | 227 int resource_count_; |
| 216 }; | 228 }; |
| 217 | 229 |
| 218 void OnImageDecodeTaskCompleted(int layer_id, | 230 void OnImageDecodeTaskCompleted(int layer_id, |
| 219 SkPixelRef* pixel_ref, | 231 SkPixelRef* pixel_ref, |
| 220 bool was_canceled); | 232 bool was_canceled); |
| 221 void OnRasterTaskCompleted(Tile::Id tile, | 233 void OnRasterTaskCompleted(Tile::Id tile, |
| 222 scoped_ptr<ScopedResource> resource, | 234 scoped_ptr<ScopedResource> resource, |
| 223 const RasterSource::SolidColorAnalysis& analysis, | 235 const RasterSource::SolidColorAnalysis& analysis, |
| 224 bool was_canceled); | 236 bool was_canceled); |
| 237 void UpdateTileDrawInfo(Tile* tile, |
| 238 scoped_ptr<ScopedResource> resource, |
| 239 const RasterSource::SolidColorAnalysis& analysis); |
| 225 | 240 |
| 226 void FreeResourcesForTile(Tile* tile); | 241 void FreeResourcesForTile(Tile* tile); |
| 227 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 242 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
| 228 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 243 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 229 SkPixelRef* pixel_ref); | 244 SkPixelRef* pixel_ref); |
| 230 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 245 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 231 | 246 |
| 232 void RebuildEvictionQueueIfNeeded(); | 247 void RebuildEvictionQueueIfNeeded(); |
| 233 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 248 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
| 234 MemoryUsage* usage); | 249 MemoryUsage* usage); |
| 235 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 250 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 236 const MemoryUsage& limit, | 251 const MemoryUsage& limit, |
| 237 const TilePriority& oother_priority, | 252 const TilePriority& oother_priority, |
| 238 MemoryUsage* usage); | 253 MemoryUsage* usage); |
| 239 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 254 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
| 240 bool IsReadyToActivate() const; | 255 bool IsReadyToActivate() const; |
| 241 bool IsReadyToDraw() const; | 256 bool IsReadyToDraw() const; |
| 257 void NotifyReadyToActivate(); |
| 258 void NotifyReadyToDraw(); |
| 242 void CheckIfReadyToActivate(); | 259 void CheckIfReadyToActivate(); |
| 243 void CheckIfReadyToDraw(); | 260 void CheckIfReadyToDraw(); |
| 244 void CheckIfMoreTilesNeedToBePrepared(); | 261 void CheckIfMoreTilesNeedToBePrepared(); |
| 245 | 262 |
| 246 TileManagerClient* client_; | 263 TileManagerClient* client_; |
| 247 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 264 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 248 ResourcePool* resource_pool_; | 265 ResourcePool* resource_pool_; |
| 249 TileTaskRunner* tile_task_runner_; | 266 TileTaskRunner* tile_task_runner_; |
| 267 Rasterizer* rasterizer_; |
| 250 GlobalStateThatImpactsTilePriority global_state_; | 268 GlobalStateThatImpactsTilePriority global_state_; |
| 251 size_t scheduled_raster_task_limit_; | 269 size_t scheduled_raster_task_limit_; |
| 252 | 270 |
| 253 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 271 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 254 TileMap tiles_; | 272 TileMap tiles_; |
| 255 | 273 |
| 256 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 274 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 257 MemoryHistory::Entry memory_stats_from_last_assign_; | 275 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 258 | 276 |
| 259 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 277 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 271 | 289 |
| 272 std::vector<Tile*> released_tiles_; | 290 std::vector<Tile*> released_tiles_; |
| 273 | 291 |
| 274 ResourceFormat resource_format_; | 292 ResourceFormat resource_format_; |
| 275 | 293 |
| 276 // Queue used when scheduling raster tasks. | 294 // Queue used when scheduling raster tasks. |
| 277 TileTaskQueue raster_queue_; | 295 TileTaskQueue raster_queue_; |
| 278 | 296 |
| 279 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 297 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
| 280 | 298 |
| 299 UniqueNotifier ready_to_activate_notifier_; |
| 300 UniqueNotifier ready_to_draw_notifier_; |
| 281 UniqueNotifier ready_to_activate_check_notifier_; | 301 UniqueNotifier ready_to_activate_check_notifier_; |
| 282 UniqueNotifier ready_to_draw_check_notifier_; | 302 UniqueNotifier ready_to_draw_check_notifier_; |
| 283 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 303 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
| 284 | 304 |
| 285 RasterTilePriorityQueue raster_priority_queue_; | 305 RasterTilePriorityQueue raster_priority_queue_; |
| 286 EvictionTilePriorityQueue eviction_priority_queue_; | 306 EvictionTilePriorityQueue eviction_priority_queue_; |
| 287 bool eviction_priority_queue_is_up_to_date_; | 307 bool eviction_priority_queue_is_up_to_date_; |
| 288 | 308 |
| 289 bool did_notify_ready_to_activate_; | 309 bool did_notify_ready_to_activate_; |
| 290 bool did_notify_ready_to_draw_; | 310 bool did_notify_ready_to_draw_; |
| 291 | 311 |
| 292 DISALLOW_COPY_AND_ASSIGN(TileManager); | 312 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 293 }; | 313 }; |
| 294 | 314 |
| 295 } // namespace cc | 315 } // namespace cc |
| 296 | 316 |
| 297 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 317 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |