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

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

Issue 1556803002: Add helpers for creating UI components. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-13
Patch Set: Created 4 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_UI_CHOREOGRAPHER_H_
6 #define MOJO_UI_CHOREOGRAPHER_H_
7
8 #include "base/time/time.h"
9 #include "mojo/public/cpp/system/macros.h"
10 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h"
11 #include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h"
12
13 namespace mojo {
14 namespace ui {
15
16 class ChoreographerDelegate;
17
18 // Coordinates drawing a frame of a scene.
19 //
20 // This class is intended to be included as a member of a View that wants to
21 // schedule drawing using the following pattern.
22 //
23 // class MyView : public mojo::ui::BaseView,
24 // public mojo::ui::ChoreographerDelegate {
25 // public:
26 // MyView(mojo::ApplicationImpl* app_impl,
27 // const mojo::ui::ViewProvider::CreateViewCallback&
28 // create_view_callback)
29 // : BaseView(app_impl, "MyView", create_view_callback),
30 // choreographer_(scene_scheduler(), this) {}
31 // ~MyView() override {}
32 //
33 // private:
34 // // |ChoreographerDelegate|:
35 // void OnDraw(const mojo::gfx::composition::FrameInfo& frame_info) override;
36 //
37 // mojo::ui::Choreographer choreographer_;
38 //
39 // MOJO_DISALLOW_COPY_AND_ASSIGN(MyView);
40 // };
41 class Choreographer {
42 public:
43 Choreographer(mojo::gfx::composition::Scene* scene,
44 ChoreographerDelegate* delegate);
45 Choreographer(mojo::gfx::composition::SceneSchedulerPtr scene_scheduler,
46 ChoreographerDelegate* delegate);
47 ~Choreographer();
48
49 // Gets the scene scheduler.
50 mojo::gfx::composition::SceneScheduler* scene_scheduler() {
51 return scene_scheduler_.get();
52 }
53
54 // Gets the most recent frame info, or null if none.
55 mojo::gfx::composition::FrameInfo* last_frame_info() {
56 return last_frame_info_.get();
57 }
58
59 // Schedules a call to the delegate's |OnDraw| using the scene scheduler.
60 void ScheduleDraw();
61
62 private:
63 mojo::gfx::composition::SceneSchedulerPtr scene_scheduler_;
64 ChoreographerDelegate* delegate_;
65 mojo::gfx::composition::FrameInfoPtr last_frame_info_;
66
67 void ScheduleFrame();
68 void DoFrame(mojo::gfx::composition::FrameInfoPtr frame_info);
69
70 bool draw_scheduled_ = false;
71 bool frame_scheduled_ = false;
72
73 MOJO_DISALLOW_COPY_AND_ASSIGN(Choreographer);
74 };
75
76 // An abstract class that the view may subclass to handle choreographer events.
77 class ChoreographerDelegate {
78 public:
79 ChoreographerDelegate() = default;
80 virtual ~ChoreographerDelegate() = default;
81
82 // Called when it is time to draw the next frame and provides timing
83 // information for the frame.
84 //
85 // The |frame_info| provides information about the frame timing.
86 // The |time_delta| is the time interval since the last draw occurred,
87 // guaranteed to be non-negative. Always zero for the first draw.
88 virtual void OnDraw(const mojo::gfx::composition::FrameInfo& frame_info,
89 const base::TimeDelta& time_delta) = 0;
90
91 private:
92 MOJO_DISALLOW_COPY_AND_ASSIGN(ChoreographerDelegate);
93 };
94
95 } // namespace ui
96 } // namespace mojo
97
98 #endif // MOJO_UI_CHOREOGRAPHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698