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/platform_color.h" | 14 #include "cc/platform_color.h" |
15 #include "cc/raster_worker_pool.h" | 15 #include "cc/raster_worker_pool.h" |
16 #include "cc/resource_pool.h" | 16 #include "cc/resource_pool.h" |
17 #include "cc/tile.h" | 17 #include "cc/tile.h" |
18 #include "skia/ext/paint_simplifier.h" | |
18 #include "third_party/skia/include/core/SkDevice.h" | 19 #include "third_party/skia/include/core/SkDevice.h" |
19 | 20 |
20 namespace cc { | 21 namespace cc { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // If we raster too fast we become upload bound, and pending | 25 // If we raster too fast we become upload bound, and pending |
25 // uploads consume memory. For maximum upload throughput, we would | 26 // uploads consume memory. For maximum upload throughput, we would |
26 // want to allow for upload_throughput * pipeline_time of pending | 27 // want to allow for upload_throughput * pipeline_time of pending |
27 // uploads, after which we are just wasting memory. Since we don't | 28 // uploads, after which we are just wasting memory. Since we don't |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 return EVENTUALLY_BIN; | 66 return EVENTUALLY_BIN; |
66 } | 67 } |
67 | 68 |
68 std::string ValueToString(scoped_ptr<base::Value> value) | 69 std::string ValueToString(scoped_ptr<base::Value> value) |
69 { | 70 { |
70 std::string str; | 71 std::string str; |
71 base::JSONWriter::Write(value.get(), &str); | 72 base::JSONWriter::Write(value.get(), &str); |
72 return str; | 73 return str; |
73 } | 74 } |
74 | 75 |
76 | |
75 } // namespace | 77 } // namespace |
76 | 78 |
77 scoped_ptr<base::Value> TileManagerBinAsValue(TileManagerBin bin) { | 79 scoped_ptr<base::Value> TileManagerBinAsValue(TileManagerBin bin) { |
78 switch (bin) { | 80 switch (bin) { |
79 case NOW_BIN: | 81 case NOW_BIN: |
80 return scoped_ptr<base::Value>(base::Value::CreateStringValue( | 82 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
81 "NOW_BIN")); | 83 "NOW_BIN")); |
82 case SOON_BIN: | 84 case SOON_BIN: |
83 return scoped_ptr<base::Value>(base::Value::CreateStringValue( | 85 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
84 "SOON_BIN")); | 86 "SOON_BIN")); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 659 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
658 ResourceProvider::ResourceId resource_id = resource->id(); | 660 ResourceProvider::ResourceId resource_id = resource->id(); |
659 | 661 |
660 raster_worker_pool_->PostRasterTaskAndReply( | 662 raster_worker_pool_->PostRasterTaskAndReply( |
661 tile->picture_pile(), | 663 tile->picture_pile(), |
662 base::Bind(&TileManager::PerformRaster, | 664 base::Bind(&TileManager::PerformRaster, |
663 resource_pool_->resource_provider()->mapPixelBuffer( | 665 resource_pool_->resource_provider()->mapPixelBuffer( |
664 resource_id), | 666 resource_id), |
665 tile->content_rect_, | 667 tile->content_rect_, |
666 tile->contents_scale(), | 668 tile->contents_scale(), |
667 use_cheapness_estimator_), | 669 use_cheapness_estimator_, |
670 ShouldSimplifyPaint(tile.get())), | |
668 base::Bind(&TileManager::OnRasterTaskCompleted, | 671 base::Bind(&TileManager::OnRasterTaskCompleted, |
669 base::Unretained(this), | 672 base::Unretained(this), |
670 tile, | 673 tile, |
671 base::Passed(&resource), | 674 base::Passed(&resource), |
672 manage_tiles_call_count_)); | 675 manage_tiles_call_count_)); |
673 } | 676 } |
674 | 677 |
675 void TileManager::PerformOneRaster(Tile* tile) { | 678 void TileManager::PerformOneRaster(Tile* tile) { |
676 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); | 679 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); |
677 ResourceProvider::ResourceId resource_id = resource->id(); | 680 ResourceProvider::ResourceId resource_id = resource->id(); |
678 | 681 |
679 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( | 682 PerformRaster(resource_pool_->resource_provider()->mapPixelBuffer( |
680 resource_id), | 683 resource_id), |
681 tile->content_rect_, | 684 tile->content_rect_, |
682 tile->contents_scale(), | 685 tile->contents_scale(), |
683 use_cheapness_estimator_, | 686 use_cheapness_estimator_, |
687 ShouldSimplifyPaint(tile), | |
684 tile->picture_pile(), | 688 tile->picture_pile(), |
685 &rendering_stats_); | 689 &rendering_stats_); |
686 | 690 |
687 OnRasterCompleted(tile, resource.Pass(), manage_tiles_call_count_); | 691 OnRasterCompleted(tile, resource.Pass(), manage_tiles_call_count_); |
688 } | 692 } |
689 | 693 |
690 void TileManager::OnRasterCompleted( | 694 void TileManager::OnRasterCompleted( |
691 scoped_refptr<Tile> tile, | 695 scoped_refptr<Tile> tile, |
692 scoped_ptr<ResourcePool::Resource> resource, | 696 scoped_ptr<ResourcePool::Resource> resource, |
693 int manage_tiles_call_count_when_dispatched) { | 697 int manage_tiles_call_count_when_dispatched) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 ++raster_state_count_[mts.raster_state][tree][bin]; | 783 ++raster_state_count_[mts.raster_state][tree][bin]; |
780 | 784 |
781 mts.tree_bin[tree] = bin; | 785 mts.tree_bin[tree] = bin; |
782 } | 786 } |
783 | 787 |
784 // static | 788 // static |
785 void TileManager::PerformRaster(uint8* buffer, | 789 void TileManager::PerformRaster(uint8* buffer, |
786 const gfx::Rect& rect, | 790 const gfx::Rect& rect, |
787 float contents_scale, | 791 float contents_scale, |
788 bool use_cheapness_estimator, | 792 bool use_cheapness_estimator, |
793 bool simplify_paint, | |
789 PicturePileImpl* picture_pile, | 794 PicturePileImpl* picture_pile, |
790 RenderingStats* stats) { | 795 RenderingStats* stats) { |
791 TRACE_EVENT0("cc", "TileManager::PerformRaster"); | 796 TRACE_EVENT0("cc", "TileManager::PerformRaster"); |
792 DCHECK(picture_pile); | 797 DCHECK(picture_pile); |
793 DCHECK(buffer); | 798 DCHECK(buffer); |
794 SkBitmap bitmap; | 799 SkBitmap bitmap; |
795 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 800 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
796 bitmap.setPixels(buffer); | 801 bitmap.setPixels(buffer); |
797 SkDevice device(bitmap); | 802 SkDevice device(bitmap); |
798 SkCanvas canvas(&device); | 803 SkCanvas canvas(&device); |
799 | 804 |
800 base::TimeTicks begin_time; | 805 base::TimeTicks begin_time; |
801 if (stats) | 806 if (stats) |
802 begin_time = base::TimeTicks::Now(); | 807 begin_time = base::TimeTicks::Now(); |
803 | 808 |
809 // FIXME: PerformRaster is a static function, so we can't just create | |
810 // one in the constructor and reuse it. But the object is refcounted | |
811 // so may not be happy living on the stack. How do we get rid of this | |
812 // new? | |
Sami
2013/02/08 13:44:01
You could create the simplifier as a member of Til
| |
813 if (simplify_paint) | |
814 canvas.setDrawFilter(new skia::PaintSimplifier); | |
815 | |
804 int64 total_pixels_rasterized = 0; | 816 int64 total_pixels_rasterized = 0; |
805 picture_pile->Raster(&canvas, rect, contents_scale, | 817 picture_pile->Raster(&canvas, rect, contents_scale, |
806 &total_pixels_rasterized); | 818 &total_pixels_rasterized); |
807 | 819 |
808 if (stats) { | 820 if (stats) { |
809 stats->totalPixelsRasterized += total_pixels_rasterized; | 821 stats->totalPixelsRasterized += total_pixels_rasterized; |
810 | 822 |
811 base::TimeTicks end_time = base::TimeTicks::Now(); | 823 base::TimeTicks end_time = base::TimeTicks::Now(); |
812 base::TimeDelta duration = end_time - begin_time; | 824 base::TimeDelta duration = end_time - begin_time; |
813 stats->totalRasterizeTime += duration; | 825 stats->totalRasterizeTime += duration; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 if (stats) | 857 if (stats) |
846 decode_begin_time = base::TimeTicks::Now(); | 858 decode_begin_time = base::TimeTicks::Now(); |
847 pixel_ref->Decode(); | 859 pixel_ref->Decode(); |
848 if (stats) { | 860 if (stats) { |
849 stats->totalDeferredImageDecodeCount++; | 861 stats->totalDeferredImageDecodeCount++; |
850 stats->totalDeferredImageDecodeTime += | 862 stats->totalDeferredImageDecodeTime += |
851 base::TimeTicks::Now() - decode_begin_time; | 863 base::TimeTicks::Now() - decode_begin_time; |
852 } | 864 } |
853 } | 865 } |
854 | 866 |
867 // Needs to be a member of TileManager to access Tile::managed_state() | |
868 bool TileManager::ShouldSimplifyPaint(Tile* tile) { | |
869 // FIXME: tree_priority can remain SMOOTHNESS_TAKES_PRIORITY an arbitrary | |
870 // length of time after a fling ends. resolution can be LOW_RESOLUTION | |
871 // at times other than mid-fling. The two only seem to be true | |
872 // together during flings & pinch-zooms. | |
873 return | |
874 GlobalState().tree_priority == SMOOTHNESS_TAKES_PRIORITY && | |
875 tile->managed_state().resolution == LOW_RESOLUTION; | |
876 } | |
877 | |
855 } // namespace cc | 878 } // namespace cc |
OLD | NEW |