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