| 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 GpuService; | 25 class GpuService; |
| 26 | 26 |
| 27 namespace demo { | 27 namespace demo { |
| 28 | 28 |
| 29 // A simple MUS Demo service. This service connects to the service:ui, creates a | 29 // 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 | 30 // 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. | 31 // a simple way to demonstrate that the graphic stack works as intended. |
| 32 class MusDemo : public service_manager::Service, | 32 class MusDemo : public service_manager::Service, |
| 33 public WindowTreeClientDelegate, | 33 public WindowTreeClientDelegate, |
| 34 public WindowManagerDelegate { | 34 public WindowManagerDelegate { |
| 35 public: | 35 public: |
| 36 MusDemo(); | 36 MusDemo(); |
| 37 ~MusDemo() override; | 37 ~MusDemo() override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 struct WindowTreeData; |
| 41 |
| 40 // service_manager::Service: | 42 // service_manager::Service: |
| 41 void OnStart() override; | 43 void OnStart() override; |
| 42 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 44 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 43 service_manager::InterfaceRegistry* registry) override; | 45 service_manager::InterfaceRegistry* registry) override; |
| 44 | 46 |
| 45 // WindowTreeClientDelegate: | 47 // WindowTreeClientDelegate: |
| 46 void OnEmbed(Window* root) override; | 48 void OnEmbed(Window* root) override; |
| 47 void OnEmbedRootDestroyed(Window* root) override; | 49 void OnEmbedRootDestroyed(Window* root) override; |
| 48 void OnLostConnection(WindowTreeClient* client) override; | 50 void OnLostConnection(WindowTreeClient* client) override; |
| 49 void OnPointerEventObserved(const PointerEvent& event, | 51 void OnPointerEventObserved(const PointerEvent& event, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 bool janky) override; | 64 bool janky) override; |
| 63 void OnWmNewDisplay(Window* window, const display::Display& display) override; | 65 void OnWmNewDisplay(Window* window, const display::Display& display) override; |
| 64 void OnWmDisplayRemoved(ui::Window* window) override; | 66 void OnWmDisplayRemoved(ui::Window* window) override; |
| 65 void OnWmDisplayModified(const display::Display& display) override; | 67 void OnWmDisplayModified(const display::Display& display) override; |
| 66 void OnWmPerformMoveLoop(Window* window, | 68 void OnWmPerformMoveLoop(Window* window, |
| 67 mojom::MoveLoopSource source, | 69 mojom::MoveLoopSource source, |
| 68 const gfx::Point& cursor_location, | 70 const gfx::Point& cursor_location, |
| 69 const base::Callback<void(bool)>& on_done) override; | 71 const base::Callback<void(bool)>& on_done) override; |
| 70 void OnWmCancelMoveLoop(Window* window) override; | 72 void OnWmCancelMoveLoop(Window* window) override; |
| 71 | 73 |
| 72 // Allocate a bitmap the same size as the window to draw into. | 74 // Creates a new WindowTreeHost and adds its context to |window_tree_datas_|. |
| 73 void AllocBitmap(); | 75 void AddWindowTreeHost(); |
| 76 |
| 77 // Sets up a timer to regularly draw frames to |window|. |
| 78 void BeginDrawingFrames(Window* window); |
| 74 | 79 |
| 75 // Draws one frame, incrementing the rotation angle. | 80 // Draws one frame, incrementing the rotation angle. |
| 76 void DrawFrame(); | 81 void DrawFrame(WindowTreeData* data); |
| 77 | 82 |
| 78 Window* window_ = nullptr; | 83 bool external_window_mode_; |
| 79 std::unique_ptr<WindowTreeClient> window_tree_client_; | 84 |
| 80 std::unique_ptr<GpuService> gpu_service_; | 85 std::unique_ptr<GpuService> gpu_service_; |
| 81 | 86 |
| 82 // Dummy screen required to be the screen instance. | 87 // Dummy screen required to be the screen instance. |
| 83 std::unique_ptr<display::ScreenBase> screen_; | 88 std::unique_ptr<display::ScreenBase> screen_; |
| 84 | 89 |
| 85 // Used to send frames to mus. | 90 // One WindowTreeData for each WindowTreeHost. |
| 86 std::unique_ptr<BitmapUploader> uploader_; | 91 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 | 92 |
| 100 DISALLOW_COPY_AND_ASSIGN(MusDemo); | 93 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
| 101 }; | 94 }; |
| 102 | 95 |
| 103 } // namespace demo | 96 } // namespace demo |
| 104 } // namespace ui | 97 } // namespace ui |
| 105 | 98 |
| 106 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ | 99 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ |
| OLD | NEW |