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 <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "services/service_manager/public/cpp/service.h" | 17 #include "services/service_manager/public/cpp/service.h" |
18 #include "services/ui/public/cpp/window_manager_delegate.h" | 18 #include "services/ui/public/cpp/window_manager_delegate.h" |
19 #include "services/ui/public/cpp/window_tree_client_delegate.h" | 19 #include "services/ui/public/cpp/window_tree_client_delegate.h" |
| 20 #include "services/ui/public/interfaces/window_tree_host.mojom.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/display/screen_base.h" | 22 #include "ui/display/screen_base.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 class BitmapUploader; | 25 class BitmapUploader; |
25 class GpuService; | 26 class GpuService; |
26 | 27 |
27 namespace demo { | 28 namespace demo { |
28 | 29 |
29 // A simple MUS Demo service. This service connects to the service:ui, creates a | 30 // A simple MUS Demo service. This service connects to the service:ui, creates a |
30 // new window and draws a spinning square in the center of the window. Provides | 31 // new window and draws a spinning square in the center of the window. Provides |
31 // a simple way to demonstrate that the graphic stack works as intended. | 32 // a simple way to demonstrate that the graphic stack works as intended. |
32 class MusDemo : public service_manager::Service, | 33 class MusDemo : public service_manager::Service, |
33 public WindowTreeClientDelegate, | 34 public WindowTreeClientDelegate, |
34 public WindowManagerDelegate { | 35 public WindowManagerDelegate { |
35 public: | 36 public: |
36 MusDemo(); | 37 MusDemo(); |
37 ~MusDemo() override; | 38 ~MusDemo() override; |
38 | 39 |
39 private: | 40 private: |
| 41 struct WindowTreeData; |
| 42 |
40 // service_manager::Service: | 43 // service_manager::Service: |
41 void OnStart() override; | 44 void OnStart() override; |
42 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 45 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
43 service_manager::InterfaceRegistry* registry) override; | 46 service_manager::InterfaceRegistry* registry) override; |
44 | 47 |
45 // WindowTreeClientDelegate: | 48 // WindowTreeClientDelegate: |
46 void OnEmbed(Window* root) override; | 49 void OnEmbed(Window* root) override; |
47 void OnEmbedRootDestroyed(Window* root) override; | 50 void OnEmbedRootDestroyed(Window* root) override; |
48 void OnLostConnection(WindowTreeClient* client) override; | 51 void OnLostConnection(WindowTreeClient* client) override; |
49 void OnPointerEventObserved(const PointerEvent& event, | 52 void OnPointerEventObserved(const PointerEvent& event, |
(...skipping 12 matching lines...) Expand all Loading... |
62 bool janky) override; | 65 bool janky) override; |
63 void OnWmNewDisplay(Window* window, const display::Display& display) override; | 66 void OnWmNewDisplay(Window* window, const display::Display& display) override; |
64 void OnWmDisplayRemoved(ui::Window* window) override; | 67 void OnWmDisplayRemoved(ui::Window* window) override; |
65 void OnWmDisplayModified(const display::Display& display) override; | 68 void OnWmDisplayModified(const display::Display& display) override; |
66 void OnWmPerformMoveLoop(Window* window, | 69 void OnWmPerformMoveLoop(Window* window, |
67 mojom::MoveLoopSource source, | 70 mojom::MoveLoopSource source, |
68 const gfx::Point& cursor_location, | 71 const gfx::Point& cursor_location, |
69 const base::Callback<void(bool)>& on_done) override; | 72 const base::Callback<void(bool)>& on_done) override; |
70 void OnWmCancelMoveLoop(Window* window) override; | 73 void OnWmCancelMoveLoop(Window* window) override; |
71 | 74 |
72 // Allocate a bitmap the same size as the window to draw into. | 75 // Creates a new WindowTreeHost and adds its context to |window_tree_datas_|. |
73 void AllocBitmap(); | 76 void AddWindowTreeHost(); |
| 77 |
| 78 // Sets up a timer to regularly draw frames to |window|. |
| 79 void BeginDrawingFrames(Window* window); |
74 | 80 |
75 // Draws one frame, incrementing the rotation angle. | 81 // Draws one frame, incrementing the rotation angle. |
76 void DrawFrame(); | 82 void DrawFrame(WindowTreeData* data); |
77 | 83 |
78 Window* window_ = nullptr; | 84 bool external_window_mode_; |
79 std::unique_ptr<WindowTreeClient> window_tree_client_; | 85 |
80 std::unique_ptr<GpuService> gpu_service_; | 86 std::unique_ptr<GpuService> gpu_service_; |
81 | 87 |
82 // Dummy screen required to be the screen instance. | 88 // Dummy screen required to be the screen instance. |
83 std::unique_ptr<display::ScreenBase> screen_; | 89 std::unique_ptr<display::ScreenBase> screen_; |
84 | 90 |
85 // Used to send frames to mus. | 91 // One WindowTreeData for each WindowTreeHost. |
86 std::unique_ptr<BitmapUploader> uploader_; | 92 std::vector<std::unique_ptr<WindowTreeData>> window_tree_datas_; |
87 | |
88 // Bitmap that is the same size as our client window area. | |
89 SkBitmap bitmap_; | |
90 | |
91 // Timer for calling DrawFrame(). | |
92 base::RepeatingTimer timer_; | |
93 | |
94 // Current rotation angle for drawing. | |
95 double angle_ = 0.0; | |
96 | |
97 // Last time a frame was drawn. | |
98 base::TimeTicks last_draw_frame_time_; | |
99 | 93 |
100 DISALLOW_COPY_AND_ASSIGN(MusDemo); | 94 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
101 }; | 95 }; |
102 | 96 |
103 } // namespace demo | 97 } // namespace demo |
104 } // namespace ui | 98 } // namespace ui |
105 | 99 |
106 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ | 100 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ |
OLD | NEW |