| 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 |
| 200 void SynchronouslyRasterizeTiles( |
| 201 const GlobalStateThatImpactsTilePriority& state); |
| 196 | 202 |
| 197 private: | 203 private: |
| 198 class MemoryUsage { | 204 class MemoryUsage { |
| 199 public: | 205 public: |
| 200 MemoryUsage(); | 206 MemoryUsage(); |
| 201 MemoryUsage(int64 memory_bytes, int resource_count); | 207 MemoryUsage(int64 memory_bytes, int resource_count); |
| 202 | 208 |
| 203 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 209 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 204 static MemoryUsage FromTile(const Tile* tile); | 210 static MemoryUsage FromTile(const Tile* tile); |
| 205 | 211 |
| 206 MemoryUsage& operator+=(const MemoryUsage& other); | 212 MemoryUsage& operator+=(const MemoryUsage& other); |
| 207 MemoryUsage& operator-=(const MemoryUsage& other); | 213 MemoryUsage& operator-=(const MemoryUsage& other); |
| 208 MemoryUsage operator-(const MemoryUsage& other); | 214 MemoryUsage operator-(const MemoryUsage& other); |
| 209 | 215 |
| 210 bool Exceeds(const MemoryUsage& limit) const; | 216 bool Exceeds(const MemoryUsage& limit) const; |
| 211 int64 memory_bytes() const { return memory_bytes_; } | 217 int64 memory_bytes() const { return memory_bytes_; } |
| 212 | 218 |
| 213 private: | 219 private: |
| 214 int64 memory_bytes_; | 220 int64 memory_bytes_; |
| 215 int resource_count_; | 221 int resource_count_; |
| 216 }; | 222 }; |
| 217 | 223 |
| 218 void OnImageDecodeTaskCompleted(int layer_id, | 224 void OnImageDecodeTaskCompleted(int layer_id, |
| 219 SkPixelRef* pixel_ref, | 225 SkPixelRef* pixel_ref, |
| 220 bool was_canceled); | 226 bool was_canceled); |
| 221 void OnRasterTaskCompleted(Tile::Id tile, | 227 void OnRasterTaskCompleted(Tile::Id tile, |
| 222 scoped_ptr<ScopedResource> resource, | 228 scoped_ptr<ScopedResource> resource, |
| 223 const RasterSource::SolidColorAnalysis& analysis, | 229 const RasterSource::SolidColorAnalysis& analysis, |
| 224 bool was_canceled); | 230 bool was_canceled); |
| 231 void UpdateTileDrawInfo(Tile* tile, scoped_ptr<ScopedResource> resource, |
| 232 const RasterSource::SolidColorAnalysis& analysis); |
| 225 | 233 |
| 226 void FreeResourcesForTile(Tile* tile); | 234 void FreeResourcesForTile(Tile* tile); |
| 227 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 235 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
| 228 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 236 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
| 229 SkPixelRef* pixel_ref); | 237 SkPixelRef* pixel_ref); |
| 230 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 238 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
| 231 | 239 |
| 232 void RebuildEvictionQueueIfNeeded(); | 240 void RebuildEvictionQueueIfNeeded(); |
| 233 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 241 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
| 234 MemoryUsage* usage); | 242 MemoryUsage* usage); |
| 235 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 243 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 236 const MemoryUsage& limit, | 244 const MemoryUsage& limit, |
| 237 const TilePriority& oother_priority, | 245 const TilePriority& oother_priority, |
| 238 MemoryUsage* usage); | 246 MemoryUsage* usage); |
| 239 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 247 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
| 240 bool IsReadyToActivate() const; | 248 bool IsReadyToActivate() const; |
| 241 bool IsReadyToDraw() const; | 249 bool IsReadyToDraw() const; |
| 250 void NotifyReadyToActivate(); |
| 251 void NotifyReadyToDraw(); |
| 242 void CheckIfReadyToActivate(); | 252 void CheckIfReadyToActivate(); |
| 243 void CheckIfReadyToDraw(); | 253 void CheckIfReadyToDraw(); |
| 244 void CheckIfMoreTilesNeedToBePrepared(); | 254 void CheckIfMoreTilesNeedToBePrepared(); |
| 245 | 255 |
| 246 TileManagerClient* client_; | 256 TileManagerClient* client_; |
| 247 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 257 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 248 ResourcePool* resource_pool_; | 258 ResourcePool* resource_pool_; |
| 249 TileTaskRunner* tile_task_runner_; | 259 TileTaskRunner* tile_task_runner_; |
| 260 Rasterizer* rasterizer_; |
| 250 GlobalStateThatImpactsTilePriority global_state_; | 261 GlobalStateThatImpactsTilePriority global_state_; |
| 251 size_t scheduled_raster_task_limit_; | 262 size_t scheduled_raster_task_limit_; |
| 252 | 263 |
| 253 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 264 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 254 TileMap tiles_; | 265 TileMap tiles_; |
| 255 | 266 |
| 256 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 267 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 257 MemoryHistory::Entry memory_stats_from_last_assign_; | 268 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 258 | 269 |
| 259 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 270 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 271 | 282 |
| 272 std::vector<Tile*> released_tiles_; | 283 std::vector<Tile*> released_tiles_; |
| 273 | 284 |
| 274 ResourceFormat resource_format_; | 285 ResourceFormat resource_format_; |
| 275 | 286 |
| 276 // Queue used when scheduling raster tasks. | 287 // Queue used when scheduling raster tasks. |
| 277 TileTaskQueue raster_queue_; | 288 TileTaskQueue raster_queue_; |
| 278 | 289 |
| 279 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 290 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
| 280 | 291 |
| 292 UniqueNotifier ready_to_activate_notifier_; |
| 293 UniqueNotifier ready_to_draw_notifier_; |
| 281 UniqueNotifier ready_to_activate_check_notifier_; | 294 UniqueNotifier ready_to_activate_check_notifier_; |
| 282 UniqueNotifier ready_to_draw_check_notifier_; | 295 UniqueNotifier ready_to_draw_check_notifier_; |
| 283 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 296 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
| 284 | 297 |
| 285 RasterTilePriorityQueue raster_priority_queue_; | 298 RasterTilePriorityQueue raster_priority_queue_; |
| 286 EvictionTilePriorityQueue eviction_priority_queue_; | 299 EvictionTilePriorityQueue eviction_priority_queue_; |
| 287 bool eviction_priority_queue_is_up_to_date_; | 300 bool eviction_priority_queue_is_up_to_date_; |
| 288 | 301 |
| 289 bool did_notify_ready_to_activate_; | 302 bool did_notify_ready_to_activate_; |
| 290 bool did_notify_ready_to_draw_; | 303 bool did_notify_ready_to_draw_; |
| 291 | 304 |
| 292 DISALLOW_COPY_AND_ASSIGN(TileManager); | 305 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 293 }; | 306 }; |
| 294 | 307 |
| 295 } // namespace cc | 308 } // namespace cc |
| 296 | 309 |
| 297 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 310 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |