Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: cc/tile_manager.cc

Issue 12082086: cc: Improve tile deletion and general tile manager performance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Detach managed state from tiles Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tile_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cc/tile_manager.h" 5 #include "cc/tile_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 case NEVER_BIN: 87 case NEVER_BIN:
88 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 88 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
89 "NEVER_BIN")); 89 "NEVER_BIN"));
90 default: 90 default:
91 DCHECK(false) << "Unrecognized TileManagerBin value"; 91 DCHECK(false) << "Unrecognized TileManagerBin value";
92 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 92 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
93 "<unknown TileManagerBin value>")); 93 "<unknown TileManagerBin value>"));
94 } 94 }
95 } 95 }
96 96
97 ManagedTileState::ManagedTileState() 97 ManagedTileState::ManagedTileState(TileManager* tile_manager)
98 : can_use_gpu_memory(false), 98 : tile_manager(tile_manager),
99 can_use_gpu_memory(false),
99 can_be_freed(true), 100 can_be_freed(true),
100 resource_is_being_initialized(false), 101 resource_is_being_initialized(false),
101 contents_swizzled(false), 102 contents_swizzled(false),
102 need_to_gather_pixel_refs(true), 103 need_to_gather_pixel_refs(true),
103 gpu_memmgr_stats_bin(NEVER_BIN), 104 gpu_memmgr_stats_bin(NEVER_BIN),
104 raster_state(IDLE_STATE) { 105 raster_state(IDLE_STATE),
106 bytes_consumed_if_allocated(0),
nduca 2013/02/05 06:50:01 I'm worried about the duplication of state here. T
reveman 2013/02/05 18:04:51 With this patch ManagedTileState can now outlive a
107 visible_high_resolution(false),
108 contents_scale(1),
109 format(GL_RGBA) {
105 for (int i = 0; i < NUM_TREES; ++i) 110 for (int i = 0; i < NUM_TREES; ++i)
106 tree_bin[i] = NEVER_BIN; 111 tree_bin[i] = NEVER_BIN;
112 tile_manager->RegisterManagedTile(this);
107 } 113 }
108 114
109 ManagedTileState::~ManagedTileState() { 115 ManagedTileState::~ManagedTileState() {
116 tile_manager->UnregisterManagedTile(this);
110 DCHECK(!resource); 117 DCHECK(!resource);
111 DCHECK(!resource_is_being_initialized); 118 DCHECK(!resource_is_being_initialized);
112 } 119 }
113 120
114 TileManager::TileManager( 121 TileManager::TileManager(
115 TileManagerClient* client, 122 TileManagerClient* client,
116 ResourceProvider* resource_provider, 123 ResourceProvider* resource_provider,
117 size_t num_raster_threads, 124 size_t num_raster_threads,
118 bool record_rendering_stats) 125 bool record_rendering_stats)
119 : client_(client), 126 : client_(client),
120 resource_pool_(ResourcePool::Create(resource_provider)), 127 resource_pool_(ResourcePool::Create(resource_provider)),
121 raster_worker_pool_(RasterWorkerPool::Create(num_raster_threads, record_re ndering_stats)), 128 raster_worker_pool_(RasterWorkerPool::Create(num_raster_threads,
129 record_rendering_stats)),
122 manage_tiles_pending_(false), 130 manage_tiles_pending_(false),
123 manage_tiles_call_count_(0), 131 manage_tiles_call_count_(0),
124 bytes_pending_set_pixels_(0), 132 bytes_pending_set_pixels_(0),
125 ever_exceeded_memory_budget_(false), 133 ever_exceeded_memory_budget_(false),
126 record_rendering_stats_(record_rendering_stats) { 134 record_rendering_stats_(record_rendering_stats) {
127 for (int i = 0; i < NUM_STATES; ++i) { 135 for (int i = 0; i < NUM_STATES; ++i) {
128 for (int j = 0; j < NUM_TREES; ++j) { 136 for (int j = 0; j < NUM_TREES; ++j) {
129 for (int k = 0; k < NUM_BINS; ++k) 137 for (int k = 0; k < NUM_BINS; ++k)
130 raster_state_count_[i][j][k] = 0; 138 raster_state_count_[i][j][k] = 0;
131 } 139 }
132 } 140 }
133 } 141 }
134 142
135 TileManager::~TileManager() { 143 TileManager::~TileManager() {
144 DCHECK_EQ(tiles_.size(), 0);
136 // Reset global state and manage. This should cause 145 // Reset global state and manage. This should cause
137 // our memory usage to drop to zero. 146 // our memory usage to drop to zero.
138 global_state_ = GlobalStateThatImpactsTilePriority(); 147 global_state_ = GlobalStateThatImpactsTilePriority();
139 AssignGpuMemoryToTiles(); 148 ManageTiles();
140 // This should finish all pending tasks and release any uninitialized 149 // This should finish all pending tasks and release any uninitialized
141 // resources. 150 // resources.
142 raster_worker_pool_.reset(); 151 raster_worker_pool_.reset();
143 CheckForCompletedTileUploads(); 152 CheckForCompletedTileUploads();
144 DCHECK(tiles_with_pending_set_pixels_.size() == 0); 153 DCHECK_EQ(tiles_that_need_to_be_rasterized_.size(), 0);
145 DCHECK(tiles_.size() == 0); 154 DCHECK_EQ(tiles_with_pending_set_pixels_.size(), 0);
155 DCHECK_EQ(managed_tiles_.size(), 0);
146 } 156 }
147 157
148 void TileManager::SetGlobalState( 158 void TileManager::SetGlobalState(
149 const GlobalStateThatImpactsTilePriority& global_state) { 159 const GlobalStateThatImpactsTilePriority& global_state) {
150 global_state_ = global_state; 160 global_state_ = global_state;
151 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); 161 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes);
152 ScheduleManageTiles(); 162 ScheduleManageTiles();
153 } 163 }
154 164
155 void TileManager::RegisterTile(Tile* tile) { 165 void TileManager::RegisterTile(Tile* tile) {
156 tiles_.push_back(tile); 166 DCHECK(tiles_.find(tile) == tiles_.end());
157 167 scoped_refptr<ManagedTileState> mts(new ManagedTileState(this));
158 const ManagedTileState& mts = tile->managed_state(); 168 tile->set_managed_state(mts);
159 for (int i = 0; i < NUM_TREES; ++i) 169 tiles_.insert(tile);
160 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]];
161
162 ScheduleManageTiles(); 170 ScheduleManageTiles();
163 } 171 }
164 172
165 void TileManager::UnregisterTile(Tile* tile) { 173 void TileManager::UnregisterTile(Tile* tile) {
166 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 174 DCHECK(tiles_.find(tile) != tiles_.end());
167 it != tiles_with_image_decoding_tasks_.end(); it++) { 175 tiles_.erase(tile);
168 if (*it == tile) { 176 ScheduleManageTiles();
169 tiles_with_image_decoding_tasks_.erase(it); 177 }
170 break; 178
171 } 179 void TileManager::RegisterManagedTile(ManagedTileState* mts) {
172 } 180 for (int i = 0; i < NUM_TREES; ++i)
173 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); 181 ++raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
174 it != tiles_that_need_to_be_rasterized_.end(); it++) { 182 }
175 if (*it == tile) { 183
176 tiles_that_need_to_be_rasterized_.erase(it); 184 void TileManager::UnregisterManagedTile(ManagedTileState* mts) {
177 break; 185 FreeResourcesForTile(mts);
178 } 186 for (int i = 0; i < NUM_TREES; ++i)
179 } 187 --raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
180 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) {
181 if (*it == tile) {
182 const ManagedTileState& mts = tile->managed_state();
183 for (int i = 0; i < NUM_TREES; ++i)
184 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]];
185 FreeResourcesForTile(tile);
186 tiles_.erase(it);
187 return;
188 }
189 }
190 DCHECK(false) << "Could not find tile version.";
191 } 188 }
192 189
193 class BinComparator { 190 class BinComparator {
194 public: 191 public:
195 bool operator() (const Tile* a, const Tile* b) const { 192 bool operator() (const ManagedTileState* a,
196 const ManagedTileState& ams = a->managed_state(); 193 const ManagedTileState* b) const {
197 const ManagedTileState& bms = b->managed_state(); 194 if (a->bin[HIGH_PRIORITY_BIN] != b->bin[HIGH_PRIORITY_BIN])
198 if (ams.bin[HIGH_PRIORITY_BIN] != bms.bin[HIGH_PRIORITY_BIN]) 195 return a->bin[HIGH_PRIORITY_BIN] < b->bin[HIGH_PRIORITY_BIN];
199 return ams.bin[HIGH_PRIORITY_BIN] < bms.bin[HIGH_PRIORITY_BIN];
200 196
201 if (ams.bin[LOW_PRIORITY_BIN] != bms.bin[LOW_PRIORITY_BIN]) 197 if (a->bin[LOW_PRIORITY_BIN] != b->bin[LOW_PRIORITY_BIN])
202 return ams.bin[LOW_PRIORITY_BIN] < bms.bin[LOW_PRIORITY_BIN]; 198 return a->bin[LOW_PRIORITY_BIN] < b->bin[LOW_PRIORITY_BIN];
203 199
204 if (ams.resolution != bms.resolution) 200 if (a->resolution != b->resolution)
205 return ams.resolution < bms.resolution; 201 return a->resolution < b->resolution;
206 202
207 if (ams.time_to_needed_in_seconds != bms.time_to_needed_in_seconds) 203 if (a->time_to_needed_in_seconds != b->time_to_needed_in_seconds)
208 return ams.time_to_needed_in_seconds < bms.time_to_needed_in_seconds; 204 return a->time_to_needed_in_seconds < b->time_to_needed_in_seconds;
209 205
210 gfx::Rect a_rect = a->content_rect(); 206 gfx::Rect a_rect = a->content_rect;
211 gfx::Rect b_rect = b->content_rect(); 207 gfx::Rect b_rect = b->content_rect;
212 if (a_rect.y() != b_rect.y()) 208 if (a_rect.y() != b_rect.y())
213 return a_rect.y() < b_rect.y(); 209 return a_rect.y() < b_rect.y();
214 return a_rect.x() < b_rect.x(); 210 return a_rect.x() < b_rect.x();
215 } 211 }
216 }; 212 };
217 213
218 void TileManager::SortTiles() { 214 void TileManager::SortTiles() {
219 TRACE_EVENT0("cc", "TileManager::SortTiles"); 215 TRACE_EVENT0("cc", "TileManager::SortTiles");
220 216
221 // Sort by bin, resolution and time until needed. 217 // Sort by bin, resolution and time until needed.
222 std::sort(tiles_.begin(), tiles_.end(), BinComparator()); 218 std::sort(managed_tiles_.begin(), managed_tiles_.end(), BinComparator());
223 } 219 }
224 220
225 void TileManager::ManageTiles() { 221 void TileManager::ManageTiles() {
226 TRACE_EVENT0("cc", "TileManager::ManageTiles"); 222 TRACE_EVENT0("cc", "TileManager::ManageTiles");
227 manage_tiles_pending_ = false; 223 manage_tiles_pending_ = false;
228 ++manage_tiles_call_count_; 224 ++manage_tiles_call_count_;
229 225
230 const TreePriority tree_priority = global_state_.tree_priority; 226 const TreePriority tree_priority = global_state_.tree_priority;
231 TRACE_COUNTER_ID1("cc", "TileCount", this, tiles_.size()); 227 TRACE_COUNTER_ID1("cc", "TileCount", this, tiles_.size());
232 228
229 // Determine tiles that should be managed by rebuilding managed_tiles_
230 // vector.
231 managed_tiles_.erase(managed_tiles_.begin(), managed_tiles_.end());
232
233 // For each tree, bin into different categories of tiles. 233 // For each tree, bin into different categories of tiles.
234 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 234 for (TileSet::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
235 Tile* tile = *it; 235 Tile* tile = *it;
236 ManagedTileState& mts = tile->managed_state(); 236
237 TilePriority combined_priority = tile->combined_priority();
238 if (!combined_priority.is_live) {
239 if (tile->managed_state()->can_be_freed)
240 FreeResourcesForTile(tile->managed_state());
241 continue;
242 }
237 243
238 TilePriority prio[NUM_BIN_PRIORITIES]; 244 TilePriority prio[NUM_BIN_PRIORITIES];
239 switch (tree_priority) { 245 switch (tree_priority) {
240 case SAME_PRIORITY_FOR_BOTH_TREES: 246 case SAME_PRIORITY_FOR_BOTH_TREES:
241 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = 247 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = combined_priority;
242 tile->combined_priority();
243 break; 248 break;
244 case SMOOTHNESS_TAKES_PRIORITY: 249 case SMOOTHNESS_TAKES_PRIORITY:
245 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); 250 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE);
246 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE); 251 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE);
247 break; 252 break;
248 case NEW_CONTENT_TAKES_PRIORITY: 253 case NEW_CONTENT_TAKES_PRIORITY:
249 prio[HIGH_PRIORITY_BIN] = tile->priority(PENDING_TREE); 254 prio[HIGH_PRIORITY_BIN] = tile->priority(PENDING_TREE);
250 prio[LOW_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); 255 prio[LOW_PRIORITY_BIN] = tile->priority(ACTIVE_TREE);
251 break; 256 break;
252 } 257 }
253 258
254 mts.resolution = prio[HIGH_PRIORITY_BIN].resolution; 259 ManagedTileState* mts = tile->managed_state();
255 mts.time_to_needed_in_seconds = 260 mts->resolution = prio[HIGH_PRIORITY_BIN].resolution;
261 mts->time_to_needed_in_seconds =
256 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds; 262 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds;
257 mts.bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]); 263 mts->bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]);
258 mts.bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]); 264 mts->bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]);
259 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority()); 265 mts->gpu_memmgr_stats_bin = BinFromTilePriority(combined_priority);
266 mts->bytes_consumed_if_allocated = tile->bytes_consumed_if_allocated();
267 mts->visible_high_resolution =
268 tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 &&
269 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION;
270 mts->picture_pile = tile->picture_pile();
271 mts->content_rect = tile->content_rect_;
272 mts->contents_scale = tile->contents_scale_;
273 mts->tile_size = tile->tile_size_.size();
274 mts->format = tile->format_;
260 275
261 DidTileBinChange(tile, 276 DidTileBinChange(mts,
262 BinFromTilePriority(tile->priority(ACTIVE_TREE)), 277 BinFromTilePriority(tile->priority(ACTIVE_TREE)),
263 ACTIVE_TREE); 278 ACTIVE_TREE);
264 DidTileBinChange(tile, 279 DidTileBinChange(mts,
265 BinFromTilePriority(tile->priority(PENDING_TREE)), 280 BinFromTilePriority(tile->priority(PENDING_TREE)),
266 PENDING_TREE); 281 PENDING_TREE);
282
283 managed_tiles_.push_back(mts);
267 } 284 }
268 285
286 TRACE_COUNTER_ID1("cc", "ManagedTileCount", this, managed_tiles_.size());
287
269 // Memory limit policy works by mapping some bin states to the NEVER bin. 288 // Memory limit policy works by mapping some bin states to the NEVER bin.
270 TileManagerBin bin_map[NUM_BINS]; 289 TileManagerBin bin_map[NUM_BINS];
271 if (global_state_.memory_limit_policy == ALLOW_NOTHING) { 290 if (global_state_.memory_limit_policy == ALLOW_NOTHING) {
272 bin_map[NOW_BIN] = NEVER_BIN; 291 bin_map[NOW_BIN] = NEVER_BIN;
273 bin_map[SOON_BIN] = NEVER_BIN; 292 bin_map[SOON_BIN] = NEVER_BIN;
274 bin_map[EVENTUALLY_BIN] = NEVER_BIN; 293 bin_map[EVENTUALLY_BIN] = NEVER_BIN;
275 bin_map[NEVER_BIN] = NEVER_BIN; 294 bin_map[NEVER_BIN] = NEVER_BIN;
276 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) { 295 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) {
277 bin_map[NOW_BIN] = NOW_BIN; 296 bin_map[NOW_BIN] = NOW_BIN;
278 bin_map[SOON_BIN] = NEVER_BIN; 297 bin_map[SOON_BIN] = NEVER_BIN;
279 bin_map[EVENTUALLY_BIN] = NEVER_BIN; 298 bin_map[EVENTUALLY_BIN] = NEVER_BIN;
280 bin_map[NEVER_BIN] = NEVER_BIN; 299 bin_map[NEVER_BIN] = NEVER_BIN;
281 } else if (global_state_.memory_limit_policy == ALLOW_PREPAINT_ONLY) { 300 } else if (global_state_.memory_limit_policy == ALLOW_PREPAINT_ONLY) {
282 bin_map[NOW_BIN] = NOW_BIN; 301 bin_map[NOW_BIN] = NOW_BIN;
283 bin_map[SOON_BIN] = SOON_BIN; 302 bin_map[SOON_BIN] = SOON_BIN;
284 bin_map[EVENTUALLY_BIN] = NEVER_BIN; 303 bin_map[EVENTUALLY_BIN] = NEVER_BIN;
285 bin_map[NEVER_BIN] = NEVER_BIN; 304 bin_map[NEVER_BIN] = NEVER_BIN;
286 } else { 305 } else {
287 bin_map[NOW_BIN] = NOW_BIN; 306 bin_map[NOW_BIN] = NOW_BIN;
288 bin_map[SOON_BIN] = SOON_BIN; 307 bin_map[SOON_BIN] = SOON_BIN;
289 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; 308 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN;
290 bin_map[NEVER_BIN] = NEVER_BIN; 309 bin_map[NEVER_BIN] = NEVER_BIN;
291 } 310 }
292 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 311 for (ManagedTileVector::iterator it = managed_tiles_.begin();
293 Tile* tile = *it; 312 it != managed_tiles_.end(); ++it) {
294 ManagedTileState& mts = tile->managed_state(); 313 ManagedTileState* mts = *it;
295 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) 314 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i)
296 mts.bin[i] = bin_map[mts.bin[i]]; 315 mts->bin[i] = bin_map[mts->bin[i]];
297 316 DidTileBinChange(mts, bin_map[mts->tree_bin[ACTIVE_TREE]], ACTIVE_TREE);
298 DidTileBinChange(tile, bin_map[mts.tree_bin[ACTIVE_TREE]], ACTIVE_TREE); 317 DidTileBinChange(mts, bin_map[mts->tree_bin[PENDING_TREE]], PENDING_TREE);
299 DidTileBinChange(tile, bin_map[mts.tree_bin[PENDING_TREE]], PENDING_TREE);
300 } 318 }
301 319
302 SortTiles(); 320 SortTiles();
303 321
304 // Assign gpu memory and determine what tiles need to be rasterized. 322 // Assign gpu memory and determine what tiles need to be rasterized.
305 AssignGpuMemoryToTiles(); 323 AssignGpuMemoryToTiles();
306 324
307 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", ValueToString(AsValue())); 325 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", ValueToString(AsValue()));
308 326
309 // Finally, kick the rasterizer. 327 // Finally, kick the rasterizer.
310 DispatchMoreTasks(); 328 DispatchMoreTasks();
311 } 329 }
312 330
313 void TileManager::CheckForCompletedTileUploads() { 331 void TileManager::CheckForCompletedTileUploads() {
314 while (!tiles_with_pending_set_pixels_.empty()) { 332 while (!tiles_with_pending_set_pixels_.empty()) {
315 Tile* tile = tiles_with_pending_set_pixels_.front(); 333 ManagedTileState* mts = tiles_with_pending_set_pixels_.front();
316 DCHECK(tile->managed_state().resource); 334 DCHECK(mts->resource);
317 335
318 // Set pixel tasks complete in the order they are posted. 336 // Set pixel tasks complete in the order they are posted.
319 if (!resource_pool_->resource_provider()->didSetPixelsComplete( 337 if (!resource_pool_->resource_provider()->didSetPixelsComplete(
320 tile->managed_state().resource->id())) { 338 mts->resource->id())) {
321 break; 339 break;
322 } 340 }
323 341
324 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && 342 if (mts->visible_high_resolution)
325 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION)
326 client_->DidUploadVisibleHighResolutionTile(); 343 client_->DidUploadVisibleHighResolutionTile();
327 344
328 // It's now safe to release the pixel buffer. 345 // It's now safe to release the pixel buffer.
329 resource_pool_->resource_provider()->releasePixelBuffer( 346 resource_pool_->resource_provider()->releasePixelBuffer(
330 tile->managed_state().resource->id()); 347 mts->resource->id());
331 348
332 DidFinishTileInitialization(tile); 349 DidFinishTileInitialization(mts);
333 350
334 bytes_pending_set_pixels_ -= tile->bytes_consumed_if_allocated(); 351 bytes_pending_set_pixels_ -= mts->bytes_consumed_if_allocated;
335 DidTileRasterStateChange(tile, IDLE_STATE); 352 DidTileRasterStateChange(mts, IDLE_STATE);
336 tiles_with_pending_set_pixels_.pop(); 353 tiles_with_pending_set_pixels_.pop();
337 } 354 }
338 355
339 DispatchMoreTasks(); 356 DispatchMoreTasks();
340 } 357 }
341 358
342 void TileManager::GetMemoryStats( 359 void TileManager::GetMemoryStats(
343 size_t* memoryRequiredBytes, 360 size_t* memory_required_bytes,
344 size_t* memoryNiceToHaveBytes, 361 size_t* memory_nice_to_have_bytes,
345 size_t* memoryUsedBytes) const { 362 size_t* memory_used_bytes) const {
346 *memoryRequiredBytes = 0; 363 *memory_required_bytes = 0;
347 *memoryNiceToHaveBytes = 0; 364 *memory_nice_to_have_bytes = 0;
348 *memoryUsedBytes = 0; 365 *memory_used_bytes = 0;
349 for(size_t i = 0; i < tiles_.size(); i++) { 366 for (ManagedTileVector::const_iterator it = managed_tiles_.begin();
350 const Tile* tile = tiles_[i]; 367 it != managed_tiles_.end(); ++it) {
351 const ManagedTileState& mts = tile->managed_state(); 368 const ManagedTileState* mts = *it;
352 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 369 size_t tile_bytes = mts->bytes_consumed_if_allocated;
353 if (mts.gpu_memmgr_stats_bin == NOW_BIN) 370 if (mts->gpu_memmgr_stats_bin == NOW_BIN)
354 *memoryRequiredBytes += tile_bytes; 371 *memory_required_bytes += tile_bytes;
355 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) 372 if (mts->gpu_memmgr_stats_bin != NEVER_BIN)
356 *memoryNiceToHaveBytes += tile_bytes; 373 *memory_nice_to_have_bytes += tile_bytes;
357 if (mts.can_use_gpu_memory) 374 if (mts->can_use_gpu_memory)
358 *memoryUsedBytes += tile_bytes; 375 *memory_used_bytes += tile_bytes;
359 } 376 }
360 } 377 }
361 378
362 scoped_ptr<base::Value> TileManager::AsValue() const { 379 scoped_ptr<base::Value> TileManager::AsValue() const {
363 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 380 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
364 state->SetInteger("tile_count", tiles_.size()); 381 state->SetInteger("tile_count", tiles_.size());
365 382 state->SetInteger("managed_tile_count", managed_tiles_.size());
366 state->Set("global_state", global_state_.AsValue().release()); 383 state->Set("global_state", global_state_.AsValue().release());
367 384 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release());
368 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); 385 return state.PassAs<base::Value>();
369 return state.PassAs<base::Value>();
370 } 386 }
371 387
372 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { 388 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const {
373 scoped_ptr<base::DictionaryValue> requirements( 389 scoped_ptr<base::DictionaryValue> requirements(new base::DictionaryValue());
374 new base::DictionaryValue());
375 390
376 size_t memoryRequiredBytes; 391 size_t memory_required_bytes;
377 size_t memoryNiceToHaveBytes; 392 size_t memory_nice_to_have_bytes;
378 size_t memoryUsedBytes; 393 size_t memory_used_bytes;
379 GetMemoryStats(&memoryRequiredBytes, 394 GetMemoryStats(&memory_required_bytes,
380 &memoryNiceToHaveBytes, 395 &memory_nice_to_have_bytes,
381 &memoryUsedBytes); 396 &memory_used_bytes);
382 requirements->SetInteger("memory_required_bytes", memoryRequiredBytes); 397 requirements->SetInteger("memory_required_bytes", memory_required_bytes);
383 requirements->SetInteger("memory_nice_to_have_bytes", memoryNiceToHaveBytes); 398 requirements->SetInteger("memory_nice_to_have_bytes",
384 requirements->SetInteger("memory_used_bytes", memoryUsedBytes); 399 memory_nice_to_have_bytes);
400 requirements->SetInteger("memory_used_bytes", memory_used_bytes);
385 return requirements.PassAs<base::Value>(); 401 return requirements.PassAs<base::Value>();
386 } 402 }
387 403
388 void TileManager::GetRenderingStats(RenderingStats* stats) { 404 void TileManager::GetRenderingStats(RenderingStats* stats) {
389 CHECK(record_rendering_stats_); 405 CHECK(record_rendering_stats_);
390 raster_worker_pool_->GetRenderingStats(stats); 406 raster_worker_pool_->GetRenderingStats(stats);
391 stats->totalDeferredImageCacheHitCount = 407 stats->totalDeferredImageCacheHitCount =
392 rendering_stats_.totalDeferredImageCacheHitCount; 408 rendering_stats_.totalDeferredImageCacheHitCount;
393 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; 409 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount;
394 stats->totalImageGatheringTime = 410 stats->totalImageGatheringTime =
(...skipping 22 matching lines...) Expand all
417 } 433 }
418 } 434 }
419 435
420 return false; 436 return false;
421 } 437 }
422 438
423 void TileManager::AssignGpuMemoryToTiles() { 439 void TileManager::AssignGpuMemoryToTiles() {
424 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); 440 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles");
425 // Some memory cannot be released. Figure out which. 441 // Some memory cannot be released. Figure out which.
426 size_t unreleasable_bytes = 0; 442 size_t unreleasable_bytes = 0;
427 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 443 for (ManagedTileVector::iterator it = managed_tiles_.begin();
428 Tile* tile = *it; 444 it != managed_tiles_.end(); ++it) {
429 if (!tile->managed_state().can_be_freed) 445 ManagedTileState* mts = *it;
430 unreleasable_bytes += tile->bytes_consumed_if_allocated(); 446 if (!mts->can_be_freed)
447 unreleasable_bytes += mts->bytes_consumed_if_allocated;
431 } 448 }
432 449
433 // Now give memory out to the tiles until we're out, and build 450 // Now give memory out to the tiles until we're out, and build
434 // the needs-to-be-rasterized queue. 451 // the needs-to-be-rasterized queue.
435 tiles_that_need_to_be_rasterized_.erase( 452 tiles_that_need_to_be_rasterized_.erase(
436 tiles_that_need_to_be_rasterized_.begin(), 453 tiles_that_need_to_be_rasterized_.begin(),
437 tiles_that_need_to_be_rasterized_.end()); 454 tiles_that_need_to_be_rasterized_.end());
438 455
439 // Reset the image decoding list so that we don't mess up with tile 456 // Reset the image decoding list so that we don't mess up with tile
440 // priorities. Tiles will be added to the image decoding list again 457 // priorities. Tiles will be added to the image decoding list again
441 // when DispatchMoreTasks() is called. 458 // when DispatchMoreTasks() is called.
442 tiles_with_image_decoding_tasks_.clear(); 459 tiles_with_image_decoding_tasks_.clear();
443 460
444 // By clearing the tiles_that_need_to_be_rasterized_ vector and 461 // By clearing the tiles_that_need_to_be_rasterized_ vector and
445 // tiles_with_image_decoding_tasks_ list above we move all tiles 462 // tiles_with_image_decoding_tasks_ list above we move all tiles
446 // currently waiting for raster to idle state. 463 // currently waiting for raster to idle state.
447 // Call DidTileRasterStateChange() for each of these tiles to 464 // Call DidTileRasterStateChange() for each of these tiles to
448 // have this state change take effect. 465 // have this state change take effect.
449 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 466 for (ManagedTileVector::iterator it = managed_tiles_.begin();
450 Tile* tile = *it; 467 it != managed_tiles_.end(); ++it) {
451 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE) 468 ManagedTileState* mts = *it;
452 DidTileRasterStateChange(tile, IDLE_STATE); 469 if (mts->raster_state == WAITING_FOR_RASTER_STATE)
470 DidTileRasterStateChange(mts, IDLE_STATE);
453 } 471 }
454 472
455 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes; 473 size_t bytes_allocatable = global_state_.memory_limit_in_bytes -
474 unreleasable_bytes;
456 size_t bytes_that_exceeded_memory_budget = 0; 475 size_t bytes_that_exceeded_memory_budget = 0;
457 size_t bytes_left = bytes_allocatable; 476 size_t bytes_left = bytes_allocatable;
458 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 477 for (ManagedTileVector::iterator it = managed_tiles_.begin();
459 Tile* tile = *it; 478 it != managed_tiles_.end(); ++it) {
460 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 479 ManagedTileState* mts = *it;
461 ManagedTileState& managed_tile_state = tile->managed_state(); 480 if (!mts->can_be_freed)
462 if (!managed_tile_state.can_be_freed)
463 continue; 481 continue;
464 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && 482 if (mts->bin[HIGH_PRIORITY_BIN] == NEVER_BIN &&
465 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { 483 mts->bin[LOW_PRIORITY_BIN] == NEVER_BIN) {
466 managed_tile_state.can_use_gpu_memory = false; 484 mts->can_use_gpu_memory = false;
467 FreeResourcesForTile(tile); 485 FreeResourcesForTile(mts);
468 continue; 486 continue;
469 } 487 }
488 size_t tile_bytes = mts->bytes_consumed_if_allocated;
470 if (tile_bytes > bytes_left) { 489 if (tile_bytes > bytes_left) {
471 managed_tile_state.can_use_gpu_memory = false; 490 mts->can_use_gpu_memory = false;
472 bytes_that_exceeded_memory_budget += tile_bytes; 491 bytes_that_exceeded_memory_budget += tile_bytes;
473 FreeResourcesForTile(tile); 492 FreeResourcesForTile(mts);
474 continue; 493 continue;
475 } 494 }
476 bytes_left -= tile_bytes; 495 bytes_left -= tile_bytes;
477 managed_tile_state.can_use_gpu_memory = true; 496 mts->can_use_gpu_memory = true;
478 if (!managed_tile_state.resource && 497 if (!mts->resource && !mts->resource_is_being_initialized) {
479 !managed_tile_state.resource_is_being_initialized) { 498 tiles_that_need_to_be_rasterized_.push_back(mts);
480 tiles_that_need_to_be_rasterized_.push_back(tile); 499 DidTileRasterStateChange(mts, WAITING_FOR_RASTER_STATE);
481 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE);
482 } 500 }
483 } 501 }
484 502
485 ever_exceeded_memory_budget_ |= bytes_that_exceeded_memory_budget > 0; 503 ever_exceeded_memory_budget_ |= bytes_that_exceeded_memory_budget > 0;
486 if (ever_exceeded_memory_budget_) { 504 if (ever_exceeded_memory_budget_) {
487 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, 505 TRACE_COUNTER_ID2("cc", "OverMemoryBudget", this,
488 "budget", global_state_.memory_limit_in_bytes, 506 "budget", global_state_.memory_limit_in_bytes,
489 "over", bytes_that_exceeded_memory_budget); 507 "over", bytes_that_exceeded_memory_budget);
490 } 508 }
491 memory_stats_from_last_assign_.bytes_allocated = 509 memory_stats_from_last_assign_.bytes_allocated =
492 bytes_allocatable - bytes_left; 510 bytes_allocatable - bytes_left;
493 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; 511 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes;
494 memory_stats_from_last_assign_.bytes_over = 512 memory_stats_from_last_assign_.bytes_over =
495 bytes_that_exceeded_memory_budget; 513 bytes_that_exceeded_memory_budget;
496 514
497 // Reverse two tiles_that_need_* vectors such that pop_back gets 515 // Reverse the tiles_that_need_to_be_rasterized_ vector such that pop_back
498 // the highest priority tile. 516 // gets the highest priority tile.
499 std::reverse( 517 std::reverse(
500 tiles_that_need_to_be_rasterized_.begin(), 518 tiles_that_need_to_be_rasterized_.begin(),
501 tiles_that_need_to_be_rasterized_.end()); 519 tiles_that_need_to_be_rasterized_.end());
502 } 520 }
503 521
504 void TileManager::FreeResourcesForTile(Tile* tile) { 522 void TileManager::FreeResourcesForTile(ManagedTileState* mts) {
505 ManagedTileState& managed_tile_state = tile->managed_state(); 523 DCHECK(mts->can_be_freed);
506 DCHECK(managed_tile_state.can_be_freed); 524 if (mts->resource)
507 if (managed_tile_state.resource) 525 resource_pool_->ReleaseResource(mts->resource.Pass());
508 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass());
509 } 526 }
510 527
511 bool TileManager::CanDispatchRasterTask(Tile* tile) { 528 bool TileManager::CanDispatchRasterTask(ManagedTileState* mts) {
512 if (raster_worker_pool_->IsBusy()) 529 if (raster_worker_pool_->IsBusy())
513 return false; 530 return false;
514 size_t new_bytes_pending = bytes_pending_set_pixels_; 531 size_t new_bytes_pending = bytes_pending_set_pixels_;
515 new_bytes_pending += tile->bytes_consumed_if_allocated(); 532 new_bytes_pending += mts->bytes_consumed_if_allocated;
516 return new_bytes_pending <= kMaxPendingUploadBytes; 533 return new_bytes_pending <= kMaxPendingUploadBytes;
517 } 534 }
518 535
519 void TileManager::DispatchMoreTasks() { 536 void TileManager::DispatchMoreTasks() {
520 // Because tiles in the image decoding list have higher priorities, we 537 // Because tiles in the image decoding list have higher priorities, we
521 // need to process those tiles first before we start to handle the tiles 538 // need to process those tiles first before we start to handle the tiles
522 // in the need_to_be_rasterized queue. 539 // in the need_to_be_rasterized queue.
523 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 540 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
524 it != tiles_with_image_decoding_tasks_.end(); ) { 541 it != tiles_with_image_decoding_tasks_.end(); ) {
525 DispatchImageDecodeTasksForTile(*it); 542 ManagedTileState* mts = *it;
526 ManagedTileState& managed_state = (*it)->managed_state(); 543 DispatchImageDecodeTasksForTile(mts);
527 if (managed_state.pending_pixel_refs.empty()) { 544 if (mts->pending_pixel_refs.empty()) {
528 if (!CanDispatchRasterTask(*it)) 545 if (!CanDispatchRasterTask(mts))
529 return; 546 return;
530 DispatchOneRasterTask(*it); 547 DispatchOneRasterTask(mts);
531 tiles_with_image_decoding_tasks_.erase(it++); 548 tiles_with_image_decoding_tasks_.erase(it++);
532 } else { 549 } else {
533 ++it; 550 ++it;
534 } 551 }
535 } 552 }
536 553
537 // Process all tiles in the need_to_be_rasterized queue. If a tile has 554 // Process all tiles in the need_to_be_rasterized queue. If a tile has
538 // image decoding tasks, put it to the back of the image decoding list. 555 // image decoding tasks, put it to the back of the image decoding list.
539 while (!tiles_that_need_to_be_rasterized_.empty()) { 556 while (!tiles_that_need_to_be_rasterized_.empty()) {
540 Tile* tile = tiles_that_need_to_be_rasterized_.back(); 557 ManagedTileState* mts = tiles_that_need_to_be_rasterized_.back();
541 DispatchImageDecodeTasksForTile(tile); 558 DispatchImageDecodeTasksForTile(mts);
542 ManagedTileState& managed_state = tile->managed_state(); 559 if (!mts->pending_pixel_refs.empty()) {
543 if (!managed_state.pending_pixel_refs.empty()) { 560 tiles_with_image_decoding_tasks_.push_back(mts);
544 tiles_with_image_decoding_tasks_.push_back(tile);
545 } else { 561 } else {
546 if (!CanDispatchRasterTask(tile)) 562 if (!CanDispatchRasterTask(mts))
547 return; 563 return;
548 DispatchOneRasterTask(tile); 564 DispatchOneRasterTask(mts);
549 } 565 }
550 tiles_that_need_to_be_rasterized_.pop_back(); 566 tiles_that_need_to_be_rasterized_.pop_back();
551 } 567 }
552 } 568 }
553 569
554 void TileManager::GatherPixelRefsForTile(Tile* tile) { 570 void TileManager::GatherPixelRefsForTile(ManagedTileState* mts) {
555 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); 571 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile");
556 ManagedTileState& managed_state = tile->managed_state(); 572 if (mts->need_to_gather_pixel_refs) {
557 if (managed_state.need_to_gather_pixel_refs) {
558 base::TimeTicks gather_begin_time; 573 base::TimeTicks gather_begin_time;
559 if (record_rendering_stats_) 574 if (record_rendering_stats_)
560 gather_begin_time = base::TimeTicks::Now(); 575 gather_begin_time = base::TimeTicks::Now();
561 tile->picture_pile()->GatherPixelRefs( 576 mts->picture_pile->GatherPixelRefs(
562 tile->content_rect_, 577 mts->content_rect,
563 tile->contents_scale_, 578 mts->contents_scale,
564 managed_state.pending_pixel_refs); 579 mts->pending_pixel_refs);
565 managed_state.need_to_gather_pixel_refs = false; 580 mts->need_to_gather_pixel_refs = false;
566 if (record_rendering_stats_) { 581 if (record_rendering_stats_) {
567 rendering_stats_.totalImageGatheringCount++; 582 rendering_stats_.totalImageGatheringCount++;
568 rendering_stats_.totalImageGatheringTime += 583 rendering_stats_.totalImageGatheringTime +=
569 base::TimeTicks::Now() - gather_begin_time; 584 base::TimeTicks::Now() - gather_begin_time;
570 } 585 }
571 } 586 }
572 } 587 }
573 588
574 void TileManager::DispatchImageDecodeTasksForTile(Tile* tile) { 589 void TileManager::DispatchImageDecodeTasksForTile(ManagedTileState* mts) {
575 GatherPixelRefsForTile(tile); 590 GatherPixelRefsForTile(mts);
576 std::list<skia::LazyPixelRef*>& pending_pixel_refs = 591 std::list<skia::LazyPixelRef*>& pending_pixel_refs = mts->pending_pixel_refs;
577 tile->managed_state().pending_pixel_refs;
578 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); 592 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin();
579 while (it != pending_pixel_refs.end()) { 593 while (it != pending_pixel_refs.end()) {
580 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( 594 if (pending_decode_tasks_.end() != pending_decode_tasks_.find(
581 (*it)->getGenerationID())) { 595 (*it)->getGenerationID())) {
582 ++it; 596 ++it;
583 continue; 597 continue;
584 } 598 }
585 // TODO(qinmin): passing correct image size to PrepareToDecode(). 599 // TODO(qinmin): passing correct image size to PrepareToDecode().
586 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { 600 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) {
587 rendering_stats_.totalDeferredImageCacheHitCount++; 601 rendering_stats_.totalDeferredImageCacheHitCount++;
588 pending_pixel_refs.erase(it++); 602 pending_pixel_refs.erase(it++);
589 } else { 603 } else {
590 if (raster_worker_pool_->IsBusy()) 604 if (raster_worker_pool_->IsBusy())
591 return; 605 return;
592 DispatchOneImageDecodeTask(tile, *it); 606 DispatchOneImageDecodeTask(mts, *it);
593 ++it; 607 ++it;
594 } 608 }
595 } 609 }
596 } 610 }
597 611
598 void TileManager::DispatchOneImageDecodeTask( 612 void TileManager::DispatchOneImageDecodeTask(
599 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { 613 scoped_refptr<ManagedTileState> mts, skia::LazyPixelRef* pixel_ref) {
600 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); 614 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask");
601 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); 615 uint32_t pixel_ref_id = pixel_ref->getGenerationID();
602 DCHECK(pending_decode_tasks_.end() == 616 DCHECK(pending_decode_tasks_.end() ==
603 pending_decode_tasks_.find(pixel_ref_id)); 617 pending_decode_tasks_.find(pixel_ref_id));
604 pending_decode_tasks_[pixel_ref_id] = pixel_ref; 618 pending_decode_tasks_[pixel_ref_id] = pixel_ref;
605 619
606 raster_worker_pool_->PostTaskAndReply( 620 raster_worker_pool_->PostTaskAndReply(
607 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), 621 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref),
608 base::Bind(&TileManager::OnImageDecodeTaskCompleted, 622 base::Bind(&TileManager::OnImageDecodeTaskCompleted,
609 base::Unretained(this), 623 base::Unretained(this),
610 tile, 624 mts,
611 pixel_ref_id)); 625 pixel_ref_id));
612 } 626 }
613 627
614 void TileManager::OnImageDecodeTaskCompleted( 628 void TileManager::OnImageDecodeTaskCompleted(
615 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { 629 scoped_refptr<ManagedTileState> mts, uint32_t pixel_ref_id) {
616 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); 630 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted");
617 pending_decode_tasks_.erase(pixel_ref_id); 631 pending_decode_tasks_.erase(pixel_ref_id);
618 632
619 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 633 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
620 it != tiles_with_image_decoding_tasks_.end(); ++it) { 634 it != tiles_with_image_decoding_tasks_.end(); ++it) {
621 std::list<skia::LazyPixelRef*>& pixel_refs = 635 std::list<skia::LazyPixelRef*>& pixel_refs = (*it)->pending_pixel_refs;
622 (*it)->managed_state().pending_pixel_refs;
623 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = 636 for (std::list<skia::LazyPixelRef*>::iterator pixel_it =
624 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { 637 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) {
625 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { 638 if (pixel_ref_id == (*pixel_it)->getGenerationID()) {
626 pixel_refs.erase(pixel_it); 639 pixel_refs.erase(pixel_it);
627 break; 640 break;
628 } 641 }
629 } 642 }
630 } 643 }
631 644
632 DispatchMoreTasks(); 645 DispatchMoreTasks();
633 } 646 }
634 647
635 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { 648 void TileManager::DispatchOneRasterTask(scoped_refptr<ManagedTileState> mts) {
636 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); 649 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask");
637 ManagedTileState& managed_tile_state = tile->managed_state(); 650 DCHECK(mts->can_use_gpu_memory);
638 DCHECK(managed_tile_state.can_use_gpu_memory);
639 scoped_ptr<ResourcePool::Resource> resource = 651 scoped_ptr<ResourcePool::Resource> resource =
640 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); 652 resource_pool_->AcquireResource(mts->tile_size, mts->format);
641 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); 653 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id());
642 654
643 managed_tile_state.resource_is_being_initialized = true; 655 mts->resource_is_being_initialized = true;
644 managed_tile_state.can_be_freed = false; 656 mts->can_be_freed = false;
645 657
646 DidTileRasterStateChange(tile, RASTER_STATE); 658 DidTileRasterStateChange(mts, RASTER_STATE);
647 659
648 ResourceProvider::ResourceId resource_id = resource->id(); 660 ResourceProvider::ResourceId resource_id = resource->id();
649 661
650 raster_worker_pool_->PostRasterTaskAndReply( 662 raster_worker_pool_->PostRasterTaskAndReply(
651 tile->picture_pile(), 663 mts->picture_pile,
652 base::Bind(&TileManager::RunRasterTask, 664 base::Bind(&TileManager::RunRasterTask,
653 resource_pool_->resource_provider()->mapPixelBuffer( 665 resource_pool_->resource_provider()->mapPixelBuffer(
654 resource_id), 666 resource_id),
655 tile->content_rect_, 667 mts->content_rect,
656 tile->contents_scale()), 668 mts->contents_scale),
657 base::Bind(&TileManager::OnRasterTaskCompleted, 669 base::Bind(&TileManager::OnRasterTaskCompleted,
658 base::Unretained(this), 670 base::Unretained(this),
659 tile, 671 mts,
660 base::Passed(&resource), 672 base::Passed(&resource),
661 manage_tiles_call_count_)); 673 manage_tiles_call_count_));
662 } 674 }
663 675
664 void TileManager::OnRasterTaskCompleted( 676 void TileManager::OnRasterTaskCompleted(
665 scoped_refptr<Tile> tile, 677 scoped_refptr<ManagedTileState> mts,
666 scoped_ptr<ResourcePool::Resource> resource, 678 scoped_ptr<ResourcePool::Resource> resource,
667 int manage_tiles_call_count_when_dispatched) { 679 int manage_tiles_call_count_when_dispatched) {
668 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); 680 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted");
669 681
670 // Release raster resources. 682 // Release raster resources.
671 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); 683 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id());
672 684
673 ManagedTileState& managed_tile_state = tile->managed_state(); 685 mts->can_be_freed = true;
674 managed_tile_state.can_be_freed = true;
675 686
676 // Tile can be freed after the completion of the raster task. Call 687 // Tile can be freed after the completion of the raster task. Call
677 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority 688 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority
678 // tiles if ManageTiles() was called since task was dispatched. The result 689 // tiles if ManageTiles() was called since task was dispatched. The result
679 // of this could be that this tile is no longer allowed to use gpu 690 // of this could be that this tile is no longer allowed to use gpu
680 // memory and in that case we need to abort initialization and free all 691 // memory and in that case we need to abort initialization and free all
681 // associated resources before calling DispatchMoreTasks(). 692 // associated resources before calling DispatchMoreTasks().
682 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) 693 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_)
683 AssignGpuMemoryToTiles(); 694 AssignGpuMemoryToTiles();
684 695
685 // Finish resource initialization if |can_use_gpu_memory| is true. 696 // Finish resource initialization if |can_use_gpu_memory| is true.
686 if (managed_tile_state.can_use_gpu_memory) { 697 if (mts->can_use_gpu_memory) {
687 // The component order may be bgra if we're uploading bgra pixels to rgba 698 // The component order may be bgra if we're uploading bgra pixels to rgba
688 // texture. Mark contents as swizzled if image component order is 699 // texture. Mark contents as swizzled if image component order is
689 // different than texture format. 700 // different than texture format.
690 managed_tile_state.contents_swizzled = 701 mts->contents_swizzled = !PlatformColor::sameComponentOrder(mts->format);
691 !PlatformColor::sameComponentOrder(tile->format_);
692 702
693 // Tile resources can't be freed until upload has completed. 703 // Tile resources can't be freed until upload has completed.
694 managed_tile_state.can_be_freed = false; 704 mts->can_be_freed = false;
695 705
696 resource_pool_->resource_provider()->beginSetPixels(resource->id()); 706 resource_pool_->resource_provider()->beginSetPixels(resource->id());
697 resource_pool_->resource_provider()->shallowFlushIfSupported(); 707 resource_pool_->resource_provider()->shallowFlushIfSupported();
698 managed_tile_state.resource = resource.Pass(); 708 mts->resource = resource.Pass();
699 709
700 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); 710 bytes_pending_set_pixels_ += mts->bytes_consumed_if_allocated;
701 DidTileRasterStateChange(tile, SET_PIXELS_STATE); 711 DidTileRasterStateChange(mts, SET_PIXELS_STATE);
702 tiles_with_pending_set_pixels_.push(tile); 712 tiles_with_pending_set_pixels_.push(mts);
703 } else { 713 } else {
704 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); 714 resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
705 resource_pool_->ReleaseResource(resource.Pass()); 715 resource_pool_->ReleaseResource(resource.Pass());
706 managed_tile_state.resource_is_being_initialized = false; 716 mts->resource_is_being_initialized = false;
707 DidTileRasterStateChange(tile, IDLE_STATE); 717 DidTileRasterStateChange(mts, IDLE_STATE);
708 } 718 }
709 719
710 DispatchMoreTasks(); 720 DispatchMoreTasks();
711 } 721 }
712 722
713 void TileManager::DidFinishTileInitialization(Tile* tile) { 723 void TileManager::DidFinishTileInitialization(ManagedTileState* mts) {
714 ManagedTileState& managed_tile_state = tile->managed_state(); 724 DCHECK(mts->resource);
715 DCHECK(managed_tile_state.resource); 725 mts->resource_is_being_initialized = false;
716 managed_tile_state.resource_is_being_initialized = false; 726 mts->can_be_freed = true;
717 managed_tile_state.can_be_freed = true;
718 } 727 }
719 728
720 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { 729 void TileManager::DidTileRasterStateChange(
721 ManagedTileState& mts = tile->managed_state(); 730 ManagedTileState* mts, TileRasterState state) {
722 DCHECK_LT(state, NUM_STATES); 731 DCHECK_LT(state, NUM_STATES);
723 732
724 for (int i = 0; i < NUM_TREES; ++i) { 733 for (int i = 0; i < NUM_TREES; ++i) {
725 // Decrement count for current state. 734 // Decrement count for current state.
726 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 735 --raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
727 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); 736 DCHECK_GE(raster_state_count_[mts->raster_state][i][mts->tree_bin[i]], 0);
728 737
729 // Increment count for new state. 738 // Increment count for new state.
730 ++raster_state_count_[state][i][mts.tree_bin[i]]; 739 ++raster_state_count_[state][i][mts->tree_bin[i]];
731 } 740 }
732 741
733 mts.raster_state = state; 742 mts->raster_state = state;
734 } 743 }
735 744
736 void TileManager::DidTileBinChange(Tile* tile, 745 void TileManager::DidTileBinChange(ManagedTileState* mts,
737 TileManagerBin bin, 746 TileManagerBin bin,
738 WhichTree tree) { 747 WhichTree tree) {
739 ManagedTileState& mts = tile->managed_state();
740
741 // Decrement count for current bin. 748 // Decrement count for current bin.
742 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; 749 --raster_state_count_[mts->raster_state][tree][mts->tree_bin[tree]];
743 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); 750 DCHECK_GE(
751 raster_state_count_[mts->raster_state][tree][mts->tree_bin[tree]], 0);
744 752
745 // Increment count for new bin. 753 // Increment count for new bin.
746 ++raster_state_count_[mts.raster_state][tree][bin]; 754 ++raster_state_count_[mts->raster_state][tree][bin];
747 755
748 mts.tree_bin[tree] = bin; 756 mts->tree_bin[tree] = bin;
749 } 757 }
750 758
751 // static 759 // static
752 void TileManager::RunRasterTask(uint8* buffer, 760 void TileManager::RunRasterTask(uint8* buffer,
753 const gfx::Rect& rect, 761 const gfx::Rect& rect,
754 float contents_scale, 762 float contents_scale,
755 PicturePileImpl* picture_pile, 763 PicturePileImpl* picture_pile,
756 RenderingStats* stats) { 764 RenderingStats* stats) {
757 TRACE_EVENT0("cc", "TileManager::RunRasterTask"); 765 TRACE_EVENT0("cc", "TileManager::RunRasterTask");
758 DCHECK(picture_pile); 766 DCHECK(picture_pile);
(...skipping 15 matching lines...) Expand all
774 decode_begin_time = base::TimeTicks::Now(); 782 decode_begin_time = base::TimeTicks::Now();
775 pixel_ref->Decode(); 783 pixel_ref->Decode();
776 if (stats) { 784 if (stats) {
777 stats->totalDeferredImageDecodeCount++; 785 stats->totalDeferredImageDecodeCount++;
778 stats->totalDeferredImageDecodeTime += 786 stats->totalDeferredImageDecodeTime +=
779 base::TimeTicks::Now() - decode_begin_time; 787 base::TimeTicks::Now() - decode_begin_time;
780 } 788 }
781 } 789 }
782 790
783 } // namespace cc 791 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698