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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 } | 629 } |
626 | 630 |
627 void TileManager::FreeResourcesForTile(Tile* tile) { | 631 void TileManager::FreeResourcesForTile(Tile* tile) { |
628 ManagedTileState& managed_tile_state = tile->managed_state(); | 632 ManagedTileState& managed_tile_state = tile->managed_state(); |
629 DCHECK(managed_tile_state.can_be_freed); | 633 DCHECK(managed_tile_state.can_be_freed); |
630 if (managed_tile_state.resource) | 634 if (managed_tile_state.resource) |
631 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); | 635 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); |
632 } | 636 } |
633 | 637 |
634 bool TileManager::CanDispatchRasterTask(Tile* tile) { | 638 bool TileManager::CanDispatchRasterTask(Tile* tile) { |
635 if (raster_worker_pool_->IsBusy()) | 639 size_t new_raster_bytes_pending = bytes_pending_raster_; |
640 new_raster_bytes_pending += tile->bytes_consumed_if_allocated(); | |
641 if (new_raster_bytes_pending > kMaxPendingRasterBytes) | |
636 return false; | 642 return false; |
637 size_t new_bytes_pending = bytes_pending_set_pixels_; | 643 |
638 new_bytes_pending += tile->bytes_consumed_if_allocated(); | 644 size_t new_upload_bytes_pending = bytes_pending_raster_ + |
639 return new_bytes_pending <= kMaxPendingUploadBytes; | 645 bytes_pending_set_pixels_; |
646 new_upload_bytes_pending += tile->bytes_consumed_if_allocated(); | |
647 if (new_upload_bytes_pending > kMaxPendingUploadBytes) | |
648 return false; | |
649 | |
650 return true; | |
640 } | 651 } |
641 | 652 |
642 void TileManager::DispatchMoreTasks() { | 653 void TileManager::DispatchMoreTasks() { |
654 // If a flush is needed, do it now before we start dispatching more tasks. | |
655 if (need_shallow_flush_) { | |
nduca
2013/02/13 08:29:32
hmmm the position of this group surprised me, I wa
reveman
2013/02/13 08:46:38
this is just common code that is always executed a
| |
656 resource_pool_->resource_provider()->shallowFlushIfSupported(); | |
657 need_shallow_flush_ = false; | |
658 } | |
659 | |
643 // Because tiles in the image decoding list have higher priorities, we | 660 // 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 | 661 // need to process those tiles first before we start to handle the tiles |
645 // in the need_to_be_rasterized queue. | 662 // in the need_to_be_rasterized queue. |
646 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 663 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
647 it != tiles_with_image_decoding_tasks_.end(); ) { | 664 it != tiles_with_image_decoding_tasks_.end(); ) { |
648 DispatchImageDecodeTasksForTile(*it); | 665 DispatchImageDecodeTasksForTile(*it); |
649 ManagedTileState& managed_state = (*it)->managed_state(); | 666 ManagedTileState& managed_state = (*it)->managed_state(); |
650 if (managed_state.pending_pixel_refs.empty()) { | 667 if (managed_state.pending_pixel_refs.empty()) { |
651 if (!CanDispatchRasterTask(*it)) | 668 if (!CanDispatchRasterTask(*it)) |
652 return; | 669 return; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( | 720 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( |
704 (*it)->getGenerationID())) { | 721 (*it)->getGenerationID())) { |
705 ++it; | 722 ++it; |
706 continue; | 723 continue; |
707 } | 724 } |
708 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 725 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
709 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 726 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
710 rendering_stats_.totalDeferredImageCacheHitCount++; | 727 rendering_stats_.totalDeferredImageCacheHitCount++; |
711 pending_pixel_refs.erase(it++); | 728 pending_pixel_refs.erase(it++); |
712 } else { | 729 } else { |
713 if (raster_worker_pool_->IsBusy()) | 730 if (!CanDispatchRasterTask(tile)) |
714 return; | 731 return; |
715 DispatchOneImageDecodeTask(tile, *it); | 732 DispatchOneImageDecodeTask(tile, *it); |
716 ++it; | 733 ++it; |
717 } | 734 } |
718 } | 735 } |
719 } | 736 } |
720 | 737 |
721 void TileManager::DispatchOneImageDecodeTask( | 738 void TileManager::DispatchOneImageDecodeTask( |
722 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { | 739 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { |
723 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); | 740 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); |
724 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); | 741 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); |
725 DCHECK(pending_decode_tasks_.end() == | 742 DCHECK(pending_decode_tasks_.end() == |
726 pending_decode_tasks_.find(pixel_ref_id)); | 743 pending_decode_tasks_.find(pixel_ref_id)); |
727 pending_decode_tasks_[pixel_ref_id] = pixel_ref; | 744 pending_decode_tasks_[pixel_ref_id] = pixel_ref; |
728 | 745 |
729 raster_worker_pool_->PostTaskAndReply( | 746 raster_worker_pool_->PostTaskAndReply( |
730 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), | 747 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), |
731 base::Bind(&TileManager::OnImageDecodeTaskCompleted, | 748 base::Bind(&TileManager::OnImageDecodeTaskCompleted, |
732 base::Unretained(this), | 749 base::Unretained(this), |
733 tile, | 750 tile, |
734 pixel_ref_id)); | 751 pixel_ref_id)); |
735 } | 752 } |
736 | 753 |
737 void TileManager::OnImageDecodeTaskCompleted( | 754 void TileManager::OnImageDecodeTaskCompleted( |
738 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { | 755 scoped_refptr<Tile> tile, |
756 uint32_t pixel_ref_id, | |
757 bool more_tasks_completed) { | |
739 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); | 758 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); |
740 pending_decode_tasks_.erase(pixel_ref_id); | 759 pending_decode_tasks_.erase(pixel_ref_id); |
741 | 760 |
742 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 761 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
743 it != tiles_with_image_decoding_tasks_.end(); ++it) { | 762 it != tiles_with_image_decoding_tasks_.end(); ++it) { |
744 std::list<skia::LazyPixelRef*>& pixel_refs = | 763 std::list<skia::LazyPixelRef*>& pixel_refs = |
745 (*it)->managed_state().pending_pixel_refs; | 764 (*it)->managed_state().pending_pixel_refs; |
746 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = | 765 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = |
747 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { | 766 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { |
748 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { | 767 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { |
749 pixel_refs.erase(pixel_it); | 768 pixel_refs.erase(pixel_it); |
750 break; | 769 break; |
751 } | 770 } |
752 } | 771 } |
753 } | 772 } |
754 | 773 |
755 DispatchMoreTasks(); | 774 if (!more_tasks_completed) |
775 DispatchMoreTasks(); | |
756 } | 776 } |
757 | 777 |
758 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( | 778 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( |
759 Tile* tile) { | 779 Tile* tile) { |
760 ManagedTileState& managed_tile_state = tile->managed_state(); | 780 ManagedTileState& managed_tile_state = tile->managed_state(); |
761 DCHECK(managed_tile_state.can_use_gpu_memory); | 781 DCHECK(managed_tile_state.can_use_gpu_memory); |
762 scoped_ptr<ResourcePool::Resource> resource = | 782 scoped_ptr<ResourcePool::Resource> resource = |
763 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); | 783 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); |
764 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); | 784 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); |
765 | 785 |
(...skipping 15 matching lines...) Expand all Loading... | |
781 resource_pool_->resource_provider()->mapPixelBuffer( | 801 resource_pool_->resource_provider()->mapPixelBuffer( |
782 resource_id), | 802 resource_id), |
783 tile->content_rect_, | 803 tile->content_rect_, |
784 tile->contents_scale(), | 804 tile->contents_scale(), |
785 use_cheapness_estimator_), | 805 use_cheapness_estimator_), |
786 base::Bind(&TileManager::OnRasterTaskCompleted, | 806 base::Bind(&TileManager::OnRasterTaskCompleted, |
787 base::Unretained(this), | 807 base::Unretained(this), |
788 tile, | 808 tile, |
789 base::Passed(&resource), | 809 base::Passed(&resource), |
790 manage_tiles_call_count_)); | 810 manage_tiles_call_count_)); |
811 | |
812 bytes_pending_raster_ += tile->bytes_consumed_if_allocated(); | |
791 } | 813 } |
792 | 814 |
793 void TileManager::PerformOneRaster(Tile* tile) { | 815 void TileManager::PerformOneRaster(Tile* tile) { |
794 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 816 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
795 ResourceProvider::ResourceId resource_id = resource->id(); | 817 ResourceProvider::ResourceId resource_id = resource->id(); |
796 | 818 |
797 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( | 819 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( |
798 resource_id), | 820 resource_id), |
799 tile->content_rect_, | 821 tile->content_rect_, |
800 tile->contents_scale(), | 822 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 | 853 // 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 | 854 // texture. Mark contents as swizzled if image component order is |
833 // different than texture format. | 855 // different than texture format. |
834 managed_tile_state.contents_swizzled = | 856 managed_tile_state.contents_swizzled = |
835 !PlatformColor::sameComponentOrder(tile->format_); | 857 !PlatformColor::sameComponentOrder(tile->format_); |
836 | 858 |
837 // Tile resources can't be freed until upload has completed. | 859 // Tile resources can't be freed until upload has completed. |
838 managed_tile_state.can_be_freed = false; | 860 managed_tile_state.can_be_freed = false; |
839 | 861 |
840 resource_pool_->resource_provider()->beginSetPixels(resource->id()); | 862 resource_pool_->resource_provider()->beginSetPixels(resource->id()); |
841 resource_pool_->resource_provider()->shallowFlushIfSupported(); | 863 need_shallow_flush_ = true; |
864 | |
842 managed_tile_state.resource = resource.Pass(); | 865 managed_tile_state.resource = resource.Pass(); |
843 | 866 |
844 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); | 867 bytes_pending_set_pixels_ += tile->bytes_consumed_if_allocated(); |
845 DidTileRasterStateChange(tile, SET_PIXELS_STATE); | 868 DidTileRasterStateChange(tile, SET_PIXELS_STATE); |
846 tiles_with_pending_set_pixels_.push(tile); | 869 tiles_with_pending_set_pixels_.push(tile); |
847 } else { | 870 } else { |
848 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); | 871 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); |
849 resource_pool_->ReleaseResource(resource.Pass()); | 872 resource_pool_->ReleaseResource(resource.Pass()); |
850 managed_tile_state.resource_is_being_initialized = false; | 873 managed_tile_state.resource_is_being_initialized = false; |
851 DidTileRasterStateChange(tile, IDLE_STATE); | 874 DidTileRasterStateChange(tile, IDLE_STATE); |
852 } | 875 } |
853 } | 876 } |
854 | 877 |
855 void TileManager::OnRasterTaskCompleted( | 878 void TileManager::OnRasterTaskCompleted( |
856 scoped_refptr<Tile> tile, | 879 scoped_refptr<Tile> tile, |
857 scoped_ptr<ResourcePool::Resource> resource, | 880 scoped_ptr<ResourcePool::Resource> resource, |
858 int manage_tiles_call_count_when_dispatched) { | 881 int manage_tiles_call_count_when_dispatched, |
882 bool more_tasks_completed) { | |
883 bytes_pending_raster_ -= tile->bytes_consumed_if_allocated(); | |
859 OnRasterCompleted(tile, resource.Pass(), | 884 OnRasterCompleted(tile, resource.Pass(), |
860 manage_tiles_call_count_when_dispatched); | 885 manage_tiles_call_count_when_dispatched); |
861 DispatchMoreTasks(); | 886 if (!more_tasks_completed) |
887 DispatchMoreTasks(); | |
862 } | 888 } |
863 | 889 |
864 void TileManager::DidFinishTileInitialization(Tile* tile) { | 890 void TileManager::DidFinishTileInitialization(Tile* tile) { |
865 ManagedTileState& managed_tile_state = tile->managed_state(); | 891 ManagedTileState& managed_tile_state = tile->managed_state(); |
866 DCHECK(managed_tile_state.resource); | 892 DCHECK(managed_tile_state.resource); |
867 managed_tile_state.resource_is_being_initialized = false; | 893 managed_tile_state.resource_is_being_initialized = false; |
868 managed_tile_state.can_be_freed = true; | 894 managed_tile_state.can_be_freed = true; |
869 } | 895 } |
870 | 896 |
871 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { | 897 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(); | 990 decode_begin_time = base::TimeTicks::Now(); |
965 pixel_ref->Decode(); | 991 pixel_ref->Decode(); |
966 if (stats) { | 992 if (stats) { |
967 stats->totalDeferredImageDecodeCount++; | 993 stats->totalDeferredImageDecodeCount++; |
968 stats->totalDeferredImageDecodeTime += | 994 stats->totalDeferredImageDecodeTime += |
969 base::TimeTicks::Now() - decode_begin_time; | 995 base::TimeTicks::Now() - decode_begin_time; |
970 } | 996 } |
971 } | 997 } |
972 | 998 |
973 } // namespace cc | 999 } // namespace cc |
OLD | NEW |