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 if (state != global_state_) { | 107 if (state != global_state_) { |
110 global_state_ = state; | 108 global_state_ = state; |
111 prioritized_tiles_dirty_ = true; | 109 prioritized_tiles_dirty_ = true; |
112 resource_pool_->SetResourceUsageLimits( | 110 resource_pool_->SetResourceUsageLimits( |
113 global_state_.memory_limit_in_bytes, | 111 global_state_.memory_limit_in_bytes, |
114 global_state_.unused_memory_limit_in_bytes, | 112 global_state_.unused_memory_limit_in_bytes, |
115 global_state_.num_resources_limit); | 113 global_state_.num_resources_limit); |
116 } | 114 } |
117 } | 115 } |
118 | 116 |
119 protected: | 117 protected: |
120 TileManager(TileManagerClient* client, | 118 TileManager(TileManagerClient* client, |
121 ResourceProvider* resource_provider, | 119 ResourceProvider* resource_provider, |
| 120 ContextProvider* context_provider, |
122 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 121 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 122 scoped_ptr<RasterWorkerPool> direct_raster_worker_pool, |
123 size_t max_raster_usage_bytes, | 123 size_t max_raster_usage_bytes, |
124 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 124 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
125 bool use_rasterize_on_demand); | 125 bool use_rasterize_on_demand); |
126 | 126 |
127 // Methods called by Tile | 127 // Methods called by Tile |
128 friend class Tile; | 128 friend class Tile; |
129 void DidChangeTilePriority(Tile* tile); | 129 void DidChangeTilePriority(Tile* tile); |
130 | 130 |
131 void CleanUpReleasedTiles(); | 131 void CleanUpReleasedTiles(); |
132 | 132 |
(...skipping 10 matching lines...) Expand all Loading... |
143 | 143 |
144 // Virtual for test | 144 // Virtual for test |
145 virtual void ScheduleTasks( | 145 virtual void ScheduleTasks( |
146 const TileVector& tiles_that_need_to_be_rasterized); | 146 const TileVector& tiles_that_need_to_be_rasterized); |
147 | 147 |
148 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 148 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, |
149 TileVector* tiles_that_need_to_be_rasterized); | 149 TileVector* tiles_that_need_to_be_rasterized); |
150 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | 150 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); |
151 | 151 |
152 private: | 152 private: |
| 153 enum RasterWorkerPoolType { |
| 154 RASTER_WORKER_POOL_TYPE_DEFAULT, |
| 155 RASTER_WORKER_POOL_TYPE_DIRECT, |
| 156 NUM_RASTER_WORKER_POOL_TYPES |
| 157 }; |
| 158 |
153 void OnImageDecodeTaskCompleted(int layer_id, | 159 void OnImageDecodeTaskCompleted(int layer_id, |
154 SkPixelRef* pixel_ref, | 160 SkPixelRef* pixel_ref, |
155 bool was_canceled); | 161 bool was_canceled); |
156 void OnRasterTaskCompleted(Tile::Id tile, | 162 void OnRasterTaskCompleted(Tile::Id tile, |
157 scoped_ptr<ScopedResource> resource, | 163 scoped_ptr<ScopedResource> resource, |
158 RasterMode raster_mode, | 164 RasterMode raster_mode, |
159 const PicturePileImpl::Analysis& analysis, | 165 const PicturePileImpl::Analysis& analysis, |
160 bool was_canceled); | 166 bool was_canceled); |
161 | 167 |
162 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 168 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
163 return Resource::MemorySizeBytes(tile->size(), | 169 return Resource::MemorySizeBytes(tile->size(), |
164 raster_worker_pool_->GetResourceFormat()); | 170 raster_worker_pool_->GetResourceFormat()); |
165 } | 171 } |
166 | 172 |
167 RasterMode DetermineRasterMode(const Tile* tile) const; | 173 RasterMode DetermineRasterMode(const Tile* tile) const; |
168 void FreeResourceForTile(Tile* tile, RasterMode mode); | 174 void FreeResourceForTile(Tile* tile, RasterMode mode); |
169 void FreeResourcesForTile(Tile* tile); | 175 void FreeResourcesForTile(Tile* tile); |
170 void FreeUnusedResourcesForTile(Tile* tile); | 176 void FreeUnusedResourcesForTile(Tile* tile); |
171 RasterWorkerPool::Task CreateImageDecodeTask(Tile* tile, | 177 RasterWorkerPool::Task CreateImageDecodeTask(Tile* tile, |
172 SkPixelRef* pixel_ref); | 178 SkPixelRef* pixel_ref); |
173 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); | 179 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
174 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 180 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
175 void UpdatePrioritizedTileSetIfNeeded(); | 181 void UpdatePrioritizedTileSetIfNeeded(); |
176 | 182 |
177 TileManagerClient* client_; | 183 TileManagerClient* client_; |
| 184 ContextProvider* context_provider_; |
178 scoped_ptr<ResourcePool> resource_pool_; | 185 scoped_ptr<ResourcePool> resource_pool_; |
179 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 186 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 187 scoped_ptr<RasterWorkerPool> direct_raster_worker_pool_; |
| 188 scoped_ptr<RasterWorkerPoolDelegate> raster_worker_pool_delegate_; |
180 GlobalStateThatImpactsTilePriority global_state_; | 189 GlobalStateThatImpactsTilePriority global_state_; |
181 | 190 |
182 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 191 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
183 TileMap tiles_; | 192 TileMap tiles_; |
184 | 193 |
185 PrioritizedTileSet prioritized_tiles_; | 194 PrioritizedTileSet prioritized_tiles_; |
186 bool prioritized_tiles_dirty_; | 195 bool prioritized_tiles_dirty_; |
187 | 196 |
188 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 197 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
189 bool all_tiles_required_for_activation_have_memory_; | 198 bool all_tiles_required_for_activation_have_memory_; |
(...skipping 19 matching lines...) Expand all Loading... |
209 | 218 |
210 typedef base::hash_map<int, int> LayerCountMap; | 219 typedef base::hash_map<int, int> LayerCountMap; |
211 LayerCountMap used_layer_counts_; | 220 LayerCountMap used_layer_counts_; |
212 | 221 |
213 RasterTaskCompletionStats update_visible_tiles_stats_; | 222 RasterTaskCompletionStats update_visible_tiles_stats_; |
214 | 223 |
215 std::vector<Tile*> released_tiles_; | 224 std::vector<Tile*> released_tiles_; |
216 | 225 |
217 bool use_rasterize_on_demand_; | 226 bool use_rasterize_on_demand_; |
218 | 227 |
219 // Queue used when scheduling raster tasks. | 228 // Queues used when scheduling raster tasks. |
220 RasterWorkerPool::RasterTask::Queue raster_tasks_; | 229 RasterWorkerPool::RasterTask::Queue |
| 230 raster_queue_[NUM_RASTER_WORKER_POOL_TYPES]; |
221 | 231 |
222 DISALLOW_COPY_AND_ASSIGN(TileManager); | 232 DISALLOW_COPY_AND_ASSIGN(TileManager); |
223 }; | 233 }; |
224 | 234 |
225 } // namespace cc | 235 } // namespace cc |
226 | 236 |
227 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 237 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |