OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "cc/devtools_instrumentation.h" | 14 #include "cc/devtools_instrumentation.h" |
15 #include "cc/math_util.h" | |
16 #include "cc/platform_color.h" | 15 #include "cc/platform_color.h" |
17 #include "cc/raster_worker_pool.h" | 16 #include "cc/raster_worker_pool.h" |
18 #include "cc/resource_pool.h" | 17 #include "cc/resource_pool.h" |
19 #include "cc/tile.h" | 18 #include "cc/tile.h" |
20 #include "third_party/skia/include/core/SkDevice.h" | 19 #include "third_party/skia/include/core/SkDevice.h" |
21 | 20 |
22 namespace cc { | 21 namespace cc { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 case UPLOAD_STATE: | 137 case UPLOAD_STATE: |
139 return scoped_ptr<base::Value>(base::Value::CreateStringValue( | 138 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
140 "UPLOAD_STATE")); | 139 "UPLOAD_STATE")); |
141 default: | 140 default: |
142 DCHECK(false) << "Unrecognized TileRasterState value"; | 141 DCHECK(false) << "Unrecognized TileRasterState value"; |
143 return scoped_ptr<base::Value>(base::Value::CreateStringValue( | 142 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
144 "<unknown TileRasterState value>")); | 143 "<unknown TileRasterState value>")); |
145 } | 144 } |
146 } | 145 } |
147 | 146 |
148 ManagedTileState::ManagedTileState() | |
149 : can_use_gpu_memory(false), | |
150 can_be_freed(true), | |
151 resource_is_being_initialized(false), | |
152 contents_swizzled(false), | |
153 need_to_gather_pixel_refs(true), | |
154 gpu_memmgr_stats_bin(NEVER_BIN), | |
155 raster_state(IDLE_STATE), | |
156 resolution(NON_IDEAL_RESOLUTION), | |
157 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()), | |
158 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()), | |
159 picture_pile_analyzed(false) { | |
160 for (int i = 0; i < NUM_TREES; ++i) { | |
161 tree_bin[i] = NEVER_BIN; | |
162 bin[i] = NEVER_BIN; | |
163 } | |
164 } | |
165 | |
166 ManagedTileState::~ManagedTileState() { | |
167 DCHECK(!resource); | |
168 DCHECK(!resource_is_being_initialized); | |
169 } | |
170 | |
171 scoped_ptr<base::Value> ManagedTileState::AsValue() const { | |
172 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | |
173 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory); | |
174 state->SetBoolean("can_be_freed", can_be_freed); | |
175 state->SetBoolean("has_resource", resource.get() != 0); | |
176 state->SetBoolean("resource_is_being_initialized", resource_is_being_initializ
ed); | |
177 state->Set("raster_state", TileRasterStateAsValue(raster_state).release()); | |
178 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); | |
179 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release()); | |
180 state->Set("gpu_memmgr_stats_bin", TileManagerBinAsValue(bin[ACTIVE_TREE]).rel
ease()); | |
181 state->Set("resolution", TileResolutionAsValue(resolution).release()); | |
182 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed
_in_seconds).release()); | |
183 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t
o_visible_in_pixels).release()); | |
184 state->SetBoolean("is_picture_pile_analyzed", picture_pile_analyzed); | |
185 state->SetBoolean("is_cheap_to_raster", picture_pile_analysis.is_cheap_to_rast
er); | |
186 state->SetBoolean("is_transparent", picture_pile_analysis.is_transparent); | |
187 state->SetBoolean("is_solid_color", picture_pile_analysis.is_solid_color); | |
188 return state.PassAs<base::Value>(); | |
189 } | |
190 | |
191 TileManager::TileManager( | 147 TileManager::TileManager( |
192 TileManagerClient* client, | 148 TileManagerClient* client, |
193 ResourceProvider* resource_provider, | 149 ResourceProvider* resource_provider, |
194 size_t num_raster_threads, | 150 size_t num_raster_threads, |
195 bool use_cheapness_estimator, | 151 bool use_cheapness_estimator, |
196 bool use_color_estimator, | 152 bool use_color_estimator, |
197 bool prediction_benchmarking) | 153 bool prediction_benchmarking) |
198 : client_(client), | 154 : client_(client), |
199 resource_pool_(ResourcePool::Create(resource_provider)), | 155 resource_pool_(ResourcePool::Create(resource_provider)), |
200 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), | 156 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 DidTileTreeBinChange(tile, | 341 DidTileTreeBinChange(tile, |
386 bin_map[BinFromTilePriority(tile->priority(ACTIVE_TREE))], | 342 bin_map[BinFromTilePriority(tile->priority(ACTIVE_TREE))], |
387 ACTIVE_TREE); | 343 ACTIVE_TREE); |
388 DidTileTreeBinChange(tile, | 344 DidTileTreeBinChange(tile, |
389 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))], | 345 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))], |
390 PENDING_TREE); | 346 PENDING_TREE); |
391 | 347 |
392 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) | 348 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) |
393 mts.bin[i] = bin_map[mts.bin[i]]; | 349 mts.bin[i] = bin_map[mts.bin[i]]; |
394 | 350 |
395 if (!tile->managed_state().resource && | 351 if (!mts.drawing_info.resource_ && |
396 !tile->managed_state().resource_is_being_initialized && | 352 !mts.drawing_info.resource_is_being_initialized_ && |
397 !tile->priority(ACTIVE_TREE).is_live && | 353 !tile->priority(ACTIVE_TREE).is_live && |
398 !tile->priority(PENDING_TREE).is_live) | 354 !tile->priority(PENDING_TREE).is_live) |
399 continue; | 355 continue; |
400 | 356 |
401 live_or_allocated_tiles_.push_back(tile); | 357 live_or_allocated_tiles_.push_back(tile); |
402 } | 358 } |
403 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, | 359 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, |
404 live_or_allocated_tiles_.size()); | 360 live_or_allocated_tiles_.size()); |
405 | 361 |
406 SortTiles(); | 362 SortTiles(); |
407 | 363 |
408 // Assign gpu memory and determine what tiles need to be rasterized. | 364 // Assign gpu memory and determine what tiles need to be rasterized. |
409 AssignGpuMemoryToTiles(); | 365 AssignGpuMemoryToTiles(); |
410 | 366 |
411 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", | 367 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", |
412 ValueToString(BasicStateAsValue())); | 368 ValueToString(BasicStateAsValue())); |
413 | 369 |
414 // Finally, kick the rasterizer. | 370 // Finally, kick the rasterizer. |
415 DispatchMoreTasks(); | 371 DispatchMoreTasks(); |
416 } | 372 } |
417 | 373 |
418 void TileManager::CheckForCompletedTileUploads() { | 374 void TileManager::CheckForCompletedTileUploads() { |
419 while (!tiles_with_pending_upload_.empty()) { | 375 while (!tiles_with_pending_upload_.empty()) { |
420 Tile* tile = tiles_with_pending_upload_.front(); | 376 Tile* tile = tiles_with_pending_upload_.front(); |
421 DCHECK(tile->managed_state().resource); | 377 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 378 DCHECK(managed_tile_state.drawing_info.resource_); |
422 | 379 |
423 // Set pixel tasks complete in the order they are posted. | 380 // Set pixel tasks complete in the order they are posted. |
424 if (!resource_pool_->resource_provider()->DidSetPixelsComplete( | 381 if (!resource_pool_->resource_provider()->DidSetPixelsComplete( |
425 tile->managed_state().resource->id())) { | 382 managed_tile_state.drawing_info.resource_->id())) { |
426 break; | 383 break; |
427 } | 384 } |
428 | 385 |
429 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && | 386 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && |
430 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) | 387 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) |
431 client_->DidUploadVisibleHighResolutionTile(); | 388 client_->DidUploadVisibleHighResolutionTile(); |
432 | 389 |
433 // It's now safe to release the pixel buffer. | 390 // It's now safe to release the pixel buffer. |
434 resource_pool_->resource_provider()->ReleasePixelBuffer( | 391 resource_pool_->resource_provider()->ReleasePixelBuffer( |
435 tile->managed_state().resource->id()); | 392 managed_tile_state.drawing_info.resource_->id()); |
436 | 393 |
437 DidFinishTileInitialization(tile); | 394 DidFinishTileInitialization(tile); |
438 | 395 |
439 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); | 396 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); |
440 DidTileRasterStateChange(tile, IDLE_STATE); | 397 DidTileRasterStateChange(tile, IDLE_STATE); |
441 tiles_with_pending_upload_.pop(); | 398 tiles_with_pending_upload_.pop(); |
442 } | 399 } |
443 | 400 |
444 DispatchMoreTasks(); | 401 DispatchMoreTasks(); |
445 } | 402 } |
446 | 403 |
447 void TileManager::AbortPendingTileUploads() { | 404 void TileManager::AbortPendingTileUploads() { |
448 while (!tiles_with_pending_upload_.empty()) { | 405 while (!tiles_with_pending_upload_.empty()) { |
449 Tile* tile = tiles_with_pending_upload_.front(); | 406 Tile* tile = tiles_with_pending_upload_.front(); |
450 ManagedTileState& managed_tile_state = tile->managed_state(); | 407 ManagedTileState& managed_tile_state = tile->managed_state(); |
451 DCHECK(managed_tile_state.resource); | 408 DCHECK(managed_tile_state.drawing_info.resource_); |
452 | 409 |
453 resource_pool_->resource_provider()->AbortSetPixels( | 410 resource_pool_->resource_provider()->AbortSetPixels( |
454 managed_tile_state.resource->id()); | 411 managed_tile_state.drawing_info.resource_->id()); |
455 resource_pool_->resource_provider()->ReleasePixelBuffer( | 412 resource_pool_->resource_provider()->ReleasePixelBuffer( |
456 managed_tile_state.resource->id()); | 413 managed_tile_state.drawing_info.resource_->id()); |
457 | 414 |
458 managed_tile_state.resource_is_being_initialized = false; | 415 managed_tile_state.drawing_info.resource_is_being_initialized_ = false; |
459 managed_tile_state.can_be_freed = true; | 416 managed_tile_state.drawing_info.can_be_freed_ = true; |
460 managed_tile_state.can_use_gpu_memory = false; | 417 managed_tile_state.can_use_gpu_memory = false; |
461 FreeResourcesForTile(tile); | 418 FreeResourcesForTile(tile); |
462 | 419 |
463 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); | 420 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); |
464 DidTileRasterStateChange(tile, IDLE_STATE); | 421 DidTileRasterStateChange(tile, IDLE_STATE); |
465 tiles_with_pending_upload_.pop(); | 422 tiles_with_pending_upload_.pop(); |
466 } | 423 } |
467 } | 424 } |
468 | 425 |
469 void TileManager::DidCompleteFrame() { | 426 void TileManager::DidCompleteFrame() { |
470 allow_cheap_tasks_ = true; | 427 allow_cheap_tasks_ = true; |
471 did_schedule_cheap_tasks_ = false; | 428 did_schedule_cheap_tasks_ = false; |
472 } | 429 } |
473 | 430 |
474 void TileManager::GetMemoryStats( | 431 void TileManager::GetMemoryStats( |
475 size_t* memoryRequiredBytes, | 432 size_t* memoryRequiredBytes, |
476 size_t* memoryNiceToHaveBytes, | 433 size_t* memoryNiceToHaveBytes, |
477 size_t* memoryUsedBytes) const { | 434 size_t* memoryUsedBytes) const { |
478 *memoryRequiredBytes = 0; | 435 *memoryRequiredBytes = 0; |
479 *memoryNiceToHaveBytes = 0; | 436 *memoryNiceToHaveBytes = 0; |
480 *memoryUsedBytes = 0; | 437 *memoryUsedBytes = 0; |
481 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { | 438 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { |
482 const Tile* tile = live_or_allocated_tiles_[i]; | 439 const Tile* tile = live_or_allocated_tiles_[i]; |
483 const ManagedTileState& mts = tile->managed_state(); | 440 const ManagedTileState& mts = tile->managed_state(); |
484 if (tile->is_transparent() || tile->is_solid_color()) | 441 if (!tile->drawing_info().requires_resource()) |
485 continue; | 442 continue; |
486 | 443 |
487 size_t tile_bytes = tile->bytes_consumed_if_allocated(); | 444 size_t tile_bytes = tile->bytes_consumed_if_allocated(); |
488 if (mts.gpu_memmgr_stats_bin == NOW_BIN) | 445 if (mts.gpu_memmgr_stats_bin == NOW_BIN) |
489 *memoryRequiredBytes += tile_bytes; | 446 *memoryRequiredBytes += tile_bytes; |
490 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) | 447 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) |
491 *memoryNiceToHaveBytes += tile_bytes; | 448 *memoryNiceToHaveBytes += tile_bytes; |
492 if (mts.can_use_gpu_memory) | 449 if (mts.can_use_gpu_memory) |
493 *memoryUsedBytes += tile_bytes; | 450 *memoryUsedBytes += tile_bytes; |
494 } | 451 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // By clearing the tiles_that_need_to_be_rasterized_ vector and | 554 // By clearing the tiles_that_need_to_be_rasterized_ vector and |
598 // tiles_with_image_decoding_tasks_ list above we move all tiles | 555 // tiles_with_image_decoding_tasks_ list above we move all tiles |
599 // currently waiting for raster to idle state. | 556 // currently waiting for raster to idle state. |
600 // Call DidTileRasterStateChange() for each of these tiles to | 557 // Call DidTileRasterStateChange() for each of these tiles to |
601 // have this state change take effect. | 558 // have this state change take effect. |
602 // Some memory cannot be released. We figure out how much in this | 559 // Some memory cannot be released. We figure out how much in this |
603 // loop as well. | 560 // loop as well. |
604 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); | 561 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); |
605 it != live_or_allocated_tiles_.end(); ++it) { | 562 it != live_or_allocated_tiles_.end(); ++it) { |
606 Tile* tile = *it; | 563 Tile* tile = *it; |
607 if (tile->is_solid_color() || tile->is_transparent()) | 564 ManagedTileState& mts = tile->managed_state(); |
| 565 if (!tile->drawing_info().requires_resource()) |
608 continue; | 566 continue; |
609 | 567 |
610 ManagedTileState& managed_tile_state = tile->managed_state(); | 568 if (!mts.drawing_info.can_be_freed_) |
611 if (!managed_tile_state.can_be_freed) | |
612 unreleasable_bytes += tile->bytes_consumed_if_allocated(); | 569 unreleasable_bytes += tile->bytes_consumed_if_allocated(); |
613 if (managed_tile_state.raster_state == WAITING_FOR_RASTER_STATE) | 570 if (mts.raster_state == WAITING_FOR_RASTER_STATE) |
614 DidTileRasterStateChange(tile, IDLE_STATE); | 571 DidTileRasterStateChange(tile, IDLE_STATE); |
615 } | 572 } |
616 | 573 |
617 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_
bytes; | 574 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_
bytes; |
618 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0; | 575 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0; |
619 size_t bytes_left = bytes_allocatable; | 576 size_t bytes_left = bytes_allocatable; |
620 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or
_allocated_tiles_.end(); ++it) { | 577 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or
_allocated_tiles_.end(); ++it) { |
621 Tile* tile = *it; | 578 Tile* tile = *it; |
622 if (tile->is_solid_color() || tile->is_transparent()) | 579 ManagedTileState& mts = tile->managed_state(); |
| 580 if (!tile->drawing_info().requires_resource()) |
623 continue; | 581 continue; |
624 | 582 |
625 ManagedTileState& managed_tile_state = tile->managed_state(); | |
626 size_t tile_bytes = tile->bytes_consumed_if_allocated(); | 583 size_t tile_bytes = tile->bytes_consumed_if_allocated(); |
627 if (!managed_tile_state.can_be_freed) | 584 if (!mts.drawing_info.can_be_freed_) |
628 continue; | 585 continue; |
629 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && | 586 if (mts.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && |
630 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { | 587 mts.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { |
631 managed_tile_state.can_use_gpu_memory = false; | 588 mts.can_use_gpu_memory = false; |
632 FreeResourcesForTile(tile); | 589 FreeResourcesForTile(tile); |
633 continue; | 590 continue; |
634 } | 591 } |
635 if (tile_bytes > bytes_left) { | 592 if (tile_bytes > bytes_left) { |
636 managed_tile_state.can_use_gpu_memory = false; | 593 mts.can_use_gpu_memory = false; |
637 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NOW_BIN || | 594 if (mts.bin[HIGH_PRIORITY_BIN] == NOW_BIN || |
638 managed_tile_state.bin[LOW_PRIORITY_BIN] == NOW_BIN) | 595 mts.bin[LOW_PRIORITY_BIN] == NOW_BIN) |
639 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; | 596 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; |
640 FreeResourcesForTile(tile); | 597 FreeResourcesForTile(tile); |
641 continue; | 598 continue; |
642 } | 599 } |
643 bytes_left -= tile_bytes; | 600 bytes_left -= tile_bytes; |
644 managed_tile_state.can_use_gpu_memory = true; | 601 mts.can_use_gpu_memory = true; |
645 if (!managed_tile_state.resource && | 602 if (!mts.drawing_info.resource_ && |
646 !managed_tile_state.resource_is_being_initialized) { | 603 !mts.drawing_info.resource_is_being_initialized_) { |
647 tiles_that_need_to_be_rasterized_.push_back(tile); | 604 tiles_that_need_to_be_rasterized_.push_back(tile); |
648 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE); | 605 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE); |
649 } | 606 } |
650 } | 607 } |
651 | 608 |
652 ever_exceeded_memory_budget_ |= | 609 ever_exceeded_memory_budget_ |= |
653 bytes_that_exceeded_memory_budget_in_now_bin > 0; | 610 bytes_that_exceeded_memory_budget_in_now_bin > 0; |
654 if (ever_exceeded_memory_budget_) { | 611 if (ever_exceeded_memory_budget_) { |
655 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, | 612 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, |
656 "budget", global_state_.memory_limit_in_bytes, | 613 "budget", global_state_.memory_limit_in_bytes, |
657 "over", bytes_that_exceeded_memory_budget_in_now_bin); | 614 "over", bytes_that_exceeded_memory_budget_in_now_bin); |
658 } | 615 } |
659 memory_stats_from_last_assign_.total_budget_in_bytes = | 616 memory_stats_from_last_assign_.total_budget_in_bytes = |
660 global_state_.memory_limit_in_bytes; | 617 global_state_.memory_limit_in_bytes; |
661 memory_stats_from_last_assign_.bytes_allocated = | 618 memory_stats_from_last_assign_.bytes_allocated = |
662 bytes_allocatable - bytes_left; | 619 bytes_allocatable - bytes_left; |
663 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; | 620 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; |
664 memory_stats_from_last_assign_.bytes_over = | 621 memory_stats_from_last_assign_.bytes_over = |
665 bytes_that_exceeded_memory_budget_in_now_bin; | 622 bytes_that_exceeded_memory_budget_in_now_bin; |
666 | 623 |
667 // Reverse two tiles_that_need_* vectors such that pop_back gets | 624 // Reverse two tiles_that_need_* vectors such that pop_back gets |
668 // the highest priority tile. | 625 // the highest priority tile. |
669 std::reverse( | 626 std::reverse( |
670 tiles_that_need_to_be_rasterized_.begin(), | 627 tiles_that_need_to_be_rasterized_.begin(), |
671 tiles_that_need_to_be_rasterized_.end()); | 628 tiles_that_need_to_be_rasterized_.end()); |
672 } | 629 } |
673 | 630 |
674 void TileManager::FreeResourcesForTile(Tile* tile) { | 631 void TileManager::FreeResourcesForTile(Tile* tile) { |
675 ManagedTileState& managed_tile_state = tile->managed_state(); | 632 ManagedTileState& managed_tile_state = tile->managed_state(); |
676 DCHECK(managed_tile_state.can_be_freed); | 633 DCHECK(managed_tile_state.drawing_info.can_be_freed_); |
677 if (managed_tile_state.resource) | 634 if (managed_tile_state.drawing_info.resource_) |
678 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); | 635 resource_pool_->ReleaseResource( |
| 636 managed_tile_state.drawing_info.resource_.Pass()); |
679 } | 637 } |
680 | 638 |
681 bool TileManager::CanDispatchRasterTask(Tile* tile) const { | 639 bool TileManager::CanDispatchRasterTask(Tile* tile) const { |
682 if (pending_tasks_ >= max_pending_tasks_) | 640 if (pending_tasks_ >= max_pending_tasks_) |
683 return false; | 641 return false; |
684 size_t new_bytes_pending = bytes_pending_upload_; | 642 size_t new_bytes_pending = bytes_pending_upload_; |
685 new_bytes_pending += tile->bytes_consumed_if_allocated(); | 643 new_bytes_pending += tile->bytes_consumed_if_allocated(); |
686 return new_bytes_pending <= kMaxPendingUploadBytes && | 644 return new_bytes_pending <= kMaxPendingUploadBytes && |
687 tiles_with_pending_upload_.size() < kMaxPendingUploads; | 645 tiles_with_pending_upload_.size() < kMaxPendingUploads; |
688 } | 646 } |
(...skipping 19 matching lines...) Expand all Loading... |
708 ++it; | 666 ++it; |
709 } | 667 } |
710 } | 668 } |
711 | 669 |
712 // Process all tiles in the need_to_be_rasterized queue. If a tile is | 670 // Process all tiles in the need_to_be_rasterized queue. If a tile is |
713 // solid/transparent, then we are done (we don't need to rasterize | 671 // solid/transparent, then we are done (we don't need to rasterize |
714 // the tile). If a tile has image decoding tasks, put it to the back | 672 // the tile). If a tile has image decoding tasks, put it to the back |
715 // of the image decoding list. | 673 // of the image decoding list. |
716 while (!tiles_that_need_to_be_rasterized_.empty()) { | 674 while (!tiles_that_need_to_be_rasterized_.empty()) { |
717 Tile* tile = tiles_that_need_to_be_rasterized_.back(); | 675 Tile* tile = tiles_that_need_to_be_rasterized_.back(); |
718 ManagedTileState& managed_tile_state = tile->managed_state(); | 676 ManagedTileState& mts = tile->managed_state(); |
719 | 677 |
720 AnalyzeTile(tile); | 678 AnalyzeTile(tile); |
721 if (tile->is_solid_color() || tile->is_transparent()) { | 679 if (!tile->drawing_info().requires_resource()) { |
722 DidTileRasterStateChange(tile, IDLE_STATE); | 680 DidTileRasterStateChange(tile, IDLE_STATE); |
723 tiles_that_need_to_be_rasterized_.pop_back(); | 681 tiles_that_need_to_be_rasterized_.pop_back(); |
724 continue; | 682 continue; |
725 } | 683 } |
726 | 684 |
727 DispatchImageDecodeTasksForTile(tile); | 685 DispatchImageDecodeTasksForTile(tile); |
728 if (!managed_tile_state.pending_pixel_refs.empty()) { | 686 if (!mts.pending_pixel_refs.empty()) { |
729 tiles_with_image_decoding_tasks_.push_back(tile); | 687 tiles_with_image_decoding_tasks_.push_back(tile); |
730 } else { | 688 } else { |
731 if (!CanDispatchRasterTask(tile)) | 689 if (!CanDispatchRasterTask(tile)) |
732 return; | 690 return; |
733 DispatchOneRasterTask(tile); | 691 DispatchOneRasterTask(tile); |
734 } | 692 } |
735 tiles_that_need_to_be_rasterized_.pop_back(); | 693 tiles_that_need_to_be_rasterized_.pop_back(); |
736 } | 694 } |
737 } | 695 } |
738 | 696 |
739 void TileManager::AnalyzeTile(Tile* tile) { | 697 void TileManager::AnalyzeTile(Tile* tile) { |
740 ManagedTileState& managed_tile_state = tile->managed_state(); | 698 ManagedTileState& managed_tile_state = tile->managed_state(); |
741 if ((use_cheapness_estimator_ || use_color_estimator_) && | 699 if ((use_cheapness_estimator_ || use_color_estimator_) && |
742 !managed_tile_state.picture_pile_analyzed) { | 700 !managed_tile_state.picture_pile_analyzed) { |
743 tile->picture_pile()->AnalyzeInRect( | 701 tile->picture_pile()->AnalyzeInRect( |
744 tile->content_rect(), | 702 tile->content_rect(), |
745 tile->contents_scale(), | 703 tile->contents_scale(), |
746 &managed_tile_state.picture_pile_analysis); | 704 &managed_tile_state.picture_pile_analysis); |
747 managed_tile_state.picture_pile_analysis.is_cheap_to_raster &= | 705 managed_tile_state.picture_pile_analysis.is_cheap_to_raster &= |
748 use_cheapness_estimator_; | 706 use_cheapness_estimator_; |
749 managed_tile_state.picture_pile_analysis.is_solid_color &= | 707 managed_tile_state.picture_pile_analysis.is_solid_color &= |
750 use_color_estimator_; | 708 use_color_estimator_; |
751 managed_tile_state.picture_pile_analysis.is_transparent &= | 709 managed_tile_state.picture_pile_analysis.is_transparent &= |
752 use_color_estimator_; | 710 use_color_estimator_; |
753 managed_tile_state.picture_pile_analyzed = true; | 711 managed_tile_state.picture_pile_analyzed = true; |
| 712 |
| 713 if (managed_tile_state.picture_pile_analysis.is_solid_color) |
| 714 tile->drawing_info().set_solid_color( |
| 715 managed_tile_state.picture_pile_analysis.solid_color); |
| 716 else if (managed_tile_state.picture_pile_analysis.is_transparent) |
| 717 tile->drawing_info().set_transparent(); |
754 } | 718 } |
755 } | 719 } |
756 | 720 |
757 void TileManager::GatherPixelRefsForTile(Tile* tile) { | 721 void TileManager::GatherPixelRefsForTile(Tile* tile) { |
758 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); | 722 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); |
759 ManagedTileState& managed_tile_state = tile->managed_state(); | 723 ManagedTileState& managed_tile_state = tile->managed_state(); |
760 if (managed_tile_state.need_to_gather_pixel_refs) { | 724 if (managed_tile_state.need_to_gather_pixel_refs) { |
761 base::TimeTicks gather_begin_time; | 725 base::TimeTicks gather_begin_time; |
762 if (record_rendering_stats_) | 726 if (record_rendering_stats_) |
763 gather_begin_time = base::TimeTicks::HighResNow(); | 727 gather_begin_time = base::TimeTicks::HighResNow(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 } | 800 } |
837 | 801 |
838 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( | 802 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( |
839 Tile* tile) { | 803 Tile* tile) { |
840 ManagedTileState& managed_tile_state = tile->managed_state(); | 804 ManagedTileState& managed_tile_state = tile->managed_state(); |
841 DCHECK(managed_tile_state.can_use_gpu_memory); | 805 DCHECK(managed_tile_state.can_use_gpu_memory); |
842 scoped_ptr<ResourcePool::Resource> resource = | 806 scoped_ptr<ResourcePool::Resource> resource = |
843 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); | 807 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); |
844 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); | 808 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); |
845 | 809 |
846 managed_tile_state.resource_is_being_initialized = true; | 810 managed_tile_state.drawing_info.resource_is_being_initialized_ = true; |
847 managed_tile_state.can_be_freed = false; | 811 managed_tile_state.drawing_info.can_be_freed_ = false; |
848 | 812 |
849 DidTileRasterStateChange(tile, RASTER_STATE); | 813 DidTileRasterStateChange(tile, RASTER_STATE); |
850 return resource.Pass(); | 814 return resource.Pass(); |
851 } | 815 } |
852 | 816 |
853 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { | 817 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { |
854 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); | 818 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); |
855 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 819 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
856 ResourceProvider::ResourceId resource_id = resource->id(); | 820 ResourceProvider::ResourceId resource_id = resource->id(); |
857 uint8* buffer = | 821 uint8* buffer = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 scoped_ptr<ResourcePool::Resource> resource, | 867 scoped_ptr<ResourcePool::Resource> resource, |
904 int manage_tiles_call_count_when_dispatched) { | 868 int manage_tiles_call_count_when_dispatched) { |
905 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); | 869 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); |
906 | 870 |
907 pending_tasks_--; | 871 pending_tasks_--; |
908 | 872 |
909 // Release raster resources. | 873 // Release raster resources. |
910 resource_pool_->resource_provider()->UnmapPixelBuffer(resource->id()); | 874 resource_pool_->resource_provider()->UnmapPixelBuffer(resource->id()); |
911 | 875 |
912 ManagedTileState& managed_tile_state = tile->managed_state(); | 876 ManagedTileState& managed_tile_state = tile->managed_state(); |
913 managed_tile_state.can_be_freed = true; | 877 managed_tile_state.drawing_info.can_be_freed_ = true; |
914 | 878 |
915 // Tile can be freed after the completion of the raster task. Call | 879 // Tile can be freed after the completion of the raster task. Call |
916 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority | 880 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority |
917 // tiles if ManageTiles() was called since task was dispatched. The result | 881 // tiles if ManageTiles() was called since task was dispatched. The result |
918 // of this could be that this tile is no longer allowed to use gpu | 882 // of this could be that this tile is no longer allowed to use gpu |
919 // memory and in that case we need to abort initialization and free all | 883 // memory and in that case we need to abort initialization and free all |
920 // associated resources before calling DispatchMoreTasks(). | 884 // associated resources before calling DispatchMoreTasks(). |
921 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) | 885 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) |
922 AssignGpuMemoryToTiles(); | 886 AssignGpuMemoryToTiles(); |
923 | 887 |
924 // Finish resource initialization if |can_use_gpu_memory| is true. | 888 // Finish resource initialization if |can_use_gpu_memory| is true. |
925 if (managed_tile_state.can_use_gpu_memory) { | 889 if (managed_tile_state.can_use_gpu_memory) { |
926 // The component order may be bgra if we're uploading bgra pixels to rgba | 890 // The component order may be bgra if we're uploading bgra pixels to rgba |
927 // texture. Mark contents as swizzled if image component order is | 891 // texture. Mark contents as swizzled if image component order is |
928 // different than texture format. | 892 // different than texture format. |
929 managed_tile_state.contents_swizzled = | 893 managed_tile_state.drawing_info.contents_swizzled_ = |
930 !PlatformColor::sameComponentOrder(tile->format_); | 894 !PlatformColor::sameComponentOrder(tile->format_); |
931 | 895 |
932 // Tile resources can't be freed until upload has completed. | 896 // Tile resources can't be freed until upload has completed. |
933 managed_tile_state.can_be_freed = false; | 897 managed_tile_state.drawing_info.can_be_freed_ = false; |
934 | 898 |
935 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); | 899 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); |
936 has_performed_uploads_since_last_flush_ = true; | 900 has_performed_uploads_since_last_flush_ = true; |
937 | 901 |
938 managed_tile_state.resource = resource.Pass(); | 902 managed_tile_state.drawing_info.resource_ = resource.Pass(); |
939 | 903 |
940 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); | 904 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); |
941 DidTileRasterStateChange(tile, UPLOAD_STATE); | 905 DidTileRasterStateChange(tile, UPLOAD_STATE); |
942 tiles_with_pending_upload_.push(tile); | 906 tiles_with_pending_upload_.push(tile); |
943 } else { | 907 } else { |
944 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id()); | 908 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id()); |
945 resource_pool_->ReleaseResource(resource.Pass()); | 909 resource_pool_->ReleaseResource(resource.Pass()); |
946 managed_tile_state.resource_is_being_initialized = false; | 910 managed_tile_state.drawing_info.resource_is_being_initialized_ = false; |
947 DidTileRasterStateChange(tile, IDLE_STATE); | 911 DidTileRasterStateChange(tile, IDLE_STATE); |
948 } | 912 } |
949 } | 913 } |
950 | 914 |
951 void TileManager::DidFinishTileInitialization(Tile* tile) { | 915 void TileManager::DidFinishTileInitialization(Tile* tile) { |
952 ManagedTileState& managed_tile_state = tile->managed_state(); | 916 ManagedTileState& managed_state = tile->managed_state(); |
953 DCHECK(managed_tile_state.resource); | 917 DCHECK(managed_state.drawing_info.resource_); |
954 managed_tile_state.resource_is_being_initialized = false; | 918 managed_state.drawing_info.resource_is_being_initialized_ = false; |
955 managed_tile_state.can_be_freed = true; | 919 managed_state.drawing_info.can_be_freed_ = true; |
956 } | 920 } |
957 | 921 |
958 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { | 922 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { |
959 ManagedTileState& mts = tile->managed_state(); | 923 ManagedTileState& mts = tile->managed_state(); |
960 DCHECK_LT(state, NUM_STATES); | 924 DCHECK_LT(state, NUM_STATES); |
961 | 925 |
962 for (int i = 0; i < NUM_TREES; ++i) { | 926 for (int i = 0; i < NUM_TREES; ++i) { |
963 // Decrement count for current state. | 927 // Decrement count for current state. |
964 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 928 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
965 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); | 929 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 decode_begin_time = base::TimeTicks::HighResNow(); | 1090 decode_begin_time = base::TimeTicks::HighResNow(); |
1127 pixel_ref->Decode(); | 1091 pixel_ref->Decode(); |
1128 if (stats) { | 1092 if (stats) { |
1129 stats->totalDeferredImageDecodeCount++; | 1093 stats->totalDeferredImageDecodeCount++; |
1130 stats->totalDeferredImageDecodeTime += | 1094 stats->totalDeferredImageDecodeTime += |
1131 base::TimeTicks::HighResNow() - decode_begin_time; | 1095 base::TimeTicks::HighResNow() - decode_begin_time; |
1132 } | 1096 } |
1133 } | 1097 } |
1134 | 1098 |
1135 } // namespace cc | 1099 } // namespace cc |
OLD | NEW |