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 |
(...skipping 26 matching lines...) Expand all Loading... |
232 void RebuildEvictionQueueIfNeeded(); | 238 void RebuildEvictionQueueIfNeeded(); |
233 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 239 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
234 MemoryUsage* usage); | 240 MemoryUsage* usage); |
235 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 241 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
236 const MemoryUsage& limit, | 242 const MemoryUsage& limit, |
237 const TilePriority& oother_priority, | 243 const TilePriority& oother_priority, |
238 MemoryUsage* usage); | 244 MemoryUsage* usage); |
239 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 245 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
240 bool IsReadyToActivate() const; | 246 bool IsReadyToActivate() const; |
241 bool IsReadyToDraw() const; | 247 bool IsReadyToDraw() const; |
| 248 void NotifyReadyToActivate(); |
| 249 void NotifyReadyToDraw(); |
242 void CheckIfReadyToActivate(); | 250 void CheckIfReadyToActivate(); |
243 void CheckIfReadyToDraw(); | 251 void CheckIfReadyToDraw(); |
244 void CheckIfMoreTilesNeedToBePrepared(); | 252 void CheckIfMoreTilesNeedToBePrepared(); |
245 | 253 |
246 TileManagerClient* client_; | 254 TileManagerClient* client_; |
247 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 255 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
248 ResourcePool* resource_pool_; | 256 ResourcePool* resource_pool_; |
249 TileTaskRunner* tile_task_runner_; | 257 TileTaskRunner* tile_task_runner_; |
| 258 Rasterizer* rasterizer_; |
250 GlobalStateThatImpactsTilePriority global_state_; | 259 GlobalStateThatImpactsTilePriority global_state_; |
251 size_t scheduled_raster_task_limit_; | 260 size_t scheduled_raster_task_limit_; |
252 | 261 |
253 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 262 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
254 TileMap tiles_; | 263 TileMap tiles_; |
255 | 264 |
256 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 265 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
257 MemoryHistory::Entry memory_stats_from_last_assign_; | 266 MemoryHistory::Entry memory_stats_from_last_assign_; |
258 | 267 |
259 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... |
271 | 280 |
272 std::vector<Tile*> released_tiles_; | 281 std::vector<Tile*> released_tiles_; |
273 | 282 |
274 ResourceFormat resource_format_; | 283 ResourceFormat resource_format_; |
275 | 284 |
276 // Queue used when scheduling raster tasks. | 285 // Queue used when scheduling raster tasks. |
277 TileTaskQueue raster_queue_; | 286 TileTaskQueue raster_queue_; |
278 | 287 |
279 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 288 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
280 | 289 |
| 290 UniqueNotifier ready_to_activate_notifier_; |
| 291 UniqueNotifier ready_to_draw_notifier_; |
281 UniqueNotifier ready_to_activate_check_notifier_; | 292 UniqueNotifier ready_to_activate_check_notifier_; |
282 UniqueNotifier ready_to_draw_check_notifier_; | 293 UniqueNotifier ready_to_draw_check_notifier_; |
283 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 294 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
284 | 295 |
285 RasterTilePriorityQueue raster_priority_queue_; | 296 RasterTilePriorityQueue raster_priority_queue_; |
286 EvictionTilePriorityQueue eviction_priority_queue_; | 297 EvictionTilePriorityQueue eviction_priority_queue_; |
287 bool eviction_priority_queue_is_up_to_date_; | 298 bool eviction_priority_queue_is_up_to_date_; |
288 | 299 |
289 bool did_notify_ready_to_activate_; | 300 bool did_notify_ready_to_activate_; |
290 bool did_notify_ready_to_draw_; | 301 bool did_notify_ready_to_draw_; |
291 | 302 |
292 DISALLOW_COPY_AND_ASSIGN(TileManager); | 303 DISALLOW_COPY_AND_ASSIGN(TileManager); |
293 }; | 304 }; |
294 | 305 |
295 } // namespace cc | 306 } // namespace cc |
296 | 307 |
297 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 308 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |