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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 tiles_that_need_to_be_rasterized_.end()); | 545 tiles_that_need_to_be_rasterized_.end()); |
546 } | 546 } |
547 | 547 |
548 void TileManager::FreeResourcesForTile(Tile* tile) { | 548 void TileManager::FreeResourcesForTile(Tile* tile) { |
549 ManagedTileState& managed_tile_state = tile->managed_state(); | 549 ManagedTileState& managed_tile_state = tile->managed_state(); |
550 DCHECK(managed_tile_state.can_be_freed); | 550 DCHECK(managed_tile_state.can_be_freed); |
551 if (managed_tile_state.resource) | 551 if (managed_tile_state.resource) |
552 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); | 552 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); |
553 } | 553 } |
554 | 554 |
555 bool TileManager::CanDispatchRasterTask(Tile* tile) { | 555 bool TileManager::CanDispatchRasterTask(Tile* tile) const { |
556 if (raster_worker_pool_->IsBusy()) | 556 if (raster_worker_pool_->IsBusy()) |
557 return false; | 557 return false; |
558 size_t new_bytes_pending = bytes_pending_set_pixels_; | 558 size_t new_bytes_pending = bytes_pending_set_pixels_; |
559 new_bytes_pending += tile->bytes_consumed_if_allocated(); | 559 new_bytes_pending += tile->bytes_consumed_if_allocated(); |
560 return new_bytes_pending <= kMaxPendingUploadBytes; | 560 return new_bytes_pending <= kMaxPendingUploadBytes; |
561 } | 561 } |
562 | 562 |
563 bool TileManager::CanPerformCheapRaster(Tile* tile) const { | |
564 if (!use_cheapness_estimator_ || !client_->CanDoAnotherCheapRaster()) | |
565 return false; | |
566 ManagedTileState& managed_state = tile->managed_state(); | |
567 DCHECK(managed_state.pending_pixel_refs.empty()); | |
568 size_t new_bytes_pending = bytes_pending_set_pixels_; | |
569 new_bytes_pending += tile->bytes_consumed_if_allocated(); | |
570 if (new_bytes_pending > kMaxPendingUploadBytes) | |
571 return false; | |
572 return tile->picture_pile()->IsCheapInRect(tile->content_rect_, | |
573 tile->contents_scale()); | |
574 } | |
575 | |
563 void TileManager::DispatchMoreTasks() { | 576 void TileManager::DispatchMoreTasks() { |
564 // Because tiles in the image decoding list have higher priorities, we | 577 // Because tiles in the image decoding list have higher priorities, we |
565 // need to process those tiles first before we start to handle the tiles | 578 // need to process those tiles first before we start to handle the tiles |
566 // in the need_to_be_rasterized queue. | 579 // in the need_to_be_rasterized queue. |
567 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 580 for(TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
568 it != tiles_with_image_decoding_tasks_.end(); ) { | 581 it != tiles_with_image_decoding_tasks_.end(); ) { |
569 DispatchImageDecodeTasksForTile(*it); | 582 DispatchImageDecodeTasksForTile(*it); |
570 ManagedTileState& managed_state = (*it)->managed_state(); | 583 ManagedTileState& managed_state = (*it)->managed_state(); |
571 if (managed_state.pending_pixel_refs.empty()) { | 584 if (managed_state.pending_pixel_refs.empty()) { |
572 if (!CanDispatchRasterTask(*it)) | 585 if (CanPerformCheapRaster(*it)) { |
573 return; | 586 PerformOneCheapRaster(*it); |
574 DispatchOneRasterTask(*it); | 587 } else { |
588 if (!CanDispatchRasterTask(*it)) | |
589 return; | |
590 DispatchOneRasterTask(*it); | |
591 } | |
575 tiles_with_image_decoding_tasks_.erase(it++); | 592 tiles_with_image_decoding_tasks_.erase(it++); |
576 } else { | 593 } else { |
577 ++it; | 594 ++it; |
578 } | 595 } |
579 } | 596 } |
580 | 597 |
581 // Process all tiles in the need_to_be_rasterized queue. If a tile has | 598 // Process all tiles in the need_to_be_rasterized queue. If a tile has |
582 // image decoding tasks, put it to the back of the image decoding list. | 599 // image decoding tasks, put it to the back of the image decoding list. |
583 while (!tiles_that_need_to_be_rasterized_.empty()) { | 600 while (!tiles_that_need_to_be_rasterized_.empty()) { |
584 Tile* tile = tiles_that_need_to_be_rasterized_.back(); | 601 Tile* tile = tiles_that_need_to_be_rasterized_.back(); |
585 DispatchImageDecodeTasksForTile(tile); | 602 DispatchImageDecodeTasksForTile(tile); |
586 ManagedTileState& managed_state = tile->managed_state(); | 603 ManagedTileState& managed_state = tile->managed_state(); |
587 if (!managed_state.pending_pixel_refs.empty()) { | 604 if (!managed_state.pending_pixel_refs.empty()) { |
588 tiles_with_image_decoding_tasks_.push_back(tile); | 605 tiles_with_image_decoding_tasks_.push_back(tile); |
606 } else if (CanPerformCheapRaster(tile)) { | |
607 PerformOneCheapRaster(tile); | |
nduca
2013/02/13 07:17:56
So how about doign this... you can save all the in
| |
589 } else { | 608 } else { |
590 if (!CanDispatchRasterTask(tile)) | 609 if (!CanDispatchRasterTask(tile)) |
591 return; | 610 return; |
592 DispatchOneRasterTask(tile); | 611 DispatchOneRasterTask(tile); |
593 } | 612 } |
594 tiles_that_need_to_be_rasterized_.pop_back(); | 613 tiles_that_need_to_be_rasterized_.pop_back(); |
595 } | 614 } |
596 } | 615 } |
597 | 616 |
598 void TileManager::GatherPixelRefsForTile(Tile* tile) { | 617 void TileManager::GatherPixelRefsForTile(Tile* tile) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 | 660 |
642 void TileManager::DispatchOneImageDecodeTask( | 661 void TileManager::DispatchOneImageDecodeTask( |
643 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { | 662 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { |
644 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); | 663 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); |
645 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); | 664 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); |
646 DCHECK(pending_decode_tasks_.end() == | 665 DCHECK(pending_decode_tasks_.end() == |
647 pending_decode_tasks_.find(pixel_ref_id)); | 666 pending_decode_tasks_.find(pixel_ref_id)); |
648 pending_decode_tasks_[pixel_ref_id] = pixel_ref; | 667 pending_decode_tasks_[pixel_ref_id] = pixel_ref; |
649 | 668 |
650 raster_worker_pool_->PostTaskAndReply( | 669 raster_worker_pool_->PostTaskAndReply( |
651 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), | 670 base::Bind(&TileManager::PerformImageDecode, pixel_ref), |
652 base::Bind(&TileManager::OnImageDecodeTaskCompleted, | 671 base::Bind(&TileManager::OnImageDecodeTaskCompleted, |
653 base::Unretained(this), | 672 base::Unretained(this), |
654 tile, | 673 tile, |
655 pixel_ref_id)); | 674 pixel_ref_id)); |
656 } | 675 } |
657 | 676 |
658 void TileManager::OnImageDecodeTaskCompleted( | 677 void TileManager::OnImageDecodeTaskCompleted( |
659 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { | 678 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { |
660 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); | 679 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); |
661 pending_decode_tasks_.erase(pixel_ref_id); | 680 pending_decode_tasks_.erase(pixel_ref_id); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 tile->content_rect_, | 723 tile->content_rect_, |
705 tile->contents_scale(), | 724 tile->contents_scale(), |
706 use_cheapness_estimator_), | 725 use_cheapness_estimator_), |
707 base::Bind(&TileManager::OnRasterTaskCompleted, | 726 base::Bind(&TileManager::OnRasterTaskCompleted, |
708 base::Unretained(this), | 727 base::Unretained(this), |
709 tile, | 728 tile, |
710 base::Passed(&resource), | 729 base::Passed(&resource), |
711 manage_tiles_call_count_)); | 730 manage_tiles_call_count_)); |
712 } | 731 } |
713 | 732 |
714 void TileManager::PerformOneRaster(Tile* tile) { | 733 void TileManager::PerformOneCheapRaster(Tile* tile) { |
734 DCHECK(use_cheapness_estimator_); | |
715 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 735 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
716 ResourceProvider::ResourceId resource_id = resource->id(); | 736 ResourceProvider::ResourceId resource_id = resource->id(); |
717 | 737 |
718 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( | 738 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( |
719 resource_id), | 739 resource_id), |
720 tile->content_rect_, | 740 tile->content_rect_, |
721 tile->contents_scale(), | 741 tile->contents_scale(), |
722 use_cheapness_estimator_, | 742 use_cheapness_estimator_, |
723 tile->picture_pile(), | 743 tile->picture_pile(), |
724 &rendering_stats_); | 744 &rendering_stats_); |
725 | |
726 OnRasterCompleted(tile, resource.Pass(), manage_tiles_call_count_); | 745 OnRasterCompleted(tile, resource.Pass(), manage_tiles_call_count_); |
746 client_->DidPerformCheapRaster(); | |
727 } | 747 } |
728 | 748 |
729 void TileManager::OnRasterCompleted( | 749 void TileManager::OnRasterCompleted( |
730 scoped_refptr<Tile> tile, | 750 scoped_refptr<Tile> tile, |
731 scoped_ptr<ResourcePool::Resource> resource, | 751 scoped_ptr<ResourcePool::Resource> resource, |
732 int manage_tiles_call_count_when_dispatched) { | 752 int manage_tiles_call_count_when_dispatched) { |
733 TRACE_EVENT0("cc", "TileManager::OnRasterCompleted"); | 753 TRACE_EVENT0("cc", "TileManager::OnRasterCompleted"); |
734 | 754 |
735 // Release raster resources. | 755 // Release raster resources. |
736 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); | 756 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 base::TimeTicks end_time = base::TimeTicks::Now(); | 870 base::TimeTicks end_time = base::TimeTicks::Now(); |
851 base::TimeDelta duration = end_time - begin_time; | 871 base::TimeDelta duration = end_time - begin_time; |
852 stats->totalRasterizeTime += duration; | 872 stats->totalRasterizeTime += duration; |
853 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", | 873 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", |
854 duration.InMilliseconds(), | 874 duration.InMilliseconds(), |
855 0, | 875 0, |
856 10, | 876 10, |
857 10); | 877 10); |
858 | 878 |
859 if (use_cheapness_estimator) { | 879 if (use_cheapness_estimator) { |
860 bool is_predicted_cheap = picture_pile->IsCheapInRect (rect, contents_scal e); | 880 bool is_predicted_cheap = picture_pile->IsCheapInRect(rect, contents_scale ); |
861 bool is_actually_cheap = duration.InMillisecondsF() <= 1.0f; | 881 bool is_actually_cheap = duration.InMillisecondsF() <= 1.0f; |
862 RecordCheapnessPredictorResults(is_predicted_cheap, is_actually_cheap); | 882 RecordCheapnessPredictorResults(is_predicted_cheap, is_actually_cheap); |
863 } | 883 } |
864 } | 884 } |
865 } | 885 } |
866 | 886 |
867 // static | 887 // static |
868 void TileManager::RecordCheapnessPredictorResults(bool is_predicted_cheap, | 888 void TileManager::RecordCheapnessPredictorResults(bool is_predicted_cheap, |
869 bool is_actually_cheap) { | 889 bool is_actually_cheap) { |
870 if (is_predicted_cheap && !is_actually_cheap) | 890 if (is_predicted_cheap && !is_actually_cheap) |
871 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorBadlyWrong", true); | 891 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorBadlyWrong", true); |
872 else if (!is_predicted_cheap && is_actually_cheap) | 892 else if (!is_predicted_cheap && is_actually_cheap) |
873 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorSafelyWrong", true); | 893 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorSafelyWrong", true); |
874 | 894 |
875 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorAccuracy", | 895 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorAccuracy", |
876 is_predicted_cheap == is_actually_cheap); | 896 is_predicted_cheap == is_actually_cheap); |
877 } | 897 } |
878 | 898 |
879 // static | 899 // static |
880 void TileManager::RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, | 900 void TileManager::PerformImageDecode(skia::LazyPixelRef* pixel_ref, |
881 RenderingStats* stats) { | 901 RenderingStats* stats) { |
882 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); | 902 TRACE_EVENT0("cc", "TileManager::PerformImageDecode"); |
883 base::TimeTicks decode_begin_time; | 903 base::TimeTicks decode_begin_time; |
884 if (stats) | 904 if (stats) |
885 decode_begin_time = base::TimeTicks::Now(); | 905 decode_begin_time = base::TimeTicks::Now(); |
886 pixel_ref->Decode(); | 906 pixel_ref->Decode(); |
887 if (stats) { | 907 if (stats) { |
888 stats->totalDeferredImageDecodeCount++; | 908 stats->totalDeferredImageDecodeCount++; |
889 stats->totalDeferredImageDecodeTime += | 909 stats->totalDeferredImageDecodeTime += |
890 base::TimeTicks::Now() - decode_begin_time; | 910 base::TimeTicks::Now() - decode_begin_time; |
891 } | 911 } |
892 } | 912 } |
893 | 913 |
894 } // namespace cc | 914 } // namespace cc |
OLD | NEW |