| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/surfaces/display_scheduler.h" | 5 #include "cc/surfaces/display_scheduler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/output/output_surface.h" | 12 #include "cc/output/output_surface.h" |
| 13 #include "cc/surfaces/surface_info.h" |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 | 16 |
| 16 DisplayScheduler::DisplayScheduler(base::SingleThreadTaskRunner* task_runner, | 17 DisplayScheduler::DisplayScheduler(base::SingleThreadTaskRunner* task_runner, |
| 17 int max_pending_swaps) | 18 int max_pending_swaps) |
| 18 : client_(nullptr), | 19 : client_(nullptr), |
| 19 begin_frame_source_(nullptr), | 20 begin_frame_source_(nullptr), |
| 20 task_runner_(task_runner), | 21 task_runner_(task_runner), |
| 21 inside_surface_damaged_(false), | 22 inside_surface_damaged_(false), |
| 22 visible_(false), | 23 visible_(false), |
| 23 output_surface_lost_(false), | 24 output_surface_lost_(false), |
| 24 root_surface_resources_locked_(true), | 25 root_surface_resources_locked_(true), |
| 25 inside_begin_frame_deadline_interval_(false), | 26 inside_begin_frame_deadline_interval_(false), |
| 26 needs_draw_(false), | 27 needs_draw_(false), |
| 27 expecting_root_surface_damage_because_of_resize_(false), | 28 expecting_root_surface_damage_because_of_resize_(false), |
| 28 all_active_child_surfaces_ready_to_draw_(false), | 29 has_pending_surfaces_(false), |
| 29 next_swap_id_(1), | 30 next_swap_id_(1), |
| 30 pending_swaps_(0), | 31 pending_swaps_(0), |
| 31 max_pending_swaps_(max_pending_swaps), | 32 max_pending_swaps_(max_pending_swaps), |
| 32 observing_begin_frame_source_(false), | 33 observing_begin_frame_source_(false), |
| 33 root_surface_damaged_(false), | |
| 34 expect_damage_from_root_surface_(false), | |
| 35 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 36 begin_frame_deadline_closure_ = base::Bind( | 35 begin_frame_deadline_closure_ = base::Bind( |
| 37 &DisplayScheduler::OnBeginFrameDeadline, weak_ptr_factory_.GetWeakPtr()); | 36 &DisplayScheduler::OnBeginFrameDeadline, weak_ptr_factory_.GetWeakPtr()); |
| 38 } | 37 } |
| 39 | 38 |
| 40 DisplayScheduler::~DisplayScheduler() { | 39 DisplayScheduler::~DisplayScheduler() { |
| 41 StopObservingBeginFrames(); | 40 StopObservingBeginFrames(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void DisplayScheduler::SetClient(DisplaySchedulerClient* client) { | 43 void DisplayScheduler::SetClient(DisplaySchedulerClient* client) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 void DisplayScheduler::ForceImmediateSwapIfPossible() { | 73 void DisplayScheduler::ForceImmediateSwapIfPossible() { |
| 75 TRACE_EVENT0("cc", "DisplayScheduler::ForceImmediateSwapIfPossible"); | 74 TRACE_EVENT0("cc", "DisplayScheduler::ForceImmediateSwapIfPossible"); |
| 76 bool in_begin = inside_begin_frame_deadline_interval_; | 75 bool in_begin = inside_begin_frame_deadline_interval_; |
| 77 bool did_draw = AttemptDrawAndSwap(); | 76 bool did_draw = AttemptDrawAndSwap(); |
| 78 if (in_begin) | 77 if (in_begin) |
| 79 DidFinishFrame(did_draw); | 78 DidFinishFrame(did_draw); |
| 80 } | 79 } |
| 81 | 80 |
| 82 void DisplayScheduler::DisplayResized() { | 81 void DisplayScheduler::DisplayResized() { |
| 83 expecting_root_surface_damage_because_of_resize_ = true; | 82 expecting_root_surface_damage_because_of_resize_ = true; |
| 84 expect_damage_from_root_surface_ = true; | |
| 85 needs_draw_ = true; | 83 needs_draw_ = true; |
| 86 ScheduleBeginFrameDeadline(); | 84 ScheduleBeginFrameDeadline(); |
| 87 } | 85 } |
| 88 | 86 |
| 89 // Notification that there was a resize or the root surface changed and | 87 // Notification that there was a resize or the root surface changed and |
| 90 // that we should just draw immediately. | 88 // that we should just draw immediately. |
| 91 void DisplayScheduler::SetNewRootSurface(const SurfaceId& root_surface_id) { | 89 void DisplayScheduler::SetNewRootSurface(const SurfaceId& root_surface_id) { |
| 92 TRACE_EVENT0("cc", "DisplayScheduler::SetNewRootSurface"); | 90 TRACE_EVENT0("cc", "DisplayScheduler::SetNewRootSurface"); |
| 93 root_surface_id_ = root_surface_id; | 91 root_surface_id_ = root_surface_id; |
| 94 SurfaceDamaged(root_surface_id); | 92 BeginFrameAck ack; |
| 93 ack.has_damage = true; |
| 94 SurfaceDamaged(root_surface_id, ack, true); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Indicates that there was damage to one of the surfaces. | 97 // Indicates that there was damage to one of the surfaces. |
| 98 // Has some logic to wait for multiple active surfaces before | 98 // Has some logic to wait for multiple active surfaces before |
| 99 // triggering the deadline. | 99 // triggering the deadline. |
| 100 void DisplayScheduler::SurfaceDamaged(const SurfaceId& surface_id) { | 100 void DisplayScheduler::SurfaceDamaged(const SurfaceId& surface_id, |
| 101 const BeginFrameAck& ack, |
| 102 bool display_damaged) { |
| 101 TRACE_EVENT1("cc", "DisplayScheduler::SurfaceDamaged", "surface_id", | 103 TRACE_EVENT1("cc", "DisplayScheduler::SurfaceDamaged", "surface_id", |
| 102 surface_id.ToString()); | 104 surface_id.ToString()); |
| 103 | 105 |
| 104 // We may cause a new BeginFrame to be run inside this method, but to help | 106 // We may cause a new BeginFrame to be run inside this method, but to help |
| 105 // avoid being reentrant to the caller of SurfaceDamaged, track when this is | 107 // avoid being reentrant to the caller of SurfaceDamaged, track when this is |
| 106 // happening with |inside_surface_damaged_|. | 108 // happening with |inside_surface_damaged_|. |
| 107 base::AutoReset<bool> auto_reset(&inside_surface_damaged_, true); | 109 base::AutoReset<bool> auto_reset(&inside_surface_damaged_, true); |
| 108 | 110 |
| 109 needs_draw_ = true; | 111 if (display_damaged) { |
| 112 needs_draw_ = true; |
| 110 | 113 |
| 111 if (surface_id == root_surface_id_) { | 114 if (surface_id == root_surface_id_) |
| 112 root_surface_damaged_ = true; | 115 expecting_root_surface_damage_because_of_resize_ = false; |
| 113 expecting_root_surface_damage_because_of_resize_ = false; | |
| 114 } else { | |
| 115 child_surface_ids_damaged_.insert(surface_id); | |
| 116 | 116 |
| 117 // TODO(mithro): Use hints from SetNeedsBeginFrames and SwapAborts. | 117 StartObservingBeginFrames(); |
| 118 all_active_child_surfaces_ready_to_draw_ = base::STLIncludes( | |
| 119 child_surface_ids_damaged_, child_surface_ids_to_expect_damage_from_); | |
| 120 } | 118 } |
| 121 | 119 |
| 122 StartObservingBeginFrames(); | 120 // Update surface state. |
| 123 ScheduleBeginFrameDeadline(); | 121 bool valid_ack = ack.sequence_number != BeginFrameArgs::kInvalidFrameNumber; |
| 122 if (valid_ack) { |
| 123 auto it = surface_states_.find(surface_id); |
| 124 if (it != surface_states_.end()) |
| 125 it->second.last_ack = ack; |
| 126 else |
| 127 valid_ack = false; |
| 128 } |
| 129 |
| 130 bool pending_surfaces_changed = false; |
| 131 if (display_damaged || valid_ack) |
| 132 pending_surfaces_changed = UpdateHasPendingSurfaces(); |
| 133 |
| 134 if (display_damaged || pending_surfaces_changed) |
| 135 ScheduleBeginFrameDeadline(); |
| 136 } |
| 137 |
| 138 void DisplayScheduler::SurfaceCreated(const SurfaceInfo& surface_info) { |
| 139 SurfaceId surface_id = surface_info.id(); |
| 140 DCHECK(!base::ContainsKey(surface_states_, surface_id)); |
| 141 surface_states_[surface_id] = SurfaceBeginFrameState(); |
| 142 } |
| 143 |
| 144 void DisplayScheduler::SurfaceDestroyed(const SurfaceId& surface_id) { |
| 145 auto it = surface_states_.find(surface_id); |
| 146 if (it == surface_states_.end()) |
| 147 return; |
| 148 surface_states_.erase(it); |
| 149 } |
| 150 |
| 151 void DisplayScheduler::SurfaceDamageExpected(const SurfaceId& surface_id, |
| 152 const BeginFrameArgs& args) { |
| 153 TRACE_EVENT1("cc", "DisplayScheduler::SurfaceDamageExpected", "surface_id", |
| 154 surface_id.ToString()); |
| 155 auto it = surface_states_.find(surface_id); |
| 156 if (it == surface_states_.end()) |
| 157 return; |
| 158 it->second.last_args = args; |
| 159 if (UpdateHasPendingSurfaces()) |
| 160 ScheduleBeginFrameDeadline(); |
| 161 } |
| 162 |
| 163 bool DisplayScheduler::UpdateHasPendingSurfaces() { |
| 164 // If we're not currently inside a deadline interval, we will call |
| 165 // UpdateHasPendingSurfaces() again during OnBeginFrameImpl(). |
| 166 if (!inside_begin_frame_deadline_interval_ || !client_) |
| 167 return false; |
| 168 |
| 169 bool old_value = has_pending_surfaces_; |
| 170 |
| 171 for (const std::pair<SurfaceId, SurfaceBeginFrameState>& entry : |
| 172 surface_states_) { |
| 173 const SurfaceId& surface_id = entry.first; |
| 174 const SurfaceBeginFrameState& state = entry.second; |
| 175 |
| 176 // Surface is ready if it hasn't received the current BeginFrame or receives |
| 177 // BeginFrames from a different source and thus likely belongs to a |
| 178 // different surface hierarchy. |
| 179 uint32_t source_id = current_begin_frame_args_.source_id; |
| 180 uint64_t sequence_number = current_begin_frame_args_.sequence_number; |
| 181 if (!state.last_args.IsValid() || state.last_args.source_id != source_id || |
| 182 state.last_args.sequence_number != sequence_number) { |
| 183 continue; |
| 184 } |
| 185 |
| 186 // Surface is ready if it has acknowledged the current BeginFrame. |
| 187 if (state.last_ack.source_id == source_id && |
| 188 state.last_ack.sequence_number == sequence_number) { |
| 189 continue; |
| 190 } |
| 191 |
| 192 // Surface is ready if there is an undrawn active CompositorFrame, because |
| 193 // its producer is CompositorFrameAck throttled. |
| 194 if (client_->SurfaceHasUndrawnFrame(entry.first)) |
| 195 continue; |
| 196 |
| 197 has_pending_surfaces_ = true; |
| 198 TRACE_EVENT_INSTANT2("cc", "DisplayScheduler::UpdateHasPendingSurfaces", |
| 199 TRACE_EVENT_SCOPE_THREAD, "has_pending_surfaces", |
| 200 has_pending_surfaces_, "pending_surface_id", |
| 201 surface_id.ToString()); |
| 202 return has_pending_surfaces_ != old_value; |
| 203 } |
| 204 has_pending_surfaces_ = false; |
| 205 TRACE_EVENT_INSTANT1("cc", "DisplayScheduler::UpdateHasPendingSurfaces", |
| 206 TRACE_EVENT_SCOPE_THREAD, "has_pending_surfaces", |
| 207 has_pending_surfaces_); |
| 208 return has_pending_surfaces_ != old_value; |
| 124 } | 209 } |
| 125 | 210 |
| 126 void DisplayScheduler::OutputSurfaceLost() { | 211 void DisplayScheduler::OutputSurfaceLost() { |
| 127 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost"); | 212 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost"); |
| 128 output_surface_lost_ = true; | 213 output_surface_lost_ = true; |
| 129 ScheduleBeginFrameDeadline(); | 214 ScheduleBeginFrameDeadline(); |
| 130 } | 215 } |
| 131 | 216 |
| 132 bool DisplayScheduler::DrawAndSwap() { | 217 bool DisplayScheduler::DrawAndSwap() { |
| 133 TRACE_EVENT0("cc", "DisplayScheduler::DrawAndSwap"); | 218 TRACE_EVENT0("cc", "DisplayScheduler::DrawAndSwap"); |
| 134 DCHECK_LT(pending_swaps_, max_pending_swaps_); | 219 DCHECK_LT(pending_swaps_, max_pending_swaps_); |
| 135 DCHECK(!output_surface_lost_); | 220 DCHECK(!output_surface_lost_); |
| 136 | 221 |
| 137 bool success = client_->DrawAndSwap(); | 222 bool success = client_->DrawAndSwap(); |
| 138 if (!success) | 223 if (!success) |
| 139 return false; | 224 return false; |
| 140 | 225 |
| 141 child_surface_ids_to_expect_damage_from_ = | |
| 142 base::STLSetIntersection<std::vector<SurfaceId>>( | |
| 143 child_surface_ids_damaged_, child_surface_ids_damaged_prev_); | |
| 144 | |
| 145 child_surface_ids_damaged_prev_.swap(child_surface_ids_damaged_); | |
| 146 child_surface_ids_damaged_.clear(); | |
| 147 | |
| 148 needs_draw_ = false; | 226 needs_draw_ = false; |
| 149 all_active_child_surfaces_ready_to_draw_ = | |
| 150 child_surface_ids_to_expect_damage_from_.empty(); | |
| 151 | |
| 152 expect_damage_from_root_surface_ = root_surface_damaged_; | |
| 153 root_surface_damaged_ = false; | |
| 154 return true; | 227 return true; |
| 155 } | 228 } |
| 156 | 229 |
| 157 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { | 230 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { |
| 158 base::TimeTicks now = base::TimeTicks::Now(); | 231 base::TimeTicks now = base::TimeTicks::Now(); |
| 159 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(), | 232 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(), |
| 160 "now", now); | 233 "now", now); |
| 161 | 234 |
| 162 if (inside_surface_damaged_) { | 235 if (inside_surface_damaged_) { |
| 163 // Repost this so that we don't run a missed BeginFrame on the same | 236 // Repost this so that we don't run a missed BeginFrame on the same |
| (...skipping 15 matching lines...) Expand all Loading... |
| 179 // destroyed if we StopObservingBeginFrames(), and it would take the |args| | 252 // destroyed if we StopObservingBeginFrames(), and it would take the |args| |
| 180 // with it. Instead save the args and cancel the |missed_begin_frame_task_|. | 253 // with it. Instead save the args and cancel the |missed_begin_frame_task_|. |
| 181 BeginFrameArgs save_args = args; | 254 BeginFrameArgs save_args = args; |
| 182 // If we get another BeginFrame before a posted missed frame, just drop the | 255 // If we get another BeginFrame before a posted missed frame, just drop the |
| 183 // missed frame. Also if this was the missed frame, drop the Callback inside | 256 // missed frame. Also if this was the missed frame, drop the Callback inside |
| 184 // it. | 257 // it. |
| 185 missed_begin_frame_task_.Cancel(); | 258 missed_begin_frame_task_.Cancel(); |
| 186 | 259 |
| 187 // If we get another BeginFrame before the previous deadline, | 260 // If we get another BeginFrame before the previous deadline, |
| 188 // synchronously trigger the previous deadline before progressing. | 261 // synchronously trigger the previous deadline before progressing. |
| 189 if (inside_begin_frame_deadline_interval_) { | 262 if (inside_begin_frame_deadline_interval_) |
| 190 OnBeginFrameDeadline(); | 263 OnBeginFrameDeadline(); |
| 191 } | |
| 192 | 264 |
| 193 // Schedule the deadline. | 265 // Schedule the deadline. |
| 194 current_begin_frame_args_ = save_args; | 266 current_begin_frame_args_ = save_args; |
| 195 current_begin_frame_args_.deadline -= | 267 current_begin_frame_args_.deadline -= |
| 196 BeginFrameArgs::DefaultEstimatedParentDrawTime(); | 268 BeginFrameArgs::DefaultEstimatedParentDrawTime(); |
| 197 inside_begin_frame_deadline_interval_ = true; | 269 inside_begin_frame_deadline_interval_ = true; |
| 270 UpdateHasPendingSurfaces(); |
| 198 ScheduleBeginFrameDeadline(); | 271 ScheduleBeginFrameDeadline(); |
| 199 | 272 |
| 200 return true; | 273 return true; |
| 201 } | 274 } |
| 202 | 275 |
| 203 void DisplayScheduler::StartObservingBeginFrames() { | 276 void DisplayScheduler::StartObservingBeginFrames() { |
| 204 if (!observing_begin_frame_source_ && ShouldDraw()) { | 277 if (!observing_begin_frame_source_ && ShouldDraw()) { |
| 205 begin_frame_source_->AddObserver(this); | 278 begin_frame_source_->AddObserver(this); |
| 206 observing_begin_frame_source_ = true; | 279 observing_begin_frame_source_ = true; |
| 207 } | 280 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 236 TRACE_EVENT_INSTANT0("cc", "Lost output surface", TRACE_EVENT_SCOPE_THREAD); | 309 TRACE_EVENT_INSTANT0("cc", "Lost output surface", TRACE_EVENT_SCOPE_THREAD); |
| 237 return base::TimeTicks(); | 310 return base::TimeTicks(); |
| 238 } | 311 } |
| 239 | 312 |
| 240 if (pending_swaps_ >= max_pending_swaps_) { | 313 if (pending_swaps_ >= max_pending_swaps_) { |
| 241 TRACE_EVENT_INSTANT0("cc", "Swap throttled", TRACE_EVENT_SCOPE_THREAD); | 314 TRACE_EVENT_INSTANT0("cc", "Swap throttled", TRACE_EVENT_SCOPE_THREAD); |
| 242 return current_begin_frame_args_.frame_time + | 315 return current_begin_frame_args_.frame_time + |
| 243 current_begin_frame_args_.interval; | 316 current_begin_frame_args_.interval; |
| 244 } | 317 } |
| 245 | 318 |
| 246 if (!needs_draw_) { | 319 bool all_surfaces_ready = |
| 320 !has_pending_surfaces_ && root_surface_id_.is_valid(); |
| 321 if (!needs_draw_ && !all_surfaces_ready) { |
| 247 TRACE_EVENT_INSTANT0("cc", "No damage yet", TRACE_EVENT_SCOPE_THREAD); | 322 TRACE_EVENT_INSTANT0("cc", "No damage yet", TRACE_EVENT_SCOPE_THREAD); |
| 248 return current_begin_frame_args_.frame_time + | 323 return current_begin_frame_args_.frame_time + |
| 249 current_begin_frame_args_.interval; | 324 current_begin_frame_args_.interval; |
| 250 } | 325 } |
| 251 | 326 |
| 252 if (root_surface_resources_locked_) { | 327 if (root_surface_resources_locked_) { |
| 253 TRACE_EVENT_INSTANT0("cc", "Root surface resources locked", | 328 TRACE_EVENT_INSTANT0("cc", "Root surface resources locked", |
| 254 TRACE_EVENT_SCOPE_THREAD); | 329 TRACE_EVENT_SCOPE_THREAD); |
| 255 return current_begin_frame_args_.frame_time + | 330 return current_begin_frame_args_.frame_time + |
| 256 current_begin_frame_args_.interval; | 331 current_begin_frame_args_.interval; |
| 257 } | 332 } |
| 258 | 333 |
| 259 bool root_ready_to_draw = | 334 if (all_surfaces_ready && !expecting_root_surface_damage_because_of_resize_) { |
| 260 !expect_damage_from_root_surface_ || root_surface_damaged_; | |
| 261 | |
| 262 if (all_active_child_surfaces_ready_to_draw_ && root_ready_to_draw) { | |
| 263 TRACE_EVENT_INSTANT0("cc", "All active surfaces ready", | 335 TRACE_EVENT_INSTANT0("cc", "All active surfaces ready", |
| 264 TRACE_EVENT_SCOPE_THREAD); | 336 TRACE_EVENT_SCOPE_THREAD); |
| 265 return base::TimeTicks(); | 337 return base::TimeTicks(); |
| 266 } | 338 } |
| 267 | 339 |
| 268 // TODO(mithro): Be smarter about resize deadlines. | 340 // TODO(mithro): Be smarter about resize deadlines. |
| 269 if (expecting_root_surface_damage_because_of_resize_) { | 341 if (expecting_root_surface_damage_because_of_resize_) { |
| 270 TRACE_EVENT_INSTANT0("cc", "Entire display damaged", | 342 TRACE_EVENT_INSTANT0("cc", "Entire display damaged", |
| 271 TRACE_EVENT_SCOPE_THREAD); | 343 TRACE_EVENT_SCOPE_THREAD); |
| 272 return current_begin_frame_args_.frame_time + | 344 return current_begin_frame_args_.frame_time + |
| 273 current_begin_frame_args_.interval; | 345 current_begin_frame_args_.interval; |
| 274 } | 346 } |
| 275 | 347 |
| 276 // Use an earlier deadline if we are only waiting for the root surface | |
| 277 // in case our expect_damage_from_root_surface heuristic is incorrect. | |
| 278 // TODO(mithro): Replace this with SetNeedsBeginFrame and SwapAbort | |
| 279 // logic. | |
| 280 if (all_active_child_surfaces_ready_to_draw_ && | |
| 281 expect_damage_from_root_surface_) { | |
| 282 TRACE_EVENT_INSTANT0("cc", "Waiting for damage from root surface", | |
| 283 TRACE_EVENT_SCOPE_THREAD); | |
| 284 // This adjusts the deadline by DefaultEstimatedParentDrawTime for | |
| 285 // a second time. The first one represented the Surfaces draw to display | |
| 286 // latency. This one represents root surface commit+raster+draw latency. | |
| 287 // We treat the root surface differently since it lives on the same thread | |
| 288 // as Surfaces and waiting for it too long may push out the Surfaces draw. | |
| 289 // If we also assume the root surface is fast to start a commit after the | |
| 290 // beginning of a frame, it'll have a chance to lock its resources, which | |
| 291 // will cause us to wait for it to unlock its resources above. | |
| 292 // TODO(mithro): Replace hard coded estimates. | |
| 293 return current_begin_frame_args_.deadline - | |
| 294 BeginFrameArgs::DefaultEstimatedParentDrawTime(); | |
| 295 } | |
| 296 | |
| 297 TRACE_EVENT_INSTANT0("cc", "More damage expected soon", | 348 TRACE_EVENT_INSTANT0("cc", "More damage expected soon", |
| 298 TRACE_EVENT_SCOPE_THREAD); | 349 TRACE_EVENT_SCOPE_THREAD); |
| 299 return current_begin_frame_args_.deadline; | 350 return current_begin_frame_args_.deadline; |
| 300 } | 351 } |
| 301 | 352 |
| 302 void DisplayScheduler::ScheduleBeginFrameDeadline() { | 353 void DisplayScheduler::ScheduleBeginFrameDeadline() { |
| 303 TRACE_EVENT0("cc", "DisplayScheduler::ScheduleBeginFrameDeadline"); | 354 TRACE_EVENT0("cc", "DisplayScheduler::ScheduleBeginFrameDeadline"); |
| 304 | 355 |
| 305 // We need to wait for the next BeginFrame before scheduling a deadline. | 356 // We need to wait for the next BeginFrame before scheduling a deadline. |
| 306 if (!inside_begin_frame_deadline_interval_) { | 357 if (!inside_begin_frame_deadline_interval_) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 337 bool DisplayScheduler::AttemptDrawAndSwap() { | 388 bool DisplayScheduler::AttemptDrawAndSwap() { |
| 338 inside_begin_frame_deadline_interval_ = false; | 389 inside_begin_frame_deadline_interval_ = false; |
| 339 begin_frame_deadline_task_.Cancel(); | 390 begin_frame_deadline_task_.Cancel(); |
| 340 begin_frame_deadline_task_time_ = base::TimeTicks(); | 391 begin_frame_deadline_task_time_ = base::TimeTicks(); |
| 341 | 392 |
| 342 if (ShouldDraw()) { | 393 if (ShouldDraw()) { |
| 343 if (pending_swaps_ < max_pending_swaps_ && !root_surface_resources_locked_) | 394 if (pending_swaps_ < max_pending_swaps_ && !root_surface_resources_locked_) |
| 344 return DrawAndSwap(); | 395 return DrawAndSwap(); |
| 345 } else { | 396 } else { |
| 346 // We are going idle, so reset expectations. | 397 // We are going idle, so reset expectations. |
| 347 child_surface_ids_to_expect_damage_from_.clear(); | 398 // TODO(eseckler): Should we avoid going idle if |
| 348 child_surface_ids_damaged_prev_.clear(); | 399 // |expecting_root_surface_damage_because_of_resize_| is true? |
| 349 child_surface_ids_damaged_.clear(); | 400 expecting_root_surface_damage_because_of_resize_ = false; |
| 350 all_active_child_surfaces_ready_to_draw_ = true; | |
| 351 expect_damage_from_root_surface_ = false; | |
| 352 | 401 |
| 353 StopObservingBeginFrames(); | 402 StopObservingBeginFrames(); |
| 354 } | 403 } |
| 355 return false; | 404 return false; |
| 356 } | 405 } |
| 357 | 406 |
| 358 void DisplayScheduler::OnBeginFrameDeadline() { | 407 void DisplayScheduler::OnBeginFrameDeadline() { |
| 359 TRACE_EVENT0("cc", "DisplayScheduler::OnBeginFrameDeadline"); | 408 TRACE_EVENT0("cc", "DisplayScheduler::OnBeginFrameDeadline"); |
| 360 DCHECK(inside_begin_frame_deadline_interval_); | 409 DCHECK(inside_begin_frame_deadline_interval_); |
| 361 | 410 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 376 } | 425 } |
| 377 | 426 |
| 378 void DisplayScheduler::DidReceiveSwapBuffersAck() { | 427 void DisplayScheduler::DidReceiveSwapBuffersAck() { |
| 379 uint32_t swap_id = next_swap_id_ - pending_swaps_; | 428 uint32_t swap_id = next_swap_id_ - pending_swaps_; |
| 380 pending_swaps_--; | 429 pending_swaps_--; |
| 381 TRACE_EVENT_ASYNC_END0("cc", "DisplayScheduler:pending_swaps", swap_id); | 430 TRACE_EVENT_ASYNC_END0("cc", "DisplayScheduler:pending_swaps", swap_id); |
| 382 ScheduleBeginFrameDeadline(); | 431 ScheduleBeginFrameDeadline(); |
| 383 } | 432 } |
| 384 | 433 |
| 385 } // namespace cc | 434 } // namespace cc |
| OLD | NEW |