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

Side by Side Diff: cc/tile_manager.cc

Issue 12289020: cc: Make the TileManager operate on ManagedTileState directly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix clang dtor nits 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return EVENTUALLY_BIN; 66 return EVENTUALLY_BIN;
67 } 67 }
68 68
69 std::string ValueToString(scoped_ptr<base::Value> value) 69 std::string ValueToString(scoped_ptr<base::Value> value)
70 { 70 {
71 std::string str; 71 std::string str;
72 base::JSONWriter::Write(value.get(), &str); 72 base::JSONWriter::Write(value.get(), &str);
73 return str; 73 return str;
74 } 74 }
75 75
76 RasterTaskMetadata GetRasterTaskMetadata(const ManagedTileState& mts) { 76 RasterTaskMetadata GetRasterTaskMetadata(const ManagedTileState* mts) {
77 RasterTaskMetadata raster_task_metadata; 77 RasterTaskMetadata raster_task_metadata;
78 raster_task_metadata.is_tile_in_pending_tree_now_bin = 78 raster_task_metadata.is_tile_in_pending_tree_now_bin =
79 mts.tree_bin[PENDING_TREE] == NOW_BIN; 79 mts->tree_bin[PENDING_TREE] == NOW_BIN;
80 raster_task_metadata.tile_resolution = mts.resolution; 80 raster_task_metadata.tile_resolution = mts->resolution;
81 return raster_task_metadata; 81 return raster_task_metadata;
82 } 82 }
83 83
84 } // namespace 84 } // namespace
85 85
86 scoped_ptr<base::Value> TileManagerBinAsValue(TileManagerBin bin) { 86 scoped_ptr<base::Value> TileManagerBinAsValue(TileManagerBin bin) {
87 switch (bin) { 87 switch (bin) {
88 case NOW_BIN: 88 case NOW_BIN:
89 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 89 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
90 "NOW_BIN")); 90 "NOW_BIN"));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 case SET_PIXELS_STATE: 135 case SET_PIXELS_STATE:
136 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 136 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
137 "SET_PIXELS_STATE")); 137 "SET_PIXELS_STATE"));
138 default: 138 default:
139 DCHECK(false) << "Unrecognized TileRasterState value"; 139 DCHECK(false) << "Unrecognized TileRasterState value";
140 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 140 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
141 "<unknown TileRasterState value>")); 141 "<unknown TileRasterState value>"));
142 } 142 }
143 } 143 }
144 144
145 ManagedTileState::ManagedTileState() 145 ManagedTileState::ManagedTileState(Tile* tile)
146 : can_use_gpu_memory(false), 146 : tile(tile),
147 can_use_gpu_memory(false),
147 can_be_freed(true), 148 can_be_freed(true),
148 resource_is_being_initialized(false), 149 resource_is_being_initialized(false),
149 contents_swizzled(false), 150 contents_swizzled(false),
150 need_to_gather_pixel_refs(true), 151 need_to_gather_pixel_refs(true),
151 gpu_memmgr_stats_bin(NEVER_BIN), 152 gpu_memmgr_stats_bin(NEVER_BIN),
152 raster_state(IDLE_STATE), 153 raster_state(IDLE_STATE),
153 resolution(NON_IDEAL_RESOLUTION), 154 resolution(NON_IDEAL_RESOLUTION),
154 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()), 155 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()),
155 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) { 156 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) {
156 for (int i = 0; i < NUM_TREES; ++i) { 157 for (int i = 0; i < NUM_TREES; ++i) {
157 tree_bin[i] = NEVER_BIN; 158 tree_bin[i] = NEVER_BIN;
158 bin[i] = NEVER_BIN; 159 bin[i] = NEVER_BIN;
159 } 160 }
161 tile->tile_manager()->RegisterManagedTile(this);
160 } 162 }
161 163
162 ManagedTileState::~ManagedTileState() { 164 ManagedTileState::~ManagedTileState() {
165 tile->tile_manager()->UnregisterManagedTile(this);
163 DCHECK(!resource); 166 DCHECK(!resource);
164 DCHECK(!resource_is_being_initialized); 167 DCHECK(!resource_is_being_initialized);
165 } 168 }
166 169
167 scoped_ptr<base::Value> ManagedTileState::AsValue() const { 170 scoped_ptr<base::Value> ManagedTileState::AsValue() const {
168 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 171 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
169 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory); 172 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory);
170 state->SetBoolean("can_be_freed", can_be_freed); 173 state->SetBoolean("can_be_freed", can_be_freed);
171 state->SetBoolean("has_resource", resource.get() != 0); 174 state->SetBoolean("has_resource", resource.get() != 0);
172 state->SetBoolean("resource_is_being_initialized", resource_is_being_initializ ed); 175 state->SetBoolean("resource_is_being_initialized", resource_is_being_initializ ed);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 DCHECK_EQ(live_or_allocated_tiles_.size(), 0); 220 DCHECK_EQ(live_or_allocated_tiles_.size(), 0);
218 } 221 }
219 222
220 void TileManager::SetGlobalState( 223 void TileManager::SetGlobalState(
221 const GlobalStateThatImpactsTilePriority& global_state) { 224 const GlobalStateThatImpactsTilePriority& global_state) {
222 global_state_ = global_state; 225 global_state_ = global_state;
223 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); 226 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes);
224 ScheduleManageTiles(); 227 ScheduleManageTiles();
225 } 228 }
226 229
227 void TileManager::RegisterTile(Tile* tile) { 230 scoped_refptr<ManagedTileState> TileManager::RegisterTile(Tile* tile) {
228 all_tiles_.insert(tile); 231 if (!tile->managed_state_) {
232 tile->managed_state_ = new ManagedTileState(tile);
233 return make_scoped_refptr(tile->managed_state_);
234 }
235 return tile->managed_state_;
236 }
229 237
230 const ManagedTileState& mts = tile->managed_state(); 238 void TileManager::RegisterManagedTile(ManagedTileState* mts) {
239 all_tiles_.insert(mts);
231 for (int i = 0; i < NUM_TREES; ++i) 240 for (int i = 0; i < NUM_TREES; ++i)
232 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 241 ++raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
233 242
234 ScheduleManageTiles(); 243 ScheduleManageTiles();
235 } 244 }
236 245
237 void TileManager::UnregisterTile(Tile* tile) { 246 void TileManager::UnregisterManagedTile(ManagedTileState* mts) {
238 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 247 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
239 it != tiles_with_image_decoding_tasks_.end(); it++) { 248 it != tiles_with_image_decoding_tasks_.end(); it++) {
240 if (*it == tile) { 249 if (*it == mts) {
241 tiles_with_image_decoding_tasks_.erase(it); 250 tiles_with_image_decoding_tasks_.erase(it);
242 break; 251 break;
243 } 252 }
244 } 253 }
245 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); 254 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin();
246 it != tiles_that_need_to_be_rasterized_.end(); it++) { 255 it != tiles_that_need_to_be_rasterized_.end(); it++) {
247 if (*it == tile) { 256 if (*it == mts) {
248 tiles_that_need_to_be_rasterized_.erase(it); 257 tiles_that_need_to_be_rasterized_.erase(it);
249 break; 258 break;
250 } 259 }
251 } 260 }
252 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); 261 for (TileVector::iterator it = live_or_allocated_tiles_.begin();
253 it != live_or_allocated_tiles_.end(); it++) { 262 it != live_or_allocated_tiles_.end(); it++) {
254 if (*it == tile) { 263 if (*it == mts) {
255 live_or_allocated_tiles_.erase(it); 264 live_or_allocated_tiles_.erase(it);
256 break; 265 break;
257 } 266 }
258 } 267 }
259 TileSet::iterator it = all_tiles_.find(tile); 268 TileSet::iterator it = all_tiles_.find(mts);
260 DCHECK(it != all_tiles_.end()); 269 DCHECK(it != all_tiles_.end());
261 const ManagedTileState& mts = tile->managed_state();
262 for (int i = 0; i < NUM_TREES; ++i) 270 for (int i = 0; i < NUM_TREES; ++i)
263 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 271 --raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
264 FreeResourcesForTile(tile); 272 FreeResourcesForTile(mts);
265 all_tiles_.erase(it); 273 all_tiles_.erase(it);
274 mts->tile->managed_state_ = NULL;
275 mts->tile = NULL;
266 } 276 }
267 277
268 class BinComparator { 278 class BinComparator {
269 public: 279 public:
270 bool operator() (const Tile* a, const Tile* b) const { 280 bool operator() (const ManagedTileState* ams,
271 const ManagedTileState& ams = a->managed_state(); 281 const ManagedTileState* bms) const {
272 const ManagedTileState& bms = b->managed_state(); 282 if (ams->bin[HIGH_PRIORITY_BIN] != bms->bin[HIGH_PRIORITY_BIN])
273 if (ams.bin[HIGH_PRIORITY_BIN] != bms.bin[HIGH_PRIORITY_BIN]) 283 return ams->bin[HIGH_PRIORITY_BIN] < bms->bin[HIGH_PRIORITY_BIN];
274 return ams.bin[HIGH_PRIORITY_BIN] < bms.bin[HIGH_PRIORITY_BIN];
275 284
276 if (ams.bin[LOW_PRIORITY_BIN] != bms.bin[LOW_PRIORITY_BIN]) 285 if (ams->bin[LOW_PRIORITY_BIN] != bms->bin[LOW_PRIORITY_BIN])
277 return ams.bin[LOW_PRIORITY_BIN] < bms.bin[LOW_PRIORITY_BIN]; 286 return ams->bin[LOW_PRIORITY_BIN] < bms->bin[LOW_PRIORITY_BIN];
278 287
279 if (ams.resolution != bms.resolution) 288 if (ams->resolution != bms->resolution)
280 return ams.resolution < bms.resolution; 289 return ams->resolution < bms->resolution;
281 290
282 if (ams.time_to_needed_in_seconds != bms.time_to_needed_in_seconds) 291 if (ams->time_to_needed_in_seconds != bms->time_to_needed_in_seconds)
283 return ams.time_to_needed_in_seconds < bms.time_to_needed_in_seconds; 292 return ams->time_to_needed_in_seconds < bms->time_to_needed_in_seconds;
284 293
285 if (ams.distance_to_visible_in_pixels != bms.distance_to_visible_in_pixels) 294 if (ams->distance_to_visible_in_pixels != bms->distance_to_visible_in_pixels )
286 return ams.distance_to_visible_in_pixels < bms.distance_to_visible_in_pixe ls; 295 return ams->distance_to_visible_in_pixels < bms->distance_to_visible_in_pi xels;
287 296
288 gfx::Rect a_rect = a->content_rect(); 297 gfx::Rect a_rect = ams->tile->content_rect();
289 gfx::Rect b_rect = b->content_rect(); 298 gfx::Rect b_rect = bms->tile->content_rect();
290 if (a_rect.y() != b_rect.y()) 299 if (a_rect.y() != b_rect.y())
291 return a_rect.y() < b_rect.y(); 300 return a_rect.y() < b_rect.y();
292 return a_rect.x() < b_rect.x(); 301 return a_rect.x() < b_rect.x();
293 } 302 }
294 }; 303 };
295 304
296 void TileManager::SortTiles() { 305 void TileManager::SortTiles() {
297 TRACE_EVENT0("cc", "TileManager::SortTiles"); 306 TRACE_EVENT0("cc", "TileManager::SortTiles");
298 TRACE_COUNTER_ID1("cc", "LiveTileCount", this, live_or_allocated_tiles_.size() ); 307 TRACE_COUNTER_ID1("cc", "LiveTileCount", this, live_or_allocated_tiles_.size() );
299 308
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 bin_map[NOW_BIN] = NOW_BIN; 340 bin_map[NOW_BIN] = NOW_BIN;
332 bin_map[SOON_BIN] = SOON_BIN; 341 bin_map[SOON_BIN] = SOON_BIN;
333 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; 342 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN;
334 bin_map[NEVER_BIN] = NEVER_BIN; 343 bin_map[NEVER_BIN] = NEVER_BIN;
335 } 344 }
336 345
337 live_or_allocated_tiles_.clear(); 346 live_or_allocated_tiles_.clear();
338 // For each tree, bin into different categories of tiles. 347 // For each tree, bin into different categories of tiles.
339 for (TileSet::iterator it = all_tiles_.begin(); 348 for (TileSet::iterator it = all_tiles_.begin();
340 it != all_tiles_.end(); ++it) { 349 it != all_tiles_.end(); ++it) {
341 Tile* tile = *it; 350 ManagedTileState* mts = *it;
342 ManagedTileState& mts = tile->managed_state();
343 351
344 TilePriority prio[NUM_BIN_PRIORITIES]; 352 TilePriority prio[NUM_BIN_PRIORITIES];
345 switch (tree_priority) { 353 switch (tree_priority) {
346 case SAME_PRIORITY_FOR_BOTH_TREES: 354 case SAME_PRIORITY_FOR_BOTH_TREES:
347 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = 355 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] =
348 tile->combined_priority(); 356 mts->tile->combined_priority();
349 break; 357 break;
350 case SMOOTHNESS_TAKES_PRIORITY: 358 case SMOOTHNESS_TAKES_PRIORITY:
351 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); 359 prio[HIGH_PRIORITY_BIN] = mts->tile->priority(ACTIVE_TREE);
352 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE); 360 prio[LOW_PRIORITY_BIN] = mts->tile->priority(PENDING_TREE);
353 break; 361 break;
354 case NEW_CONTENT_TAKES_PRIORITY: 362 case NEW_CONTENT_TAKES_PRIORITY:
355 prio[HIGH_PRIORITY_BIN] = tile->priority(PENDING_TREE); 363 prio[HIGH_PRIORITY_BIN] = mts->tile->priority(PENDING_TREE);
356 prio[LOW_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); 364 prio[LOW_PRIORITY_BIN] = mts->tile->priority(ACTIVE_TREE);
357 break; 365 break;
358 } 366 }
359 367
360 mts.resolution = prio[HIGH_PRIORITY_BIN].resolution; 368 mts->resolution = prio[HIGH_PRIORITY_BIN].resolution;
361 mts.time_to_needed_in_seconds = 369 mts->time_to_needed_in_seconds =
362 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds; 370 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds;
363 mts.distance_to_visible_in_pixels = 371 mts->distance_to_visible_in_pixels =
364 prio[HIGH_PRIORITY_BIN].distance_to_visible_in_pixels; 372 prio[HIGH_PRIORITY_BIN].distance_to_visible_in_pixels;
365 mts.bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]); 373 mts->bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]);
366 mts.bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]); 374 mts->bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]);
367 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority()); 375 mts->gpu_memmgr_stats_bin = BinFromTilePriority(
376 mts->tile->combined_priority());
368 377
369 DidTileTreeBinChange(tile, 378 DidTileTreeBinChange(
370 BinFromTilePriority(tile->priority(ACTIVE_TREE)), 379 mts,
380 BinFromTilePriority(mts->tile->priority(ACTIVE_TREE)),
381 ACTIVE_TREE);
382 DidTileTreeBinChange(
383 mts,
384 BinFromTilePriority(mts->tile->priority(PENDING_TREE)),
385 PENDING_TREE);
386
387 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i)
388 mts->bin[i] = bin_map[mts->bin[i]];
389
390 DidTileTreeBinChange(mts, bin_map[mts->tree_bin[ACTIVE_TREE]],
371 ACTIVE_TREE); 391 ACTIVE_TREE);
372 DidTileTreeBinChange(tile, 392 DidTileTreeBinChange(mts, bin_map[mts->tree_bin[PENDING_TREE]],
373 BinFromTilePriority(tile->priority(PENDING_TREE)),
374 PENDING_TREE); 393 PENDING_TREE);
375 394
376 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) 395 if (mts->tile->priority(ACTIVE_TREE).is_live ||
377 mts.bin[i] = bin_map[mts.bin[i]]; 396 mts->tile->priority(PENDING_TREE).is_live ||
378 397 mts->resource ||
379 DidTileTreeBinChange(tile, bin_map[mts.tree_bin[ACTIVE_TREE]], 398 mts->resource_is_being_initialized) {
380 ACTIVE_TREE); 399 live_or_allocated_tiles_.push_back(mts);
381 DidTileTreeBinChange(tile, bin_map[mts.tree_bin[PENDING_TREE]],
382 PENDING_TREE);
383
384 if (tile->priority(ACTIVE_TREE).is_live ||
385 tile->priority(PENDING_TREE).is_live ||
386 tile->managed_state().resource ||
387 tile->managed_state().resource_is_being_initialized) {
388 live_or_allocated_tiles_.push_back(tile);
389 } 400 }
390 } 401 }
391 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, 402 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this,
392 live_or_allocated_tiles_.size()); 403 live_or_allocated_tiles_.size());
393 404
394 SortTiles(); 405 SortTiles();
395 406
396 // Assign gpu memory and determine what tiles need to be rasterized. 407 // Assign gpu memory and determine what tiles need to be rasterized.
397 AssignGpuMemoryToTiles(); 408 AssignGpuMemoryToTiles();
398 409
399 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", 410 TRACE_EVENT_INSTANT1("cc", "DidManage", "state",
400 ValueToString(BasicStateAsValue())); 411 ValueToString(BasicStateAsValue()));
401 412
402 // Finally, kick the rasterizer. 413 // Finally, kick the rasterizer.
403 DispatchMoreTasks(); 414 DispatchMoreTasks();
404 } 415 }
405 416
406 void TileManager::CheckForCompletedTileUploads() { 417 void TileManager::CheckForCompletedTileUploads() {
407 while (!tiles_with_pending_set_pixels_.empty()) { 418 while (!tiles_with_pending_set_pixels_.empty()) {
408 Tile* tile = tiles_with_pending_set_pixels_.front(); 419 ManagedTileState* mts = tiles_with_pending_set_pixels_.front();
409 DCHECK(tile->managed_state().resource); 420 DCHECK(mts->resource);
410 421
411 // Set pixel tasks complete in the order they are posted. 422 // Set pixel tasks complete in the order they are posted.
412 if (!resource_pool_->resource_provider()->didSetPixelsComplete( 423 if (!resource_pool_->resource_provider()->didSetPixelsComplete(
413 tile->managed_state().resource->id())) { 424 mts->resource->id())) {
414 break; 425 break;
415 } 426 }
416 427
417 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && 428 if (mts->tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 &&
418 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) 429 mts->tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION)
419 client_->DidUploadVisibleHighResolutionTile(); 430 client_->DidUploadVisibleHighResolutionTile();
420 431
421 // It's now safe to release the pixel buffer. 432 // It's now safe to release the pixel buffer.
422 resource_pool_->resource_provider()->releasePixelBuffer( 433 resource_pool_->resource_provider()->releasePixelBuffer(
423 tile->managed_state().resource->id()); 434 mts->resource->id());
424 435
425 DidFinishTileInitialization(tile); 436 DidFinishTileInitialization(mts);
426 437
427 bytes_pending_set_pixels_ -= tile->bytes_consumed_if_allocated(); 438 bytes_pending_set_pixels_ -= mts->tile->bytes_consumed_if_allocated();
428 DidTileRasterStateChange(tile, IDLE_STATE); 439 DidTileRasterStateChange(mts, IDLE_STATE);
429 tiles_with_pending_set_pixels_.pop(); 440 tiles_with_pending_set_pixels_.pop();
430 } 441 }
431 442
432 DispatchMoreTasks(); 443 DispatchMoreTasks();
433 } 444 }
434 445
435 void TileManager::AbortPendingTileUploads() { 446 void TileManager::AbortPendingTileUploads() {
436 while (!tiles_with_pending_set_pixels_.empty()) { 447 while (!tiles_with_pending_set_pixels_.empty()) {
437 Tile* tile = tiles_with_pending_set_pixels_.front(); 448 ManagedTileState* mts = tiles_with_pending_set_pixels_.front();
438 ManagedTileState& managed_tile_state = tile->managed_state(); 449 DCHECK(mts->resource);
439 DCHECK(managed_tile_state.resource);
440 450
441 resource_pool_->resource_provider()->abortSetPixels( 451 resource_pool_->resource_provider()->abortSetPixels(
442 managed_tile_state.resource->id()); 452 mts->resource->id());
443 resource_pool_->resource_provider()->releasePixelBuffer( 453 resource_pool_->resource_provider()->releasePixelBuffer(
444 managed_tile_state.resource->id()); 454 mts->resource->id());
445 455
446 managed_tile_state.resource_is_being_initialized = false; 456 mts->resource_is_being_initialized = false;
447 managed_tile_state.can_be_freed = true; 457 mts->can_be_freed = true;
448 managed_tile_state.can_use_gpu_memory = false; 458 mts->can_use_gpu_memory = false;
449 FreeResourcesForTile(tile); 459 FreeResourcesForTile(mts);
450 460
451 bytes_pending_set_pixels_ -= tile->bytes_consumed_if_allocated(); 461 bytes_pending_set_pixels_ -= mts->tile->bytes_consumed_if_allocated();
452 DidTileRasterStateChange(tile, IDLE_STATE); 462 DidTileRasterStateChange(mts, IDLE_STATE);
453 tiles_with_pending_set_pixels_.pop(); 463 tiles_with_pending_set_pixels_.pop();
454 } 464 }
455 } 465 }
456 466
457 void TileManager::GetMemoryStats( 467 void TileManager::GetMemoryStats(
458 size_t* memoryRequiredBytes, 468 size_t* memoryRequiredBytes,
459 size_t* memoryNiceToHaveBytes, 469 size_t* memoryNiceToHaveBytes,
460 size_t* memoryUsedBytes) const { 470 size_t* memoryUsedBytes) const {
461 *memoryRequiredBytes = 0; 471 *memoryRequiredBytes = 0;
462 *memoryNiceToHaveBytes = 0; 472 *memoryNiceToHaveBytes = 0;
463 *memoryUsedBytes = 0; 473 *memoryUsedBytes = 0;
464 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { 474 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) {
465 const Tile* tile = live_or_allocated_tiles_[i]; 475 const ManagedTileState* mts = live_or_allocated_tiles_[i];
466 const ManagedTileState& mts = tile->managed_state(); 476 size_t tile_bytes = mts->tile->bytes_consumed_if_allocated();
467 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 477 if (mts->gpu_memmgr_stats_bin == NOW_BIN)
468 if (mts.gpu_memmgr_stats_bin == NOW_BIN)
469 *memoryRequiredBytes += tile_bytes; 478 *memoryRequiredBytes += tile_bytes;
470 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) 479 if (mts->gpu_memmgr_stats_bin != NEVER_BIN)
471 *memoryNiceToHaveBytes += tile_bytes; 480 *memoryNiceToHaveBytes += tile_bytes;
472 if (mts.can_use_gpu_memory) 481 if (mts->can_use_gpu_memory)
473 *memoryUsedBytes += tile_bytes; 482 *memoryUsedBytes += tile_bytes;
474 } 483 }
475 } 484 }
476 485
477 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { 486 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const {
478 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 487 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
479 state->SetInteger("tile_count", all_tiles_.size()); 488 state->SetInteger("tile_count", all_tiles_.size());
480 489
481 state->Set("global_state", global_state_.AsValue().release()); 490 state->Set("global_state", global_state_.AsValue().release());
482 491
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 585
577 // By clearing the tiles_that_need_to_be_rasterized_ vector and 586 // By clearing the tiles_that_need_to_be_rasterized_ vector and
578 // tiles_with_image_decoding_tasks_ list above we move all tiles 587 // tiles_with_image_decoding_tasks_ list above we move all tiles
579 // currently waiting for raster to idle state. 588 // currently waiting for raster to idle state.
580 // Call DidTileRasterStateChange() for each of these tiles to 589 // Call DidTileRasterStateChange() for each of these tiles to
581 // have this state change take effect. 590 // have this state change take effect.
582 // Some memory cannot be released. We figure out how much in this 591 // Some memory cannot be released. We figure out how much in this
583 // loop as well. 592 // loop as well.
584 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); 593 for (TileVector::iterator it = live_or_allocated_tiles_.begin();
585 it != live_or_allocated_tiles_.end(); ++it) { 594 it != live_or_allocated_tiles_.end(); ++it) {
586 Tile* tile = *it; 595 ManagedTileState* mts = *it;
587 if (!tile->managed_state().can_be_freed) 596 if (!mts->can_be_freed)
588 unreleasable_bytes += tile->bytes_consumed_if_allocated(); 597 unreleasable_bytes += mts->tile->bytes_consumed_if_allocated();
589 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE) 598 if (mts->raster_state == WAITING_FOR_RASTER_STATE)
590 DidTileRasterStateChange(tile, IDLE_STATE); 599 DidTileRasterStateChange(mts, IDLE_STATE);
591 } 600 }
592 601
593 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes; 602 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes;
594 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0; 603 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0;
595 size_t bytes_left = bytes_allocatable; 604 size_t bytes_left = bytes_allocatable;
596 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) { 605 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) {
597 Tile* tile = *it; 606 ManagedTileState* mts = *it;
598 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 607 size_t tile_bytes = mts->tile->bytes_consumed_if_allocated();
599 ManagedTileState& managed_tile_state = tile->managed_state(); 608 if (!mts->can_be_freed)
600 if (!managed_tile_state.can_be_freed)
601 continue; 609 continue;
602 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && 610 if (mts->bin[HIGH_PRIORITY_BIN] == NEVER_BIN &&
603 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { 611 mts->bin[LOW_PRIORITY_BIN] == NEVER_BIN) {
604 managed_tile_state.can_use_gpu_memory = false; 612 mts->can_use_gpu_memory = false;
605 FreeResourcesForTile(tile); 613 FreeResourcesForTile(mts);
606 continue; 614 continue;
607 } 615 }
608 if (tile_bytes > bytes_left) { 616 if (tile_bytes > bytes_left) {
609 managed_tile_state.can_use_gpu_memory = false; 617 mts->can_use_gpu_memory = false;
610 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NOW_BIN || 618 if (mts->bin[HIGH_PRIORITY_BIN] == NOW_BIN ||
611 managed_tile_state.bin[LOW_PRIORITY_BIN] == NOW_BIN) 619 mts->bin[LOW_PRIORITY_BIN] == NOW_BIN)
612 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; 620 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes;
613 FreeResourcesForTile(tile); 621 FreeResourcesForTile(mts);
614 continue; 622 continue;
615 } 623 }
616 bytes_left -= tile_bytes; 624 bytes_left -= tile_bytes;
617 managed_tile_state.can_use_gpu_memory = true; 625 mts->can_use_gpu_memory = true;
618 if (!managed_tile_state.resource && 626 if (!mts->resource &&
619 !managed_tile_state.resource_is_being_initialized) { 627 !mts->resource_is_being_initialized) {
620 tiles_that_need_to_be_rasterized_.push_back(tile); 628 tiles_that_need_to_be_rasterized_.push_back(mts);
621 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE); 629 DidTileRasterStateChange(mts, WAITING_FOR_RASTER_STATE);
622 } 630 }
623 } 631 }
624 632
625 ever_exceeded_memory_budget_ |= 633 ever_exceeded_memory_budget_ |=
626 bytes_that_exceeded_memory_budget_in_now_bin > 0; 634 bytes_that_exceeded_memory_budget_in_now_bin > 0;
627 if (ever_exceeded_memory_budget_) { 635 if (ever_exceeded_memory_budget_) {
628 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, 636 TRACE_COUNTER_ID2("cc", "over_memory_budget", this,
629 "budget", global_state_.memory_limit_in_bytes, 637 "budget", global_state_.memory_limit_in_bytes,
630 "over", bytes_that_exceeded_memory_budget_in_now_bin); 638 "over", bytes_that_exceeded_memory_budget_in_now_bin);
631 } 639 }
632 memory_stats_from_last_assign_.total_budget_in_bytes = 640 memory_stats_from_last_assign_.total_budget_in_bytes =
633 global_state_.memory_limit_in_bytes; 641 global_state_.memory_limit_in_bytes;
634 memory_stats_from_last_assign_.bytes_allocated = 642 memory_stats_from_last_assign_.bytes_allocated =
635 bytes_allocatable - bytes_left; 643 bytes_allocatable - bytes_left;
636 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; 644 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes;
637 memory_stats_from_last_assign_.bytes_over = 645 memory_stats_from_last_assign_.bytes_over =
638 bytes_that_exceeded_memory_budget_in_now_bin; 646 bytes_that_exceeded_memory_budget_in_now_bin;
639 647
640 // Reverse two tiles_that_need_* vectors such that pop_back gets 648 // Reverse two tiles_that_need_* vectors such that pop_back gets
641 // the highest priority tile. 649 // the highest priority tile.
642 std::reverse( 650 std::reverse(
643 tiles_that_need_to_be_rasterized_.begin(), 651 tiles_that_need_to_be_rasterized_.begin(),
644 tiles_that_need_to_be_rasterized_.end()); 652 tiles_that_need_to_be_rasterized_.end());
645 } 653 }
646 654
647 void TileManager::FreeResourcesForTile(Tile* tile) { 655 void TileManager::FreeResourcesForTile(ManagedTileState* mts) {
648 ManagedTileState& managed_tile_state = tile->managed_state(); 656 DCHECK(mts->can_be_freed);
649 DCHECK(managed_tile_state.can_be_freed); 657 if (mts->resource)
650 if (managed_tile_state.resource) 658 resource_pool_->ReleaseResource(mts->resource.Pass());
651 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass());
652 } 659 }
653 660
654 bool TileManager::CanDispatchRasterTask(Tile* tile) { 661 bool TileManager::CanDispatchRasterTask(ManagedTileState* mts) {
655 if (raster_worker_pool_->IsBusy()) 662 if (raster_worker_pool_->IsBusy())
656 return false; 663 return false;
657 size_t new_bytes_pending = bytes_pending_set_pixels_; 664 size_t new_bytes_pending = bytes_pending_set_pixels_;
658 new_bytes_pending += tile->bytes_consumed_if_allocated(); 665 new_bytes_pending += mts->tile->bytes_consumed_if_allocated();
659 return new_bytes_pending <= kMaxPendingUploadBytes && 666 return new_bytes_pending <= kMaxPendingUploadBytes &&
660 tiles_with_pending_set_pixels_.size() < kMaxPendingUploads; 667 tiles_with_pending_set_pixels_.size() < kMaxPendingUploads;
661 } 668 }
662 669
663 void TileManager::DispatchMoreTasks() { 670 void TileManager::DispatchMoreTasks() {
664 // Because tiles in the image decoding list have higher priorities, we 671 // Because tiles in the image decoding list have higher priorities, we
665 // need to process those tiles first before we start to handle the tiles 672 // need to process those tiles first before we start to handle the tiles
666 // in the need_to_be_rasterized queue. 673 // in the need_to_be_rasterized queue.
667 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 674 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
668 it != tiles_with_image_decoding_tasks_.end(); ) { 675 it != tiles_with_image_decoding_tasks_.end(); ) {
669 DispatchImageDecodeTasksForTile(*it); 676 ManagedTileState* mts = *it;
670 ManagedTileState& managed_state = (*it)->managed_state(); 677 DispatchImageDecodeTasksForTile(mts);
671 if (managed_state.pending_pixel_refs.empty()) { 678 if (mts->pending_pixel_refs.empty()) {
672 if (!CanDispatchRasterTask(*it)) 679 if (!CanDispatchRasterTask(mts))
673 return; 680 return;
674 DispatchOneRasterTask(*it); 681 DispatchOneRasterTask(mts);
675 tiles_with_image_decoding_tasks_.erase(it++); 682 tiles_with_image_decoding_tasks_.erase(it++);
676 } else { 683 } else {
677 ++it; 684 ++it;
678 } 685 }
679 } 686 }
680 687
681 // Process all tiles in the need_to_be_rasterized queue. If a tile has 688 // Process all tiles in the need_to_be_rasterized queue. If a tile has
682 // image decoding tasks, put it to the back of the image decoding list. 689 // image decoding tasks, put it to the back of the image decoding list.
683 while (!tiles_that_need_to_be_rasterized_.empty()) { 690 while (!tiles_that_need_to_be_rasterized_.empty()) {
684 Tile* tile = tiles_that_need_to_be_rasterized_.back(); 691 ManagedTileState* mts = tiles_that_need_to_be_rasterized_.back();
685 DispatchImageDecodeTasksForTile(tile); 692 DispatchImageDecodeTasksForTile(mts);
686 ManagedTileState& managed_state = tile->managed_state(); 693 if (!mts->pending_pixel_refs.empty()) {
687 if (!managed_state.pending_pixel_refs.empty()) { 694 tiles_with_image_decoding_tasks_.push_back(mts);
688 tiles_with_image_decoding_tasks_.push_back(tile);
689 } else { 695 } else {
690 if (!CanDispatchRasterTask(tile)) 696 if (!CanDispatchRasterTask(mts))
691 return; 697 return;
692 DispatchOneRasterTask(tile); 698 DispatchOneRasterTask(mts);
693 } 699 }
694 tiles_that_need_to_be_rasterized_.pop_back(); 700 tiles_that_need_to_be_rasterized_.pop_back();
695 } 701 }
696 } 702 }
697 703
698 void TileManager::GatherPixelRefsForTile(Tile* tile) { 704 void TileManager::GatherPixelRefsForTile(ManagedTileState* mts) {
699 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); 705 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile");
700 ManagedTileState& managed_state = tile->managed_state(); 706 if (mts->need_to_gather_pixel_refs) {
701 if (managed_state.need_to_gather_pixel_refs) {
702 base::TimeTicks gather_begin_time; 707 base::TimeTicks gather_begin_time;
703 if (record_rendering_stats_) 708 if (record_rendering_stats_)
704 gather_begin_time = base::TimeTicks::HighResNow(); 709 gather_begin_time = base::TimeTicks::HighResNow();
705 tile->picture_pile()->GatherPixelRefs( 710 mts->tile->picture_pile()->GatherPixelRefs(
706 tile->content_rect_, 711 mts->tile->content_rect_,
707 tile->contents_scale_, 712 mts->tile->contents_scale_,
708 managed_state.pending_pixel_refs); 713 mts->pending_pixel_refs);
709 managed_state.need_to_gather_pixel_refs = false; 714 mts->need_to_gather_pixel_refs = false;
710 if (record_rendering_stats_) { 715 if (record_rendering_stats_) {
711 rendering_stats_.totalImageGatheringCount++; 716 rendering_stats_.totalImageGatheringCount++;
712 rendering_stats_.totalImageGatheringTime += 717 rendering_stats_.totalImageGatheringTime +=
713 base::TimeTicks::HighResNow() - gather_begin_time; 718 base::TimeTicks::HighResNow() - gather_begin_time;
714 } 719 }
715 } 720 }
716 } 721 }
717 722
718 void TileManager::DispatchImageDecodeTasksForTile(Tile* tile) { 723 void TileManager::DispatchImageDecodeTasksForTile(ManagedTileState* mts) {
719 GatherPixelRefsForTile(tile); 724 GatherPixelRefsForTile(mts);
720 std::list<skia::LazyPixelRef*>& pending_pixel_refs = 725 std::list<skia::LazyPixelRef*>& pending_pixel_refs =
721 tile->managed_state().pending_pixel_refs; 726 mts->pending_pixel_refs;
722 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); 727 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin();
723 while (it != pending_pixel_refs.end()) { 728 while (it != pending_pixel_refs.end()) {
724 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( 729 if (pending_decode_tasks_.end() != pending_decode_tasks_.find(
725 (*it)->getGenerationID())) { 730 (*it)->getGenerationID())) {
726 ++it; 731 ++it;
727 continue; 732 continue;
728 } 733 }
729 // TODO(qinmin): passing correct image size to PrepareToDecode(). 734 // TODO(qinmin): passing correct image size to PrepareToDecode().
730 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { 735 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) {
731 rendering_stats_.totalDeferredImageCacheHitCount++; 736 rendering_stats_.totalDeferredImageCacheHitCount++;
732 pending_pixel_refs.erase(it++); 737 pending_pixel_refs.erase(it++);
733 } else { 738 } else {
734 if (raster_worker_pool_->IsBusy()) 739 if (raster_worker_pool_->IsBusy())
735 return; 740 return;
736 DispatchOneImageDecodeTask(tile, *it); 741 DispatchOneImageDecodeTask(mts, *it);
737 ++it; 742 ++it;
738 } 743 }
739 } 744 }
740 } 745 }
741 746
742 void TileManager::DispatchOneImageDecodeTask( 747 void TileManager::DispatchOneImageDecodeTask(
743 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { 748 scoped_refptr<ManagedTileState> mts, skia::LazyPixelRef* pixel_ref) {
744 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); 749 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask");
745 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); 750 uint32_t pixel_ref_id = pixel_ref->getGenerationID();
746 DCHECK(pending_decode_tasks_.end() == 751 DCHECK(pending_decode_tasks_.end() ==
747 pending_decode_tasks_.find(pixel_ref_id)); 752 pending_decode_tasks_.find(pixel_ref_id));
748 pending_decode_tasks_[pixel_ref_id] = pixel_ref; 753 pending_decode_tasks_[pixel_ref_id] = pixel_ref;
749 754
750 raster_worker_pool_->PostTaskAndReply( 755 raster_worker_pool_->PostTaskAndReply(
751 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), 756 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref),
752 base::Bind(&TileManager::OnImageDecodeTaskCompleted, 757 base::Bind(&TileManager::OnImageDecodeTaskCompleted,
753 base::Unretained(this), 758 base::Unretained(this),
754 tile, 759 mts,
755 pixel_ref_id)); 760 pixel_ref_id));
756 } 761 }
757 762
758 void TileManager::OnImageDecodeTaskCompleted( 763 void TileManager::OnImageDecodeTaskCompleted(
759 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { 764 scoped_refptr<ManagedTileState> mts, uint32_t pixel_ref_id) {
760 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); 765 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted");
761 pending_decode_tasks_.erase(pixel_ref_id); 766 pending_decode_tasks_.erase(pixel_ref_id);
762 767
763 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 768 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
764 it != tiles_with_image_decoding_tasks_.end(); ++it) { 769 it != tiles_with_image_decoding_tasks_.end(); ++it) {
765 std::list<skia::LazyPixelRef*>& pixel_refs = 770 std::list<skia::LazyPixelRef*>& pixel_refs =
766 (*it)->managed_state().pending_pixel_refs; 771 (*it)->pending_pixel_refs;
767 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = 772 for (std::list<skia::LazyPixelRef*>::iterator pixel_it =
768 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { 773 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) {
769 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { 774 if (pixel_ref_id == (*pixel_it)->getGenerationID()) {
770 pixel_refs.erase(pixel_it); 775 pixel_refs.erase(pixel_it);
771 break; 776 break;
772 } 777 }
773 } 778 }
774 } 779 }
775 } 780 }
776 781
777 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( 782 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster(
778 Tile* tile) { 783 ManagedTileState* mts) {
779 ManagedTileState& managed_tile_state = tile->managed_state(); 784 DCHECK(mts->can_use_gpu_memory);
780 DCHECK(managed_tile_state.can_use_gpu_memory);
781 scoped_ptr<ResourcePool::Resource> resource = 785 scoped_ptr<ResourcePool::Resource> resource =
782 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); 786 resource_pool_->AcquireResource(mts->tile->tile_size_.size(),
787 mts->tile->format_);
783 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); 788 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id());
784 789
785 managed_tile_state.resource_is_being_initialized = true; 790 mts->resource_is_being_initialized = true;
786 managed_tile_state.can_be_freed = false; 791 mts->can_be_freed = false;
787 792
788 DidTileRasterStateChange(tile, RASTER_STATE); 793 DidTileRasterStateChange(mts, RASTER_STATE);
789 return resource.Pass(); 794 return resource.Pass();
790 } 795 }
791 796
792 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { 797 void TileManager::DispatchOneRasterTask(scoped_refptr<ManagedTileState> mts) {
793 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); 798 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask");
794 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); 799 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(mts);
795 ResourceProvider::ResourceId resource_id = resource->id(); 800 ResourceProvider::ResourceId resource_id = resource->id();
796 801
797 raster_worker_pool_->PostRasterTaskAndReply( 802 raster_worker_pool_->PostRasterTaskAndReply(
798 tile->picture_pile(), 803 mts->tile->picture_pile(),
799 base::Bind(&TileManager::PerformRaster, 804 base::Bind(&TileManager::PerformRaster,
800 resource_pool_->resource_provider()->mapPixelBuffer( 805 resource_pool_->resource_provider()->mapPixelBuffer(
801 resource_id), 806 resource_id),
802 tile->content_rect_, 807 mts->tile->content_rect_,
803 tile->contents_scale(), 808 mts->tile->contents_scale(),
804 use_cheapness_estimator_, 809 use_cheapness_estimator_,
805 GetRasterTaskMetadata(tile->managed_state())), 810 GetRasterTaskMetadata(mts)),
806 base::Bind(&TileManager::OnRasterTaskCompleted, 811 base::Bind(&TileManager::OnRasterTaskCompleted,
807 base::Unretained(this), 812 base::Unretained(this),
808 tile, 813 mts,
809 base::Passed(&resource), 814 base::Passed(&resource),
810 manage_tiles_call_count_)); 815 manage_tiles_call_count_));
811 } 816 }
812 817
813 void TileManager::PerformOneRaster(Tile* tile) { 818 void TileManager::PerformOneRaster(ManagedTileState* mts) {
814 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); 819 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(mts);
815 ResourceProvider::ResourceId resource_id = resource->id(); 820 ResourceProvider::ResourceId resource_id = resource->id();
816 821
817 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( 822 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer(
818 resource_id), 823 resource_id),
819 tile->content_rect_, 824 mts->tile->content_rect_,
820 tile->contents_scale(), 825 mts->tile->contents_scale(),
821 use_cheapness_estimator_, 826 use_cheapness_estimator_,
822 GetRasterTaskMetadata(tile->managed_state()), 827 GetRasterTaskMetadata(mts->tile->managed_state()),
823 tile->picture_pile(), 828 mts->tile->picture_pile(),
824 &rendering_stats_); 829 &rendering_stats_);
825 830
826 OnRasterCompleted(tile, resource.Pass(), manage_tiles_call_count_); 831 OnRasterCompleted(mts, resource.Pass(), manage_tiles_call_count_);
827 } 832 }
828 833
829 void TileManager::OnRasterCompleted( 834 void TileManager::OnRasterCompleted(
830 scoped_refptr<Tile> tile, 835 scoped_refptr<ManagedTileState> mts,
831 scoped_ptr<ResourcePool::Resource> resource, 836 scoped_ptr<ResourcePool::Resource> resource,
832 int manage_tiles_call_count_when_dispatched) { 837 int manage_tiles_call_count_when_dispatched) {
833 TRACE_EVENT0("cc", "TileManager::OnRasterCompleted"); 838 TRACE_EVENT0("cc", "TileManager::OnRasterCompleted");
834 839
835 // Release raster resources. 840 // Release raster resources.
836 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); 841 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id());
837 842
838 ManagedTileState& managed_tile_state = tile->managed_state(); 843 mts->can_be_freed = true;
839 managed_tile_state.can_be_freed = true;
840 844
841 // Tile can be freed after the completion of the raster task. Call 845 // Tile can be freed after the completion of the raster task. Call
842 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority 846 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority
843 // tiles if ManageTiles() was called since task was dispatched. The result 847 // tiles if ManageTiles() was called since task was dispatched. The result
844 // of this could be that this tile is no longer allowed to use gpu 848 // of this could be that this tile is no longer allowed to use gpu
845 // memory and in that case we need to abort initialization and free all 849 // memory and in that case we need to abort initialization and free all
846 // associated resources before calling DispatchMoreTasks(). 850 // associated resources before calling DispatchMoreTasks().
847 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) 851 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_)
848 AssignGpuMemoryToTiles(); 852 AssignGpuMemoryToTiles();
849 853
850 // Finish resource initialization if |can_use_gpu_memory| is true. 854 // Finish resource initialization if |can_use_gpu_memory| is true.
851 if (managed_tile_state.can_use_gpu_memory) { 855 if (mts->can_use_gpu_memory) {
852 // The component order may be bgra if we're uploading bgra pixels to rgba 856 // The component order may be bgra if we're uploading bgra pixels to rgba
853 // texture. Mark contents as swizzled if image component order is 857 // texture. Mark contents as swizzled if image component order is
854 // different than texture format. 858 // different than texture format.
855 managed_tile_state.contents_swizzled = 859 mts->contents_swizzled =
856 !PlatformColor::sameComponentOrder(tile->format_); 860 !PlatformColor::sameComponentOrder(mts->tile->format_);
857 861
858 // Tile resources can't be freed until upload has completed. 862 // Tile resources can't be freed until upload has completed.
859 managed_tile_state.can_be_freed = false; 863 mts->can_be_freed = false;
860 864
861 resource_pool_->resource_provider()->beginSetPixels(resource->id()); 865 resource_pool_->resource_provider()->beginSetPixels(resource->id());
862 has_performed_uploads_since_last_flush_ = true; 866 has_performed_uploads_since_last_flush_ = true;
863 867
864 managed_tile_state.resource = resource.Pass(); 868 mts->resource = resource.Pass();
865 869
866 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); 870 bytes_pending_set_pixels_ += mts->tile->bytes_consumed_if_allocated();
867 DidTileRasterStateChange(tile, SET_PIXELS_STATE); 871 DidTileRasterStateChange(mts, SET_PIXELS_STATE);
868 tiles_with_pending_set_pixels_.push(tile); 872 tiles_with_pending_set_pixels_.push(mts);
869 } else { 873 } else {
870 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); 874 resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
871 resource_pool_->ReleaseResource(resource.Pass()); 875 resource_pool_->ReleaseResource(resource.Pass());
872 managed_tile_state.resource_is_being_initialized = false; 876 mts->resource_is_being_initialized = false;
873 DidTileRasterStateChange(tile, IDLE_STATE); 877 DidTileRasterStateChange(mts, IDLE_STATE);
874 } 878 }
875 } 879 }
876 880
877 void TileManager::OnRasterTaskCompleted( 881 void TileManager::OnRasterTaskCompleted(
878 scoped_refptr<Tile> tile, 882 scoped_refptr<ManagedTileState> mts,
879 scoped_ptr<ResourcePool::Resource> resource, 883 scoped_ptr<ResourcePool::Resource> resource,
880 int manage_tiles_call_count_when_dispatched) { 884 int manage_tiles_call_count_when_dispatched) {
881 OnRasterCompleted(tile, resource.Pass(), 885 OnRasterCompleted(mts, resource.Pass(),
882 manage_tiles_call_count_when_dispatched); 886 manage_tiles_call_count_when_dispatched);
883 } 887 }
884 888
885 void TileManager::DidFinishTileInitialization(Tile* tile) { 889 void TileManager::DidFinishTileInitialization(ManagedTileState* mts) {
886 ManagedTileState& managed_tile_state = tile->managed_state(); 890 DCHECK(mts->resource);
887 DCHECK(managed_tile_state.resource); 891 mts->resource_is_being_initialized = false;
888 managed_tile_state.resource_is_being_initialized = false; 892 mts->can_be_freed = true;
889 managed_tile_state.can_be_freed = true;
890 } 893 }
891 894
892 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { 895 void TileManager::DidTileRasterStateChange(
893 ManagedTileState& mts = tile->managed_state(); 896 ManagedTileState* mts, TileRasterState state) {
894 DCHECK_LT(state, NUM_STATES); 897 DCHECK_LT(state, NUM_STATES);
895 898
896 for (int i = 0; i < NUM_TREES; ++i) { 899 for (int i = 0; i < NUM_TREES; ++i) {
897 // Decrement count for current state. 900 // Decrement count for current state.
898 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 901 --raster_state_count_[mts->raster_state][i][mts->tree_bin[i]];
899 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); 902 DCHECK_GE(raster_state_count_[mts->raster_state][i][mts->tree_bin[i]], 0);
900 903
901 // Increment count for new state. 904 // Increment count for new state.
902 ++raster_state_count_[state][i][mts.tree_bin[i]]; 905 ++raster_state_count_[state][i][mts->tree_bin[i]];
903 } 906 }
904 907
905 mts.raster_state = state; 908 mts->raster_state = state;
906 } 909 }
907 910
908 void TileManager::DidTileTreeBinChange(Tile* tile, 911 void TileManager::DidTileTreeBinChange(ManagedTileState* mts,
909 TileManagerBin new_tree_bin, 912 TileManagerBin new_tree_bin,
910 WhichTree tree) { 913 WhichTree tree) {
911 ManagedTileState& mts = tile->managed_state();
912
913 // Decrement count for current bin. 914 // Decrement count for current bin.
914 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; 915 --raster_state_count_[mts->raster_state][tree][mts->tree_bin[tree]];
915 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); 916 DCHECK_GE(raster_state_count_[mts->raster_state][tree][mts->tree_bin[tree]], 0 );
916 917
917 // Increment count for new bin. 918 // Increment count for new bin.
918 ++raster_state_count_[mts.raster_state][tree][new_tree_bin]; 919 ++raster_state_count_[mts->raster_state][tree][new_tree_bin];
919 920
920 mts.tree_bin[tree] = new_tree_bin; 921 mts->tree_bin[tree] = new_tree_bin;
921 } 922 }
922 923
923 // static 924 // static
924 void TileManager::PerformRaster(uint8* buffer, 925 void TileManager::PerformRaster(uint8* buffer,
925 const gfx::Rect& rect, 926 const gfx::Rect& rect,
926 float contents_scale, 927 float contents_scale,
927 bool use_cheapness_estimator, 928 bool use_cheapness_estimator,
928 const RasterTaskMetadata& raster_task_metadata, 929 const RasterTaskMetadata& raster_task_metadata,
929 PicturePileImpl* picture_pile, 930 PicturePileImpl* picture_pile,
930 RenderingStats* stats) { 931 RenderingStats* stats) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 decode_begin_time = base::TimeTicks::HighResNow(); 996 decode_begin_time = base::TimeTicks::HighResNow();
996 pixel_ref->Decode(); 997 pixel_ref->Decode();
997 if (stats) { 998 if (stats) {
998 stats->totalDeferredImageDecodeCount++; 999 stats->totalDeferredImageDecodeCount++;
999 stats->totalDeferredImageDecodeTime += 1000 stats->totalDeferredImageDecodeTime +=
1000 base::TimeTicks::HighResNow() - decode_begin_time; 1001 base::TimeTicks::HighResNow() - decode_begin_time;
1001 } 1002 }
1002 } 1003 }
1003 1004
1004 } // namespace cc 1005 } // 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