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& desired_texture_size, | 118 const gfx::Size& desired_texture_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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 167 |
167 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 168 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
168 scheduled_raster_task_limit_ = limit; | 169 scheduled_raster_task_limit_ = limit; |
169 } | 170 } |
170 | 171 |
171 protected: | 172 protected: |
172 TileManager(TileManagerClient* client, | 173 TileManager(TileManagerClient* client, |
173 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 174 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
174 ResourcePool* resource_pool, | 175 ResourcePool* resource_pool, |
175 TileTaskRunner* tile_task_runner, | 176 TileTaskRunner* tile_task_runner, |
| 177 Rasterizer* rasterizer, |
176 size_t scheduled_raster_task_limit); | 178 size_t scheduled_raster_task_limit); |
177 | 179 |
178 void FreeResourcesForReleasedTiles(); | 180 void FreeResourcesForReleasedTiles(); |
179 void CleanUpReleasedTiles(); | 181 void CleanUpReleasedTiles(); |
180 | 182 |
181 // Overriden from RefCountedManager<Tile>: | 183 // Overriden from RefCountedManager<Tile>: |
182 friend class Tile; | 184 friend class Tile; |
183 void Release(Tile* tile) override; | 185 void Release(Tile* tile) override; |
184 | 186 |
185 // Overriden from TileTaskRunnerClient: | 187 // Overriden from TileTaskRunnerClient: |
186 void DidFinishRunningTileTasks(TaskSet task_set) override; | 188 void DidFinishRunningTileTasks(TaskSet task_set) override; |
187 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; | 189 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; |
188 | 190 |
189 typedef std::vector<Tile*> TileVector; | 191 typedef std::vector<Tile*> TileVector; |
190 typedef std::set<Tile*> TileSet; | 192 typedef std::set<Tile*> TileSet; |
191 | 193 |
192 // Virtual for test | 194 // Virtual for test |
193 virtual void ScheduleTasks( | 195 virtual void ScheduleTasks( |
194 const TileVector& tiles_that_need_to_be_rasterized); | 196 const TileVector& tiles_that_need_to_be_rasterized); |
195 | 197 |
196 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); | 198 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized, |
| 199 size_t scheduled_raser_task_limit, |
| 200 bool required_for_draw_only); |
| 201 |
| 202 void SynchronouslyRasterizeTiles( |
| 203 const GlobalStateThatImpactsTilePriority& state); |
197 | 204 |
198 private: | 205 private: |
199 class MemoryUsage { | 206 class MemoryUsage { |
200 public: | 207 public: |
201 MemoryUsage(); | 208 MemoryUsage(); |
202 MemoryUsage(int64 memory_bytes, int resource_count); | 209 MemoryUsage(int64 memory_bytes, int resource_count); |
203 | 210 |
204 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 211 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
205 static MemoryUsage FromTile(const Tile* tile); | 212 static MemoryUsage FromTile(const Tile* tile); |
206 | 213 |
207 MemoryUsage& operator+=(const MemoryUsage& other); | 214 MemoryUsage& operator+=(const MemoryUsage& other); |
208 MemoryUsage& operator-=(const MemoryUsage& other); | 215 MemoryUsage& operator-=(const MemoryUsage& other); |
209 MemoryUsage operator-(const MemoryUsage& other); | 216 MemoryUsage operator-(const MemoryUsage& other); |
210 | 217 |
211 bool Exceeds(const MemoryUsage& limit) const; | 218 bool Exceeds(const MemoryUsage& limit) const; |
212 int64 memory_bytes() const { return memory_bytes_; } | 219 int64 memory_bytes() const { return memory_bytes_; } |
213 | 220 |
214 private: | 221 private: |
215 int64 memory_bytes_; | 222 int64 memory_bytes_; |
216 int resource_count_; | 223 int resource_count_; |
217 }; | 224 }; |
218 | 225 |
219 void OnImageDecodeTaskCompleted(int layer_id, | 226 void OnImageDecodeTaskCompleted(int layer_id, |
220 SkPixelRef* pixel_ref, | 227 SkPixelRef* pixel_ref, |
221 bool was_canceled); | 228 bool was_canceled); |
222 void OnRasterTaskCompleted(Tile::Id tile, | 229 void OnRasterTaskCompleted(Tile::Id tile, |
223 scoped_ptr<ScopedResource> resource, | 230 scoped_ptr<ScopedResource> resource, |
224 const RasterSource::SolidColorAnalysis& analysis, | 231 const RasterSource::SolidColorAnalysis& analysis, |
225 bool was_canceled); | 232 bool was_canceled); |
| 233 void UpdateTileDrawInfo(Tile* tile, |
| 234 scoped_ptr<ScopedResource> resource, |
| 235 const RasterSource::SolidColorAnalysis& analysis); |
226 | 236 |
227 void FreeResourcesForTile(Tile* tile); | 237 void FreeResourcesForTile(Tile* tile); |
228 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 238 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
229 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 239 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
230 SkPixelRef* pixel_ref); | 240 SkPixelRef* pixel_ref); |
231 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 241 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
232 | 242 |
233 void RebuildEvictionQueueIfNeeded(); | 243 void RebuildEvictionQueueIfNeeded(); |
234 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 244 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
235 MemoryUsage* usage); | 245 MemoryUsage* usage); |
236 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 246 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
237 const MemoryUsage& limit, | 247 const MemoryUsage& limit, |
238 const TilePriority& oother_priority, | 248 const TilePriority& oother_priority, |
239 MemoryUsage* usage); | 249 MemoryUsage* usage); |
240 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 250 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
241 bool IsReadyToActivate() const; | 251 bool IsReadyToActivate() const; |
242 bool IsReadyToDraw() const; | 252 bool IsReadyToDraw() const; |
| 253 void NotifyReadyToActivate(); |
| 254 void NotifyReadyToDraw(); |
243 void CheckIfReadyToActivate(); | 255 void CheckIfReadyToActivate(); |
244 void CheckIfReadyToDraw(); | 256 void CheckIfReadyToDraw(); |
245 void CheckIfMoreTilesNeedToBePrepared(); | 257 void CheckIfMoreTilesNeedToBePrepared(); |
246 | 258 |
247 TileManagerClient* client_; | 259 TileManagerClient* client_; |
248 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 260 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
249 ResourcePool* resource_pool_; | 261 ResourcePool* resource_pool_; |
250 TileTaskRunner* tile_task_runner_; | 262 TileTaskRunner* tile_task_runner_; |
| 263 Rasterizer* rasterizer_; |
251 GlobalStateThatImpactsTilePriority global_state_; | 264 GlobalStateThatImpactsTilePriority global_state_; |
252 size_t scheduled_raster_task_limit_; | 265 size_t scheduled_raster_task_limit_; |
253 | 266 |
254 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 267 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
255 TileMap tiles_; | 268 TileMap tiles_; |
256 | 269 |
257 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 270 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
258 MemoryHistory::Entry memory_stats_from_last_assign_; | 271 MemoryHistory::Entry memory_stats_from_last_assign_; |
259 | 272 |
260 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 273 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
(...skipping 11 matching lines...) Expand all Loading... |
272 | 285 |
273 std::vector<Tile*> released_tiles_; | 286 std::vector<Tile*> released_tiles_; |
274 | 287 |
275 ResourceFormat resource_format_; | 288 ResourceFormat resource_format_; |
276 | 289 |
277 // Queue used when scheduling raster tasks. | 290 // Queue used when scheduling raster tasks. |
278 TileTaskQueue raster_queue_; | 291 TileTaskQueue raster_queue_; |
279 | 292 |
280 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 293 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
281 | 294 |
| 295 UniqueNotifier ready_to_activate_notifier_; |
| 296 UniqueNotifier ready_to_draw_notifier_; |
282 UniqueNotifier ready_to_activate_check_notifier_; | 297 UniqueNotifier ready_to_activate_check_notifier_; |
283 UniqueNotifier ready_to_draw_check_notifier_; | 298 UniqueNotifier ready_to_draw_check_notifier_; |
284 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 299 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
285 | 300 |
286 RasterTilePriorityQueue raster_priority_queue_; | 301 RasterTilePriorityQueue raster_priority_queue_; |
287 EvictionTilePriorityQueue eviction_priority_queue_; | 302 EvictionTilePriorityQueue eviction_priority_queue_; |
288 bool eviction_priority_queue_is_up_to_date_; | 303 bool eviction_priority_queue_is_up_to_date_; |
289 | 304 |
290 bool did_notify_ready_to_activate_; | 305 bool did_notify_ready_to_activate_; |
291 bool did_notify_ready_to_draw_; | 306 bool did_notify_ready_to_draw_; |
292 | 307 |
293 DISALLOW_COPY_AND_ASSIGN(TileManager); | 308 DISALLOW_COPY_AND_ASSIGN(TileManager); |
294 }; | 309 }; |
295 | 310 |
296 } // namespace cc | 311 } // namespace cc |
297 | 312 |
298 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 313 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |