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_TILE_MANAGER_H_ | 5 #ifndef CC_TILE_MANAGER_H_ |
6 #define CC_TILE_MANAGER_H_ | 6 #define CC_TILE_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "cc/memory_history.h" | 16 #include "cc/memory_history.h" |
17 #include "cc/rendering_stats.h" | 17 #include "cc/rendering_stats.h" |
18 #include "cc/resource_pool.h" | 18 #include "cc/resource_pool.h" |
19 #include "cc/tile_priority.h" | 19 #include "cc/tile_priority.h" |
20 #include "cc/worker_pool.h" | 20 #include "cc/worker_pool.h" |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 class RasterWorkerPool; | 23 class RasterWorkerPool; |
24 class ResourceProvider; | 24 class ResourceProvider; |
25 class Tile; | 25 class Tile; |
| 26 class TileManager; |
26 class TileVersion; | 27 class TileVersion; |
27 | 28 |
28 class CC_EXPORT TileManagerClient { | 29 class CC_EXPORT TileManagerClient { |
29 public: | 30 public: |
30 virtual void ScheduleManageTiles() = 0; | 31 virtual void ScheduleManageTiles() = 0; |
31 virtual void DidUploadVisibleHighResolutionTile() = 0; | 32 virtual void DidUploadVisibleHighResolutionTile() = 0; |
32 | 33 |
33 protected: | 34 protected: |
34 virtual ~TileManagerClient() {} | 35 virtual ~TileManagerClient() {} |
35 }; | 36 }; |
(...skipping 30 matching lines...) Expand all Loading... |
66 TileRasterState bin); | 67 TileRasterState bin); |
67 | 68 |
68 // Metadata that is passed to raster tasks for diagnostic purposes. | 69 // Metadata that is passed to raster tasks for diagnostic purposes. |
69 struct RasterTaskMetadata { | 70 struct RasterTaskMetadata { |
70 bool is_tile_in_pending_tree_now_bin; | 71 bool is_tile_in_pending_tree_now_bin; |
71 TileResolution tile_resolution; | 72 TileResolution tile_resolution; |
72 }; | 73 }; |
73 | 74 |
74 // This is state that is specific to a tile that is | 75 // This is state that is specific to a tile that is |
75 // managed by the TileManager. | 76 // managed by the TileManager. |
76 class CC_EXPORT ManagedTileState { | 77 class CC_EXPORT ManagedTileState : public base::RefCounted<ManagedTileState> { |
77 public: | 78 public: |
78 ManagedTileState(); | 79 ManagedTileState(Tile* tile); |
79 ~ManagedTileState(); | |
80 scoped_ptr<base::Value> AsValue() const; | 80 scoped_ptr<base::Value> AsValue() const; |
81 | 81 |
82 // Persisted state: valid all the time. | 82 // Persisted state: valid all the time. |
| 83 scoped_refptr<Tile> tile; |
83 bool can_use_gpu_memory; | 84 bool can_use_gpu_memory; |
84 bool can_be_freed; | 85 bool can_be_freed; |
85 scoped_ptr<ResourcePool::Resource> resource; | 86 scoped_ptr<ResourcePool::Resource> resource; |
86 bool resource_is_being_initialized; | 87 bool resource_is_being_initialized; |
87 bool contents_swizzled; | 88 bool contents_swizzled; |
88 bool need_to_gather_pixel_refs; | 89 bool need_to_gather_pixel_refs; |
89 std::list<skia::LazyPixelRef*> pending_pixel_refs; | 90 std::list<skia::LazyPixelRef*> pending_pixel_refs; |
90 TileRasterState raster_state; | 91 TileRasterState raster_state; |
91 | 92 |
92 // Ephemeral state, valid only during Manage. | 93 // Ephemeral state, valid only during Manage. |
93 TileManagerBin bin[NUM_BIN_PRIORITIES]; | 94 TileManagerBin bin[NUM_BIN_PRIORITIES]; |
94 TileManagerBin tree_bin[NUM_TREES]; | 95 TileManagerBin tree_bin[NUM_TREES]; |
95 // The bin that the tile would have if the GPU memory manager had a maximally
permissive policy, | 96 // The bin that the tile would have if the GPU memory manager had a maximally
permissive policy, |
96 // send to the GPU memory manager to determine policy. | 97 // send to the GPU memory manager to determine policy. |
97 TileManagerBin gpu_memmgr_stats_bin; | 98 TileManagerBin gpu_memmgr_stats_bin; |
98 TileResolution resolution; | 99 TileResolution resolution; |
99 float time_to_needed_in_seconds; | 100 float time_to_needed_in_seconds; |
100 float distance_to_visible_in_pixels; | 101 float distance_to_visible_in_pixels; |
| 102 |
| 103 private: |
| 104 friend class base::RefCounted<ManagedTileState>; |
| 105 ~ManagedTileState(); |
101 }; | 106 }; |
102 | 107 |
103 // This class manages tiles, deciding which should get rasterized and which | 108 // This class manages tiles, deciding which should get rasterized and which |
104 // should no longer have any memory assigned to them. Tile objects are "owned" | 109 // should no longer have any memory assigned to them. Tile objects are "owned" |
105 // by layers; they automatically register with the manager when they are | 110 // by layers; they automatically register with the manager when they are |
106 // created, and unregister from the manager when they are deleted. | 111 // created, and unregister from the manager when they are deleted. |
107 class CC_EXPORT TileManager : public WorkerPoolClient { | 112 class CC_EXPORT TileManager : public WorkerPoolClient { |
108 public: | 113 public: |
109 TileManager(TileManagerClient* client, | 114 TileManager(TileManagerClient* client, |
110 ResourceProvider *resource_provider, | 115 ResourceProvider *resource_provider, |
(...skipping 22 matching lines...) Expand all Loading... |
133 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 138 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
134 return memory_stats_from_last_assign_; | 139 return memory_stats_from_last_assign_; |
135 } | 140 } |
136 | 141 |
137 // Overridden from WorkerPoolClient: | 142 // Overridden from WorkerPoolClient: |
138 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE; | 143 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE; |
139 | 144 |
140 protected: | 145 protected: |
141 // Methods called by Tile | 146 // Methods called by Tile |
142 friend class Tile; | 147 friend class Tile; |
143 void RegisterTile(Tile* tile); | 148 friend class TileHandle; |
144 void UnregisterTile(Tile* tile); | 149 friend class ManagedTileState; |
| 150 scoped_refptr<ManagedTileState> RegisterTile(Tile* tile); |
145 void WillModifyTilePriority( | 151 void WillModifyTilePriority( |
146 Tile* tile, WhichTree tree, const TilePriority& new_priority) { | 152 Tile* tile, WhichTree tree, const TilePriority& new_priority) { |
147 // TODO(nduca): Do something smarter if reprioritization turns out to be | 153 // TODO(nduca): Do something smarter if reprioritization turns out to be |
148 // costly. | 154 // costly. |
149 ScheduleManageTiles(); | 155 ScheduleManageTiles(); |
150 } | 156 } |
151 | 157 |
152 private: | 158 private: |
| 159 void RegisterManagedTile(ManagedTileState* mts); |
| 160 void UnregisterManagedTile(ManagedTileState* mts); |
153 void SortTiles(); | 161 void SortTiles(); |
154 void AssignGpuMemoryToTiles(); | 162 void AssignGpuMemoryToTiles(); |
155 void FreeResourcesForTile(Tile* tile); | 163 void FreeResourcesForTile(ManagedTileState* mts); |
156 void ScheduleManageTiles() { | 164 void ScheduleManageTiles() { |
157 if (manage_tiles_pending_) | 165 if (manage_tiles_pending_) |
158 return; | 166 return; |
159 client_->ScheduleManageTiles(); | 167 client_->ScheduleManageTiles(); |
160 manage_tiles_pending_ = true; | 168 manage_tiles_pending_ = true; |
161 } | 169 } |
162 void DispatchMoreTasks(); | 170 void DispatchMoreTasks(); |
163 void GatherPixelRefsForTile(Tile* tile); | 171 void GatherPixelRefsForTile(ManagedTileState* mts); |
164 void DispatchImageDecodeTasksForTile(Tile* tile); | 172 void DispatchImageDecodeTasksForTile(ManagedTileState* mts); |
165 void DispatchOneImageDecodeTask( | 173 void DispatchOneImageDecodeTask( |
166 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref); | 174 scoped_refptr<ManagedTileState> tile, skia::LazyPixelRef* pixel_ref); |
167 void OnImageDecodeTaskCompleted( | 175 void OnImageDecodeTaskCompleted( |
168 scoped_refptr<Tile> tile, | 176 scoped_refptr<ManagedTileState> tile, uint32_t pixel_ref_id); |
169 uint32_t pixel_ref_id); | 177 bool CanDispatchRasterTask(ManagedTileState* mts); |
170 bool CanDispatchRasterTask(Tile* tile); | 178 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster( |
171 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster(Tile* tile); | 179 ManagedTileState* mts); |
172 void DispatchOneRasterTask(scoped_refptr<Tile> tile); | 180 void DispatchOneRasterTask(scoped_refptr<ManagedTileState> tile); |
173 void PerformOneRaster(Tile* tile); | 181 void PerformOneRaster(ManagedTileState* mts); |
174 void OnRasterCompleted( | 182 void OnRasterCompleted( |
175 scoped_refptr<Tile> tile, | 183 scoped_refptr<ManagedTileState> tile, |
176 scoped_ptr<ResourcePool::Resource> resource, | 184 scoped_ptr<ResourcePool::Resource> resource, |
177 int manage_tiles_call_count_when_dispatched); | 185 int manage_tiles_call_count_when_dispatched); |
178 void OnRasterTaskCompleted( | 186 void OnRasterTaskCompleted( |
179 scoped_refptr<Tile> tile, | 187 scoped_refptr<ManagedTileState> tile, |
180 scoped_ptr<ResourcePool::Resource> resource, | 188 scoped_ptr<ResourcePool::Resource> resource, |
181 int manage_tiles_call_count_when_dispatched); | 189 int manage_tiles_call_count_when_dispatched); |
182 void DidFinishTileInitialization(Tile* tile); | 190 void DidFinishTileInitialization(ManagedTileState* mts); |
183 void DidTileRasterStateChange(Tile* tile, TileRasterState state); | 191 void DidTileRasterStateChange(ManagedTileState* mts, TileRasterState state); |
184 void DidTileTreeBinChange(Tile* tile, | 192 void DidTileTreeBinChange(ManagedTileState* mts, |
185 TileManagerBin new_tree_bin, | 193 TileManagerBin new_tree_bin, |
186 WhichTree tree); | 194 WhichTree tree); |
187 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; | 195 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; |
188 | 196 |
189 static void PerformRaster(uint8* buffer, | 197 static void PerformRaster(uint8* buffer, |
190 const gfx::Rect& rect, | 198 const gfx::Rect& rect, |
191 float contents_scale, | 199 float contents_scale, |
192 bool use_cheapness_estimator, | 200 bool use_cheapness_estimator, |
193 const RasterTaskMetadata& raster_task_metadata, | 201 const RasterTaskMetadata& raster_task_metadata, |
194 PicturePileImpl* picture_pile, | 202 PicturePileImpl* picture_pile, |
195 RenderingStats* stats); | 203 RenderingStats* stats); |
196 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, | 204 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, |
197 RenderingStats* stats); | 205 RenderingStats* stats); |
198 | 206 |
199 static void RecordCheapnessPredictorResults(bool is_predicted_cheap, | 207 static void RecordCheapnessPredictorResults(bool is_predicted_cheap, |
200 bool is_actually_cheap); | 208 bool is_actually_cheap); |
201 | 209 |
202 TileManagerClient* client_; | 210 TileManagerClient* client_; |
203 scoped_ptr<ResourcePool> resource_pool_; | 211 scoped_ptr<ResourcePool> resource_pool_; |
204 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 212 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
205 bool manage_tiles_pending_; | 213 bool manage_tiles_pending_; |
206 int manage_tiles_call_count_; | 214 int manage_tiles_call_count_; |
207 | 215 |
208 GlobalStateThatImpactsTilePriority global_state_; | 216 GlobalStateThatImpactsTilePriority global_state_; |
209 | 217 |
210 typedef std::vector<Tile*> TileVector; | 218 typedef std::vector<ManagedTileState*> TileVector; |
211 typedef std::set<Tile*> TileSet; | 219 typedef std::set<ManagedTileState*> TileSet; |
212 TileSet all_tiles_; | 220 TileSet all_tiles_; |
213 TileVector live_or_allocated_tiles_; | 221 TileVector live_or_allocated_tiles_; |
214 TileVector tiles_that_need_to_be_rasterized_; | 222 TileVector tiles_that_need_to_be_rasterized_; |
215 | 223 |
216 typedef std::list<Tile*> TileList; | 224 typedef std::list<ManagedTileState*> TileList; |
217 // Tiles with image decoding tasks. These tiles need to be rasterized | 225 // Tiles with image decoding tasks. These tiles need to be rasterized |
218 // when all the image decoding tasks finish. | 226 // when all the image decoding tasks finish. |
219 TileList tiles_with_image_decoding_tasks_; | 227 TileList tiles_with_image_decoding_tasks_; |
220 | 228 |
221 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap; | 229 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap; |
222 PixelRefMap pending_decode_tasks_; | 230 PixelRefMap pending_decode_tasks_; |
223 | 231 |
224 typedef std::queue<scoped_refptr<Tile> > TileQueue; | 232 typedef std::queue<scoped_refptr<ManagedTileState> > TileQueue; |
225 TileQueue tiles_with_pending_set_pixels_; | 233 TileQueue tiles_with_pending_set_pixels_; |
226 size_t bytes_pending_set_pixels_; | 234 size_t bytes_pending_set_pixels_; |
227 bool has_performed_uploads_since_last_flush_; | 235 bool has_performed_uploads_since_last_flush_; |
228 bool ever_exceeded_memory_budget_; | 236 bool ever_exceeded_memory_budget_; |
229 MemoryHistory::Entry memory_stats_from_last_assign_; | 237 MemoryHistory::Entry memory_stats_from_last_assign_; |
230 | 238 |
231 bool record_rendering_stats_; | 239 bool record_rendering_stats_; |
232 RenderingStats rendering_stats_; | 240 RenderingStats rendering_stats_; |
233 | 241 |
234 bool use_cheapness_estimator_; | 242 bool use_cheapness_estimator_; |
235 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS]; | 243 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS]; |
236 | 244 |
237 DISALLOW_COPY_AND_ASSIGN(TileManager); | 245 DISALLOW_COPY_AND_ASSIGN(TileManager); |
238 }; | 246 }; |
239 | 247 |
240 } // namespace cc | 248 } // namespace cc |
241 | 249 |
242 #endif // CC_TILE_MANAGER_H_ | 250 #endif // CC_TILE_MANAGER_H_ |
OLD | NEW |