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 <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "cc/base/ref_counted_managed.h" | 15 #include "cc/base/ref_counted_managed.h" |
16 #include "cc/debug/rendering_stats_instrumentation.h" | 16 #include "cc/debug/rendering_stats_instrumentation.h" |
17 #include "cc/resources/managed_tile_state.h" | 17 #include "cc/resources/managed_tile_state.h" |
18 #include "cc/resources/memory_history.h" | 18 #include "cc/resources/memory_history.h" |
19 #include "cc/resources/picture_pile_impl.h" | 19 #include "cc/resources/picture_pile_impl.h" |
20 #include "cc/resources/prioritized_tile_set.h" | 20 #include "cc/resources/prioritized_tile_set.h" |
21 #include "cc/resources/raster_worker_pool.h" | 21 #include "cc/resources/raster_worker_pool.h" |
22 #include "cc/resources/resource_pool.h" | 22 #include "cc/resources/resource_pool.h" |
23 #include "cc/resources/tile.h" | 23 #include "cc/resources/tile.h" |
24 | 24 |
25 namespace cc { | 25 namespace cc { |
| 26 class RasterWorkerPoolDelegate; |
26 class ResourceProvider; | 27 class ResourceProvider; |
27 | 28 |
28 class CC_EXPORT TileManagerClient { | 29 class CC_EXPORT TileManagerClient { |
29 public: | 30 public: |
30 virtual void NotifyReadyToActivate() = 0; | 31 virtual void NotifyReadyToActivate() = 0; |
31 | 32 |
32 protected: | 33 protected: |
33 virtual ~TileManagerClient() {} | 34 virtual ~TileManagerClient() {} |
34 }; | 35 }; |
35 | 36 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ManagedTileState& mts = tiles[i]->managed_state(); | 94 ManagedTileState& mts = tiles[i]->managed_state(); |
94 ManagedTileState::TileVersion& tile_version = | 95 ManagedTileState::TileVersion& tile_version = |
95 mts.tile_versions[HIGH_QUALITY_NO_LCD_RASTER_MODE]; | 96 mts.tile_versions[HIGH_QUALITY_NO_LCD_RASTER_MODE]; |
96 | 97 |
97 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 98 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); |
98 | 99 |
99 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | 100 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); |
100 ++resources_releasable_; | 101 ++resources_releasable_; |
101 } | 102 } |
102 } | 103 } |
103 RasterWorkerPool* RasterWorkerPoolForTesting() { | |
104 return raster_worker_pool_.get(); | |
105 } | |
106 | 104 |
107 void SetGlobalStateForTesting( | 105 void SetGlobalStateForTesting( |
108 const GlobalStateThatImpactsTilePriority& state) { | 106 const GlobalStateThatImpactsTilePriority& state) { |
109 // Soft limit is used for resource pool such that | 107 // Soft limit is used for resource pool such that |
110 // memory returns to soft limit after going over. | 108 // memory returns to soft limit after going over. |
111 if (state != global_state_) { | 109 if (state != global_state_) { |
112 global_state_ = state; | 110 global_state_ = state; |
113 prioritized_tiles_dirty_ = true; | 111 prioritized_tiles_dirty_ = true; |
114 resource_pool_->SetResourceUsageLimits( | 112 resource_pool_->SetResourceUsageLimits( |
115 global_state_.soft_memory_limit_in_bytes, | 113 global_state_.soft_memory_limit_in_bytes, |
116 global_state_.unused_memory_limit_in_bytes, | 114 global_state_.unused_memory_limit_in_bytes, |
117 global_state_.num_resources_limit); | 115 global_state_.num_resources_limit); |
118 } | 116 } |
119 } | 117 } |
120 | 118 |
121 protected: | 119 protected: |
122 TileManager(TileManagerClient* client, | 120 TileManager(TileManagerClient* client, |
123 ResourceProvider* resource_provider, | 121 ResourceProvider* resource_provider, |
| 122 ContextProvider* context_provider, |
124 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 123 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 124 scoped_ptr<RasterWorkerPool> direct_raster_worker_pool, |
125 size_t max_raster_usage_bytes, | 125 size_t max_raster_usage_bytes, |
126 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 126 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
127 bool use_rasterize_on_demand); | 127 bool use_rasterize_on_demand); |
128 | 128 |
129 // Methods called by Tile | 129 // Methods called by Tile |
130 friend class Tile; | 130 friend class Tile; |
131 void DidChangeTilePriority(Tile* tile); | 131 void DidChangeTilePriority(Tile* tile); |
132 | 132 |
133 void CleanUpReleasedTiles(); | 133 void CleanUpReleasedTiles(); |
134 | 134 |
(...skipping 10 matching lines...) Expand all Loading... |
145 | 145 |
146 // Virtual for test | 146 // Virtual for test |
147 virtual void ScheduleTasks( | 147 virtual void ScheduleTasks( |
148 const TileVector& tiles_that_need_to_be_rasterized); | 148 const TileVector& tiles_that_need_to_be_rasterized); |
149 | 149 |
150 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 150 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, |
151 TileVector* tiles_that_need_to_be_rasterized); | 151 TileVector* tiles_that_need_to_be_rasterized); |
152 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | 152 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); |
153 | 153 |
154 private: | 154 private: |
| 155 enum RasterWorkerPoolType { |
| 156 RASTER_WORKER_POOL_TYPE_DEFAULT, |
| 157 RASTER_WORKER_POOL_TYPE_DIRECT, |
| 158 NUM_RASTER_WORKER_POOL_TYPES |
| 159 }; |
| 160 |
155 void OnImageDecodeTaskCompleted(int layer_id, | 161 void OnImageDecodeTaskCompleted(int layer_id, |
156 SkPixelRef* pixel_ref, | 162 SkPixelRef* pixel_ref, |
157 bool was_canceled); | 163 bool was_canceled); |
158 void OnRasterTaskCompleted(Tile::Id tile, | 164 void OnRasterTaskCompleted(Tile::Id tile, |
159 scoped_ptr<ScopedResource> resource, | 165 scoped_ptr<ScopedResource> resource, |
160 RasterMode raster_mode, | 166 RasterMode raster_mode, |
161 const PicturePileImpl::Analysis& analysis, | 167 const PicturePileImpl::Analysis& analysis, |
162 bool was_canceled); | 168 bool was_canceled); |
163 | 169 |
164 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 170 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
165 return Resource::MemorySizeBytes(tile->size(), | 171 return Resource::MemorySizeBytes(tile->size(), |
166 raster_worker_pool_->GetResourceFormat()); | 172 raster_worker_pool_->GetResourceFormat()); |
167 } | 173 } |
168 | 174 |
169 RasterMode DetermineRasterMode(const Tile* tile) const; | 175 RasterMode DetermineRasterMode(const Tile* tile) const; |
170 void FreeResourceForTile(Tile* tile, RasterMode mode); | 176 void FreeResourceForTile(Tile* tile, RasterMode mode); |
171 void FreeResourcesForTile(Tile* tile); | 177 void FreeResourcesForTile(Tile* tile); |
172 void FreeUnusedResourcesForTile(Tile* tile); | 178 void FreeUnusedResourcesForTile(Tile* tile); |
173 RasterWorkerPool::Task CreateImageDecodeTask(Tile* tile, | 179 RasterWorkerPool::Task CreateImageDecodeTask(Tile* tile, |
174 SkPixelRef* pixel_ref); | 180 SkPixelRef* pixel_ref); |
175 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); | 181 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
176 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 182 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
177 void UpdatePrioritizedTileSetIfNeeded(); | 183 void UpdatePrioritizedTileSetIfNeeded(); |
178 | 184 |
179 TileManagerClient* client_; | 185 TileManagerClient* client_; |
| 186 ContextProvider* context_provider_; |
180 scoped_ptr<ResourcePool> resource_pool_; | 187 scoped_ptr<ResourcePool> resource_pool_; |
181 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 188 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 189 scoped_ptr<RasterWorkerPool> direct_raster_worker_pool_; |
| 190 scoped_ptr<RasterWorkerPoolDelegate> raster_worker_pool_delegate_; |
182 GlobalStateThatImpactsTilePriority global_state_; | 191 GlobalStateThatImpactsTilePriority global_state_; |
183 | 192 |
184 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 193 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
185 TileMap tiles_; | 194 TileMap tiles_; |
186 | 195 |
187 PrioritizedTileSet prioritized_tiles_; | 196 PrioritizedTileSet prioritized_tiles_; |
188 bool prioritized_tiles_dirty_; | 197 bool prioritized_tiles_dirty_; |
189 | 198 |
190 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 199 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
191 bool all_tiles_required_for_activation_have_memory_; | 200 bool all_tiles_required_for_activation_have_memory_; |
(...skipping 19 matching lines...) Expand all Loading... |
211 | 220 |
212 typedef base::hash_map<int, int> LayerCountMap; | 221 typedef base::hash_map<int, int> LayerCountMap; |
213 LayerCountMap used_layer_counts_; | 222 LayerCountMap used_layer_counts_; |
214 | 223 |
215 RasterTaskCompletionStats update_visible_tiles_stats_; | 224 RasterTaskCompletionStats update_visible_tiles_stats_; |
216 | 225 |
217 std::vector<Tile*> released_tiles_; | 226 std::vector<Tile*> released_tiles_; |
218 | 227 |
219 bool use_rasterize_on_demand_; | 228 bool use_rasterize_on_demand_; |
220 | 229 |
221 // Queue used when scheduling raster tasks. | 230 // Queues used when scheduling raster tasks. |
222 RasterWorkerPool::RasterTask::Queue raster_tasks_; | 231 RasterWorkerPool::RasterTask::Queue |
| 232 raster_queue_[NUM_RASTER_WORKER_POOL_TYPES]; |
223 | 233 |
224 DISALLOW_COPY_AND_ASSIGN(TileManager); | 234 DISALLOW_COPY_AND_ASSIGN(TileManager); |
225 }; | 235 }; |
226 | 236 |
227 } // namespace cc | 237 } // namespace cc |
228 | 238 |
229 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 239 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |