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

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

Issue 1910613002: Clean up task category assignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const RasterSource::PlaybackSettings& playback_settings, 51 const RasterSource::PlaybackSettings& playback_settings,
52 TileResolution tile_resolution, 52 TileResolution tile_resolution,
53 int layer_id, 53 int layer_id,
54 uint64_t source_prepare_tiles_id, 54 uint64_t source_prepare_tiles_id,
55 const void* tile, 55 const void* tile,
56 uint64_t new_content_id, 56 uint64_t new_content_id,
57 uint64_t previous_content_id, 57 uint64_t previous_content_id,
58 uint64_t resource_content_id, 58 uint64_t resource_content_id,
59 int source_frame_number, 59 int source_frame_number,
60 const base::Callback<void(bool)>& reply, 60 const base::Callback<void(bool)>& reply,
61 TileTask::Vector* dependencies) 61 TileTask::Vector* dependencies,
62 : TileTask(true, dependencies), 62 bool supports_concurrent_execution)
63 : TileTask(supports_concurrent_execution, dependencies),
63 resource_(resource), 64 resource_(resource),
64 raster_source_(std::move(raster_source)), 65 raster_source_(std::move(raster_source)),
65 content_rect_(content_rect), 66 content_rect_(content_rect),
66 invalid_content_rect_(invalid_content_rect), 67 invalid_content_rect_(invalid_content_rect),
67 contents_scale_(contents_scale), 68 contents_scale_(contents_scale),
68 playback_settings_(playback_settings), 69 playback_settings_(playback_settings),
69 tile_resolution_(tile_resolution), 70 tile_resolution_(tile_resolution),
70 layer_id_(layer_id), 71 layer_id_(layer_id),
71 source_prepare_tiles_id_(source_prepare_tiles_id), 72 source_prepare_tiles_id_(source_prepare_tiles_id),
72 tile_(tile), 73 tile_(tile),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 uint64_t new_content_id_; 125 uint64_t new_content_id_;
125 uint64_t previous_content_id_; 126 uint64_t previous_content_id_;
126 uint64_t resource_content_id_; 127 uint64_t resource_content_id_;
127 int source_frame_number_; 128 int source_frame_number_;
128 const base::Callback<void(bool)> reply_; 129 const base::Callback<void(bool)> reply_;
129 std::unique_ptr<RasterBuffer> raster_buffer_; 130 std::unique_ptr<RasterBuffer> raster_buffer_;
130 131
131 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); 132 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl);
132 }; 133 };
133 134
135 TaskCategory TaskCategoryForTileTask(TileTask* task, bool high_priority) {
prashant.n 2016/04/23 04:55:19 May be replace high_priority with is_foreground or
ericrk 2016/05/02 23:04:37 Done.
136 if (!task->supports_concurrent_execution()) {
137 return TASK_CATEGORY_NONCONCURRENT_FOREGROUND;
138 }
vmpstr 2016/04/25 18:23:34 nit: remove braces please
ericrk 2016/05/02 23:04:37 Done.
139 if (high_priority) {
140 return TASK_CATEGORY_FOREGROUND;
141 }
142 return TASK_CATEGORY_BACKGROUND;
143 }
144
145 bool IsHighPriorityCategory(uint16_t category) {
prashant.n 2016/04/23 04:55:19 Should we use simple function name IsForeground()
ericrk 2016/05/02 23:04:37 Using IsForegroundCategory - I agree that HighPrio
146 TaskCategory enum_category = static_cast<TaskCategory>(category);
147 switch (enum_category) {
148 case TASK_CATEGORY_NONCONCURRENT_FOREGROUND:
149 case TASK_CATEGORY_FOREGROUND:
150 return true;
151 case TASK_CATEGORY_BACKGROUND:
152 return false;
153 }
154
155 DCHECK(false);
156 return false;
157 }
158
134 // Task priorities that make sure that the task set done tasks run before any 159 // Task priorities that make sure that the task set done tasks run before any
135 // other remaining tasks. 160 // other remaining tasks.
136 const size_t kRequiredForActivationDoneTaskPriority = 1u; 161 const size_t kRequiredForActivationDoneTaskPriority = 1u;
137 const size_t kRequiredForDrawDoneTaskPriority = 2u; 162 const size_t kRequiredForDrawDoneTaskPriority = 2u;
138 const size_t kAllDoneTaskPriority = 3u; 163 const size_t kAllDoneTaskPriority = 3u;
139 164
140 // For correctness, |kTileTaskPriorityBase| must be greater than 165 // For correctness, |kTileTaskPriorityBase| must be greater than
141 // all task set done task priorities. 166 // all task set done task priorities.
142 size_t kTileTaskPriorityBase = 10u; 167 size_t kTileTaskPriorityBase = 10u;
143 168
144 void InsertNodeForTask(TaskGraph* graph, 169 void InsertNodeForTask(TaskGraph* graph,
145 TileTask* task, 170 TileTask* task,
146 uint16_t category, 171 uint16_t category,
147 uint16_t priority, 172 uint16_t priority,
148 size_t dependencies) { 173 size_t dependencies) {
149 DCHECK(std::find_if(graph->nodes.begin(), graph->nodes.end(), 174 DCHECK(std::find_if(graph->nodes.begin(), graph->nodes.end(),
150 [task](const TaskGraph::Node& node) { 175 [task](const TaskGraph::Node& node) {
151 return node.task == task; 176 return node.task == task;
152 }) == graph->nodes.end()); 177 }) == graph->nodes.end());
153 graph->nodes.push_back( 178 graph->nodes.push_back(
154 TaskGraph::Node(task, category, priority, dependencies)); 179 TaskGraph::Node(task, category, priority, dependencies));
155 } 180 }
156 181
157 void InsertNodeForDecodeTask(TaskGraph* graph, 182 void InsertNodeForDecodeTask(TaskGraph* graph,
158 TileTask* task, 183 TileTask* task,
159 uint16_t category, 184 bool high_prioirty,
prashant.n 2016/04/23 04:55:19 May be replace high_priority with is_foreground or
ericrk 2016/05/02 23:04:37 Done.
160 uint16_t priority) { 185 uint16_t priority) {
161 uint32_t dependency_count = 0u; 186 uint32_t dependency_count = 0u;
162 if (task->dependencies().size()) { 187 if (task->dependencies().size()) {
163 DCHECK_EQ(task->dependencies().size(), 1u); 188 DCHECK_EQ(task->dependencies().size(), 1u);
164 auto* dependency = task->dependencies()[0].get(); 189 auto* dependency = task->dependencies()[0].get();
165 if (!dependency->HasCompleted()) { 190 if (!dependency->HasCompleted()) {
166 InsertNodeForDecodeTask(graph, dependency, category, priority); 191 InsertNodeForDecodeTask(graph, dependency, high_prioirty, priority);
167 graph->edges.push_back(TaskGraph::Edge(dependency, task)); 192 graph->edges.push_back(TaskGraph::Edge(dependency, task));
168 dependency_count = 1u; 193 dependency_count = 1u;
169 } 194 }
170 } 195 }
171 InsertNodeForTask(graph, task, task->supports_concurrent_execution() 196 InsertNodeForTask(graph, task, TaskCategoryForTileTask(task, high_prioirty),
172 ? category
173 : TASK_CATEGORY_NONCONCURRENT_FOREGROUND,
174 priority, dependency_count); 197 priority, dependency_count);
175 } 198 }
176 199
177 void InsertNodesForRasterTask(TaskGraph* graph, 200 void InsertNodesForRasterTask(TaskGraph* graph,
178 TileTask* raster_task, 201 TileTask* raster_task,
179 const TileTask::Vector& decode_tasks, 202 const TileTask::Vector& decode_tasks,
180 size_t priority, 203 size_t priority,
prashant.n 2016/04/23 04:55:19 Replace this with task_priority.
ericrk 2016/05/02 23:04:37 Should be less confusing now that we only have one
181 bool use_gpu_rasterization,
182 bool high_priority) { 204 bool high_priority) {
prashant.n 2016/04/23 04:55:19 Replace this with tile_priority for better readabi
ericrk 2016/05/02 23:04:37 Done.
183 size_t dependencies = 0u; 205 size_t dependencies = 0u;
184 206
185 // Determine the TaskCategory for raster tasks - if a task uses GPU, it
186 // cannot run concurrently and is assigned
187 // TASK_CATEGORY_NONCONCURRENT_FOREGROUND, regardless of its priority.
188 // Otherwise its category is based on its priority.
189 TaskCategory raster_task_category;
190 if (use_gpu_rasterization) {
191 raster_task_category = TASK_CATEGORY_NONCONCURRENT_FOREGROUND;
192 } else {
193 raster_task_category =
194 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND;
195 }
196
197 // Determine the TaskCategory for decode tasks. This category is based on
198 // the priority of the raster task which depends on it.
199 TaskCategory decode_task_category =
200 high_priority ? TASK_CATEGORY_FOREGROUND : TASK_CATEGORY_BACKGROUND;
201
202 // Insert image decode tasks. 207 // Insert image decode tasks.
203 for (TileTask::Vector::const_iterator it = decode_tasks.begin(); 208 for (TileTask::Vector::const_iterator it = decode_tasks.begin();
204 it != decode_tasks.end(); ++it) { 209 it != decode_tasks.end(); ++it) {
205 TileTask* decode_task = it->get(); 210 TileTask* decode_task = it->get();
206 211
207 // Skip if already decoded. 212 // Skip if already decoded.
208 if (decode_task->HasCompleted()) 213 if (decode_task->HasCompleted())
209 continue; 214 continue;
210 215
211 dependencies++; 216 dependencies++;
212 217
213 // Add decode task if it doesn't already exists in graph. 218 // Add decode task if it doesn't already exists in graph.
214 TaskGraph::Node::Vector::iterator decode_it = 219 TaskGraph::Node::Vector::iterator decode_it =
215 std::find_if(graph->nodes.begin(), graph->nodes.end(), 220 std::find_if(graph->nodes.begin(), graph->nodes.end(),
216 [decode_task](const TaskGraph::Node& node) { 221 [decode_task](const TaskGraph::Node& node) {
217 return node.task == decode_task; 222 return node.task == decode_task;
218 }); 223 });
219 224
220 // In rare circumstances, a low priority task may come in before a high 225 // In rare circumstances, a low priority task may come in before a high
221 // priority task. In these cases, upgrade any low-priority dependencies of 226 // priority task. In these cases, upgrade any low-priority dependencies of
222 // the current task. 227 // the current task.
223 // TODO(ericrk): Task iterators should be updated to avoid this. 228 // TODO(ericrk): Task iterators should be updated to avoid this.
224 // crbug.com/594851 229 // crbug.com/594851
230 // TODO(ericrk): This should handle dependencies recursively.
231 // crbug.com/605234
225 if (decode_it != graph->nodes.end() && high_priority && 232 if (decode_it != graph->nodes.end() && high_priority &&
226 decode_it->category != decode_task_category) { 233 !IsHighPriorityCategory(decode_it->category)) {
227 decode_it->category = decode_task_category; 234 decode_it->category = TASK_CATEGORY_FOREGROUND;
228 } 235 }
229 236
230 if (decode_it == graph->nodes.end()) { 237 if (decode_it == graph->nodes.end()) {
231 InsertNodeForDecodeTask(graph, decode_task, decode_task_category, 238 InsertNodeForDecodeTask(graph, decode_task, high_priority, priority);
232 priority);
233 } 239 }
234 240
235 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); 241 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task));
236 } 242 }
237 243
238 InsertNodeForTask(graph, raster_task, raster_task_category, priority, 244 InsertNodeForTask(graph, raster_task,
239 dependencies); 245 TaskCategoryForTileTask(raster_task, high_priority),
246 priority, dependencies);
240 } 247 }
241 248
242 class TaskSetFinishedTaskImpl : public TileTask { 249 class TaskSetFinishedTaskImpl : public TileTask {
243 public: 250 public:
244 explicit TaskSetFinishedTaskImpl( 251 explicit TaskSetFinishedTaskImpl(
245 base::SequencedTaskRunner* task_runner, 252 base::SequencedTaskRunner* task_runner,
246 const base::Closure& on_task_set_finished_callback) 253 const base::Closure& on_task_set_finished_callback)
247 : TileTask(true), 254 : TileTask(true),
248 task_runner_(task_runner), 255 task_runner_(task_runner),
249 on_task_set_finished_callback_(on_task_set_finished_callback) {} 256 on_task_set_finished_callback_(on_task_set_finished_callback) {}
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 all_count++; 805 all_count++;
799 graph_.edges.push_back(TaskGraph::Edge(task, all_done_task.get())); 806 graph_.edges.push_back(TaskGraph::Edge(task, all_done_task.get()));
800 807
801 // A tile is high priority if it is either blocking future compositing 808 // A tile is high priority if it is either blocking future compositing
802 // (required for draw or required for activation), or if it has a priority 809 // (required for draw or required for activation), or if it has a priority
803 // bin of NOW for another reason (low resolution tiles). 810 // bin of NOW for another reason (low resolution tiles).
804 bool high_priority = 811 bool high_priority =
805 tile->required_for_draw() || tile->required_for_activation() || 812 tile->required_for_draw() || tile->required_for_activation() ||
806 prioritized_tile.priority().priority_bin == TilePriority::NOW; 813 prioritized_tile.priority().priority_bin == TilePriority::NOW;
807 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++, 814 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++,
808 use_gpu_rasterization_, high_priority); 815 high_priority);
809 } 816 }
810 817
811 // Insert nodes for our task completion tasks. We enqueue these using 818 // Insert nodes for our task completion tasks. We enqueue these using
812 // NONCONCURRENT_FOREGROUND priority as this is the highest prioirty and we'd 819 // NONCONCURRENT_FOREGROUND priority as this is the highest prioirty and we'd
813 // like to run these tasks as soon as possible. 820 // like to run these tasks as soon as possible.
814 InsertNodeForTask(&graph_, required_for_activation_done_task.get(), 821 InsertNodeForTask(&graph_, required_for_activation_done_task.get(),
815 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, 822 TASK_CATEGORY_NONCONCURRENT_FOREGROUND,
816 kRequiredForActivationDoneTaskPriority, 823 kRequiredForActivationDoneTaskPriority,
817 required_for_activate_count); 824 required_for_activate_count);
818 InsertNodeForTask(&graph_, required_for_draw_done_task.get(), 825 InsertNodeForTask(&graph_, required_for_draw_done_task.get(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 *it, prepare_tiles_count_, &task); 900 *it, prepare_tiles_count_, &task);
894 if (task) 901 if (task)
895 decode_tasks.push_back(task); 902 decode_tasks.push_back(task);
896 903
897 if (need_to_unref_when_finished) 904 if (need_to_unref_when_finished)
898 ++it; 905 ++it;
899 else 906 else
900 it = images.erase(it); 907 it = images.erase(it);
901 } 908 }
902 909
910 bool supports_concurrent_execution = !use_gpu_rasterization_;
903 return make_scoped_refptr(new RasterTaskImpl( 911 return make_scoped_refptr(new RasterTaskImpl(
904 resource, prioritized_tile.raster_source(), tile->content_rect(), 912 resource, prioritized_tile.raster_source(), tile->content_rect(),
905 tile->invalidated_content_rect(), tile->contents_scale(), 913 tile->invalidated_content_rect(), tile->contents_scale(),
906 playback_settings, prioritized_tile.priority().resolution, 914 playback_settings, prioritized_tile.priority().resolution,
907 tile->layer_id(), prepare_tiles_count_, static_cast<const void*>(tile), 915 tile->layer_id(), prepare_tiles_count_, static_cast<const void*>(tile),
908 tile->id(), tile->invalidated_id(), resource_content_id, 916 tile->id(), tile->invalidated_id(), resource_content_id,
909 tile->source_frame_number(), 917 tile->source_frame_number(),
910 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), 918 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this),
911 tile->id(), resource), 919 tile->id(), resource),
912 &decode_tasks)); 920 &decode_tasks, supports_concurrent_execution));
913 } 921 }
914 922
915 void TileManager::OnRasterTaskCompleted( 923 void TileManager::OnRasterTaskCompleted(
916 Tile::Id tile_id, 924 Tile::Id tile_id,
917 Resource* resource, 925 Resource* resource,
918 bool was_canceled) { 926 bool was_canceled) {
919 DCHECK(tiles_.find(tile_id) != tiles_.end()); 927 DCHECK(tiles_.find(tile_id) != tiles_.end());
920 928
921 Tile* tile = tiles_[tile_id]; 929 Tile* tile = tiles_[tile_id];
922 TileDrawInfo& draw_info = tile->draw_info(); 930 TileDrawInfo& draw_info = tile->draw_info();
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 void TileManager::Signals::reset() { 1247 void TileManager::Signals::reset() {
1240 ready_to_activate = false; 1248 ready_to_activate = false;
1241 did_notify_ready_to_activate = false; 1249 did_notify_ready_to_activate = false;
1242 ready_to_draw = false; 1250 ready_to_draw = false;
1243 did_notify_ready_to_draw = false; 1251 did_notify_ready_to_draw = false;
1244 all_tile_tasks_completed = false; 1252 all_tile_tasks_completed = false;
1245 did_notify_all_tile_tasks_completed = false; 1253 did_notify_all_tile_tasks_completed = false;
1246 } 1254 }
1247 1255
1248 } // namespace cc 1256 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698