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

Side by Side Diff: cc/tile_manager.cc

Issue 12353003: cc: Refactored Tile::GetResourceId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more changes Created 7 years, 9 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
« cc/tile_manager.h ('K') | « 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 "UPLOAD_STATE")); 130 "UPLOAD_STATE"));
131 default: 131 default:
132 DCHECK(false) << "Unrecognized TileRasterState value"; 132 DCHECK(false) << "Unrecognized TileRasterState value";
133 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 133 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
134 "<unknown TileRasterState value>")); 134 "<unknown TileRasterState value>"));
135 } 135 }
136 } 136 }
137 137
138 ManagedTileState::ManagedTileState() 138 ManagedTileState::ManagedTileState()
139 : can_use_gpu_memory(false), 139 : can_use_gpu_memory(false),
140 can_be_freed(true),
141 resource_is_being_initialized(false),
142 contents_swizzled(false),
143 need_to_gather_pixel_refs(true), 140 need_to_gather_pixel_refs(true),
144 gpu_memmgr_stats_bin(NEVER_BIN), 141 gpu_memmgr_stats_bin(NEVER_BIN),
145 raster_state(IDLE_STATE), 142 raster_state(IDLE_STATE),
146 resolution(NON_IDEAL_RESOLUTION), 143 resolution(NON_IDEAL_RESOLUTION),
147 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()), 144 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()),
148 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) { 145 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) {
149 for (int i = 0; i < NUM_TREES; ++i) { 146 for (int i = 0; i < NUM_TREES; ++i) {
150 tree_bin[i] = NEVER_BIN; 147 tree_bin[i] = NEVER_BIN;
151 bin[i] = NEVER_BIN; 148 bin[i] = NEVER_BIN;
152 } 149 }
153 } 150 }
154 151
155 ManagedTileState::~ManagedTileState() { 152 ManagedTileState::~ManagedTileState() {
156 DCHECK(!resource);
157 DCHECK(!resource_is_being_initialized);
158 } 153 }
159 154
160 scoped_ptr<base::Value> ManagedTileState::AsValue() const { 155 scoped_ptr<base::Value> ManagedTileState::AsValue() const {
161 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 156 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
162 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory); 157 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory);
163 state->SetBoolean("can_be_freed", can_be_freed);
164 state->SetBoolean("has_resource", resource.get() != 0);
165 state->SetBoolean("resource_is_being_initialized", resource_is_being_initializ ed);
166 state->Set("raster_state", TileRasterStateAsValue(raster_state).release()); 158 state->Set("raster_state", TileRasterStateAsValue(raster_state).release());
167 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); 159 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release());
168 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release()); 160 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release());
169 state->Set("gpu_memmgr_stats_bin", TileManagerBinAsValue(bin[ACTIVE_TREE]).rel ease()); 161 state->Set("gpu_memmgr_stats_bin", TileManagerBinAsValue(bin[ACTIVE_TREE]).rel ease());
170 state->Set("resolution", TileResolutionAsValue(resolution).release()); 162 state->Set("resolution", TileResolutionAsValue(resolution).release());
171 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed _in_seconds).release()); 163 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed _in_seconds).release());
172 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t o_visible_in_pixels).release()); 164 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t o_visible_in_pixels).release());
173 return state.PassAs<base::Value>(); 165 return state.PassAs<base::Value>();
174 } 166 }
175 167
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 ACTIVE_TREE); 358 ACTIVE_TREE);
367 DidTileTreeBinChange(tile, 359 DidTileTreeBinChange(tile,
368 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))], 360 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))],
369 PENDING_TREE); 361 PENDING_TREE);
370 362
371 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) 363 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i)
372 mts.bin[i] = bin_map[mts.bin[i]]; 364 mts.bin[i] = bin_map[mts.bin[i]];
373 365
374 if (tile->priority(ACTIVE_TREE).is_live || 366 if (tile->priority(ACTIVE_TREE).is_live ||
375 tile->priority(PENDING_TREE).is_live || 367 tile->priority(PENDING_TREE).is_live ||
376 tile->managed_state().resource || 368 tile->drawing_info().resource_ ||
377 tile->managed_state().resource_is_being_initialized) { 369 tile->drawing_info().initializing_resource_) {
378 live_or_allocated_tiles_.push_back(tile); 370 live_or_allocated_tiles_.push_back(tile);
379 } 371 }
380 } 372 }
381 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, 373 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this,
382 live_or_allocated_tiles_.size()); 374 live_or_allocated_tiles_.size());
383 375
384 SortTiles(); 376 SortTiles();
385 377
386 // Assign gpu memory and determine what tiles need to be rasterized. 378 // Assign gpu memory and determine what tiles need to be rasterized.
387 AssignGpuMemoryToTiles(); 379 AssignGpuMemoryToTiles();
388 380
389 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", 381 TRACE_EVENT_INSTANT1("cc", "DidManage", "state",
390 ValueToString(BasicStateAsValue())); 382 ValueToString(BasicStateAsValue()));
391 383
392 // Finally, kick the rasterizer. 384 // Finally, kick the rasterizer.
393 DispatchMoreTasks(); 385 DispatchMoreTasks();
394 } 386 }
395 387
396 void TileManager::CheckForCompletedTileUploads() { 388 void TileManager::CheckForCompletedTileUploads() {
397 while (!tiles_with_pending_upload_.empty()) { 389 while (!tiles_with_pending_upload_.empty()) {
398 Tile* tile = tiles_with_pending_upload_.front(); 390 Tile* tile = tiles_with_pending_upload_.front();
399 DCHECK(tile->managed_state().resource); 391 TileDrawingInfo& drawing_info = tile->drawing_info();
392 DCHECK(drawing_info.resource_);
400 393
401 // Set pixel tasks complete in the order they are posted. 394 // Set pixel tasks complete in the order they are posted.
402 if (!resource_pool_->resource_provider()->didSetPixelsComplete( 395 if (!resource_pool_->resource_provider()->didSetPixelsComplete(
403 tile->managed_state().resource->id())) { 396 drawing_info.resource_->id())) {
404 break; 397 break;
405 } 398 }
406 399
407 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && 400 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 &&
408 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) 401 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION)
409 client_->DidUploadVisibleHighResolutionTile(); 402 client_->DidUploadVisibleHighResolutionTile();
410 403
411 // It's now safe to release the pixel buffer. 404 // It's now safe to release the pixel buffer.
412 resource_pool_->resource_provider()->releasePixelBuffer( 405 resource_pool_->resource_provider()->releasePixelBuffer(
413 tile->managed_state().resource->id()); 406 drawing_info.resource_->id());
414 407
415 DidFinishTileInitialization(tile); 408 DidFinishTileInitialization(tile);
416 409
417 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); 410 bytes_pending_upload_ -= tile->bytes_consumed_if_texture_allocated();
418 DidTileRasterStateChange(tile, IDLE_STATE); 411 DidTileRasterStateChange(tile, IDLE_STATE);
419 tiles_with_pending_upload_.pop(); 412 tiles_with_pending_upload_.pop();
420 } 413 }
421 414
422 DispatchMoreTasks(); 415 DispatchMoreTasks();
423 } 416 }
424 417
425 void TileManager::AbortPendingTileUploads() { 418 void TileManager::AbortPendingTileUploads() {
426 while (!tiles_with_pending_upload_.empty()) { 419 while (!tiles_with_pending_upload_.empty()) {
427 Tile* tile = tiles_with_pending_upload_.front(); 420 Tile* tile = tiles_with_pending_upload_.front();
428 ManagedTileState& managed_tile_state = tile->managed_state(); 421 ManagedTileState& managed_tile_state = tile->managed_state();
429 DCHECK(managed_tile_state.resource); 422 TileDrawingInfo& drawing_info = tile->drawing_info();
423 DCHECK(drawing_info.resource_);
430 424
431 resource_pool_->resource_provider()->abortSetPixels( 425 resource_pool_->resource_provider()->abortSetPixels(
432 managed_tile_state.resource->id()); 426 drawing_info.resource_->id());
433 resource_pool_->resource_provider()->releasePixelBuffer( 427 resource_pool_->resource_provider()->releasePixelBuffer(
434 managed_tile_state.resource->id()); 428 drawing_info.resource_->id());
435 429
436 managed_tile_state.resource_is_being_initialized = false; 430 drawing_info.initializing_resource_ = false;
437 managed_tile_state.can_be_freed = true; 431 drawing_info.can_be_freed_ = true;
438 managed_tile_state.can_use_gpu_memory = false; 432 managed_tile_state.can_use_gpu_memory = false;
439 FreeResourcesForTile(tile); 433 FreeResourcesForTile(tile);
440 434
441 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); 435 bytes_pending_upload_ -= tile->bytes_consumed_if_texture_allocated();
442 DidTileRasterStateChange(tile, IDLE_STATE); 436 DidTileRasterStateChange(tile, IDLE_STATE);
443 tiles_with_pending_upload_.pop(); 437 tiles_with_pending_upload_.pop();
444 } 438 }
445 } 439 }
446 440
447 void TileManager::DidCompleteFrame() { 441 void TileManager::DidCompleteFrame() {
448 allow_cheap_tasks_ = true; 442 allow_cheap_tasks_ = true;
449 did_schedule_cheap_tasks_ = false; 443 did_schedule_cheap_tasks_ = false;
450 } 444 }
451 445
452 void TileManager::GetMemoryStats( 446 void TileManager::GetMemoryStats(
453 size_t* memoryRequiredBytes, 447 size_t* memoryRequiredBytes,
454 size_t* memoryNiceToHaveBytes, 448 size_t* memoryNiceToHaveBytes,
455 size_t* memoryUsedBytes) const { 449 size_t* memoryUsedBytes) const {
456 *memoryRequiredBytes = 0; 450 *memoryRequiredBytes = 0;
457 *memoryNiceToHaveBytes = 0; 451 *memoryNiceToHaveBytes = 0;
458 *memoryUsedBytes = 0; 452 *memoryUsedBytes = 0;
459 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { 453 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) {
460 const Tile* tile = live_or_allocated_tiles_[i]; 454 const Tile* tile = live_or_allocated_tiles_[i];
461 const ManagedTileState& mts = tile->managed_state(); 455 const ManagedTileState& mts = tile->managed_state();
462 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 456 size_t tile_bytes = tile->bytes_consumed_if_texture_allocated();
463 if (mts.gpu_memmgr_stats_bin == NOW_BIN) 457 if (mts.gpu_memmgr_stats_bin == NOW_BIN)
464 *memoryRequiredBytes += tile_bytes; 458 *memoryRequiredBytes += tile_bytes;
465 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) 459 if (mts.gpu_memmgr_stats_bin != NEVER_BIN)
466 *memoryNiceToHaveBytes += tile_bytes; 460 *memoryNiceToHaveBytes += tile_bytes;
467 if (mts.can_use_gpu_memory) 461 if (mts.can_use_gpu_memory)
468 *memoryUsedBytes += tile_bytes; 462 *memoryUsedBytes += tile_bytes;
469 } 463 }
470 } 464 }
471 465
472 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { 466 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 // By clearing the tiles_that_need_to_be_rasterized_ vector and 566 // By clearing the tiles_that_need_to_be_rasterized_ vector and
573 // tiles_with_image_decoding_tasks_ list above we move all tiles 567 // tiles_with_image_decoding_tasks_ list above we move all tiles
574 // currently waiting for raster to idle state. 568 // currently waiting for raster to idle state.
575 // Call DidTileRasterStateChange() for each of these tiles to 569 // Call DidTileRasterStateChange() for each of these tiles to
576 // have this state change take effect. 570 // have this state change take effect.
577 // Some memory cannot be released. We figure out how much in this 571 // Some memory cannot be released. We figure out how much in this
578 // loop as well. 572 // loop as well.
579 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); 573 for (TileVector::iterator it = live_or_allocated_tiles_.begin();
580 it != live_or_allocated_tiles_.end(); ++it) { 574 it != live_or_allocated_tiles_.end(); ++it) {
581 Tile* tile = *it; 575 Tile* tile = *it;
582 if (!tile->managed_state().can_be_freed) 576 if (!tile->drawing_info().can_be_freed_)
583 unreleasable_bytes += tile->bytes_consumed_if_allocated(); 577 unreleasable_bytes += tile->bytes_consumed_if_texture_allocated();
584 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE) 578 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE)
585 DidTileRasterStateChange(tile, IDLE_STATE); 579 DidTileRasterStateChange(tile, IDLE_STATE);
586 } 580 }
587 581
588 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes; 582 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes;
589 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0; 583 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0;
590 size_t bytes_left = bytes_allocatable; 584 size_t bytes_left = bytes_allocatable;
591 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) { 585 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) {
592 Tile* tile = *it; 586 Tile* tile = *it;
593 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 587 size_t tile_bytes = tile->bytes_consumed_if_texture_allocated();
594 ManagedTileState& managed_tile_state = tile->managed_state(); 588 ManagedTileState& managed_tile_state = tile->managed_state();
595 if (!managed_tile_state.can_be_freed) 589 TileDrawingInfo& drawing_info = tile->drawing_info();
590 if (!tile->drawing_info().can_be_freed_)
596 continue; 591 continue;
597 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && 592 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN &&
598 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { 593 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) {
599 managed_tile_state.can_use_gpu_memory = false; 594 managed_tile_state.can_use_gpu_memory = false;
600 FreeResourcesForTile(tile); 595 FreeResourcesForTile(tile);
601 continue; 596 continue;
602 } 597 }
603 if (tile_bytes > bytes_left) { 598 if (tile_bytes > bytes_left) {
604 managed_tile_state.can_use_gpu_memory = false; 599 managed_tile_state.can_use_gpu_memory = false;
605 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NOW_BIN || 600 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NOW_BIN ||
606 managed_tile_state.bin[LOW_PRIORITY_BIN] == NOW_BIN) 601 managed_tile_state.bin[LOW_PRIORITY_BIN] == NOW_BIN)
607 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; 602 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes;
608 FreeResourcesForTile(tile); 603 FreeResourcesForTile(tile);
609 continue; 604 continue;
610 } 605 }
611 bytes_left -= tile_bytes; 606 bytes_left -= tile_bytes;
612 managed_tile_state.can_use_gpu_memory = true; 607 managed_tile_state.can_use_gpu_memory = true;
613 if (!managed_tile_state.resource && 608 if (!drawing_info.resource_ &&
614 !managed_tile_state.resource_is_being_initialized) { 609 !drawing_info.initializing_resource_) {
615 tiles_that_need_to_be_rasterized_.push_back(tile); 610 tiles_that_need_to_be_rasterized_.push_back(tile);
616 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE); 611 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE);
617 } 612 }
618 } 613 }
619 614
620 ever_exceeded_memory_budget_ |= 615 ever_exceeded_memory_budget_ |=
621 bytes_that_exceeded_memory_budget_in_now_bin > 0; 616 bytes_that_exceeded_memory_budget_in_now_bin > 0;
622 if (ever_exceeded_memory_budget_) { 617 if (ever_exceeded_memory_budget_) {
623 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, 618 TRACE_COUNTER_ID2("cc", "over_memory_budget", this,
624 "budget", global_state_.memory_limit_in_bytes, 619 "budget", global_state_.memory_limit_in_bytes,
625 "over", bytes_that_exceeded_memory_budget_in_now_bin); 620 "over", bytes_that_exceeded_memory_budget_in_now_bin);
626 } 621 }
627 memory_stats_from_last_assign_.total_budget_in_bytes = 622 memory_stats_from_last_assign_.total_budget_in_bytes =
628 global_state_.memory_limit_in_bytes; 623 global_state_.memory_limit_in_bytes;
629 memory_stats_from_last_assign_.bytes_allocated = 624 memory_stats_from_last_assign_.bytes_allocated =
630 bytes_allocatable - bytes_left; 625 bytes_allocatable - bytes_left;
631 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; 626 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes;
632 memory_stats_from_last_assign_.bytes_over = 627 memory_stats_from_last_assign_.bytes_over =
633 bytes_that_exceeded_memory_budget_in_now_bin; 628 bytes_that_exceeded_memory_budget_in_now_bin;
634 629
635 // Reverse two tiles_that_need_* vectors such that pop_back gets 630 // Reverse two tiles_that_need_* vectors such that pop_back gets
636 // the highest priority tile. 631 // the highest priority tile.
637 std::reverse( 632 std::reverse(
638 tiles_that_need_to_be_rasterized_.begin(), 633 tiles_that_need_to_be_rasterized_.begin(),
639 tiles_that_need_to_be_rasterized_.end()); 634 tiles_that_need_to_be_rasterized_.end());
640 } 635 }
641 636
642 void TileManager::FreeResourcesForTile(Tile* tile) { 637 void TileManager::FreeResourcesForTile(Tile* tile) {
643 ManagedTileState& managed_tile_state = tile->managed_state(); 638 TileDrawingInfo& drawing_info = tile->drawing_info();
644 DCHECK(managed_tile_state.can_be_freed); 639 DCHECK(drawing_info.can_be_freed_);
645 if (managed_tile_state.resource) 640 if (drawing_info.resource_)
646 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); 641 resource_pool_->ReleaseResource(drawing_info.resource_.Pass());
647 } 642 }
648 643
649 bool TileManager::CanDispatchRasterTask(Tile* tile) const { 644 bool TileManager::CanDispatchRasterTask(Tile* tile) const {
650 if (raster_worker_pool_->IsBusy()) 645 if (raster_worker_pool_->IsBusy())
651 return false; 646 return false;
652 size_t new_bytes_pending = bytes_pending_upload_; 647 size_t new_bytes_pending = bytes_pending_upload_;
653 new_bytes_pending += tile->bytes_consumed_if_allocated(); 648 new_bytes_pending += tile->bytes_consumed_if_texture_allocated();
654 return new_bytes_pending <= kMaxPendingUploadBytes && 649 return new_bytes_pending <= kMaxPendingUploadBytes &&
655 tiles_with_pending_upload_.size() < kMaxPendingUploads; 650 tiles_with_pending_upload_.size() < kMaxPendingUploads;
656 } 651 }
657 652
658 void TileManager::DispatchMoreTasks() { 653 void TileManager::DispatchMoreTasks() {
659 if (did_schedule_cheap_tasks_) 654 if (did_schedule_cheap_tasks_)
660 allow_cheap_tasks_ = false; 655 allow_cheap_tasks_ = false;
661 656
662 // Because tiles in the image decoding list have higher priorities, we 657 // Because tiles in the image decoding list have higher priorities, we
663 // need to process those tiles first before we start to handle the tiles 658 // need to process those tiles first before we start to handle the tiles
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 pixel_refs.erase(pixel_it); 763 pixel_refs.erase(pixel_it);
769 break; 764 break;
770 } 765 }
771 } 766 }
772 } 767 }
773 } 768 }
774 769
775 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( 770 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster(
776 Tile* tile) { 771 Tile* tile) {
777 ManagedTileState& managed_tile_state = tile->managed_state(); 772 ManagedTileState& managed_tile_state = tile->managed_state();
773 TileDrawingInfo& drawing_info = tile->drawing_info();
778 DCHECK(managed_tile_state.can_use_gpu_memory); 774 DCHECK(managed_tile_state.can_use_gpu_memory);
779 scoped_ptr<ResourcePool::Resource> resource = 775 scoped_ptr<ResourcePool::Resource> resource =
780 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); 776 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_);
781 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); 777 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id());
782 778
783 managed_tile_state.resource_is_being_initialized = true; 779 drawing_info.initializing_resource_ = true;
784 managed_tile_state.can_be_freed = false; 780 drawing_info.can_be_freed_ = false;
785 781
786 DidTileRasterStateChange(tile, RASTER_STATE); 782 DidTileRasterStateChange(tile, RASTER_STATE);
787 return resource.Pass(); 783 return resource.Pass();
788 } 784 }
789 785
790 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { 786 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) {
791 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); 787 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask");
792 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); 788 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile);
793 ResourceProvider::ResourceId resource_id = resource->id(); 789 ResourceProvider::ResourceId resource_id = resource->id();
794 uint8* buffer = 790 uint8* buffer =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 void TileManager::OnRasterTaskCompleted( 824 void TileManager::OnRasterTaskCompleted(
829 scoped_refptr<Tile> tile, 825 scoped_refptr<Tile> tile,
830 scoped_ptr<ResourcePool::Resource> resource, 826 scoped_ptr<ResourcePool::Resource> resource,
831 int manage_tiles_call_count_when_dispatched) { 827 int manage_tiles_call_count_when_dispatched) {
832 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); 828 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted");
833 829
834 // Release raster resources. 830 // Release raster resources.
835 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); 831 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id());
836 832
837 ManagedTileState& managed_tile_state = tile->managed_state(); 833 ManagedTileState& managed_tile_state = tile->managed_state();
838 managed_tile_state.can_be_freed = true; 834 TileDrawingInfo& drawing_info = tile->drawing_info();
835 tile->drawing_info().can_be_freed_ = true;
839 836
840 // Tile can be freed after the completion of the raster task. Call 837 // Tile can be freed after the completion of the raster task. Call
841 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority 838 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority
842 // tiles if ManageTiles() was called since task was dispatched. The result 839 // tiles if ManageTiles() was called since task was dispatched. The result
843 // of this could be that this tile is no longer allowed to use gpu 840 // of this could be that this tile is no longer allowed to use gpu
844 // memory and in that case we need to abort initialization and free all 841 // memory and in that case we need to abort initialization and free all
845 // associated resources before calling DispatchMoreTasks(). 842 // associated resources before calling DispatchMoreTasks().
846 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) 843 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_)
847 AssignGpuMemoryToTiles(); 844 AssignGpuMemoryToTiles();
848 845
849 // Finish resource initialization if |can_use_gpu_memory| is true. 846 // Finish resource initialization if |can_use_gpu_memory| is true.
850 if (managed_tile_state.can_use_gpu_memory) { 847 if (managed_tile_state.can_use_gpu_memory) {
851 // The component order may be bgra if we're uploading bgra pixels to rgba 848 // The component order may be bgra if we're uploading bgra pixels to rgba
852 // texture. Mark contents as swizzled if image component order is 849 // texture. Mark contents as swizzled if image component order is
853 // different than texture format. 850 // different than texture format.
854 managed_tile_state.contents_swizzled = 851 drawing_info.contents_swizzled_ =
855 !PlatformColor::sameComponentOrder(tile->format_); 852 !PlatformColor::sameComponentOrder(tile->format_);
856 853
857 // Tile resources can't be freed until upload has completed. 854 // Tile resources can't be freed until upload has completed.
858 managed_tile_state.can_be_freed = false; 855 tile->drawing_info().can_be_freed_ = false;
859 856
860 resource_pool_->resource_provider()->beginSetPixels(resource->id()); 857 resource_pool_->resource_provider()->beginSetPixels(resource->id());
861 has_performed_uploads_since_last_flush_ = true; 858 has_performed_uploads_since_last_flush_ = true;
862 859
863 managed_tile_state.resource = resource.Pass(); 860 drawing_info.resource_ = resource.Pass();
864 861
865 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); 862 bytes_pending_upload_ += tile->bytes_consumed_if_texture_allocated();
866 DidTileRasterStateChange(tile, UPLOAD_STATE); 863 DidTileRasterStateChange(tile, UPLOAD_STATE);
867 tiles_with_pending_upload_.push(tile); 864 tiles_with_pending_upload_.push(tile);
868 } else { 865 } else {
869 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); 866 resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
870 resource_pool_->ReleaseResource(resource.Pass()); 867 resource_pool_->ReleaseResource(resource.Pass());
871 managed_tile_state.resource_is_being_initialized = false; 868 drawing_info.initializing_resource_ = false;
872 DidTileRasterStateChange(tile, IDLE_STATE); 869 DidTileRasterStateChange(tile, IDLE_STATE);
873 } 870 }
874 } 871 }
875 872
876 void TileManager::DidFinishTileInitialization(Tile* tile) { 873 void TileManager::DidFinishTileInitialization(Tile* tile) {
877 ManagedTileState& managed_tile_state = tile->managed_state(); 874 TileDrawingInfo& drawing_info = tile->drawing_info();
878 DCHECK(managed_tile_state.resource); 875 DCHECK(drawing_info.resource_);
879 managed_tile_state.resource_is_being_initialized = false; 876 drawing_info.initializing_resource_ = false;
880 managed_tile_state.can_be_freed = true; 877 drawing_info.can_be_freed_ = true;
881 } 878 }
882 879
883 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { 880 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) {
884 ManagedTileState& mts = tile->managed_state(); 881 ManagedTileState& mts = tile->managed_state();
885 DCHECK_LT(state, NUM_STATES); 882 DCHECK_LT(state, NUM_STATES);
886 883
887 for (int i = 0; i < NUM_TREES; ++i) { 884 for (int i = 0; i < NUM_TREES; ++i) {
888 // Decrement count for current state. 885 // Decrement count for current state.
889 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 886 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]];
890 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); 887 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 decode_begin_time = base::TimeTicks::HighResNow(); 985 decode_begin_time = base::TimeTicks::HighResNow();
989 pixel_ref->Decode(); 986 pixel_ref->Decode();
990 if (stats) { 987 if (stats) {
991 stats->totalDeferredImageDecodeCount++; 988 stats->totalDeferredImageDecodeCount++;
992 stats->totalDeferredImageDecodeTime += 989 stats->totalDeferredImageDecodeTime +=
993 base::TimeTicks::HighResNow() - decode_begin_time; 990 base::TimeTicks::HighResNow() - decode_begin_time;
994 } 991 }
995 } 992 }
996 993
997 } // namespace cc 994 } // namespace cc
OLDNEW
« cc/tile_manager.h ('K') | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698