Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: cc/tiles/tile_manager.cc

Issue 1890903002: cc: Simplify Task and its derived classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_tile_task_runner
Patch Set: nits Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/tiles/tile_manager.h" 5 #include "cc/tiles/tile_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 24 matching lines...) Expand all
35 35
36 // Flag to indicate whether we should try and detect that 36 // Flag to indicate whether we should try and detect that
37 // a tile is of solid color. 37 // a tile is of solid color.
38 const bool kUseColorEstimator = true; 38 const bool kUseColorEstimator = true;
39 39
40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( 40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(
41 ScopedRasterTaskTimer, 41 ScopedRasterTaskTimer,
42 "Compositing.%s.RasterTask.RasterUs", 42 "Compositing.%s.RasterTask.RasterUs",
43 "Compositing.%s.RasterTask.RasterPixelsPerMs"); 43 "Compositing.%s.RasterTask.RasterPixelsPerMs");
44 44
45 class RasterTaskImpl : public RasterTask { 45 class RasterTaskImpl : public TileTask {
46 public: 46 public:
47 RasterTaskImpl(const Resource* resource, 47 RasterTaskImpl(const Resource* resource,
48 scoped_refptr<RasterSource> raster_source, 48 scoped_refptr<RasterSource> raster_source,
49 const gfx::Rect& content_rect, 49 const gfx::Rect& content_rect,
50 const gfx::Rect& invalid_content_rect, 50 const gfx::Rect& invalid_content_rect,
51 float contents_scale, 51 float contents_scale,
52 const RasterSource::PlaybackSettings& playback_settings, 52 const RasterSource::PlaybackSettings& playback_settings,
53 TileResolution tile_resolution, 53 TileResolution tile_resolution,
54 int layer_id, 54 int layer_id,
55 uint64_t source_prepare_tiles_id, 55 uint64_t source_prepare_tiles_id,
56 const void* tile, 56 const void* tile,
57 uint64_t new_content_id, 57 uint64_t new_content_id,
58 uint64_t previous_content_id, 58 uint64_t previous_content_id,
59 uint64_t resource_content_id, 59 uint64_t resource_content_id,
60 int source_frame_number, 60 int source_frame_number,
61 const base::Callback<void(bool)>& reply, 61 const base::Callback<void(bool)>& reply,
62 ImageDecodeTask::Vector* dependencies) 62 TileTask::Vector* dependencies)
63 : RasterTask(dependencies), 63 : TileTask(dependencies),
64 resource_(resource), 64 resource_(resource),
65 raster_source_(std::move(raster_source)), 65 raster_source_(std::move(raster_source)),
66 content_rect_(content_rect), 66 content_rect_(content_rect),
67 invalid_content_rect_(invalid_content_rect), 67 invalid_content_rect_(invalid_content_rect),
68 contents_scale_(contents_scale), 68 contents_scale_(contents_scale),
69 playback_settings_(playback_settings), 69 playback_settings_(playback_settings),
70 tile_resolution_(tile_resolution), 70 tile_resolution_(tile_resolution),
71 layer_id_(layer_id), 71 layer_id_(layer_id),
72 source_prepare_tiles_id_(source_prepare_tiles_id), 72 source_prepare_tiles_id_(source_prepare_tiles_id),
73 tile_(tile), 73 tile_(tile),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 size_t dependencies) { 149 size_t dependencies) {
150 DCHECK(std::find_if(graph->nodes.begin(), graph->nodes.end(), 150 DCHECK(std::find_if(graph->nodes.begin(), graph->nodes.end(),
151 [task](const TaskGraph::Node& node) { 151 [task](const TaskGraph::Node& node) {
152 return node.task == task; 152 return node.task == task;
153 }) == graph->nodes.end()); 153 }) == graph->nodes.end());
154 graph->nodes.push_back( 154 graph->nodes.push_back(
155 TaskGraph::Node(task, category, priority, dependencies)); 155 TaskGraph::Node(task, category, priority, dependencies));
156 } 156 }
157 157
158 void InsertNodeForDecodeTask(TaskGraph* graph, 158 void InsertNodeForDecodeTask(TaskGraph* graph,
159 ImageDecodeTask* task, 159 TileTask* task,
160 uint16_t category, 160 uint16_t category,
161 uint16_t priority) { 161 uint16_t priority) {
162 uint32_t dependency_count = 0u; 162 uint32_t dependency_count = 0u;
163 auto* dependency = task->dependency().get(); 163 if (task->dependencies().size()) {
164 if (dependency && !dependency->HasCompleted()) { 164 DCHECK_EQ(task->dependencies().size(), 1u);
165 InsertNodeForDecodeTask(graph, dependency, category, priority); 165 auto* dependency = task->dependencies()[0].get();
166 graph->edges.push_back(TaskGraph::Edge(dependency, task)); 166 if (!dependency->HasCompleted()) {
167 dependency_count = 1u; 167 InsertNodeForDecodeTask(graph, dependency, category, priority);
168 graph->edges.push_back(TaskGraph::Edge(dependency, task));
169 dependency_count = 1u;
170 }
168 } 171 }
169 InsertNodeForTask(graph, task, task->SupportsConcurrentExecution() 172 InsertNodeForTask(graph, task, task->SupportsConcurrentExecution()
170 ? category 173 ? category
171 : TASK_CATEGORY_NONCONCURRENT_FOREGROUND, 174 : TASK_CATEGORY_NONCONCURRENT_FOREGROUND,
172 priority, dependency_count); 175 priority, dependency_count);
173 } 176 }
174 177
175 void InsertNodesForRasterTask(TaskGraph* graph, 178 void InsertNodesForRasterTask(TaskGraph* graph,
176 RasterTask* raster_task, 179 TileTask* raster_task,
177 const ImageDecodeTask::Vector& decode_tasks, 180 const TileTask::Vector& decode_tasks,
178 size_t priority, 181 size_t priority,
179 bool use_gpu_rasterization, 182 bool use_gpu_rasterization,
180 bool high_priority) { 183 bool high_priority) {
181 size_t dependencies = 0u; 184 size_t dependencies = 0u;
182 185
183 // Determine the TaskCategory for raster tasks - if a task uses GPU, it 186 // Determine the TaskCategory for raster tasks - if a task uses GPU, it
184 // cannot run concurrently and is assigned 187 // cannot run concurrently and is assigned
185 // TASK_CATEGORY_NONCONCURRENT_FOREGROUND, regardless of its priority. 188 // TASK_CATEGORY_NONCONCURRENT_FOREGROUND, regardless of its priority.
186 // Otherwise its category is based on its priority. 189 // Otherwise its category is based on its priority.
187 TaskCategory raster_task_category; 190 TaskCategory raster_task_category;
188 if (use_gpu_rasterization) { 191 if (use_gpu_rasterization) {
189 raster_task_category = TASK_CATEGORY_NONCONCURRENT_FOREGROUND; 192 raster_task_category = TASK_CATEGORY_NONCONCURRENT_FOREGROUND;
190 } else { 193 } else {
191 raster_task_category = 194 raster_task_category =
192 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND; 195 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND;
193 } 196 }
194 197
195 // Determine the TaskCategory for decode tasks. This category is based on 198 // Determine the TaskCategory for decode tasks. This category is based on
196 // the priority of the raster task which depends on it. 199 // the priority of the raster task which depends on it.
197 TaskCategory decode_task_category = 200 TaskCategory decode_task_category =
198 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND; 201 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND;
199 202
200 // Insert image decode tasks. 203 // Insert image decode tasks.
201 for (ImageDecodeTask::Vector::const_iterator it = decode_tasks.begin(); 204 for (TileTask::Vector::const_iterator it = decode_tasks.begin();
202 it != decode_tasks.end(); ++it) { 205 it != decode_tasks.end(); ++it) {
203 ImageDecodeTask* decode_task = it->get(); 206 TileTask* decode_task = it->get();
204 207
205 // Skip if already decoded. 208 // Skip if already decoded.
206 if (decode_task->HasCompleted()) 209 if (decode_task->HasCompleted())
207 continue; 210 continue;
208 211
209 dependencies++; 212 dependencies++;
210 213
211 // Add decode task if it doesn't already exists in graph. 214 // Add decode task if it doesn't already exists in graph.
212 TaskGraph::Node::Vector::iterator decode_it = 215 TaskGraph::Node::Vector::iterator decode_it =
213 std::find_if(graph->nodes.begin(), graph->nodes.end(), 216 std::find_if(graph->nodes.begin(), graph->nodes.end(),
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // are added in order of priority, highest priority task first. 775 // are added in order of priority, highest priority task first.
773 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) { 776 for (auto& prioritized_tile : tiles_that_need_to_be_rasterized) {
774 Tile* tile = prioritized_tile.tile(); 777 Tile* tile = prioritized_tile.tile();
775 778
776 DCHECK(tile->draw_info().requires_resource()); 779 DCHECK(tile->draw_info().requires_resource());
777 DCHECK(!tile->draw_info().resource_); 780 DCHECK(!tile->draw_info().resource_);
778 781
779 if (!tile->raster_task_) 782 if (!tile->raster_task_)
780 tile->raster_task_ = CreateRasterTask(prioritized_tile); 783 tile->raster_task_ = CreateRasterTask(prioritized_tile);
781 784
782 RasterTask* task = tile->raster_task_.get(); 785 TileTask* task = tile->raster_task_.get();
783 DCHECK(!task->HasCompleted()); 786 DCHECK(!task->HasCompleted());
784 787
785 if (tile->required_for_activation()) { 788 if (tile->required_for_activation()) {
786 required_for_activate_count++; 789 required_for_activate_count++;
787 graph_.edges.push_back( 790 graph_.edges.push_back(
788 TaskGraph::Edge(task, required_for_activation_done_task.get())); 791 TaskGraph::Edge(task, required_for_activation_done_task.get()));
789 } 792 }
790 if (tile->required_for_draw()) { 793 if (tile->required_for_draw()) {
791 required_for_draw_count++; 794 required_for_draw_count++;
792 graph_.edges.push_back( 795 graph_.edges.push_back(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 std::move(required_for_activation_done_task); 841 std::move(required_for_activation_done_task);
839 required_for_draw_done_task_ = std::move(required_for_draw_done_task); 842 required_for_draw_done_task_ = std::move(required_for_draw_done_task);
840 all_done_task_ = std::move(all_done_task); 843 all_done_task_ = std::move(all_done_task);
841 844
842 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; 845 did_check_for_completed_tasks_since_last_schedule_tasks_ = false;
843 846
844 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", 847 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state",
845 ScheduledTasksStateAsValue()); 848 ScheduledTasksStateAsValue());
846 } 849 }
847 850
848 scoped_refptr<RasterTask> TileManager::CreateRasterTask( 851 scoped_refptr<TileTask> TileManager::CreateRasterTask(
849 const PrioritizedTile& prioritized_tile) { 852 const PrioritizedTile& prioritized_tile) {
850 Tile* tile = prioritized_tile.tile(); 853 Tile* tile = prioritized_tile.tile();
851 854
852 // Get the resource. 855 // Get the resource.
853 uint64_t resource_content_id = 0; 856 uint64_t resource_content_id = 0;
854 Resource* resource = nullptr; 857 Resource* resource = nullptr;
855 if (use_partial_raster_ && tile->invalidated_id()) { 858 if (use_partial_raster_ && tile->invalidated_id()) {
856 // TODO(danakj): For resources that are in use, we should still grab them 859 // TODO(danakj): For resources that are in use, we should still grab them
857 // and copy from them instead of rastering everything. crbug.com/492754 860 // and copy from them instead of rastering everything. crbug.com/492754
858 resource = 861 resource =
859 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); 862 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id());
860 } 863 }
861 if (resource) { 864 if (resource) {
862 resource_content_id = tile->invalidated_id(); 865 resource_content_id = tile->invalidated_id();
863 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); 866 DCHECK_EQ(DetermineResourceFormat(tile), resource->format());
864 } else { 867 } else {
865 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), 868 resource = resource_pool_->AcquireResource(tile->desired_texture_size(),
866 DetermineResourceFormat(tile)); 869 DetermineResourceFormat(tile));
867 } 870 }
868 871
869 // For LOW_RESOLUTION tiles, we don't draw or predecode images. 872 // For LOW_RESOLUTION tiles, we don't draw or predecode images.
870 RasterSource::PlaybackSettings playback_settings; 873 RasterSource::PlaybackSettings playback_settings;
871 playback_settings.skip_images = 874 playback_settings.skip_images =
872 prioritized_tile.priority().resolution == LOW_RESOLUTION; 875 prioritized_tile.priority().resolution == LOW_RESOLUTION;
873 876
874 // Create and queue all image decode tasks that this tile depends on. 877 // Create and queue all image decode tasks that this tile depends on.
875 ImageDecodeTask::Vector decode_tasks; 878 TileTask::Vector decode_tasks;
876 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; 879 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()];
877 images.clear(); 880 images.clear();
878 if (!playback_settings.skip_images) { 881 if (!playback_settings.skip_images) {
879 prioritized_tile.raster_source()->GetDiscardableImagesInRect( 882 prioritized_tile.raster_source()->GetDiscardableImagesInRect(
880 tile->enclosing_layer_rect(), tile->contents_scale(), &images); 883 tile->enclosing_layer_rect(), tile->contents_scale(), &images);
881 } 884 }
882 885
883 // We can skip the image hijack canvas if we have no images. 886 // We can skip the image hijack canvas if we have no images.
884 playback_settings.use_image_hijack_canvas = !images.empty(); 887 playback_settings.use_image_hijack_canvas = !images.empty();
885 for (auto it = images.begin(); it != images.end();) { 888 for (auto it = images.begin(); it != images.end();) {
886 scoped_refptr<ImageDecodeTask> task; 889 scoped_refptr<TileTask> task;
887 bool need_to_unref_when_finished = 890 bool need_to_unref_when_finished =
888 image_decode_controller_->GetTaskForImageAndRef( 891 image_decode_controller_->GetTaskForImageAndRef(
889 *it, prepare_tiles_count_, &task); 892 *it, prepare_tiles_count_, &task);
890 if (task) 893 if (task)
891 decode_tasks.push_back(task); 894 decode_tasks.push_back(task);
892 895
893 if (need_to_unref_when_finished) 896 if (need_to_unref_when_finished)
894 ++it; 897 ++it;
895 else 898 else
896 it = images.erase(it); 899 it = images.erase(it);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 void TileManager::Signals::reset() { 1238 void TileManager::Signals::reset() {
1236 ready_to_activate = false; 1239 ready_to_activate = false;
1237 did_notify_ready_to_activate = false; 1240 did_notify_ready_to_activate = false;
1238 ready_to_draw = false; 1241 ready_to_draw = false;
1239 did_notify_ready_to_draw = false; 1242 did_notify_ready_to_draw = false;
1240 all_tile_tasks_completed = false; 1243 all_tile_tasks_completed = false;
1241 did_notify_all_tile_tasks_completed = false; 1244 did_notify_all_tile_tasks_completed = false;
1242 } 1245 }
1243 1246
1244 } // namespace cc 1247 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698