OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "cc/scheduler/begin_frame_tracker.h" | |
6 | |
7 namespace cc { | |
8 | |
9 BeginFrameTracker::BeginFrameTracker(const tracked_objects::Location& location) | |
10 : location_(location), | |
11 location_string_(location.ToString()), | |
12 current_updated_at_(), | |
13 current_args_(), | |
14 current_finished_at_(base::TimeTicks::FromInternalValue(-1)) { | |
15 } | |
16 | |
17 BeginFrameTracker::~BeginFrameTracker() { | |
18 } | |
19 | |
20 void BeginFrameTracker::Start(BeginFrameArgs new_args) { | |
21 // Trace the frame time being passed between BeginFrameTrackers. | |
22 TRACE_EVENT_FLOW_STEP0( | |
23 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", | |
24 new_args.frame_time.ToInternalValue(), location_string_); | |
25 | |
26 // Trace this specific begin frame tracker Start/Finish times. | |
27 TRACE_EVENT_ASYNC_BEGIN2( | |
28 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
29 location_string_.c_str(), new_args.frame_time.ToInternalValue(), | |
30 "new args", new_args.AsValue(), "current args", current_args_.AsValue()); | |
31 | |
32 // Check the new BeginFrameArgs are valid and monotonically increasing. | |
33 DCHECK(new_args.IsValid()); | |
34 DCHECK_LT(current_args_.frame_time, new_args.frame_time); | |
35 | |
36 DCHECK(HasFinished()) | |
37 << "Tried to start a new frame before finishing an existing frame."; | |
38 current_updated_at_ = base::TimeTicks::NowFromSystemTraceTime(); | |
39 current_args_ = new_args; | |
40 current_finished_at_ = base::TimeTicks(); | |
41 | |
42 // TODO(mithro): Add UMA tracking of delta between current_updated_at_ time | |
43 // and the new_args.frame_time argument. This will give us how long after a | |
44 // BeginFrameArgs message was created before we started processing it. | |
45 } | |
46 | |
47 const BeginFrameArgs& BeginFrameTracker::Get() const { | |
48 DCHECK(!HasFinished()) | |
49 << "Tried to use BeginFrameArgs after marking the frame finished."; | |
50 DCHECK(current_args_.IsValid()) | |
51 << "Tried to use BeginFrameArgs before starting a frame!"; | |
52 return current_args_; | |
53 } | |
54 | |
55 void BeginFrameTracker::Finish() { | |
brianderson
2014/12/18 02:01:38
Or is this important for debug / frame timing purp
mithro-old
2014/12/18 17:22:40
The start/finish methods help control access to th
| |
56 DCHECK(!HasFinished()) << "Tried to finish an already finished frame"; | |
57 current_finished_at_ = base::TimeTicks::NowFromSystemTraceTime(); | |
58 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
59 location_string_.c_str(), | |
60 current_args_.frame_time.ToInternalValue()); | |
61 } | |
62 | |
63 const BeginFrameArgs& BeginFrameTracker::Last() const { | |
64 DCHECK(current_args_.IsValid()) | |
65 << "Tried to use last BeginFrameArgs before starting a frame!"; | |
66 DCHECK(HasFinished()) | |
67 << "Tried to use last BeginFrameArgs before the frame is finished."; | |
68 return current_args_; | |
brianderson
2014/12/18 02:01:38
Would it make sense for this to always return the
mithro-old
2014/12/18 17:22:40
I want the caller to make a conscious decision abo
| |
69 } | |
70 | |
71 base::TimeDelta BeginFrameTracker::Interval() const { | |
72 base::TimeDelta interval = current_args_.interval; | |
73 // Normal interval will be ~16ms, 200Hz (5ms) screens are the fastest | |
74 // easily available so anything less than that is likely an error. | |
75 if (interval < base::TimeDelta::FromMilliseconds(4)) { | |
76 interval = BeginFrameArgs::DefaultInterval(); | |
77 } | |
78 return interval; | |
79 } | |
80 | |
81 } // namespace cc | |
OLD | NEW |