OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> |
| 6 |
| 7 #include "base/json/json_writer.h" |
5 #include "cc/output/begin_frame_args.h" | 8 #include "cc/output/begin_frame_args.h" |
6 #include "ui/gfx/frame_time.h" | 9 #include "ui/gfx/frame_time.h" |
7 | 10 |
8 namespace cc { | 11 namespace cc { |
9 | 12 |
10 BeginFrameArgs::BeginFrameArgs() | 13 BeginFrameArgs::BeginFrameArgs() |
11 : frame_time(base::TimeTicks()), | 14 : frame_time(base::TimeTicks()), |
12 deadline(base::TimeTicks()), | 15 deadline(base::TimeTicks()), |
13 interval(base::TimeDelta::FromMicroseconds(-1)) { | 16 interval(base::TimeDelta::FromMicroseconds(-1)) { |
14 } | 17 } |
15 | 18 |
16 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, | 19 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, |
17 base::TimeTicks deadline, | 20 base::TimeTicks deadline, |
18 base::TimeDelta interval) | 21 base::TimeDelta interval) |
19 : frame_time(frame_time), | 22 : frame_time(frame_time), |
20 deadline(deadline), | 23 deadline(deadline), |
21 interval(interval) | 24 interval(interval) |
22 {} | 25 {} |
23 | 26 |
24 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, | 27 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, |
25 base::TimeTicks deadline, | 28 base::TimeTicks deadline, |
26 base::TimeDelta interval) { | 29 base::TimeDelta interval) { |
27 return BeginFrameArgs(frame_time, deadline, interval); | 30 return BeginFrameArgs(frame_time, deadline, interval); |
28 } | 31 } |
29 | 32 |
| 33 scoped_ptr<base::Value> BeginFrameArgs::AsValue() const { |
| 34 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); |
| 35 state->SetString("type", "BeginFrameArgs"); |
| 36 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); |
| 37 state->SetDouble("deadline_us", deadline.ToInternalValue()); |
| 38 state->SetDouble("interval_us", interval.InMicroseconds()); |
| 39 return state.PassAs<base::Value>(); |
| 40 } |
| 41 |
| 42 namespace { |
| 43 |
| 44 // TODO(mithro): This class should be part of base/debug/trace code. |
| 45 class TracedValue : public base::debug::ConvertableToTraceFormat { |
| 46 public: |
| 47 static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue( |
| 48 scoped_ptr<base::Value> value); |
| 49 |
| 50 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE; |
| 51 |
| 52 private: |
| 53 explicit TracedValue(base::Value* value); |
| 54 virtual ~TracedValue(); |
| 55 |
| 56 scoped_ptr<base::Value> value_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(TracedValue); |
| 59 }; |
| 60 |
| 61 scoped_refptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( |
| 62 scoped_ptr<base::Value> value) { |
| 63 return scoped_refptr<base::debug::ConvertableToTraceFormat>( |
| 64 new TracedValue(value.release())); |
| 65 } |
| 66 |
| 67 TracedValue::~TracedValue() { |
| 68 } |
| 69 |
| 70 void TracedValue::AppendAsTraceFormat(std::string* out) const { |
| 71 std::string tmp; |
| 72 base::JSONWriter::Write(value_.get(), &tmp); |
| 73 *out += tmp; |
| 74 } |
| 75 |
| 76 TracedValue::TracedValue(base::Value* value) : value_(value) { |
| 77 } |
| 78 } // namespace |
| 79 |
| 80 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsTrace() |
| 81 const { |
| 82 return TracedValue::FromValue(AsValue()); |
| 83 } |
| 84 |
30 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor() { | 85 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor() { |
31 // For WebView/SynchronousCompositor, we always want to draw immediately, | 86 // For WebView/SynchronousCompositor, we always want to draw immediately, |
32 // so we set the deadline to 0 and guess that the interval is 16 milliseconds. | 87 // so we set the deadline to 0 and guess that the interval is 16 milliseconds. |
33 return BeginFrameArgs(gfx::FrameTime::Now(), | 88 return BeginFrameArgs(gfx::FrameTime::Now(), |
34 base::TimeTicks(), | 89 base::TimeTicks(), |
35 DefaultInterval()); | 90 DefaultInterval()); |
36 } | 91 } |
37 | 92 |
38 BeginFrameArgs BeginFrameArgs::CreateForTesting() { | 93 BeginFrameArgs BeginFrameArgs::CreateForTesting() { |
39 base::TimeTicks now = gfx::FrameTime::Now(); | 94 base::TimeTicks now = gfx::FrameTime::Now(); |
(...skipping 21 matching lines...) Expand all Loading... |
61 | 116 |
62 base::TimeDelta BeginFrameArgs::DefaultInterval() { | 117 base::TimeDelta BeginFrameArgs::DefaultInterval() { |
63 return base::TimeDelta::FromMicroseconds(16666); | 118 return base::TimeDelta::FromMicroseconds(16666); |
64 } | 119 } |
65 | 120 |
66 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { | 121 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { |
67 return base::TimeDelta::FromMicroseconds(4444); | 122 return base::TimeDelta::FromMicroseconds(4444); |
68 } | 123 } |
69 | 124 |
70 } // namespace cc | 125 } // namespace cc |
OLD | NEW |