-void OutputSurface::SetNeedsBeginImplFrame(bool enable) {
- TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginImplFrame", "enable", enable);
- needs_begin_impl_frame_ = enable;
- client_ready_for_begin_impl_frame_ = true;
- if (frame_rate_controller_) {
- BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable);
- if (skipped.IsValid())
- skipped_begin_impl_frame_args_ = skipped;
- }
- if (needs_begin_impl_frame_)
- PostCheckForRetroactiveBeginImplFrame();
-}
-
-void OutputSurface::BeginImplFrame(const BeginFrameArgs& args) {
- TRACE_EVENT2("cc", "OutputSurface::BeginImplFrame",
- "client_ready_for_begin_impl_frame_",
- client_ready_for_begin_impl_frame_,
- "pending_swap_buffers_", pending_swap_buffers_);
- if (!needs_begin_impl_frame_ || !client_ready_for_begin_impl_frame_ ||
- (pending_swap_buffers_ >= max_frames_pending_ &&
- max_frames_pending_ > 0)) {
- skipped_begin_impl_frame_args_ = args;
- } else {
- client_ready_for_begin_impl_frame_ = false;
- client_->BeginImplFrame(args);
- // args might be an alias for skipped_begin_impl_frame_args_.
- // Do not reset it before calling BeginImplFrame!
- skipped_begin_impl_frame_args_ = BeginFrameArgs();
- }
-}
-
-base::TimeTicks OutputSurface::RetroactiveBeginImplFrameDeadline() {
- // TODO(brianderson): Remove the alternative deadline once we have better
- // deadline estimations.
- base::TimeTicks alternative_deadline =
- skipped_begin_impl_frame_args_.frame_time +
- BeginFrameArgs::DefaultRetroactiveBeginFramePeriod();
- return std::max(skipped_begin_impl_frame_args_.deadline,
- alternative_deadline);
-}
-
-void OutputSurface::PostCheckForRetroactiveBeginImplFrame() {
- if (!skipped_begin_impl_frame_args_.IsValid() ||
- check_for_retroactive_begin_impl_frame_pending_)
- return;
-
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&OutputSurface::CheckForRetroactiveBeginImplFrame,
- weak_ptr_factory_.GetWeakPtr()));
- check_for_retroactive_begin_impl_frame_pending_ = true;
-}
-
-void OutputSurface::CheckForRetroactiveBeginImplFrame() {
- TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginImplFrame");
- check_for_retroactive_begin_impl_frame_pending_ = false;
- if (gfx::FrameTime::Now() < RetroactiveBeginImplFrameDeadline())
- BeginImplFrame(skipped_begin_impl_frame_args_);
-}
-
-void OutputSurface::DidSwapBuffers() {
- pending_swap_buffers_++;
- TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers",
- "pending_swap_buffers_", pending_swap_buffers_);
- client_->DidSwapBuffers();
- if (frame_rate_controller_)
- frame_rate_controller_->DidSwapBuffers();
- PostCheckForRetroactiveBeginImplFrame();
-}
-
-void OutputSurface::OnSwapBuffersComplete() {
- pending_swap_buffers_--;
- TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete",
- "pending_swap_buffers_", pending_swap_buffers_);
- client_->OnSwapBuffersComplete();
- if (frame_rate_controller_)
- frame_rate_controller_->DidSwapBuffersComplete();
- PostCheckForRetroactiveBeginImplFrame();
-}
-