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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/base/ref_counted_managed.h" | 17 #include "cc/base/ref_counted_managed.h" |
18 #include "cc/debug/rendering_stats_instrumentation.h" | 18 #include "cc/debug/rendering_stats_instrumentation.h" |
19 #include "cc/layers/picture_layer_impl.h" | 19 #include "cc/layers/picture_layer_impl.h" |
20 #include "cc/resources/managed_tile_state.h" | 20 #include "cc/resources/managed_tile_state.h" |
21 #include "cc/resources/memory_history.h" | 21 #include "cc/resources/memory_history.h" |
22 #include "cc/resources/picture_pile_impl.h" | 22 #include "cc/resources/picture_pile_impl.h" |
23 #include "cc/resources/prioritized_tile_set.h" | |
24 #include "cc/resources/rasterizer.h" | 23 #include "cc/resources/rasterizer.h" |
25 #include "cc/resources/rasterizer_delegate.h" | 24 #include "cc/resources/rasterizer_delegate.h" |
26 #include "cc/resources/resource_pool.h" | 25 #include "cc/resources/resource_pool.h" |
27 #include "cc/resources/tile.h" | 26 #include "cc/resources/tile.h" |
28 | 27 |
29 namespace cc { | 28 namespace cc { |
30 class RasterizerDelegate; | 29 class RasterizerDelegate; |
31 class ResourceProvider; | 30 class ResourceProvider; |
32 | 31 |
33 class CC_EXPORT TileManagerClient { | 32 class CC_EXPORT TileManagerClient { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 64 |
66 class CC_EXPORT RasterTileIterator { | 65 class CC_EXPORT RasterTileIterator { |
67 public: | 66 public: |
68 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 67 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
69 ~RasterTileIterator(); | 68 ~RasterTileIterator(); |
70 | 69 |
71 RasterTileIterator& operator++(); | 70 RasterTileIterator& operator++(); |
72 operator bool() const; | 71 operator bool() const; |
73 Tile* operator*(); | 72 Tile* operator*(); |
74 | 73 |
| 74 bool HasTilesRequiredForActivation() const; |
| 75 |
75 private: | 76 private: |
76 struct PairedPictureLayerIterator { | 77 struct PairedPictureLayerIterator { |
77 PairedPictureLayerIterator(); | 78 PairedPictureLayerIterator(); |
78 ~PairedPictureLayerIterator(); | 79 ~PairedPictureLayerIterator(); |
79 | 80 |
80 Tile* PeekTile(TreePriority tree_priority); | 81 Tile* PeekTile(TreePriority tree_priority); |
81 void PopTile(TreePriority tree_priority); | 82 void PopTile(TreePriority tree_priority); |
82 | 83 |
83 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> | 84 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> |
84 NextTileIterator(TreePriority tree_priority); | 85 NextTileIterator(TreePriority tree_priority); |
(...skipping 23 matching lines...) Expand all Loading... |
108 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); | 109 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); |
109 }; | 110 }; |
110 | 111 |
111 struct CC_EXPORT EvictionTileIterator { | 112 struct CC_EXPORT EvictionTileIterator { |
112 public: | 113 public: |
113 EvictionTileIterator(); | 114 EvictionTileIterator(); |
114 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 115 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
115 ~EvictionTileIterator(); | 116 ~EvictionTileIterator(); |
116 | 117 |
117 EvictionTileIterator& operator++(); | 118 EvictionTileIterator& operator++(); |
118 operator bool() const; | 119 operator bool(); |
119 Tile* operator*(); | 120 Tile* operator*(); |
120 | 121 |
121 private: | 122 private: |
122 struct PairedPictureLayerIterator { | 123 struct PairedPictureLayerIterator { |
123 PairedPictureLayerIterator(); | 124 PairedPictureLayerIterator(); |
124 ~PairedPictureLayerIterator(); | 125 ~PairedPictureLayerIterator(); |
125 | 126 |
126 Tile* PeekTile(TreePriority tree_priority); | 127 Tile* PeekTile(TreePriority tree_priority); |
127 void PopTile(TreePriority tree_priority); | 128 void PopTile(TreePriority tree_priority); |
128 | 129 |
(...skipping 10 matching lines...) Expand all Loading... |
139 public: | 140 public: |
140 explicit EvictionOrderComparator(TreePriority tree_priority); | 141 explicit EvictionOrderComparator(TreePriority tree_priority); |
141 | 142 |
142 bool operator()(PairedPictureLayerIterator* a, | 143 bool operator()(PairedPictureLayerIterator* a, |
143 PairedPictureLayerIterator* b) const; | 144 PairedPictureLayerIterator* b) const; |
144 | 145 |
145 private: | 146 private: |
146 TreePriority tree_priority_; | 147 TreePriority tree_priority_; |
147 }; | 148 }; |
148 | 149 |
| 150 void Initialize(); |
| 151 |
| 152 bool initialized_; |
| 153 TileManager* tile_manager_; |
149 std::vector<PairedPictureLayerIterator> paired_iterators_; | 154 std::vector<PairedPictureLayerIterator> paired_iterators_; |
150 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 155 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
151 TreePriority tree_priority_; | 156 TreePriority tree_priority_; |
152 EvictionOrderComparator comparator_; | 157 EvictionOrderComparator comparator_; |
153 | 158 |
154 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); | 159 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); |
155 }; | 160 }; |
156 | 161 |
157 static scoped_ptr<TileManager> Create( | 162 static scoped_ptr<TileManager> Create( |
158 TileManagerClient* client, | 163 TileManagerClient* client, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 217 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
213 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 218 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
214 } | 219 } |
215 } | 220 } |
216 } | 221 } |
217 | 222 |
218 void SetGlobalStateForTesting( | 223 void SetGlobalStateForTesting( |
219 const GlobalStateThatImpactsTilePriority& state) { | 224 const GlobalStateThatImpactsTilePriority& state) { |
220 // Soft limit is used for resource pool such that | 225 // Soft limit is used for resource pool such that |
221 // memory returns to soft limit after going over. | 226 // memory returns to soft limit after going over. |
222 if (state != global_state_) { | 227 global_state_ = state; |
223 global_state_ = state; | |
224 prioritized_tiles_dirty_ = true; | |
225 } | |
226 } | 228 } |
227 | 229 |
228 void SetRasterizersForTesting(Rasterizer* rasterizer, | 230 void SetRasterizersForTesting(Rasterizer* rasterizer, |
229 Rasterizer* gpu_rasterizer); | 231 Rasterizer* gpu_rasterizer); |
230 | 232 |
231 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } | 233 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } |
232 | 234 |
233 protected: | 235 protected: |
234 TileManager(TileManagerClient* client, | 236 TileManager(TileManagerClient* client, |
235 ResourcePool* resource_pool, | 237 ResourcePool* resource_pool, |
236 Rasterizer* rasterizer, | 238 Rasterizer* rasterizer, |
237 Rasterizer* gpu_rasterizer, | 239 Rasterizer* gpu_rasterizer, |
238 bool use_rasterize_on_demand, | 240 bool use_rasterize_on_demand, |
239 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 241 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
240 | 242 |
241 // Methods called by Tile | |
242 friend class Tile; | |
243 void DidChangeTilePriority(Tile* tile); | |
244 | |
245 void CleanUpReleasedTiles(); | 243 void CleanUpReleasedTiles(); |
246 | 244 |
247 // Overriden from RefCountedManager<Tile>: | 245 // Overriden from RefCountedManager<Tile>: |
| 246 friend class Tile; |
248 virtual void Release(Tile* tile) OVERRIDE; | 247 virtual void Release(Tile* tile) OVERRIDE; |
249 | 248 |
250 // Overriden from RasterizerClient: | 249 // Overriden from RasterizerClient: |
251 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 250 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
252 virtual void DidFinishRunningTasks() OVERRIDE; | 251 virtual void DidFinishRunningTasks() OVERRIDE; |
253 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 252 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
254 | 253 |
255 typedef std::vector<Tile*> TileVector; | 254 typedef std::vector<Tile*> TileVector; |
256 typedef std::set<Tile*> TileSet; | 255 typedef std::set<Tile*> TileSet; |
257 | 256 |
258 // Virtual for test | 257 // Virtual for test |
259 virtual void ScheduleTasks( | 258 virtual void ScheduleTasks( |
260 const TileVector& tiles_that_need_to_be_rasterized); | 259 const TileVector& tiles_that_need_to_be_rasterized); |
261 | 260 |
262 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 261 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
263 TileVector* tiles_that_need_to_be_rasterized); | |
264 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
265 | 262 |
266 private: | 263 private: |
267 enum RasterizerType { | 264 enum RasterizerType { |
268 RASTERIZER_TYPE_DEFAULT, | 265 RASTERIZER_TYPE_DEFAULT, |
269 RASTERIZER_TYPE_GPU, | 266 RASTERIZER_TYPE_GPU, |
270 NUM_RASTERIZER_TYPES | 267 NUM_RASTERIZER_TYPES |
271 }; | 268 }; |
272 | 269 |
| 270 struct MemoryBudget { |
| 271 int64 soft_memory_bytes; |
| 272 int64 hard_memory_bytes; |
| 273 int resource_count; |
| 274 |
| 275 bool Exceeds(const MemoryBudget& other) const { |
| 276 return soft_memory_bytes > other.soft_memory_bytes || |
| 277 hard_memory_bytes > other.hard_memory_bytes || |
| 278 resource_count > other.resource_count; |
| 279 } |
| 280 }; |
| 281 |
273 void OnImageDecodeTaskCompleted(int layer_id, | 282 void OnImageDecodeTaskCompleted(int layer_id, |
274 SkPixelRef* pixel_ref, | 283 SkPixelRef* pixel_ref, |
275 bool was_canceled); | 284 bool was_canceled); |
276 void OnRasterTaskCompleted(Tile::Id tile, | 285 void OnRasterTaskCompleted(Tile::Id tile, |
277 scoped_ptr<ScopedResource> resource, | 286 scoped_ptr<ScopedResource> resource, |
278 RasterMode raster_mode, | 287 RasterMode raster_mode, |
279 const PicturePileImpl::Analysis& analysis, | 288 const PicturePileImpl::Analysis& analysis, |
280 bool was_canceled); | 289 bool was_canceled); |
281 | 290 |
282 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 291 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
283 return Resource::MemorySizeBytes(tile->size(), | 292 return Resource::MemorySizeBytes(tile->size(), |
284 resource_pool_->resource_format()); | 293 resource_pool_->resource_format()); |
285 } | 294 } |
286 | 295 |
287 void FreeResourceForTile(Tile* tile, RasterMode mode); | 296 void FreeResourceForTile(Tile* tile, RasterMode mode); |
288 void FreeResourcesForTile(Tile* tile); | 297 void FreeResourcesForTile(Tile* tile); |
289 void FreeUnusedResourcesForTile(Tile* tile); | 298 void FreeUnusedResourcesForTile(Tile* tile); |
290 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 299 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
291 SkPixelRef* pixel_ref); | 300 SkPixelRef* pixel_ref); |
292 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 301 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
293 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 302 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
294 void UpdatePrioritizedTileSetIfNeeded(); | 303 bool EvictTiles(EvictionTileIterator* eviction_iterator, |
| 304 const MemoryBudget& required_budget, |
| 305 MemoryBudget* current_budget, |
| 306 const TilePriority& raster_priority, |
| 307 bool evict_unconditionally); |
295 void CleanUpLayers(); | 308 void CleanUpLayers(); |
296 | 309 |
297 TileManagerClient* client_; | 310 TileManagerClient* client_; |
298 ResourcePool* resource_pool_; | 311 ResourcePool* resource_pool_; |
299 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; | 312 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; |
300 GlobalStateThatImpactsTilePriority global_state_; | 313 GlobalStateThatImpactsTilePriority global_state_; |
301 | 314 |
302 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 315 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
303 TileMap tiles_; | 316 TileMap tiles_; |
304 | 317 |
305 PrioritizedTileSet prioritized_tiles_; | |
306 bool prioritized_tiles_dirty_; | |
307 | |
308 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 318 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
309 bool all_tiles_required_for_activation_have_memory_; | 319 bool all_tiles_required_for_activation_have_memory_; |
310 | 320 |
311 size_t memory_required_bytes_; | |
312 size_t memory_nice_to_have_bytes_; | |
313 | |
314 size_t bytes_releasable_; | 321 size_t bytes_releasable_; |
315 size_t resources_releasable_; | 322 size_t resources_releasable_; |
316 | 323 |
317 bool ever_exceeded_memory_budget_; | 324 bool ever_exceeded_memory_budget_; |
318 MemoryHistory::Entry memory_stats_from_last_assign_; | 325 MemoryHistory::Entry memory_stats_from_last_assign_; |
319 | 326 |
320 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 327 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
321 | 328 |
322 bool did_initialize_visible_tile_; | 329 bool did_initialize_visible_tile_; |
323 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 330 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
(...skipping 20 matching lines...) Expand all Loading... |
344 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 351 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
345 | 352 |
346 std::vector<PictureLayerImpl*> layers_; | 353 std::vector<PictureLayerImpl*> layers_; |
347 | 354 |
348 DISALLOW_COPY_AND_ASSIGN(TileManager); | 355 DISALLOW_COPY_AND_ASSIGN(TileManager); |
349 }; | 356 }; |
350 | 357 |
351 } // namespace cc | 358 } // namespace cc |
352 | 359 |
353 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 360 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |