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/surfaces/display_scheduler.h" | |
6 | |
7 #include "base/debug/trace_event.h" | |
8 #include "cc/output/output_surface.h" | |
9 #include "ui/gfx/frame_time.h" | |
10 | |
11 namespace cc { | |
12 | |
13 const size_t kDurationHistorySize = 60; | |
14 const double kDrawDurationEstimationPercentile = 95.0; | |
15 const int kDrawDurationEstimatePaddingInMicroseconds = 0; | |
16 | |
17 DisplayScheduler::DisplayScheduler( | |
18 OutputSurface* output_surface, | |
19 Display* display, | |
20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
21 : output_surface_(output_surface), | |
22 display_(display), | |
23 task_runner_(task_runner), | |
24 draw_duration_history_(kDurationHistorySize), | |
25 output_surface_lost_(false), | |
26 need_draw_(false), | |
27 pending_frames_(0), | |
28 weak_ptr_factory_(this) { | |
29 begin_frame_source_ = SyntheticBeginFrameSource::Create( | |
30 task_runner_.get(), gfx::FrameTime::Now(), | |
31 BeginFrameArgs::DefaultInterval()); | |
32 begin_frame_source_->AddObserver(this); | |
33 } | |
34 | |
35 DisplayScheduler::~DisplayScheduler() { | |
36 } | |
37 | |
38 void DisplayScheduler::CommitVSyncParameters(base::TimeTicks timebase, | |
39 base::TimeDelta interval) { | |
40 if (begin_frame_source_ && interval != base::TimeDelta()) | |
41 begin_frame_source_->OnUpdateVSyncParameters(timebase, interval); | |
42 } | |
43 | |
44 void DisplayScheduler::DisplayDamaged() { | |
45 TRACE_EVENT0("cc", "DisplayScheduler::DisplayDamaged"); | |
46 begin_frame_source_->SetNeedsBeginFrames(!output_surface_lost_); | |
47 need_draw_ = true; | |
48 } | |
49 | |
50 void DisplayScheduler::OutputSurfaceLost() { | |
51 output_surface_lost_ = true; | |
52 begin_frame_source_->SetNeedsBeginFrames(false); | |
53 } | |
54 | |
55 void DisplayScheduler::Draw() { | |
56 TRACE_EVENT0("cc", "DisplayScheduler::Draw"); | |
57 if (!need_draw_) { | |
58 begin_frame_source_->SetNeedsBeginFrames(false); | |
59 return; | |
60 } | |
61 if (pending_frames_ >= display_->GetMaxFramesPending()) | |
62 return; | |
63 if (output_surface_lost_) | |
64 return; | |
65 need_draw_ = false; | |
66 base::TimeTicks start_time = gfx::FrameTime::Now(); | |
67 display_->Draw(); | |
68 draw_duration_history_.InsertSample(gfx::FrameTime::Now() - start_time); | |
69 } | |
70 | |
71 void DisplayScheduler::OnBeginFrame(const BeginFrameArgs& args) { | |
brianderson
2014/11/19 02:40:21
Until the DisplayScheduler has knowledge about all
| |
72 TRACE_EVENT0("cc", "DisplayScheduler::OnBeginFrame"); | |
73 current_begin_frame_args_ = args; | |
74 | |
75 current_begin_frame_args_.deadline -= | |
76 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile) + | |
77 base::TimeDelta::FromMicroseconds( | |
78 kDrawDurationEstimatePaddingInMicroseconds); | |
79 | |
80 base::TimeDelta draw_delay = | |
81 current_begin_frame_args_.deadline - gfx::FrameTime::Now(); | |
82 if (draw_delay < base::TimeDelta()) | |
83 draw_delay = base::TimeDelta(); | |
84 task_runner_->PostDelayedTask( | |
85 FROM_HERE, | |
86 base::Bind(&DisplayScheduler::Draw, weak_ptr_factory_.GetWeakPtr()), | |
87 draw_delay); | |
88 } | |
89 | |
90 const BeginFrameArgs DisplayScheduler::LastUsedBeginFrameArgs() const { | |
91 return current_begin_frame_args_; | |
92 } | |
93 | |
94 void DisplayScheduler::AsValueInto(base::debug::TracedValue* dict) const { | |
95 } | |
96 | |
97 void DisplayScheduler::DidSwapBuffers() { | |
98 pending_frames_++; | |
99 } | |
100 | |
101 void DisplayScheduler::DidSwapBuffersComplete() { | |
102 pending_frames_--; | |
103 } | |
104 | |
105 } // namespace cc | |
OLD | NEW |