OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef SERVICES_UI_DEMO_MUS_DEMO_H_ | 5 #ifndef SERVICES_UI_DEMO_MUS_DEMO_H_ |
6 #define SERVICES_UI_DEMO_MUS_DEMO_H_ | 6 #define SERVICES_UI_DEMO_MUS_DEMO_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
| 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
16 #include "services/shell/public/cpp/service.h" | 17 #include "services/shell/public/cpp/service.h" |
17 #include "services/ui/public/cpp/window_manager_delegate.h" | 18 #include "services/ui/public/cpp/window_manager_delegate.h" |
18 #include "services/ui/public/cpp/window_tree_client_delegate.h" | 19 #include "services/ui/public/cpp/window_tree_client_delegate.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
20 | 21 |
21 namespace bitmap_uploader { | 22 namespace bitmap_uploader { |
22 class BitmapUploader; | 23 class BitmapUploader; |
23 } | 24 } |
24 | 25 |
25 namespace mus_demo { | 26 namespace ui { |
| 27 namespace demo { |
26 | 28 |
27 // A simple MUS Demo mojo app. This app connects to the mojo:ui, creates a new | 29 // A simple MUS Demo mojo app. This app connects to the mojo:ui, creates a new |
28 // window and draws a spinning square in the center of the window. Provides a | 30 // window and draws a spinning square in the center of the window. Provides a |
29 // simple way to demonstrate that the graphic stack works as intended. | 31 // simple way to demonstrate that the graphic stack works as intended. |
30 class MusDemo : public shell::Service, | 32 class MusDemo : public shell::Service, |
31 public ui::WindowTreeClientDelegate, | 33 public WindowTreeClientDelegate, |
32 public ui::WindowManagerDelegate { | 34 public WindowManagerDelegate { |
33 public: | 35 public: |
34 MusDemo(); | 36 MusDemo(); |
35 ~MusDemo() override; | 37 ~MusDemo() override; |
36 | 38 |
37 private: | 39 private: |
38 // shell::Service: | 40 // shell::Service: |
39 void OnStart(shell::Connector* connector, | 41 void OnStart(shell::Connector* connector, |
40 const shell::Identity& identity, | 42 const shell::Identity& identity, |
41 uint32_t id) override; | 43 uint32_t id) override; |
42 bool OnConnect(shell::Connection* connection) override; | 44 bool OnConnect(shell::Connection* connection) override; |
43 | 45 |
44 // WindowTreeClientDelegate: | 46 // WindowTreeClientDelegate: |
45 void OnEmbed(ui::Window* root) override; | 47 void OnEmbed(Window* root) override; |
46 void OnDidDestroyClient(ui::WindowTreeClient* client) override; | 48 void OnDidDestroyClient(WindowTreeClient* client) override; |
47 void OnEventObserved(const ui::Event& event, ui::Window* target) override; | 49 void OnEventObserved(const Event& event, Window* target) override; |
48 | 50 |
49 // WindowManagerDelegate: | 51 // WindowManagerDelegate: |
50 void SetWindowManagerClient(ui::WindowManagerClient* client) override; | 52 void SetWindowManagerClient(WindowManagerClient* client) override; |
51 bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override; | 53 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; |
52 bool OnWmSetProperty( | 54 bool OnWmSetProperty( |
53 ui::Window* window, | 55 Window* window, |
54 const std::string& name, | 56 const std::string& name, |
55 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | 57 std::unique_ptr<std::vector<uint8_t>>* new_data) override; |
56 ui::Window* OnWmCreateTopLevelWindow( | 58 Window* OnWmCreateTopLevelWindow( |
57 std::map<std::string, std::vector<uint8_t>>* properties) override; | 59 std::map<std::string, std::vector<uint8_t>>* properties) override; |
58 void OnWmClientJankinessChanged(const std::set<ui::Window*>& client_windows, | 60 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, |
59 bool janky) override; | 61 bool janky) override; |
60 void OnWmNewDisplay(ui::Window* window, | 62 void OnWmNewDisplay(Window* window, const display::Display& display) override; |
61 const display::Display& display) override; | 63 void OnWmPerformMoveLoop(Window* window, |
62 void OnWmPerformMoveLoop(ui::Window* window, | 64 mojom::MoveLoopSource source, |
63 ui::mojom::MoveLoopSource source, | |
64 const gfx::Point& cursor_location, | 65 const gfx::Point& cursor_location, |
65 const base::Callback<void(bool)>& on_done) override; | 66 const base::Callback<void(bool)>& on_done) override; |
66 void OnWmCancelMoveLoop(ui::Window* window) override; | 67 void OnWmCancelMoveLoop(Window* window) override; |
67 | 68 |
68 // Allocate a bitmap the same size as the window to draw into. | 69 // Allocate a bitmap the same size as the window to draw into. |
69 void AllocBitmap(); | 70 void AllocBitmap(); |
70 | 71 |
71 // Draws one frame, incrementing the rotation angle. | 72 // Draws one frame, incrementing the rotation angle. |
72 void DrawFrame(); | 73 void DrawFrame(); |
73 | 74 |
74 shell::Connector* connector_ = nullptr; | 75 shell::Connector* connector_ = nullptr; |
75 | 76 |
76 ui::Window* window_ = nullptr; | 77 Window* window_ = nullptr; |
77 ui::WindowTreeClient* window_tree_client_ = nullptr; | 78 WindowTreeClient* window_tree_client_ = nullptr; |
78 | 79 |
79 // Used to send frames to mus. | 80 // Used to send frames to mus. |
80 std::unique_ptr<bitmap_uploader::BitmapUploader> uploader_; | 81 std::unique_ptr<bitmap_uploader::BitmapUploader> uploader_; |
81 | 82 |
82 // Bitmap that is the same size as our client window area. | 83 // Bitmap that is the same size as our client window area. |
83 SkBitmap bitmap_; | 84 SkBitmap bitmap_; |
84 | 85 |
85 // Timer for calling DrawFrame(). | 86 // Timer for calling DrawFrame(). |
86 base::RepeatingTimer timer_; | 87 base::RepeatingTimer timer_; |
87 | 88 |
88 // Current rotation angle for drawing. | 89 // Current rotation angle for drawing. |
89 double angle_ = 0.0; | 90 double angle_ = 0.0; |
90 | 91 |
91 DISALLOW_COPY_AND_ASSIGN(MusDemo); | 92 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
92 }; | 93 }; |
93 | 94 |
94 } // namespace ui_demo | 95 } // namespace demo |
| 96 } // namespace ui |
95 | 97 |
96 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ | 98 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ |
OLD | NEW |