Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: mojo/ui/choreographer.cc

Issue 1997513002: Mozart: Generalize frame scheduling. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-jank2
Patch Set: add comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/ui/choreographer.h ('k') | services/gfx/compositor/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/ui/choreographer.h" 5 #include "mojo/ui/choreographer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "mojo/public/cpp/system/time.h" 9 #include "mojo/public/cpp/system/time.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace ui { 12 namespace ui {
13 13
14 Choreographer::Choreographer(mojo::gfx::composition::Scene* scene, 14 Choreographer::Choreographer(mojo::gfx::composition::Scene* scene,
15 ChoreographerDelegate* delegate) 15 ChoreographerDelegate* delegate)
16 : delegate_(delegate) { 16 : delegate_(delegate) {
17 DCHECK(delegate_); 17 DCHECK(delegate_);
18 scene->GetScheduler(mojo::GetProxy(&scene_scheduler_)); 18 scene->GetScheduler(mojo::GetProxy(&frame_scheduler_));
19 } 19 }
20 20
21 Choreographer::Choreographer( 21 Choreographer::Choreographer(
22 mojo::gfx::composition::SceneSchedulerPtr scene_scheduler, 22 mojo::gfx::composition::FrameSchedulerPtr frame_scheduler,
23 ChoreographerDelegate* delegate) 23 ChoreographerDelegate* delegate)
24 : scene_scheduler_(scene_scheduler.Pass()), delegate_(delegate) { 24 : frame_scheduler_(frame_scheduler.Pass()), delegate_(delegate) {
25 DCHECK(scene_scheduler_); 25 DCHECK(frame_scheduler_);
26 DCHECK(delegate_); 26 DCHECK(delegate_);
27 } 27 }
28 28
29 Choreographer::~Choreographer() {} 29 Choreographer::~Choreographer() {}
30 30
31 void Choreographer::ScheduleDraw() { 31 void Choreographer::ScheduleDraw() {
32 if (!draw_scheduled_) { 32 if (!draw_scheduled_) {
33 draw_scheduled_ = true; 33 draw_scheduled_ = true;
34 ScheduleFrame(); 34 ScheduleFrame();
35 } 35 }
36 } 36 }
37 37
38 void Choreographer::ScheduleFrame() { 38 void Choreographer::ScheduleFrame() {
39 if (!frame_scheduled_) { 39 if (!frame_scheduled_) {
40 frame_scheduled_ = true; 40 frame_scheduled_ = true;
41 scene_scheduler_->ScheduleFrame( 41 frame_scheduler_->ScheduleFrame(
42 base::Bind(&Choreographer::DoFrame, base::Unretained(this))); 42 base::Bind(&Choreographer::DoFrame, base::Unretained(this)));
43 } 43 }
44 } 44 }
45 45
46 void Choreographer::DoFrame(mojo::gfx::composition::FrameInfoPtr frame_info) { 46 void Choreographer::DoFrame(mojo::gfx::composition::FrameInfoPtr frame_info) {
47 DCHECK(frame_info); 47 DCHECK(frame_info);
48 DCHECK(frame_scheduled_); 48 DCHECK(frame_scheduled_);
49 frame_scheduled_ = false; 49 frame_scheduled_ = false;
50 50
51 if (draw_scheduled_) { 51 if (draw_scheduled_) {
52 draw_scheduled_ = false; 52 draw_scheduled_ = false;
53 53
54 // To reduce latency and jank, anticipate the next frame to be drawn by 54 // To reduce latency and jank, anticipate the next frame to be drawn by
55 // scheduling it early. 55 // scheduling it early.
56 // 56 //
57 // TODO(jeffbrown): Reenable this once issue #604 is fixed. Unfortunately 57 // TODO(jeffbrown): Reenable this once issue #604 is fixed. Unfortunately
58 // this exacerbates starvation issues in the Mojo message pump. 58 // this exacerbates starvation issues in the Mojo message pump.
59 // ScheduleFrame(); 59 // ScheduleFrame();
60 60
61 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds( 61 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds(
62 frame_tracker_.Update(*frame_info, mojo::GetTimeTicksNow())); 62 frame_tracker_.Update(*frame_info, mojo::GetTimeTicksNow()));
63 delegate_->OnDraw(frame_tracker_.frame_info(), time_delta); 63 delegate_->OnDraw(frame_tracker_.frame_info(), time_delta);
64 } 64 }
65 } 65 }
66 66
67 } // namespace ui 67 } // namespace ui
68 } // namespace mojo 68 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/ui/choreographer.h ('k') | services/gfx/compositor/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698