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> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 LOW_PRIORITY_BIN = 1, | 53 LOW_PRIORITY_BIN = 1, |
54 NUM_BIN_PRIORITIES = 2 | 54 NUM_BIN_PRIORITIES = 2 |
55 }; | 55 }; |
56 scoped_ptr<base::Value> TileManagerBinPriorityAsValue( | 56 scoped_ptr<base::Value> TileManagerBinPriorityAsValue( |
57 TileManagerBinPriority bin); | 57 TileManagerBinPriority bin); |
58 | 58 |
59 // This class manages tiles, deciding which should get rasterized and which | 59 // This class manages tiles, deciding which should get rasterized and which |
60 // should no longer have any memory assigned to them. Tile objects are "owned" | 60 // should no longer have any memory assigned to them. Tile objects are "owned" |
61 // by layers; they automatically register with the manager when they are | 61 // by layers; they automatically register with the manager when they are |
62 // created, and unregister from the manager when they are deleted. | 62 // created, and unregister from the manager when they are deleted. |
63 class CC_EXPORT TileManager : public WorkerPoolClient { | 63 class CC_EXPORT TileManager : public RasterWorkerPoolClient { |
64 public: | 64 public: |
65 typedef base::hash_set<uint32_t> PixelRefSet; | 65 typedef base::hash_set<uint32_t> PixelRefSet; |
66 | 66 |
67 static scoped_ptr<TileManager> Create( | 67 static scoped_ptr<TileManager> Create( |
68 TileManagerClient* client, | 68 TileManagerClient* client, |
69 ResourceProvider* resource_provider, | 69 ResourceProvider* resource_provider, |
70 size_t num_raster_threads, | 70 size_t num_raster_threads, |
71 bool use_color_estimator, | 71 bool use_color_estimator, |
72 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 72 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
73 bool use_map_image); | 73 bool use_map_image); |
74 virtual ~TileManager(); | 74 virtual ~TileManager(); |
75 | 75 |
76 const GlobalStateThatImpactsTilePriority& GlobalState() const { | 76 const GlobalStateThatImpactsTilePriority& GlobalState() const { |
77 return global_state_; | 77 return global_state_; |
78 } | 78 } |
79 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); | 79 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); |
80 | 80 |
81 void ManageTiles(); | 81 void ManageTiles(); |
82 void CheckForCompletedTileUploads(); | 82 void CheckForCompletedTileUploads(); |
83 void AbortPendingTileUploads(); | |
84 | 83 |
85 scoped_ptr<base::Value> BasicStateAsValue() const; | 84 scoped_ptr<base::Value> BasicStateAsValue() const; |
86 scoped_ptr<base::Value> AllTilesAsValue() const; | 85 scoped_ptr<base::Value> AllTilesAsValue() const; |
87 void GetMemoryStats(size_t* memory_required_bytes, | 86 void GetMemoryStats(size_t* memory_required_bytes, |
88 size_t* memory_nice_to_have_bytes, | 87 size_t* memory_nice_to_have_bytes, |
89 size_t* memory_used_bytes) const; | 88 size_t* memory_used_bytes) const; |
90 | 89 |
91 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 90 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
92 return memory_stats_from_last_assign_; | 91 return memory_stats_from_last_assign_; |
93 } | 92 } |
94 | 93 |
95 // Overridden from WorkerPoolClient: | 94 // Overridden from RasterWorkerPoolClient: |
96 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE; | 95 virtual void DidFinishDispatchingRasterWorkerPoolCompletionCallbacks() |
| 96 OVERRIDE; |
97 | 97 |
98 void WillModifyTilePriorities() { | 98 void WillModifyTilePriorities() { |
99 ScheduleManageTiles(); | 99 ScheduleManageTiles(); |
100 } | 100 } |
101 | 101 |
102 bool AreTilesRequiredForActivationReady() const { | 102 bool AreTilesRequiredForActivationReady() const { |
103 return tiles_that_need_to_be_initialized_for_activation_.empty(); | 103 return tiles_that_need_to_be_initialized_for_activation_.empty(); |
104 } | 104 } |
105 | 105 |
106 protected: | 106 protected: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void ScheduleManageTiles() { | 139 void ScheduleManageTiles() { |
140 if (manage_tiles_pending_) | 140 if (manage_tiles_pending_) |
141 return; | 141 return; |
142 client_->ScheduleManageTiles(); | 142 client_->ScheduleManageTiles(); |
143 manage_tiles_pending_ = true; | 143 manage_tiles_pending_ = true; |
144 } | 144 } |
145 RasterWorkerPool::Task CreateImageDecodeTask( | 145 RasterWorkerPool::Task CreateImageDecodeTask( |
146 Tile* tile, skia::LazyPixelRef* pixel_ref); | 146 Tile* tile, skia::LazyPixelRef* pixel_ref); |
147 void OnImageDecodeTaskCompleted( | 147 void OnImageDecodeTaskCompleted( |
148 scoped_refptr<Tile> tile, | 148 scoped_refptr<Tile> tile, |
149 uint32_t pixel_ref_id, | 149 uint32_t pixel_ref_id); |
150 bool was_canceled); | |
151 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; | 150 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; |
152 RasterWorkerPool::Task CreateRasterTask(Tile* tile); | 151 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
153 void OnRasterTaskCompleted( | 152 void OnRasterTaskCompleted( |
154 scoped_refptr<Tile> tile, | 153 scoped_refptr<Tile> tile, |
155 scoped_ptr<ResourcePool::Resource> resource, | 154 scoped_ptr<ResourcePool::Resource> resource, |
156 PicturePileImpl::Analysis* analysis, | 155 PicturePileImpl::Analysis* analysis, |
157 bool was_canceled); | 156 bool was_canceled); |
158 void DidFinishTileInitialization(Tile* tile); | 157 void DidFinishTileInitialization(Tile* tile); |
159 void DidTileTreeBinChange(Tile* tile, | 158 void DidTileTreeBinChange(Tile* tile, |
160 TileManagerBin new_tree_bin, | 159 TileManagerBin new_tree_bin, |
161 WhichTree tree); | 160 WhichTree tree); |
162 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; | 161 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; |
163 void AddRequiredTileForActivation(Tile* tile); | 162 void AddRequiredTileForActivation(Tile* tile); |
164 | 163 |
165 static void RunImageDecodeTask( | 164 static void RunImageDecodeTask( |
166 skia::LazyPixelRef* pixel_ref, | 165 skia::LazyPixelRef* pixel_ref, |
167 int layer_id, | 166 int layer_id, |
168 RenderingStatsInstrumentation* stats_instrumentation); | 167 RenderingStatsInstrumentation* stats_instrumentation); |
169 static void RunAnalyzeAndRasterTask( | 168 static bool RunAnalyzeAndRasterTask( |
170 const RasterWorkerPool::PictureTask::Callback& analyze_task, | 169 const base::Callback<void(PicturePileImpl*)>& analyze_task, |
171 const RasterWorkerPool::PictureTask::Callback& raster_task, | 170 const RasterWorkerPool::RasterTask::Callback& raster_task, |
| 171 uint8* buffer, |
172 PicturePileImpl* picture_pile); | 172 PicturePileImpl* picture_pile); |
173 static void RunAnalyzeTask( | 173 static void RunAnalyzeTask( |
174 PicturePileImpl::Analysis* analysis, | 174 PicturePileImpl::Analysis* analysis, |
175 gfx::Rect rect, | 175 gfx::Rect rect, |
176 float contents_scale, | 176 float contents_scale, |
177 bool use_color_estimator, | 177 bool use_color_estimator, |
178 const RasterTaskMetadata& metadata, | 178 const RasterTaskMetadata& metadata, |
179 RenderingStatsInstrumentation* stats_instrumentation, | 179 RenderingStatsInstrumentation* stats_instrumentation, |
180 PicturePileImpl* picture_pile); | 180 PicturePileImpl* picture_pile); |
181 static void RunRasterTask( | 181 static bool RunRasterTask( |
182 uint8* buffer, | |
183 PicturePileImpl::Analysis* analysis, | 182 PicturePileImpl::Analysis* analysis, |
184 gfx::Rect rect, | 183 gfx::Rect rect, |
185 float contents_scale, | 184 float contents_scale, |
186 const RasterTaskMetadata& metadata, | 185 const RasterTaskMetadata& metadata, |
187 RenderingStatsInstrumentation* stats_instrumentation, | 186 RenderingStatsInstrumentation* stats_instrumentation, |
| 187 uint8* buffer, |
188 PicturePileImpl* picture_pile); | 188 PicturePileImpl* picture_pile); |
189 | 189 |
190 TileManagerClient* client_; | 190 TileManagerClient* client_; |
191 scoped_ptr<ResourcePool> resource_pool_; | 191 scoped_ptr<ResourcePool> resource_pool_; |
192 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 192 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
193 bool manage_tiles_pending_; | 193 bool manage_tiles_pending_; |
194 | 194 |
195 GlobalStateThatImpactsTilePriority global_state_; | 195 GlobalStateThatImpactsTilePriority global_state_; |
196 | 196 |
197 typedef std::vector<Tile*> TileVector; | 197 typedef std::vector<Tile*> TileVector; |
198 TileVector tiles_; | 198 TileVector tiles_; |
199 TileVector tiles_that_need_to_be_rasterized_; | 199 TileVector tiles_that_need_to_be_rasterized_; |
200 typedef std::set<Tile*> TileSet; | 200 typedef std::set<Tile*> TileSet; |
201 TileSet tiles_that_need_to_be_initialized_for_activation_; | 201 TileSet tiles_that_need_to_be_initialized_for_activation_; |
202 | 202 |
203 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; | 203 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; |
204 PixelRefMap pending_decode_tasks_; | 204 PixelRefMap pending_decode_tasks_; |
205 | 205 |
206 typedef std::queue<scoped_refptr<Tile> > TileQueue; | |
207 TileQueue tiles_with_pending_upload_; | |
208 size_t bytes_pending_upload_; | |
209 bool has_performed_uploads_since_last_flush_; | |
210 bool ever_exceeded_memory_budget_; | 206 bool ever_exceeded_memory_budget_; |
211 MemoryHistory::Entry memory_stats_from_last_assign_; | 207 MemoryHistory::Entry memory_stats_from_last_assign_; |
212 | 208 |
213 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 209 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
214 | 210 |
215 bool use_color_estimator_; | 211 bool use_color_estimator_; |
216 bool did_initialize_visible_tile_; | 212 bool did_initialize_visible_tile_; |
217 | 213 |
218 size_t max_pending_tasks_; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(TileManager); | 214 DISALLOW_COPY_AND_ASSIGN(TileManager); |
221 }; | 215 }; |
222 | 216 |
223 } // namespace cc | 217 } // namespace cc |
224 | 218 |
225 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 219 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |