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" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 // If we raster too fast we become upload bound, and pending | 24 // If we raster too fast we become upload bound, and pending |
25 // uploads consume memory. For maximum upload throughput, we would | 25 // uploads consume memory. For maximum upload throughput, we would |
26 // want to allow for upload_throughput * pipeline_time of pending | 26 // want to allow for upload_throughput * pipeline_time of pending |
27 // uploads, after which we are just wasting memory. Since we don't | 27 // uploads, after which we are just wasting memory. Since we don't |
28 // know our upload throughput yet, this just caps our memory usage. | 28 // know our upload throughput yet, this just caps our memory usage. |
29 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
30 // For reference, the Nexus10 can upload 1MB in about 2.5ms. | 30 // For reference, the Nexus10 can upload 1MB in about 2.5ms. |
31 // Assuming a three frame deep pipeline this implies ~20MB. | 31 // Assuming a three frame deep pipeline this implies ~20MB. |
32 const int kMaxPendingUploadBytes = 20 * 1024 * 1024; | 32 const int kMaxPendingUploadBytes = 20 * 1024 * 1024; |
33 const int kMaxPendingRasterBytes = 2 * 1024 * 1024; | |
33 #else | 34 #else |
34 const int kMaxPendingUploadBytes = 100 * 1024 * 1024; | 35 const int kMaxPendingUploadBytes = 100 * 1024 * 1024; |
36 const int kMaxPendingRasterBytes = 10 * 1024 * 1024; | |
35 #endif | 37 #endif |
36 | 38 |
37 // Determine bin based on three categories of tiles: things we need now, | 39 // Determine bin based on three categories of tiles: things we need now, |
38 // things we need soon, and eventually. | 40 // things we need soon, and eventually. |
39 inline TileManagerBin BinFromTilePriority(const TilePriority& prio) { | 41 inline TileManagerBin BinFromTilePriority(const TilePriority& prio) { |
40 if (!prio.is_live) | 42 if (!prio.is_live) |
41 return NEVER_BIN; | 43 return NEVER_BIN; |
42 | 44 |
43 // The amount of time for which we want to have prepainting coverage. | 45 // The amount of time for which we want to have prepainting coverage. |
44 const double prepainting_window_time_seconds = 1.0; | 46 const double prepainting_window_time_seconds = 1.0; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 return state.PassAs<base::Value>(); | 164 return state.PassAs<base::Value>(); |
163 } | 165 } |
164 | 166 |
165 TileManager::TileManager( | 167 TileManager::TileManager( |
166 TileManagerClient* client, | 168 TileManagerClient* client, |
167 ResourceProvider* resource_provider, | 169 ResourceProvider* resource_provider, |
168 size_t num_raster_threads, | 170 size_t num_raster_threads, |
169 bool use_cheapness_estimator) | 171 bool use_cheapness_estimator) |
170 : client_(client), | 172 : client_(client), |
171 resource_pool_(ResourcePool::Create(resource_provider)), | 173 resource_pool_(ResourcePool::Create(resource_provider)), |
172 raster_worker_pool_(RasterWorkerPool::Create(num_raster_threads)), | 174 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), |
173 manage_tiles_pending_(false), | 175 manage_tiles_pending_(false), |
174 manage_tiles_call_count_(0), | 176 manage_tiles_call_count_(0), |
177 bytes_pending_raster_(0), | |
175 bytes_pending_set_pixels_(0), | 178 bytes_pending_set_pixels_(0), |
179 need_shallow_flush_(false), | |
176 ever_exceeded_memory_budget_(false), | 180 ever_exceeded_memory_budget_(false), |
177 record_rendering_stats_(false), | 181 record_rendering_stats_(false), |
178 use_cheapness_estimator_(use_cheapness_estimator) { | 182 use_cheapness_estimator_(use_cheapness_estimator) { |
179 for (int i = 0; i < NUM_STATES; ++i) { | 183 for (int i = 0; i < NUM_STATES; ++i) { |
180 for (int j = 0; j < NUM_TREES; ++j) { | 184 for (int j = 0; j < NUM_TREES; ++j) { |
181 for (int k = 0; k < NUM_BINS; ++k) | 185 for (int k = 0; k < NUM_BINS; ++k) |
182 raster_state_count_[i][j][k] = 0; | 186 raster_state_count_[i][j][k] = 0; |
183 } | 187 } |
184 } | 188 } |
185 } | 189 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 case IDLE_STATE: | 538 case IDLE_STATE: |
535 break; | 539 break; |
536 default: | 540 default: |
537 NOTREACHED(); | 541 NOTREACHED(); |
538 } | 542 } |
539 } | 543 } |
540 | 544 |
541 return false; | 545 return false; |
542 } | 546 } |
543 | 547 |
548 void TileManager::DidFinishDispatchingCompletionCallbacks() { | |
549 // If a flush is needed, do it now before starting to dispatch more tasks. | |
550 if (need_shallow_flush_) { | |
nduca
2013/02/13 10:53:37
has_performed_uploads_since_last_shallow_flush_?
reveman
2013/02/13 15:32:58
ok, I changed to has_performed_uploads_since_last_
| |
551 resource_pool_->resource_provider()->shallowFlushIfSupported(); | |
552 need_shallow_flush_ = false; | |
553 } | |
554 | |
555 DispatchMoreTasks(); | |
556 } | |
557 | |
544 void TileManager::AssignGpuMemoryToTiles() { | 558 void TileManager::AssignGpuMemoryToTiles() { |
545 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 559 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
546 // Some memory cannot be released. Figure out which. | 560 // Some memory cannot be released. Figure out which. |
547 size_t unreleasable_bytes = 0; | 561 size_t unreleasable_bytes = 0; |
548 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 562 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
549 Tile* tile = *it; | 563 Tile* tile = *it; |
550 if (!tile->managed_state().can_be_freed) | 564 if (!tile->managed_state().can_be_freed) |
551 unreleasable_bytes += tile->bytes_consumed_if_allocated(); | 565 unreleasable_bytes += tile->bytes_consumed_if_allocated(); |
552 } | 566 } |
553 | 567 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 } | 639 } |
626 | 640 |
627 void TileManager::FreeResourcesForTile(Tile* tile) { | 641 void TileManager::FreeResourcesForTile(Tile* tile) { |
628 ManagedTileState& managed_tile_state = tile->managed_state(); | 642 ManagedTileState& managed_tile_state = tile->managed_state(); |
629 DCHECK(managed_tile_state.can_be_freed); | 643 DCHECK(managed_tile_state.can_be_freed); |
630 if (managed_tile_state.resource) | 644 if (managed_tile_state.resource) |
631 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); | 645 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); |
632 } | 646 } |
633 | 647 |
634 bool TileManager::CanDispatchRasterTask(Tile* tile) { | 648 bool TileManager::CanDispatchRasterTask(Tile* tile) { |
635 if (raster_worker_pool_->IsBusy()) | 649 size_t new_raster_bytes_pending = bytes_pending_raster_; |
650 new_raster_bytes_pending += tile->bytes_consumed_if_allocated(); | |
651 if (new_raster_bytes_pending > kMaxPendingRasterBytes) | |
636 return false; | 652 return false; |
637 size_t new_bytes_pending = bytes_pending_set_pixels_; | 653 |
638 new_bytes_pending += tile->bytes_consumed_if_allocated(); | 654 size_t new_upload_bytes_pending = bytes_pending_raster_ + |
639 return new_bytes_pending <= kMaxPendingUploadBytes; | 655 bytes_pending_set_pixels_; |
656 new_upload_bytes_pending += tile->bytes_consumed_if_allocated(); | |
657 if (new_upload_bytes_pending > kMaxPendingUploadBytes) | |
658 return false; | |
659 | |
660 return true; | |
640 } | 661 } |
641 | 662 |
642 void TileManager::DispatchMoreTasks() { | 663 void TileManager::DispatchMoreTasks() { |
643 // Because tiles in the image decoding list have higher priorities, we | 664 // Because tiles in the image decoding list have higher priorities, we |
644 // need to process those tiles first before we start to handle the tiles | 665 // need to process those tiles first before we start to handle the tiles |
645 // in the need_to_be_rasterized queue. | 666 // in the need_to_be_rasterized queue. |
646 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 667 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
647 it != tiles_with_image_decoding_tasks_.end(); ) { | 668 it != tiles_with_image_decoding_tasks_.end(); ) { |
648 DispatchImageDecodeTasksForTile(*it); | 669 DispatchImageDecodeTasksForTile(*it); |
649 ManagedTileState& managed_state = (*it)->managed_state(); | 670 ManagedTileState& managed_state = (*it)->managed_state(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( | 724 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( |
704 (*it)->getGenerationID())) { | 725 (*it)->getGenerationID())) { |
705 ++it; | 726 ++it; |
706 continue; | 727 continue; |
707 } | 728 } |
708 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 729 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
709 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 730 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
710 rendering_stats_.totalDeferredImageCacheHitCount++; | 731 rendering_stats_.totalDeferredImageCacheHitCount++; |
711 pending_pixel_refs.erase(it++); | 732 pending_pixel_refs.erase(it++); |
712 } else { | 733 } else { |
713 if (raster_worker_pool_->IsBusy()) | 734 if (!CanDispatchRasterTask(tile)) |
714 return; | 735 return; |
715 DispatchOneImageDecodeTask(tile, *it); | 736 DispatchOneImageDecodeTask(tile, *it); |
716 ++it; | 737 ++it; |
717 } | 738 } |
718 } | 739 } |
719 } | 740 } |
720 | 741 |
721 void TileManager::DispatchOneImageDecodeTask( | 742 void TileManager::DispatchOneImageDecodeTask( |
722 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { | 743 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { |
723 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); | 744 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); |
(...skipping 20 matching lines...) Expand all Loading... | |
744 std::list<skia::LazyPixelRef*>& pixel_refs = | 765 std::list<skia::LazyPixelRef*>& pixel_refs = |
745 (*it)->managed_state().pending_pixel_refs; | 766 (*it)->managed_state().pending_pixel_refs; |
746 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = | 767 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = |
747 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { | 768 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { |
748 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { | 769 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { |
749 pixel_refs.erase(pixel_it); | 770 pixel_refs.erase(pixel_it); |
750 break; | 771 break; |
751 } | 772 } |
752 } | 773 } |
753 } | 774 } |
754 | |
755 DispatchMoreTasks(); | |
756 } | 775 } |
757 | 776 |
758 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( | 777 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( |
759 Tile* tile) { | 778 Tile* tile) { |
760 ManagedTileState& managed_tile_state = tile->managed_state(); | 779 ManagedTileState& managed_tile_state = tile->managed_state(); |
761 DCHECK(managed_tile_state.can_use_gpu_memory); | 780 DCHECK(managed_tile_state.can_use_gpu_memory); |
762 scoped_ptr<ResourcePool::Resource> resource = | 781 scoped_ptr<ResourcePool::Resource> resource = |
763 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); | 782 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); |
764 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); | 783 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); |
765 | 784 |
(...skipping 15 matching lines...) Expand all Loading... | |
781 resource_pool_->resource_provider()->mapPixelBuffer( | 800 resource_pool_->resource_provider()->mapPixelBuffer( |
782 resource_id), | 801 resource_id), |
783 tile->content_rect_, | 802 tile->content_rect_, |
784 tile->contents_scale(), | 803 tile->contents_scale(), |
785 use_cheapness_estimator_), | 804 use_cheapness_estimator_), |
786 base::Bind(&TileManager::OnRasterTaskCompleted, | 805 base::Bind(&TileManager::OnRasterTaskCompleted, |
787 base::Unretained(this), | 806 base::Unretained(this), |
788 tile, | 807 tile, |
789 base::Passed(&resource), | 808 base::Passed(&resource), |
790 manage_tiles_call_count_)); | 809 manage_tiles_call_count_)); |
810 | |
811 bytes_pending_raster_ += tile->bytes_consumed_if_allocated(); | |
791 } | 812 } |
792 | 813 |
793 void TileManager::PerformOneRaster(Tile* tile) { | 814 void TileManager::PerformOneRaster(Tile* tile) { |
794 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 815 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
795 ResourceProvider::ResourceId resource_id = resource->id(); | 816 ResourceProvider::ResourceId resource_id = resource->id(); |
796 | 817 |
797 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( | 818 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( |
798 resource_id), | 819 resource_id), |
799 tile->content_rect_, | 820 tile->content_rect_, |
800 tile->contents_scale(), | 821 tile->contents_scale(), |
(...skipping 30 matching lines...) Expand all Loading... | |
831 // The component order may be bgra if we're uploading bgra pixels to rgba | 852 // The component order may be bgra if we're uploading bgra pixels to rgba |
832 // texture. Mark contents as swizzled if image component order is | 853 // texture. Mark contents as swizzled if image component order is |
833 // different than texture format. | 854 // different than texture format. |
834 managed_tile_state.contents_swizzled = | 855 managed_tile_state.contents_swizzled = |
835 !PlatformColor::sameComponentOrder(tile->format_); | 856 !PlatformColor::sameComponentOrder(tile->format_); |
836 | 857 |
837 // Tile resources can't be freed until upload has completed. | 858 // Tile resources can't be freed until upload has completed. |
838 managed_tile_state.can_be_freed = false; | 859 managed_tile_state.can_be_freed = false; |
839 | 860 |
840 resource_pool_->resource_provider()->beginSetPixels(resource->id()); | 861 resource_pool_->resource_provider()->beginSetPixels(resource->id()); |
841 resource_pool_->resource_provider()->shallowFlushIfSupported(); | 862 need_shallow_flush_ = true; |
863 | |
842 managed_tile_state.resource = resource.Pass(); | 864 managed_tile_state.resource = resource.Pass(); |
843 | 865 |
844 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); | 866 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); |
845 DidTileRasterStateChange(tile, SET_PIXELS_STATE); | 867 DidTileRasterStateChange(tile, SET_PIXELS_STATE); |
846 tiles_with_pending_set_pixels_.push(tile); | 868 tiles_with_pending_set_pixels_.push(tile); |
847 } else { | 869 } else { |
848 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); | 870 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); |
849 resource_pool_->ReleaseResource(resource.Pass()); | 871 resource_pool_->ReleaseResource(resource.Pass()); |
850 managed_tile_state.resource_is_being_initialized = false; | 872 managed_tile_state.resource_is_being_initialized = false; |
851 DidTileRasterStateChange(tile, IDLE_STATE); | 873 DidTileRasterStateChange(tile, IDLE_STATE); |
852 } | 874 } |
853 } | 875 } |
854 | 876 |
855 void TileManager::OnRasterTaskCompleted( | 877 void TileManager::OnRasterTaskCompleted( |
856 scoped_refptr<Tile> tile, | 878 scoped_refptr<Tile> tile, |
857 scoped_ptr<ResourcePool::Resource> resource, | 879 scoped_ptr<ResourcePool::Resource> resource, |
858 int manage_tiles_call_count_when_dispatched) { | 880 int manage_tiles_call_count_when_dispatched) { |
881 bytes_pending_raster_ -= tile->bytes_consumed_if_allocated(); | |
859 OnRasterCompleted(tile, resource.Pass(), | 882 OnRasterCompleted(tile, resource.Pass(), |
860 manage_tiles_call_count_when_dispatched); | 883 manage_tiles_call_count_when_dispatched); |
861 DispatchMoreTasks(); | |
862 } | 884 } |
863 | 885 |
864 void TileManager::DidFinishTileInitialization(Tile* tile) { | 886 void TileManager::DidFinishTileInitialization(Tile* tile) { |
865 ManagedTileState& managed_tile_state = tile->managed_state(); | 887 ManagedTileState& managed_tile_state = tile->managed_state(); |
866 DCHECK(managed_tile_state.resource); | 888 DCHECK(managed_tile_state.resource); |
867 managed_tile_state.resource_is_being_initialized = false; | 889 managed_tile_state.resource_is_being_initialized = false; |
868 managed_tile_state.can_be_freed = true; | 890 managed_tile_state.can_be_freed = true; |
869 } | 891 } |
870 | 892 |
871 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { | 893 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 decode_begin_time = base::TimeTicks::Now(); | 986 decode_begin_time = base::TimeTicks::Now(); |
965 pixel_ref->Decode(); | 987 pixel_ref->Decode(); |
966 if (stats) { | 988 if (stats) { |
967 stats->totalDeferredImageDecodeCount++; | 989 stats->totalDeferredImageDecodeCount++; |
968 stats->totalDeferredImageDecodeTime += | 990 stats->totalDeferredImageDecodeTime += |
969 base::TimeTicks::Now() - decode_begin_time; | 991 base::TimeTicks::Now() - decode_begin_time; |
970 } | 992 } |
971 } | 993 } |
972 | 994 |
973 } // namespace cc | 995 } // namespace cc |
OLD | NEW |