Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / debug / rendering_stats_instrumentation.cc
blob9655241c63976bcb2cd688ee1826a1843d0d30f7
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
3 // found in the LICENSE file.
5 #include "cc/debug/rendering_stats_instrumentation.h"
7 namespace cc {
9 // static
10 scoped_ptr<RenderingStatsInstrumentation>
11 RenderingStatsInstrumentation::Create() {
12 return make_scoped_ptr(new RenderingStatsInstrumentation());
15 RenderingStatsInstrumentation::RenderingStatsInstrumentation()
16 : record_rendering_stats_(false) {
19 RenderingStatsInstrumentation::~RenderingStatsInstrumentation() {}
21 MainThreadRenderingStats
22 RenderingStatsInstrumentation::main_thread_rendering_stats() {
23 base::AutoLock scoped_lock(lock_);
24 return main_thread_rendering_stats_;
27 ImplThreadRenderingStats
28 RenderingStatsInstrumentation::impl_thread_rendering_stats() {
29 base::AutoLock scoped_lock(lock_);
30 return impl_thread_rendering_stats_;
33 RenderingStats RenderingStatsInstrumentation::GetRenderingStats() {
34 base::AutoLock scoped_lock(lock_);
35 RenderingStats rendering_stats;
36 rendering_stats.main_stats = main_thread_rendering_stats_accu_;
37 rendering_stats.main_stats.Add(main_thread_rendering_stats_);
38 rendering_stats.impl_stats = impl_thread_rendering_stats_accu_;
39 rendering_stats.impl_stats.Add(impl_thread_rendering_stats_);
40 return rendering_stats;
43 void RenderingStatsInstrumentation::AccumulateAndClearMainThreadStats() {
44 base::AutoLock scoped_lock(lock_);
45 main_thread_rendering_stats_accu_.Add(main_thread_rendering_stats_);
46 main_thread_rendering_stats_ = MainThreadRenderingStats();
49 void RenderingStatsInstrumentation::AccumulateAndClearImplThreadStats() {
50 base::AutoLock scoped_lock(lock_);
51 impl_thread_rendering_stats_accu_.Add(impl_thread_rendering_stats_);
52 impl_thread_rendering_stats_ = ImplThreadRenderingStats();
55 base::TimeTicks RenderingStatsInstrumentation::StartRecording() const {
56 if (record_rendering_stats_) {
57 if (base::TimeTicks::IsThreadNowSupported())
58 return base::TimeTicks::ThreadNow();
59 return base::TimeTicks::HighResNow();
61 return base::TimeTicks();
64 base::TimeDelta RenderingStatsInstrumentation::EndRecording(
65 base::TimeTicks start_time) const {
66 if (!start_time.is_null()) {
67 if (base::TimeTicks::IsThreadNowSupported())
68 return base::TimeTicks::ThreadNow() - start_time;
69 return base::TimeTicks::HighResNow() - start_time;
71 return base::TimeDelta();
74 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count,
75 bool main_thread) {
76 if (!record_rendering_stats_)
77 return;
79 base::AutoLock scoped_lock(lock_);
80 if (main_thread)
81 main_thread_rendering_stats_.frame_count += count;
82 else
83 impl_thread_rendering_stats_.frame_count += count;
86 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
87 int64 pixels) {
88 if (!record_rendering_stats_)
89 return;
91 base::AutoLock scoped_lock(lock_);
92 main_thread_rendering_stats_.paint_time += duration;
93 main_thread_rendering_stats_.painted_pixel_count += pixels;
96 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
97 int64 pixels) {
98 if (!record_rendering_stats_)
99 return;
101 base::AutoLock scoped_lock(lock_);
102 main_thread_rendering_stats_.record_time += duration;
103 main_thread_rendering_stats_.recorded_pixel_count += pixels;
106 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
107 int64 pixels) {
108 if (!record_rendering_stats_)
109 return;
111 base::AutoLock scoped_lock(lock_);
112 impl_thread_rendering_stats_.rasterize_time += duration;
113 impl_thread_rendering_stats_.rasterized_pixel_count += pixels;
116 void RenderingStatsInstrumentation::AddAnalysis(base::TimeDelta duration,
117 int64 pixels) {
118 if (!record_rendering_stats_)
119 return;
121 base::AutoLock scoped_lock(lock_);
122 impl_thread_rendering_stats_.analysis_time += duration;
125 void RenderingStatsInstrumentation::AddVisibleContentArea(int64 area) {
126 if (!record_rendering_stats_)
127 return;
129 base::AutoLock scoped_lock(lock_);
130 impl_thread_rendering_stats_.visible_content_area += area;
133 void RenderingStatsInstrumentation::AddApproximatedVisibleContentArea(
134 int64 area) {
135 if (!record_rendering_stats_)
136 return;
138 base::AutoLock scoped_lock(lock_);
139 impl_thread_rendering_stats_.approximated_visible_content_area += area;
142 } // namespace cc