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/resource_pool.h" | 24 #include "cc/resources/resource_pool.h" |
26 #include "cc/resources/tile.h" | 25 #include "cc/resources/tile.h" |
27 | 26 |
28 namespace cc { | 27 namespace cc { |
29 class RasterizerDelegate; | 28 class RasterizerDelegate; |
30 class ResourceProvider; | 29 class ResourceProvider; |
31 | 30 |
32 class CC_EXPORT TileManagerClient { | 31 class CC_EXPORT TileManagerClient { |
33 public: | 32 public: |
(...skipping 23 matching lines...) Expand all Loading... |
57 PairedPictureLayer(); | 56 PairedPictureLayer(); |
58 ~PairedPictureLayer(); | 57 ~PairedPictureLayer(); |
59 | 58 |
60 PictureLayerImpl* active_layer; | 59 PictureLayerImpl* active_layer; |
61 PictureLayerImpl* pending_layer; | 60 PictureLayerImpl* pending_layer; |
62 }; | 61 }; |
63 | 62 |
64 class CC_EXPORT RasterTileIterator { | 63 class CC_EXPORT RasterTileIterator { |
65 public: | 64 public: |
66 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 65 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
| 66 RasterTileIterator(const RasterTileIterator& other); |
67 ~RasterTileIterator(); | 67 ~RasterTileIterator(); |
68 | 68 |
69 RasterTileIterator& operator++(); | 69 RasterTileIterator& operator++(); |
70 operator bool() const; | 70 operator bool() const; |
71 Tile* operator*(); | 71 Tile* operator*(); |
| 72 RasterTileIterator& operator=(const RasterTileIterator& other); |
| 73 |
| 74 bool HasTilesRequiredForActivation() const; |
72 | 75 |
73 private: | 76 private: |
74 struct PairedPictureLayerIterator { | 77 struct PairedPictureLayerIterator { |
75 PairedPictureLayerIterator(); | 78 PairedPictureLayerIterator(); |
76 ~PairedPictureLayerIterator(); | 79 ~PairedPictureLayerIterator(); |
77 | 80 |
78 Tile* PeekTile(TreePriority tree_priority); | 81 Tile* PeekTile(TreePriority tree_priority); |
79 void PopTile(TreePriority tree_priority); | 82 void PopTile(TreePriority tree_priority); |
80 | 83 |
81 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> | 84 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> |
(...skipping 18 matching lines...) Expand all Loading... |
100 | 103 |
101 std::vector<PairedPictureLayerIterator> paired_iterators_; | 104 std::vector<PairedPictureLayerIterator> paired_iterators_; |
102 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 105 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
103 TreePriority tree_priority_; | 106 TreePriority tree_priority_; |
104 RasterOrderComparator comparator_; | 107 RasterOrderComparator comparator_; |
105 }; | 108 }; |
106 | 109 |
107 struct CC_EXPORT EvictionTileIterator { | 110 struct CC_EXPORT EvictionTileIterator { |
108 public: | 111 public: |
109 EvictionTileIterator(); | 112 EvictionTileIterator(); |
| 113 EvictionTileIterator(const EvictionTileIterator& other); |
110 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 114 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
111 ~EvictionTileIterator(); | 115 ~EvictionTileIterator(); |
112 | 116 |
113 EvictionTileIterator& operator++(); | 117 EvictionTileIterator& operator++(); |
114 operator bool() const; | 118 operator bool() const; |
115 Tile* operator*(); | 119 Tile* operator*(); |
| 120 EvictionTileIterator& operator=(const EvictionTileIterator& other); |
116 | 121 |
117 private: | 122 private: |
118 struct PairedPictureLayerIterator { | 123 struct PairedPictureLayerIterator { |
119 PairedPictureLayerIterator(); | 124 PairedPictureLayerIterator(); |
120 ~PairedPictureLayerIterator(); | 125 ~PairedPictureLayerIterator(); |
121 | 126 |
122 Tile* PeekTile(TreePriority tree_priority); | 127 Tile* PeekTile(TreePriority tree_priority); |
123 void PopTile(TreePriority tree_priority); | 128 void PopTile(TreePriority tree_priority); |
124 | 129 |
125 PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator( | 130 PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 214 } |
210 } | 215 } |
211 } | 216 } |
212 | 217 |
213 void SetGlobalStateForTesting( | 218 void SetGlobalStateForTesting( |
214 const GlobalStateThatImpactsTilePriority& state) { | 219 const GlobalStateThatImpactsTilePriority& state) { |
215 // Soft limit is used for resource pool such that | 220 // Soft limit is used for resource pool such that |
216 // memory returns to soft limit after going over. | 221 // memory returns to soft limit after going over. |
217 if (state != global_state_) { | 222 if (state != global_state_) { |
218 global_state_ = state; | 223 global_state_ = state; |
219 prioritized_tiles_dirty_ = true; | |
220 resource_pool_->SetResourceUsageLimits( | 224 resource_pool_->SetResourceUsageLimits( |
221 global_state_.soft_memory_limit_in_bytes, | 225 global_state_.soft_memory_limit_in_bytes, |
222 global_state_.unused_memory_limit_in_bytes, | 226 global_state_.unused_memory_limit_in_bytes, |
223 global_state_.num_resources_limit); | 227 global_state_.num_resources_limit); |
224 } | 228 } |
225 } | 229 } |
226 | 230 |
227 protected: | 231 protected: |
228 TileManager(TileManagerClient* client, | 232 TileManager(TileManagerClient* client, |
229 ResourcePool* resource_pool, | 233 ResourcePool* resource_pool, |
(...skipping 17 matching lines...) Expand all Loading... |
247 virtual void DidFinishRunningTasks() OVERRIDE; | 251 virtual void DidFinishRunningTasks() OVERRIDE; |
248 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 252 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
249 | 253 |
250 typedef std::vector<Tile*> TileVector; | 254 typedef std::vector<Tile*> TileVector; |
251 typedef std::set<Tile*> TileSet; | 255 typedef std::set<Tile*> TileSet; |
252 | 256 |
253 // Virtual for test | 257 // Virtual for test |
254 virtual void ScheduleTasks( | 258 virtual void ScheduleTasks( |
255 const TileVector& tiles_that_need_to_be_rasterized); | 259 const TileVector& tiles_that_need_to_be_rasterized); |
256 | 260 |
257 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 261 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
258 TileVector* tiles_that_need_to_be_rasterized); | |
259 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
260 | 262 |
261 private: | 263 private: |
262 enum RasterizerType { | 264 enum RasterizerType { |
263 RASTERIZER_TYPE_DEFAULT, | 265 RASTERIZER_TYPE_DEFAULT, |
264 RASTERIZER_TYPE_GPU, | 266 RASTERIZER_TYPE_GPU, |
265 NUM_RASTERIZER_TYPES | 267 NUM_RASTERIZER_TYPES |
266 }; | 268 }; |
267 | 269 |
268 void OnImageDecodeTaskCompleted(int layer_id, | 270 void OnImageDecodeTaskCompleted(int layer_id, |
269 SkPixelRef* pixel_ref, | 271 SkPixelRef* pixel_ref, |
270 bool was_canceled); | 272 bool was_canceled); |
271 void OnRasterTaskCompleted(Tile::Id tile, | 273 void OnRasterTaskCompleted(Tile::Id tile, |
272 scoped_ptr<ScopedResource> resource, | 274 scoped_ptr<ScopedResource> resource, |
273 RasterMode raster_mode, | 275 RasterMode raster_mode, |
274 const PicturePileImpl::Analysis& analysis, | 276 const PicturePileImpl::Analysis& analysis, |
275 bool was_canceled); | 277 bool was_canceled); |
276 | 278 |
277 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 279 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
278 return Resource::MemorySizeBytes(tile->size(), | 280 return Resource::MemorySizeBytes(tile->size(), |
279 resource_pool_->resource_format()); | 281 resource_pool_->resource_format()); |
280 } | 282 } |
281 | 283 |
282 void FreeResourceForTile(Tile* tile, RasterMode mode); | 284 void FreeResourceForTile(Tile* tile, RasterMode mode); |
283 void FreeResourcesForTile(Tile* tile); | 285 void FreeResourcesForTile(Tile* tile); |
284 void FreeUnusedResourcesForTile(Tile* tile); | 286 void FreeUnusedResourcesForTile(Tile* tile); |
285 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 287 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
286 SkPixelRef* pixel_ref); | 288 SkPixelRef* pixel_ref); |
287 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 289 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
288 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 290 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
289 void UpdatePrioritizedTileSetIfNeeded(); | |
290 | 291 |
291 TileManagerClient* client_; | 292 TileManagerClient* client_; |
292 ResourcePool* resource_pool_; | 293 ResourcePool* resource_pool_; |
293 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; | 294 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; |
294 GlobalStateThatImpactsTilePriority global_state_; | 295 GlobalStateThatImpactsTilePriority global_state_; |
295 | 296 |
296 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 297 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
297 TileMap tiles_; | 298 TileMap tiles_; |
298 | 299 |
299 PrioritizedTileSet prioritized_tiles_; | |
300 bool prioritized_tiles_dirty_; | |
301 | |
302 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 300 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
303 bool all_tiles_required_for_activation_have_memory_; | 301 bool all_tiles_required_for_activation_have_memory_; |
304 | 302 |
305 size_t memory_required_bytes_; | |
306 size_t memory_nice_to_have_bytes_; | |
307 | |
308 size_t bytes_releasable_; | 303 size_t bytes_releasable_; |
309 size_t resources_releasable_; | 304 size_t resources_releasable_; |
310 size_t max_raster_usage_bytes_; | 305 size_t max_raster_usage_bytes_; |
311 | 306 |
312 bool ever_exceeded_memory_budget_; | 307 bool ever_exceeded_memory_budget_; |
313 MemoryHistory::Entry memory_stats_from_last_assign_; | 308 MemoryHistory::Entry memory_stats_from_last_assign_; |
314 | 309 |
315 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 310 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
316 | 311 |
317 bool did_initialize_visible_tile_; | 312 bool did_initialize_visible_tile_; |
(...skipping 21 matching lines...) Expand all Loading... |
339 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 334 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
340 | 335 |
341 std::vector<PictureLayerImpl*> layers_; | 336 std::vector<PictureLayerImpl*> layers_; |
342 | 337 |
343 DISALLOW_COPY_AND_ASSIGN(TileManager); | 338 DISALLOW_COPY_AND_ASSIGN(TileManager); |
344 }; | 339 }; |
345 | 340 |
346 } // namespace cc | 341 } // namespace cc |
347 | 342 |
348 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 343 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |