OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <set> | 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 skipped_begin_frame_args_ = args; | 210 skipped_begin_frame_args_ = args; |
210 } else { | 211 } else { |
211 begin_frame_pending_ = true; | 212 begin_frame_pending_ = true; |
212 client_->BeginFrame(args); | 213 client_->BeginFrame(args); |
213 // args might be an alias for skipped_begin_frame_args_. | 214 // args might be an alias for skipped_begin_frame_args_. |
214 // Do not reset it before calling BeginFrame! | 215 // Do not reset it before calling BeginFrame! |
215 skipped_begin_frame_args_ = BeginFrameArgs(); | 216 skipped_begin_frame_args_ = BeginFrameArgs(); |
216 } | 217 } |
217 } | 218 } |
218 | 219 |
219 base::TimeDelta OutputSurface::RetroactiveBeginFramePeriod() { | 220 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() { |
220 return BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); | 221 base::TimeTicks alternative_deadline = |
| 222 skipped_begin_frame_args_.frame_time + |
| 223 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); |
| 224 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline); |
221 } | 225 } |
222 | 226 |
223 void OutputSurface::PostCheckForRetroactiveBeginFrame() { | 227 void OutputSurface::PostCheckForRetroactiveBeginFrame() { |
224 if (!skipped_begin_frame_args_.IsValid() || | 228 if (!skipped_begin_frame_args_.IsValid() || |
225 check_for_retroactive_begin_frame_pending_) | 229 check_for_retroactive_begin_frame_pending_) |
226 return; | 230 return; |
227 | 231 |
228 base::MessageLoop::current()->PostTask( | 232 base::MessageLoop::current()->PostTask( |
229 FROM_HERE, | 233 FROM_HERE, |
230 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, | 234 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, |
231 weak_ptr_factory_.GetWeakPtr())); | 235 weak_ptr_factory_.GetWeakPtr())); |
232 check_for_retroactive_begin_frame_pending_ = true; | 236 check_for_retroactive_begin_frame_pending_ = true; |
233 } | 237 } |
234 | 238 |
235 void OutputSurface::CheckForRetroactiveBeginFrame() { | 239 void OutputSurface::CheckForRetroactiveBeginFrame() { |
236 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); | 240 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); |
237 check_for_retroactive_begin_frame_pending_ = false; | 241 check_for_retroactive_begin_frame_pending_ = false; |
238 base::TimeTicks now = base::TimeTicks::Now(); | 242 if (base::TimeTicks::Now() < RetroactiveBeginFrameDeadline()) |
239 base::TimeTicks alternative_deadline = | |
240 skipped_begin_frame_args_.frame_time + | |
241 RetroactiveBeginFramePeriod(); | |
242 if (now < skipped_begin_frame_args_.deadline || | |
243 now < alternative_deadline) { | |
244 BeginFrame(skipped_begin_frame_args_); | 243 BeginFrame(skipped_begin_frame_args_); |
245 } | |
246 } | 244 } |
247 | 245 |
248 void OutputSurface::DidSwapBuffers() { | 246 void OutputSurface::DidSwapBuffers() { |
249 begin_frame_pending_ = false; | 247 begin_frame_pending_ = false; |
250 pending_swap_buffers_++; | 248 pending_swap_buffers_++; |
251 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", | 249 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", |
252 "pending_swap_buffers_", pending_swap_buffers_); | 250 "pending_swap_buffers_", pending_swap_buffers_); |
253 if (frame_rate_controller_) | 251 if (frame_rate_controller_) |
254 frame_rate_controller_->DidSwapBuffers(); | 252 frame_rate_controller_->DidSwapBuffers(); |
255 PostCheckForRetroactiveBeginFrame(); | 253 PostCheckForRetroactiveBeginFrame(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 420 |
423 void OutputSurface::SetMemoryPolicy(const ManagedMemoryPolicy& policy, | 421 void OutputSurface::SetMemoryPolicy(const ManagedMemoryPolicy& policy, |
424 bool discard_backbuffer_when_not_visible) { | 422 bool discard_backbuffer_when_not_visible) { |
425 TRACE_EVENT2("cc", "OutputSurface::SetMemoryPolicy", | 423 TRACE_EVENT2("cc", "OutputSurface::SetMemoryPolicy", |
426 "bytes_limit_when_visible", policy.bytes_limit_when_visible, | 424 "bytes_limit_when_visible", policy.bytes_limit_when_visible, |
427 "discard_backbuffer", discard_backbuffer_when_not_visible); | 425 "discard_backbuffer", discard_backbuffer_when_not_visible); |
428 client_->SetMemoryPolicy(policy, discard_backbuffer_when_not_visible); | 426 client_->SetMemoryPolicy(policy, discard_backbuffer_when_not_visible); |
429 } | 427 } |
430 | 428 |
431 } // namespace cc | 429 } // namespace cc |
OLD | NEW |