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/resources/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Flag to indicate whether we should try and detect that | 28 // Flag to indicate whether we should try and detect that |
29 // a tile is of solid color. | 29 // a tile is of solid color. |
30 const bool kUseColorEstimator = true; | 30 const bool kUseColorEstimator = true; |
31 | 31 |
32 class RasterTaskImpl : public RasterTask { | 32 class RasterTaskImpl : public RasterTask { |
33 public: | 33 public: |
34 RasterTaskImpl( | 34 RasterTaskImpl( |
35 const Resource* resource, | 35 const Resource* resource, |
36 PicturePileImpl* picture_pile, | 36 RasterSource* raster_source, |
37 const gfx::Rect& content_rect, | 37 const gfx::Rect& content_rect, |
38 float contents_scale, | 38 float contents_scale, |
39 TileResolution tile_resolution, | 39 TileResolution tile_resolution, |
40 int layer_id, | 40 int layer_id, |
41 const void* tile_id, | 41 const void* tile_id, |
42 int source_frame_number, | 42 int source_frame_number, |
43 bool analyze_picture, | 43 bool analyze_picture, |
44 RenderingStatsInstrumentation* rendering_stats, | 44 RenderingStatsInstrumentation* rendering_stats, |
45 const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply, | 45 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& |
| 46 reply, |
46 ImageDecodeTask::Vector* dependencies) | 47 ImageDecodeTask::Vector* dependencies) |
47 : RasterTask(resource, dependencies), | 48 : RasterTask(resource, dependencies), |
48 picture_pile_(picture_pile), | 49 raster_source_(raster_source), |
49 content_rect_(content_rect), | 50 content_rect_(content_rect), |
50 contents_scale_(contents_scale), | 51 contents_scale_(contents_scale), |
51 tile_resolution_(tile_resolution), | 52 tile_resolution_(tile_resolution), |
52 layer_id_(layer_id), | 53 layer_id_(layer_id), |
53 tile_id_(tile_id), | 54 tile_id_(tile_id), |
54 source_frame_number_(source_frame_number), | 55 source_frame_number_(source_frame_number), |
55 analyze_picture_(analyze_picture), | 56 analyze_picture_(analyze_picture), |
56 rendering_stats_(rendering_stats), | 57 rendering_stats_(rendering_stats), |
57 reply_(reply) {} | 58 reply_(reply) {} |
58 | 59 |
59 // Overridden from Task: | 60 // Overridden from Task: |
60 void RunOnWorkerThread() override { | 61 void RunOnWorkerThread() override { |
61 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); | 62 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); |
62 | 63 |
63 DCHECK(picture_pile_.get()); | 64 DCHECK(raster_source_.get()); |
64 DCHECK(raster_buffer_); | 65 DCHECK(raster_buffer_); |
65 | 66 |
66 if (analyze_picture_) { | 67 if (analyze_picture_) { |
67 Analyze(picture_pile_.get()); | 68 Analyze(raster_source_.get()); |
68 if (analysis_.is_solid_color) | 69 if (analysis_.is_solid_color) |
69 return; | 70 return; |
70 } | 71 } |
71 | 72 |
72 Raster(picture_pile_.get()); | 73 Raster(raster_source_.get()); |
73 } | 74 } |
74 | 75 |
75 // Overridden from RasterizerTask: | 76 // Overridden from RasterizerTask: |
76 void ScheduleOnOriginThread(RasterizerTaskClient* client) override { | 77 void ScheduleOnOriginThread(RasterizerTaskClient* client) override { |
77 DCHECK(!raster_buffer_); | 78 DCHECK(!raster_buffer_); |
78 raster_buffer_ = client->AcquireBufferForRaster(resource()); | 79 raster_buffer_ = client->AcquireBufferForRaster(resource()); |
79 } | 80 } |
80 void CompleteOnOriginThread(RasterizerTaskClient* client) override { | 81 void CompleteOnOriginThread(RasterizerTaskClient* client) override { |
81 client->ReleaseBufferForRaster(raster_buffer_.Pass()); | 82 client->ReleaseBufferForRaster(raster_buffer_.Pass()); |
82 } | 83 } |
83 void RunReplyOnOriginThread() override { | 84 void RunReplyOnOriginThread() override { |
84 DCHECK(!raster_buffer_); | 85 DCHECK(!raster_buffer_); |
85 reply_.Run(analysis_, !HasFinishedRunning()); | 86 reply_.Run(analysis_, !HasFinishedRunning()); |
86 } | 87 } |
87 | 88 |
88 protected: | 89 protected: |
89 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 90 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
90 | 91 |
91 private: | 92 private: |
92 void Analyze(const PicturePileImpl* picture_pile) { | 93 void Analyze(const RasterSource* raster_source) { |
93 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | 94 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
94 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 95 tile_id_, tile_resolution_, source_frame_number_, layer_id_); |
95 | 96 |
96 DCHECK(picture_pile); | 97 DCHECK(raster_source); |
97 | 98 |
98 picture_pile->AnalyzeInRect( | 99 raster_source->PerformSolidColorAnalysis( |
99 content_rect_, contents_scale_, &analysis_, rendering_stats_); | 100 content_rect_, contents_scale_, &analysis_, rendering_stats_); |
100 | 101 |
101 // Record the solid color prediction. | 102 // Record the solid color prediction. |
102 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 103 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
103 analysis_.is_solid_color); | 104 analysis_.is_solid_color); |
104 | 105 |
105 // Clear the flag if we're not using the estimator. | 106 // Clear the flag if we're not using the estimator. |
106 analysis_.is_solid_color &= kUseColorEstimator; | 107 analysis_.is_solid_color &= kUseColorEstimator; |
107 } | 108 } |
108 | 109 |
109 void Raster(const PicturePileImpl* picture_pile) { | 110 void Raster(const RasterSource* raster_source) { |
110 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 111 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
111 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 112 tile_id_, tile_resolution_, source_frame_number_, layer_id_); |
112 devtools_instrumentation::ScopedLayerTask layer_task( | 113 devtools_instrumentation::ScopedLayerTask layer_task( |
113 devtools_instrumentation::kRasterTask, layer_id_); | 114 devtools_instrumentation::kRasterTask, layer_id_); |
114 | 115 |
115 base::TimeDelta prev_rasterize_time = | 116 base::TimeDelta prev_rasterize_time = |
116 rendering_stats_->impl_thread_rendering_stats().rasterize_time; | 117 rendering_stats_->impl_thread_rendering_stats().rasterize_time; |
117 | 118 |
118 // Only record rasterization time for highres tiles, because | 119 // Only record rasterization time for highres tiles, because |
119 // lowres tiles are not required for activation and therefore | 120 // lowres tiles are not required for activation and therefore |
120 // introduce noise in the measurement (sometimes they get rasterized | 121 // introduce noise in the measurement (sometimes they get rasterized |
121 // before we draw and sometimes they aren't) | 122 // before we draw and sometimes they aren't) |
122 RenderingStatsInstrumentation* stats = | 123 RenderingStatsInstrumentation* stats = |
123 tile_resolution_ == HIGH_RESOLUTION ? rendering_stats_ : NULL; | 124 tile_resolution_ == HIGH_RESOLUTION ? rendering_stats_ : NULL; |
124 DCHECK(picture_pile); | 125 DCHECK(raster_source); |
125 | 126 |
126 raster_buffer_->Playback( | 127 raster_buffer_->Playback( |
127 picture_pile_.get(), content_rect_, contents_scale_, stats); | 128 raster_source_.get(), content_rect_, contents_scale_, stats); |
128 | 129 |
129 if (rendering_stats_->record_rendering_stats()) { | 130 if (rendering_stats_->record_rendering_stats()) { |
130 base::TimeDelta current_rasterize_time = | 131 base::TimeDelta current_rasterize_time = |
131 rendering_stats_->impl_thread_rendering_stats().rasterize_time; | 132 rendering_stats_->impl_thread_rendering_stats().rasterize_time; |
132 LOCAL_HISTOGRAM_CUSTOM_COUNTS( | 133 LOCAL_HISTOGRAM_CUSTOM_COUNTS( |
133 "Renderer4.PictureRasterTimeUS", | 134 "Renderer4.PictureRasterTimeUS", |
134 (current_rasterize_time - prev_rasterize_time).InMicroseconds(), | 135 (current_rasterize_time - prev_rasterize_time).InMicroseconds(), |
135 0, | 136 0, |
136 100000, | 137 100000, |
137 100); | 138 100); |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 PicturePileImpl::Analysis analysis_; | 142 RasterSource::SolidColorAnalysis analysis_; |
142 scoped_refptr<PicturePileImpl> picture_pile_; | 143 scoped_refptr<RasterSource> raster_source_; |
143 gfx::Rect content_rect_; | 144 gfx::Rect content_rect_; |
144 float contents_scale_; | 145 float contents_scale_; |
145 TileResolution tile_resolution_; | 146 TileResolution tile_resolution_; |
146 int layer_id_; | 147 int layer_id_; |
147 const void* tile_id_; | 148 const void* tile_id_; |
148 int source_frame_number_; | 149 int source_frame_number_; |
149 bool analyze_picture_; | 150 bool analyze_picture_; |
150 RenderingStatsInstrumentation* rendering_stats_; | 151 RenderingStatsInstrumentation* rendering_stats_; |
151 const base::Callback<void(const PicturePileImpl::Analysis&, bool)> reply_; | 152 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> |
| 153 reply_; |
152 scoped_ptr<RasterBuffer> raster_buffer_; | 154 scoped_ptr<RasterBuffer> raster_buffer_; |
153 | 155 |
154 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 156 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
155 }; | 157 }; |
156 | 158 |
157 class ImageDecodeTaskImpl : public ImageDecodeTask { | 159 class ImageDecodeTaskImpl : public ImageDecodeTask { |
158 public: | 160 public: |
159 ImageDecodeTaskImpl(SkPixelRef* pixel_ref, | 161 ImageDecodeTaskImpl(SkPixelRef* pixel_ref, |
160 int layer_id, | 162 int layer_id, |
161 RenderingStatsInstrumentation* rendering_stats, | 163 RenderingStatsInstrumentation* rendering_stats, |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 scoped_refptr<RasterTask> TileManager::CreateRasterTask(Tile* tile) { | 728 scoped_refptr<RasterTask> TileManager::CreateRasterTask(Tile* tile) { |
727 ManagedTileState& mts = tile->managed_state(); | 729 ManagedTileState& mts = tile->managed_state(); |
728 | 730 |
729 scoped_ptr<ScopedResource> resource = | 731 scoped_ptr<ScopedResource> resource = |
730 resource_pool_->AcquireResource(tile->size()); | 732 resource_pool_->AcquireResource(tile->size()); |
731 const ScopedResource* const_resource = resource.get(); | 733 const ScopedResource* const_resource = resource.get(); |
732 | 734 |
733 // Create and queue all image decode tasks that this tile depends on. | 735 // Create and queue all image decode tasks that this tile depends on. |
734 ImageDecodeTask::Vector decode_tasks; | 736 ImageDecodeTask::Vector decode_tasks; |
735 PixelRefTaskMap& existing_pixel_refs = image_decode_tasks_[tile->layer_id()]; | 737 PixelRefTaskMap& existing_pixel_refs = image_decode_tasks_[tile->layer_id()]; |
736 for (PicturePileImpl::PixelRefIterator iter( | 738 std::vector<SkPixelRef*> pixel_refs; |
737 tile->content_rect(), tile->contents_scale(), tile->picture_pile()); | 739 tile->raster_source()->GatherPixelRefs( |
738 iter; | 740 tile->content_rect(), tile->contents_scale(), &pixel_refs); |
739 ++iter) { | 741 for (SkPixelRef* pixel_ref : pixel_refs) { |
740 SkPixelRef* pixel_ref = *iter; | |
741 uint32_t id = pixel_ref->getGenerationID(); | 742 uint32_t id = pixel_ref->getGenerationID(); |
742 | 743 |
743 // Append existing image decode task if available. | 744 // Append existing image decode task if available. |
744 PixelRefTaskMap::iterator decode_task_it = existing_pixel_refs.find(id); | 745 PixelRefTaskMap::iterator decode_task_it = existing_pixel_refs.find(id); |
745 if (decode_task_it != existing_pixel_refs.end()) { | 746 if (decode_task_it != existing_pixel_refs.end()) { |
746 decode_tasks.push_back(decode_task_it->second); | 747 decode_tasks.push_back(decode_task_it->second); |
747 continue; | 748 continue; |
748 } | 749 } |
749 | 750 |
750 // Create and append new image decode task for this pixel ref. | 751 // Create and append new image decode task for this pixel ref. |
751 scoped_refptr<ImageDecodeTask> decode_task = | 752 scoped_refptr<ImageDecodeTask> decode_task = |
752 CreateImageDecodeTask(tile, pixel_ref); | 753 CreateImageDecodeTask(tile, pixel_ref); |
753 decode_tasks.push_back(decode_task); | 754 decode_tasks.push_back(decode_task); |
754 existing_pixel_refs[id] = decode_task; | 755 existing_pixel_refs[id] = decode_task; |
755 } | 756 } |
756 | 757 |
757 return make_scoped_refptr( | 758 return make_scoped_refptr( |
758 new RasterTaskImpl(const_resource, | 759 new RasterTaskImpl(const_resource, |
759 tile->picture_pile(), | 760 tile->raster_source(), |
760 tile->content_rect(), | 761 tile->content_rect(), |
761 tile->contents_scale(), | 762 tile->contents_scale(), |
762 mts.resolution, | 763 mts.resolution, |
763 tile->layer_id(), | 764 tile->layer_id(), |
764 static_cast<const void*>(tile), | 765 static_cast<const void*>(tile), |
765 tile->source_frame_number(), | 766 tile->source_frame_number(), |
766 tile->use_picture_analysis(), | 767 tile->use_picture_analysis(), |
767 rendering_stats_instrumentation_, | 768 rendering_stats_instrumentation_, |
768 base::Bind(&TileManager::OnRasterTaskCompleted, | 769 base::Bind(&TileManager::OnRasterTaskCompleted, |
769 base::Unretained(this), | 770 base::Unretained(this), |
(...skipping 18 matching lines...) Expand all Loading... |
788 PixelRefTaskMap::iterator task_it = | 789 PixelRefTaskMap::iterator task_it = |
789 pixel_ref_tasks.find(pixel_ref->getGenerationID()); | 790 pixel_ref_tasks.find(pixel_ref->getGenerationID()); |
790 | 791 |
791 if (task_it != pixel_ref_tasks.end()) | 792 if (task_it != pixel_ref_tasks.end()) |
792 pixel_ref_tasks.erase(task_it); | 793 pixel_ref_tasks.erase(task_it); |
793 } | 794 } |
794 | 795 |
795 void TileManager::OnRasterTaskCompleted( | 796 void TileManager::OnRasterTaskCompleted( |
796 Tile::Id tile_id, | 797 Tile::Id tile_id, |
797 scoped_ptr<ScopedResource> resource, | 798 scoped_ptr<ScopedResource> resource, |
798 const PicturePileImpl::Analysis& analysis, | 799 const RasterSource::SolidColorAnalysis& analysis, |
799 bool was_canceled) { | 800 bool was_canceled) { |
800 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 801 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
801 | 802 |
802 Tile* tile = tiles_[tile_id]; | 803 Tile* tile = tiles_[tile_id]; |
803 ManagedTileState& mts = tile->managed_state(); | 804 ManagedTileState& mts = tile->managed_state(); |
804 DCHECK(mts.raster_task.get()); | 805 DCHECK(mts.raster_task.get()); |
805 orphan_raster_tasks_.push_back(mts.raster_task); | 806 orphan_raster_tasks_.push_back(mts.raster_task); |
806 mts.raster_task = NULL; | 807 mts.raster_task = NULL; |
807 | 808 |
808 if (was_canceled) { | 809 if (was_canceled) { |
(...skipping 11 matching lines...) Expand all Loading... |
820 mts.draw_info.set_use_resource(); | 821 mts.draw_info.set_use_resource(); |
821 mts.draw_info.resource_ = resource.Pass(); | 822 mts.draw_info.resource_ = resource.Pass(); |
822 } | 823 } |
823 | 824 |
824 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) | 825 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) |
825 did_initialize_visible_tile_ = true; | 826 did_initialize_visible_tile_ = true; |
826 | 827 |
827 client_->NotifyTileStateChanged(tile); | 828 client_->NotifyTileStateChanged(tile); |
828 } | 829 } |
829 | 830 |
830 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, | 831 scoped_refptr<Tile> TileManager::CreateTile(RasterSource* raster_source, |
831 const gfx::Size& tile_size, | 832 const gfx::Size& tile_size, |
832 const gfx::Rect& content_rect, | 833 const gfx::Rect& content_rect, |
833 float contents_scale, | 834 float contents_scale, |
834 int layer_id, | 835 int layer_id, |
835 int source_frame_number, | 836 int source_frame_number, |
836 int flags) { | 837 int flags) { |
837 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this, | 838 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this, |
838 picture_pile, | 839 raster_source, |
839 tile_size, | 840 tile_size, |
840 content_rect, | 841 content_rect, |
841 contents_scale, | 842 contents_scale, |
842 layer_id, | 843 layer_id, |
843 source_frame_number, | 844 source_frame_number, |
844 flags)); | 845 flags)); |
845 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 846 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
846 | 847 |
847 tiles_[tile->id()] = tile.get(); | 848 tiles_[tile->id()] = tile.get(); |
848 used_layer_counts_[tile->layer_id()]++; | 849 used_layer_counts_[tile->layer_id()]++; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 result -= other; | 922 result -= other; |
922 return result; | 923 return result; |
923 } | 924 } |
924 | 925 |
925 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 926 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
926 return memory_bytes_ > limit.memory_bytes_ || | 927 return memory_bytes_ > limit.memory_bytes_ || |
927 resource_count_ > limit.resource_count_; | 928 resource_count_ > limit.resource_count_; |
928 } | 929 } |
929 | 930 |
930 } // namespace cc | 931 } // namespace cc |
OLD | NEW |