summaryrefslogtreecommitdiffstats
path: root/cc/test/begin_frame_args_test.cc
blob: 64e2e7d1580529c61f3628480eed89d9c9a53f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/test/begin_frame_args_test.h"

#include "base/time/time.h"
#include "cc/output/begin_frame_args.h"

namespace cc {

BeginFrameArgs CreateBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location) {
  return CreateBeginFrameArgsForTesting(location, base::TimeTicks::Now());
}

BeginFrameArgs CreateBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location,
    base::TimeTicks frame_time) {
  return BeginFrameArgs::Create(
      location, frame_time,
      frame_time + BeginFrameArgs::DefaultInterval() -
          BeginFrameArgs::DefaultEstimatedParentDrawTime(),
      BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL);
}

BeginFrameArgs CreateBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location,
    int64 frame_time,
    int64 deadline,
    int64 interval) {
  return BeginFrameArgs::Create(
      location, base::TimeTicks::FromInternalValue(frame_time),
      base::TimeTicks::FromInternalValue(deadline),
      base::TimeDelta::FromInternalValue(interval), BeginFrameArgs::NORMAL);
}

BeginFrameArgs CreateBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location,
    int64 frame_time,
    int64 deadline,
    int64 interval,
    BeginFrameArgs::BeginFrameArgsType type) {
  return BeginFrameArgs::Create(
      location, base::TimeTicks::FromInternalValue(frame_time),
      base::TimeTicks::FromInternalValue(deadline),
      base::TimeDelta::FromInternalValue(interval), type);
}

BeginFrameArgs CreateExpiredBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location) {
  base::TimeTicks now = base::TimeTicks::Now();
  return BeginFrameArgs::Create(
      location, now, now - BeginFrameArgs::DefaultInterval(),
      BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL);
}

BeginFrameArgs CreateBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location,
    base::SimpleTestTickClock* now_src) {
  base::TimeTicks now = now_src->NowTicks();
  return BeginFrameArgs::Create(
      location, now, now + BeginFrameArgs::DefaultInterval() -
                         BeginFrameArgs::DefaultEstimatedParentDrawTime(),
      BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL);
}

BeginFrameArgs CreateExpiredBeginFrameArgsForTesting(
    BeginFrameArgs::CreationLocation location,
    base::SimpleTestTickClock* now_src) {
  base::TimeTicks now = now_src->NowTicks();
  return BeginFrameArgs::Create(
      location, now, now - BeginFrameArgs::DefaultInterval(),
      BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL);
}

bool operator==(const BeginFrameArgs& lhs, const BeginFrameArgs& rhs) {
  return (lhs.type == rhs.type) && (lhs.frame_time == rhs.frame_time) &&
         (lhs.deadline == rhs.deadline) && (lhs.interval == rhs.interval);
}

::std::ostream& operator<<(::std::ostream& os, const BeginFrameArgs& args) {
  PrintTo(args, &os);
  return os;
}

void PrintTo(const BeginFrameArgs& args, ::std::ostream* os) {
  *os << "BeginFrameArgs(" << BeginFrameArgs::TypeToString(args.type) << ", "
      << args.frame_time.ToInternalValue() << ", "
      << args.deadline.ToInternalValue() << ", "
      << args.interval.InMicroseconds() << "us)";
}

}  // namespace cc