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 <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 }; | 101 }; |
102 | 102 |
103 std::vector<PairedPictureLayerIterator> paired_iterators_; | 103 std::vector<PairedPictureLayerIterator> paired_iterators_; |
104 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 104 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
105 TreePriority tree_priority_; | 105 TreePriority tree_priority_; |
106 RasterOrderComparator comparator_; | 106 RasterOrderComparator comparator_; |
107 }; | 107 }; |
108 | 108 |
109 static scoped_ptr<TileManager> Create( | 109 static scoped_ptr<TileManager> Create( |
110 TileManagerClient* client, | 110 TileManagerClient* client, |
111 ResourceProvider* resource_provider, | 111 ResourcePool* resource_pool, |
112 Rasterizer* rasterizer, | 112 Rasterizer* rasterizer, |
113 Rasterizer* gpu_rasterizer, | 113 Rasterizer* gpu_rasterizer, |
114 size_t max_raster_usage_bytes, | 114 size_t max_raster_usage_bytes, |
115 bool use_rasterize_on_demand, | 115 bool use_rasterize_on_demand, |
116 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 116 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
117 virtual ~TileManager(); | 117 virtual ~TileManager(); |
118 | 118 |
119 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 119 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); |
120 | 120 |
121 // Returns true when visible tiles have been initialized. | 121 // Returns true when visible tiles have been initialized. |
(...skipping 17 matching lines...) Expand all Loading... |
139 size_t* memory_nice_to_have_bytes, | 139 size_t* memory_nice_to_have_bytes, |
140 size_t* memory_allocated_bytes, | 140 size_t* memory_allocated_bytes, |
141 size_t* memory_used_bytes) const; | 141 size_t* memory_used_bytes) const; |
142 | 142 |
143 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 143 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
144 return memory_stats_from_last_assign_; | 144 return memory_stats_from_last_assign_; |
145 } | 145 } |
146 | 146 |
147 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; | 147 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; |
148 | 148 |
149 ResourcePool* resource_pool() { return resource_pool_.get(); } | |
150 | |
151 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 149 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
152 for (size_t i = 0; i < tiles.size(); ++i) { | 150 for (size_t i = 0; i < tiles.size(); ++i) { |
153 ManagedTileState& mts = tiles[i]->managed_state(); | 151 ManagedTileState& mts = tiles[i]->managed_state(); |
154 ManagedTileState::TileVersion& tile_version = | 152 ManagedTileState::TileVersion& tile_version = |
155 mts.tile_versions[HIGH_QUALITY_NO_LCD_RASTER_MODE]; | 153 mts.tile_versions[HIGH_QUALITY_NO_LCD_RASTER_MODE]; |
156 | 154 |
157 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 155 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); |
158 | 156 |
159 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | 157 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); |
160 ++resources_releasable_; | 158 ++resources_releasable_; |
161 } | 159 } |
162 } | 160 } |
163 | 161 |
164 void SetGlobalStateForTesting( | 162 void SetGlobalStateForTesting( |
165 const GlobalStateThatImpactsTilePriority& state) { | 163 const GlobalStateThatImpactsTilePriority& state) { |
166 // Soft limit is used for resource pool such that | 164 // Soft limit is used for resource pool such that |
167 // memory returns to soft limit after going over. | 165 // memory returns to soft limit after going over. |
168 if (state != global_state_) { | 166 if (state != global_state_) { |
169 global_state_ = state; | 167 global_state_ = state; |
170 prioritized_tiles_dirty_ = true; | 168 prioritized_tiles_dirty_ = true; |
171 resource_pool_->SetResourceUsageLimits( | 169 resource_pool_->SetResourceUsageLimits( |
172 global_state_.soft_memory_limit_in_bytes, | 170 global_state_.soft_memory_limit_in_bytes, |
173 global_state_.unused_memory_limit_in_bytes, | 171 global_state_.unused_memory_limit_in_bytes, |
174 global_state_.num_resources_limit); | 172 global_state_.num_resources_limit); |
175 } | 173 } |
176 } | 174 } |
177 | 175 |
178 protected: | 176 protected: |
179 TileManager(TileManagerClient* client, | 177 TileManager(TileManagerClient* client, |
180 ResourceProvider* resource_provider, | 178 ResourcePool* resource_pool, |
181 Rasterizer* rasterizer, | 179 Rasterizer* rasterizer, |
182 Rasterizer* gpu_rasterizer, | 180 Rasterizer* gpu_rasterizer, |
183 size_t max_raster_usage_bytes, | 181 size_t max_raster_usage_bytes, |
184 bool use_rasterize_on_demand, | 182 bool use_rasterize_on_demand, |
185 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 183 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
186 | 184 |
187 // Methods called by Tile | 185 // Methods called by Tile |
188 friend class Tile; | 186 friend class Tile; |
189 void DidChangeTilePriority(Tile* tile); | 187 void DidChangeTilePriority(Tile* tile); |
190 | 188 |
(...skipping 28 matching lines...) Expand all Loading... |
219 void OnImageDecodeTaskCompleted(int layer_id, | 217 void OnImageDecodeTaskCompleted(int layer_id, |
220 SkPixelRef* pixel_ref, | 218 SkPixelRef* pixel_ref, |
221 bool was_canceled); | 219 bool was_canceled); |
222 void OnRasterTaskCompleted(Tile::Id tile, | 220 void OnRasterTaskCompleted(Tile::Id tile, |
223 scoped_ptr<ScopedResource> resource, | 221 scoped_ptr<ScopedResource> resource, |
224 RasterMode raster_mode, | 222 RasterMode raster_mode, |
225 const PicturePileImpl::Analysis& analysis, | 223 const PicturePileImpl::Analysis& analysis, |
226 bool was_canceled); | 224 bool was_canceled); |
227 | 225 |
228 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 226 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
229 return Resource::MemorySizeBytes(tile->size(), resource_format_); | 227 return Resource::MemorySizeBytes(tile->size(), |
| 228 resource_pool_->resource_format()); |
230 } | 229 } |
231 | 230 |
232 void FreeResourceForTile(Tile* tile, RasterMode mode); | 231 void FreeResourceForTile(Tile* tile, RasterMode mode); |
233 void FreeResourcesForTile(Tile* tile); | 232 void FreeResourcesForTile(Tile* tile); |
234 void FreeUnusedResourcesForTile(Tile* tile); | 233 void FreeUnusedResourcesForTile(Tile* tile); |
235 scoped_refptr<internal::ImageDecodeTask> CreateImageDecodeTask( | 234 scoped_refptr<internal::ImageDecodeTask> CreateImageDecodeTask( |
236 Tile* tile, | 235 Tile* tile, |
237 SkPixelRef* pixel_ref); | 236 SkPixelRef* pixel_ref); |
238 scoped_refptr<internal::RasterTask> CreateRasterTask(Tile* tile); | 237 scoped_refptr<internal::RasterTask> CreateRasterTask(Tile* tile); |
239 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 238 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
240 void UpdatePrioritizedTileSetIfNeeded(); | 239 void UpdatePrioritizedTileSetIfNeeded(); |
241 | 240 |
242 TileManagerClient* client_; | 241 TileManagerClient* client_; |
243 scoped_ptr<ResourcePool> resource_pool_; | 242 ResourcePool* resource_pool_; |
244 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; | 243 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; |
245 GlobalStateThatImpactsTilePriority global_state_; | 244 GlobalStateThatImpactsTilePriority global_state_; |
246 | 245 |
247 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 246 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
248 TileMap tiles_; | 247 TileMap tiles_; |
249 | 248 |
250 PrioritizedTileSet prioritized_tiles_; | 249 PrioritizedTileSet prioritized_tiles_; |
251 bool prioritized_tiles_dirty_; | 250 bool prioritized_tiles_dirty_; |
252 | 251 |
253 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 252 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 std::vector<scoped_refptr<internal::RasterTask> > orphan_raster_tasks_; | 289 std::vector<scoped_refptr<internal::RasterTask> > orphan_raster_tasks_; |
291 | 290 |
292 std::vector<PictureLayerImpl*> layers_; | 291 std::vector<PictureLayerImpl*> layers_; |
293 | 292 |
294 DISALLOW_COPY_AND_ASSIGN(TileManager); | 293 DISALLOW_COPY_AND_ASSIGN(TileManager); |
295 }; | 294 }; |
296 | 295 |
297 } // namespace cc | 296 } // namespace cc |
298 | 297 |
299 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 298 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |