Fady Samuel | 0cfa6cba | 2018-10-16 20:05:43 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/viz/common/quads/frame_deadline.h" |
| 6 | |
| 7 | #include <cinttypes> |
| 8 | |
| 9 | #include "base/strings/string_number_conversions.h" |
| 10 | #include "base/strings/stringprintf.h" |
| 11 | |
| 12 | namespace viz { |
| 13 | |
Saman Sami | 1064d5ea | 2019-03-20 17:05:40 | [diff] [blame] | 14 | // static |
| 15 | FrameDeadline FrameDeadline::MakeZero() { |
| 16 | return FrameDeadline(base::TimeTicks(), 0, base::TimeDelta(), false); |
| 17 | } |
| 18 | |
Fady Samuel | 0cfa6cba | 2018-10-16 20:05:43 | [diff] [blame] | 19 | base::TimeTicks FrameDeadline::ToWallTime( |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 20 | absl::optional<uint32_t> default_deadline_in_frames) const { |
Fady Samuel | 0cfa6cba | 2018-10-16 20:05:43 | [diff] [blame] | 21 | uint32_t deadline_in_frames = deadline_in_frames_; |
| 22 | if (use_default_lower_bound_deadline_) { |
| 23 | deadline_in_frames = |
| 24 | std::max(deadline_in_frames, default_deadline_in_frames.value_or( |
| 25 | std::numeric_limits<uint32_t>::max())); |
| 26 | } |
| 27 | return frame_start_time_ + deadline_in_frames * frame_interval_; |
| 28 | } |
| 29 | |
Saman Sami | a77e3e6f | 2019-04-08 16:07:48 | [diff] [blame] | 30 | bool FrameDeadline::IsZero() const { |
| 31 | return deadline_in_frames_ == 0 && !use_default_lower_bound_deadline_; |
| 32 | } |
| 33 | |
Fady Samuel | 0cfa6cba | 2018-10-16 20:05:43 | [diff] [blame] | 34 | std::string FrameDeadline::ToString() const { |
| 35 | const base::TimeDelta start_time_delta = |
| 36 | frame_start_time_ - base::TimeTicks(); |
| 37 | return base::StringPrintf( |
| 38 | "FrameDeadline(start time: %" PRId64 |
| 39 | " ms, deadline in frames: %s, frame interval: %" PRId64 " ms)", |
| 40 | start_time_delta.InMilliseconds(), |
| 41 | use_default_lower_bound_deadline_ |
| 42 | ? "unresolved" |
Raul Tambre | f88e510 | 2019-02-06 10:54:03 | [diff] [blame] | 43 | : base::NumberToString(deadline_in_frames_).c_str(), |
Fady Samuel | 0cfa6cba | 2018-10-16 20:05:43 | [diff] [blame] | 44 | frame_interval_.InMilliseconds()); |
| 45 | } |
| 46 | |
| 47 | std::ostream& operator<<(std::ostream& out, |
| 48 | const FrameDeadline& frame_deadline) { |
| 49 | return out << frame_deadline.ToString(); |
| 50 | } |
| 51 | |
| 52 | } // namespace viz |