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

Side by Side Diff: cc/surfaces/display_scheduler.cc

Issue 2183333003: cc: Post the missed BeginFrame to a new stack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: post-swapcomplete: ignoreresult Created 4 years, 4 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 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } else { 90 } else {
91 child_surface_ids_damaged_.insert(surface_id); 91 child_surface_ids_damaged_.insert(surface_id);
92 92
93 // TODO(mithro): Use hints from SetNeedsBeginFrames and SwapAborts. 93 // TODO(mithro): Use hints from SetNeedsBeginFrames and SwapAborts.
94 all_active_child_surfaces_ready_to_draw_ = base::STLIncludes( 94 all_active_child_surfaces_ready_to_draw_ = base::STLIncludes(
95 child_surface_ids_damaged_, child_surface_ids_to_expect_damage_from_); 95 child_surface_ids_damaged_, child_surface_ids_to_expect_damage_from_);
96 } 96 }
97 97
98 if (!output_surface_lost_ && !observing_begin_frame_source_) { 98 if (!output_surface_lost_ && !observing_begin_frame_source_) {
99 observing_begin_frame_source_ = true; 99 observing_begin_frame_source_ = true;
100 // When we call AddObserver() this will cause a missed BeginFrame to
101 // occur. We need to detect this and not process it immediately in the
102 // same call stack.
103 inside_add_observer_ = true;
sunnyps 2016/07/27 02:00:14 nit: base::AutoReset<bool> mark_inside(&inside_add
danakj 2016/07/27 02:19:04 Done.
100 begin_frame_source_->AddObserver(this); 104 begin_frame_source_->AddObserver(this);
105 inside_add_observer_ = false;
101 } 106 }
102 107
103 ScheduleBeginFrameDeadline(); 108 ScheduleBeginFrameDeadline();
104 } 109 }
105 110
106 void DisplayScheduler::OutputSurfaceLost() { 111 void DisplayScheduler::OutputSurfaceLost() {
107 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost"); 112 TRACE_EVENT0("cc", "DisplayScheduler::OutputSurfaceLost");
108 output_surface_lost_ = true; 113 output_surface_lost_ = true;
109 ScheduleBeginFrameDeadline(); 114 ScheduleBeginFrameDeadline();
110 } 115 }
(...skipping 20 matching lines...) Expand all
131 136
132 expect_damage_from_root_surface_ = root_surface_damaged_; 137 expect_damage_from_root_surface_ = root_surface_damaged_;
133 root_surface_damaged_ = false; 138 root_surface_damaged_ = false;
134 } 139 }
135 140
136 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { 141 bool DisplayScheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) {
137 base::TimeTicks now = base::TimeTicks::Now(); 142 base::TimeTicks now = base::TimeTicks::Now();
138 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(), 143 TRACE_EVENT2("cc", "DisplayScheduler::BeginFrame", "args", args.AsValue(),
139 "now", now); 144 "now", now);
140 145
146 if (inside_add_observer_) {
147 // Repost this so that we don't run a missed BeginFrame on the same
148 // callstack. Otherwise we end up running unexpected scheduler actions
149 // immediately while inside some other action (such as submitting a frame
150 // for a SurfaceFactory).
151 DCHECK_EQ(args.type, BeginFrameArgs::MISSED);
152 DCHECK(missed_begin_frame_task_.IsCancelled());
153 missed_begin_frame_task_.Reset(base::Bind(
154 base::IgnoreResult(&DisplayScheduler::OnBeginFrameDerivedImpl),
155 weak_ptr_factory_.GetWeakPtr(), args));
156 task_runner_->PostTask(FROM_HERE, missed_begin_frame_task_.callback());
157 return true;
158 } else {
159 // If we get another BeginFrame before a posted missed frame, just drop the
160 // missed frame.
161 missed_begin_frame_task_.Cancel();
162 }
163
141 // If we get another BeginFrame before the previous deadline, 164 // If we get another BeginFrame before the previous deadline,
142 // synchronously trigger the previous deadline before progressing. 165 // synchronously trigger the previous deadline before progressing.
143 if (inside_begin_frame_deadline_interval_) { 166 if (inside_begin_frame_deadline_interval_) {
144 OnBeginFrameDeadline(); 167 OnBeginFrameDeadline();
145 } 168 }
146 169
147 // Schedule the deadline. 170 // Schedule the deadline.
148 current_begin_frame_args_ = args; 171 current_begin_frame_args_ = args;
149 current_begin_frame_args_.deadline -= 172 current_begin_frame_args_.deadline -=
150 BeginFrameArgs::DefaultEstimatedParentDrawTime(); 173 BeginFrameArgs::DefaultEstimatedParentDrawTime();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 324 }
302 325
303 void DisplayScheduler::DidSwapBuffersComplete() { 326 void DisplayScheduler::DidSwapBuffersComplete() {
304 pending_swaps_--; 327 pending_swaps_--;
305 TRACE_EVENT_ASYNC_END1("cc", "DisplayScheduler:pending_swaps", this, 328 TRACE_EVENT_ASYNC_END1("cc", "DisplayScheduler:pending_swaps", this,
306 "pending_frames", pending_swaps_); 329 "pending_frames", pending_swaps_);
307 ScheduleBeginFrameDeadline(); 330 ScheduleBeginFrameDeadline();
308 } 331 }
309 332
310 } // namespace cc 333 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698