Chromium Code Reviews| 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/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 ScheduleBeginFrameDeadline(); | 89 ScheduleBeginFrameDeadline(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DisplayScheduler::OutputSurfaceLost() { | 92 void DisplayScheduler::OutputSurfaceLost() { |
| 93 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost"); | 93 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost"); |
| 94 output_surface_lost_ = true; | 94 output_surface_lost_ = true; |
| 95 begin_frame_source_->SetNeedsBeginFrames(false); | 95 begin_frame_source_->SetNeedsBeginFrames(false); |
| 96 ScheduleBeginFrameDeadline(); | 96 ScheduleBeginFrameDeadline(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DisplayScheduler::UpdateSurfaceDamageExpectations() { | |
| 100 expect_damage_from_root_surface_ = root_surface_damaged_; | |
|
sunnyps
2015/07/23 03:02:40
Set root_surface_damaged_ to false here instead of
brianderson
2015/07/23 18:21:46
This will work for the case where this method is c
| |
| 101 | |
| 102 std::vector<SurfaceId> partial_union = | |
| 103 base::STLSetUnion<std::vector<SurfaceId>>( | |
| 104 child_surface_ids_damaged_, child_surface_ids_damaged_prev_); | |
| 105 child_surface_ids_to_expect_damage_from_ = | |
| 106 base::STLSetUnion<std::vector<SurfaceId>>( | |
| 107 partial_union, child_surface_ids_damaged_prev_prev_); | |
| 108 | |
| 109 child_surface_ids_damaged_prev_prev_.swap(child_surface_ids_damaged_prev_); | |
| 110 child_surface_ids_damaged_prev_.swap(child_surface_ids_damaged_); | |
| 111 child_surface_ids_damaged_.clear(); | |
| 112 | |
| 113 all_active_child_surfaces_ready_to_draw_ = | |
| 114 child_surface_ids_to_expect_damage_from_.empty(); | |
| 115 } | |
| 116 | |
| 99 void DisplayScheduler::DrawAndSwap() { | 117 void DisplayScheduler::DrawAndSwap() { |
| 100 TRACE_EVENT0("cc", "DisplayScheduler::DrawAndSwap"); | 118 TRACE_EVENT0("cc", "DisplayScheduler::DrawAndSwap"); |
| 101 DCHECK_LT(pending_swaps_, max_pending_swaps_); | 119 DCHECK_LT(pending_swaps_, max_pending_swaps_); |
| 102 DCHECK(!output_surface_lost_); | 120 DCHECK(!output_surface_lost_); |
| 103 | 121 |
| 104 bool success = client_->DrawAndSwap(); | 122 bool success = client_->DrawAndSwap(); |
| 105 if (!success) | 123 if (!success) |
| 106 return; | 124 return; |
| 107 | 125 |
| 108 child_surface_ids_to_expect_damage_from_ = | 126 UpdateSurfaceDamageExpectations(); |
| 109 base::STLSetIntersection<std::vector<SurfaceId>>( | |
| 110 child_surface_ids_damaged_, child_surface_ids_damaged_prev_); | |
| 111 | 127 |
| 112 child_surface_ids_damaged_prev_.swap(child_surface_ids_damaged_); | 128 // Update state regarding what needs to be drawn. |
| 113 child_surface_ids_damaged_.clear(); | |
| 114 | |
| 115 needs_draw_ = false; | 129 needs_draw_ = false; |
| 116 entire_display_damaged_ = false; | 130 entire_display_damaged_ = false; |
| 117 all_active_child_surfaces_ready_to_draw_ = | |
| 118 child_surface_ids_to_expect_damage_from_.empty(); | |
| 119 | |
| 120 expect_damage_from_root_surface_ = root_surface_damaged_; | |
| 121 root_surface_damaged_ = false; | 131 root_surface_damaged_ = false; |
| 122 } | 132 } |
| 123 | 133 |
| 124 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { | 134 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { |
| 125 base::TimeTicks now = base::TimeTicks::Now(); | 135 base::TimeTicks now = base::TimeTicks::Now(); |
| 126 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(), | 136 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(), |
| 127 "now", now); | 137 "now", now); |
| 128 | 138 |
| 129 // If we get another BeginFrame before the previous deadline, | 139 // If we get another BeginFrame before the previous deadline, |
| 130 // synchronously trigger the previous deadline before progressing. | 140 // synchronously trigger the previous deadline before progressing. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 begin_frame_deadline_task_.callback(), delta); | 252 begin_frame_deadline_task_.callback(), delta); |
| 243 TRACE_EVENT2("cc", "Using new deadline", "delta", delta.ToInternalValue(), | 253 TRACE_EVENT2("cc", "Using new deadline", "delta", delta.ToInternalValue(), |
| 244 "desired_deadline", desired_deadline); | 254 "desired_deadline", desired_deadline); |
| 245 } | 255 } |
| 246 | 256 |
| 247 void DisplayScheduler::AttemptDrawAndSwap() { | 257 void DisplayScheduler::AttemptDrawAndSwap() { |
| 248 inside_begin_frame_deadline_interval_ = false; | 258 inside_begin_frame_deadline_interval_ = false; |
| 249 begin_frame_deadline_task_.Cancel(); | 259 begin_frame_deadline_task_.Cancel(); |
| 250 begin_frame_deadline_task_time_ = base::TimeTicks(); | 260 begin_frame_deadline_task_time_ = base::TimeTicks(); |
| 251 | 261 |
| 252 if (needs_draw_ && !output_surface_lost_) { | 262 bool stay_active = !output_surface_lost_ && |
| 253 if (pending_swaps_ < max_pending_swaps_ && !root_surface_resources_locked_) | 263 (needs_draw_ || expect_damage_from_root_surface_ || |
| 254 DrawAndSwap(); | 264 child_surface_ids_to_expect_damage_from_.size() != 0); |
|
sunnyps
2015/07/23 03:02:40
Can you use all_active_child_surfaces_ready_to_dra
brianderson
2015/07/23 18:21:46
I think that would work, however "child_surface_id
| |
| 265 | |
| 266 if (stay_active) { | |
| 267 if (needs_draw_) { | |
| 268 if (pending_swaps_ < max_pending_swaps_ && | |
| 269 !root_surface_resources_locked_) | |
| 270 DrawAndSwap(); | |
| 271 } else { | |
| 272 // In order to properly go idle, make sure to update expectations that | |
| 273 // will cause stay_active to go false even if we have nothing to draw. | |
|
sunnyps
2015/07/23 03:02:40
nit: "stay_active" instead of "stay active"
brianderson
2015/07/23 18:21:46
Looks like it's already stay_active, but I'll add
| |
| 274 // Verify no child surfaces are currently damaged, since | |
| 275 // UpdateSurfaceDamageExpectatations will clear that list. | |
| 276 DCHECK(child_surface_ids_damaged_.empty()); | |
|
sunnyps
2015/07/23 03:02:40
Can probably add more DCHECKs here - like DCHECK(!
brianderson
2015/07/23 18:21:46
Sounds good. I will added a DCHECK(!root_surface_d
| |
| 277 UpdateSurfaceDamageExpectations(); | |
| 278 } | |
| 255 } else { | 279 } else { |
| 256 // We are going idle, so reset expectations. | 280 // We are going idle, so reset expectations. |
| 257 child_surface_ids_to_expect_damage_from_.clear(); | 281 child_surface_ids_to_expect_damage_from_.clear(); |
| 282 child_surface_ids_damaged_prev_prev_.clear(); | |
| 258 child_surface_ids_damaged_prev_.clear(); | 283 child_surface_ids_damaged_prev_.clear(); |
| 259 child_surface_ids_damaged_.clear(); | 284 child_surface_ids_damaged_.clear(); |
| 260 all_active_child_surfaces_ready_to_draw_ = true; | 285 all_active_child_surfaces_ready_to_draw_ = true; |
| 261 expect_damage_from_root_surface_ = false; | 286 expect_damage_from_root_surface_ = false; |
| 262 | 287 |
| 263 begin_frame_source_->SetNeedsBeginFrames(false); | 288 begin_frame_source_->SetNeedsBeginFrames(false); |
| 264 } | 289 } |
| 265 } | 290 } |
| 266 | 291 |
| 267 void DisplayScheduler::OnBeginFrameDeadline() { | 292 void DisplayScheduler::OnBeginFrameDeadline() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 278 } | 303 } |
| 279 | 304 |
| 280 void DisplayScheduler::DidSwapBuffersComplete() { | 305 void DisplayScheduler::DidSwapBuffersComplete() { |
| 281 pending_swaps_--; | 306 pending_swaps_--; |
| 282 TRACE_EVENT1("cc", "DisplayScheduler::DidSwapBuffersComplete", | 307 TRACE_EVENT1("cc", "DisplayScheduler::DidSwapBuffersComplete", |
| 283 "pending_frames", pending_swaps_); | 308 "pending_frames", pending_swaps_); |
| 284 ScheduleBeginFrameDeadline(); | 309 ScheduleBeginFrameDeadline(); |
| 285 } | 310 } |
| 286 | 311 |
| 287 } // namespace cc | 312 } // namespace cc |
| OLD | NEW |