| 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" | |
| 19 #include "services/ui/public/cpp/window_tree_client_delegate.h" | |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/aura/mus/window_manager_delegate.h" |
| 20 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 21 #include "ui/display/screen_base.h" | 21 #include "ui/display/screen_base.h" |
| 22 | 22 |
| 23 namespace aura { |
| 24 class Env; |
| 25 class PropertyConverter; |
| 26 |
| 27 namespace client { |
| 28 class DefaultCaptureClient; |
| 29 } |
| 30 } // namespace aura |
| 31 |
| 32 namespace aura_extra { |
| 33 class ImageWindowDelegate; |
| 34 } |
| 35 |
| 36 namespace wm { |
| 37 class WMState; |
| 38 } |
| 39 |
| 23 namespace ui { | 40 namespace ui { |
| 24 class BitmapUploader; | 41 class ContextFactory; |
| 25 class GpuService; | 42 class GpuService; |
| 26 | 43 |
| 27 namespace demo { | 44 namespace demo { |
| 28 | 45 |
| 29 // A simple MUS Demo service. This service connects to the service:ui, creates a | 46 // A simple MUS Demo service. This service connects to the service:ui, adds a |
| 30 // new window and draws a spinning square in the center of the window. Provides | 47 // new window to the root Window, and draws a spinning square in the center of |
| 31 // a simple way to demonstrate that the graphic stack works as intended. | 48 // the window. Provides a simple way to demonstrate that the graphic stack works |
| 49 // as intended. |
| 32 class MusDemo : public service_manager::Service, | 50 class MusDemo : public service_manager::Service, |
| 33 public WindowTreeClientDelegate, | 51 public aura::WindowTreeClientDelegate, |
| 34 public WindowManagerDelegate { | 52 public aura::WindowManagerDelegate { |
| 35 public: | 53 public: |
| 36 MusDemo(); | 54 MusDemo(); |
| 37 ~MusDemo() override; | 55 ~MusDemo() override; |
| 38 | 56 |
| 39 private: | 57 private: |
| 40 // service_manager::Service: | 58 // service_manager::Service: |
| 41 void OnStart() override; | 59 void OnStart() override; |
| 42 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 60 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 43 service_manager::InterfaceRegistry* registry) override; | 61 service_manager::InterfaceRegistry* registry) override; |
| 44 | 62 |
| 45 // WindowTreeClientDelegate: | 63 // aura::WindowTreeClientDelegate: |
| 46 void OnEmbed(Window* root) override; | 64 void OnEmbed( |
| 47 void OnEmbedRootDestroyed(Window* root) override; | 65 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override; |
| 48 void OnLostConnection(WindowTreeClient* client) override; | 66 void OnUnembed(aura::Window* root) override; |
| 49 void OnPointerEventObserved(const PointerEvent& event, | 67 void OnEmbedRootDestroyed(aura::Window* root) override; |
| 50 Window* target) override; | 68 void OnLostConnection(aura::WindowTreeClient* client) override; |
| 69 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 70 aura::Window* target) override; |
| 71 aura::client::CaptureClient* GetCaptureClient() override; |
| 72 aura::PropertyConverter* GetPropertyConverter() override; |
| 51 | 73 |
| 52 // WindowManagerDelegate: | 74 // aura::WindowManagerDelegate: |
| 53 void SetWindowManagerClient(WindowManagerClient* client) override; | 75 void SetWindowManagerClient(aura::WindowManagerClient* client) override; |
| 54 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; | 76 bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override; |
| 55 bool OnWmSetProperty( | 77 bool OnWmSetProperty( |
| 56 Window* window, | 78 aura::Window* window, |
| 57 const std::string& name, | 79 const std::string& name, |
| 58 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | 80 std::unique_ptr<std::vector<uint8_t>>* new_data) override; |
| 59 Window* OnWmCreateTopLevelWindow( | 81 aura::Window* OnWmCreateTopLevelWindow( |
| 82 ui::mojom::WindowType window_type, |
| 60 std::map<std::string, std::vector<uint8_t>>* properties) override; | 83 std::map<std::string, std::vector<uint8_t>>* properties) override; |
| 61 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, | 84 void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows, |
| 62 bool janky) override; | 85 bool janky) override; |
| 63 void OnWmNewDisplay(Window* window, const display::Display& display) override; | 86 void OnWmWillCreateDisplay(const display::Display& display) override; |
| 64 void OnWmDisplayRemoved(ui::Window* window) override; | 87 void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 88 const display::Display& display) override; |
| 89 void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override; |
| 65 void OnWmDisplayModified(const display::Display& display) override; | 90 void OnWmDisplayModified(const display::Display& display) override; |
| 66 void OnWmPerformMoveLoop(Window* window, | 91 ui::mojom::EventResult OnAccelerator(uint32_t id, |
| 67 mojom::MoveLoopSource source, | 92 const ui::Event& event) override; |
| 93 void OnWmPerformMoveLoop(aura::Window* window, |
| 94 ui::mojom::MoveLoopSource source, |
| 68 const gfx::Point& cursor_location, | 95 const gfx::Point& cursor_location, |
| 69 const base::Callback<void(bool)>& on_done) override; | 96 const base::Callback<void(bool)>& on_done) override; |
| 70 void OnWmCancelMoveLoop(Window* window) override; | 97 void OnWmCancelMoveLoop(aura::Window* window) override; |
| 71 | 98 void OnWmSetClientArea( |
| 72 // Allocate a bitmap the same size as the window to draw into. | 99 aura::Window* window, |
| 73 void AllocBitmap(); | 100 const gfx::Insets& insets, |
| 101 const std::vector<gfx::Rect>& additional_client_areas) override; |
| 74 | 102 |
| 75 // Draws one frame, incrementing the rotation angle. | 103 // Draws one frame, incrementing the rotation angle. |
| 76 void DrawFrame(); | 104 void DrawFrame(); |
| 77 | 105 |
| 78 Window* window_ = nullptr; | 106 aura::Window* root_window_ = nullptr; |
| 79 std::unique_ptr<WindowTreeClient> window_tree_client_; | 107 std::unique_ptr<aura::WindowTreeClient> window_tree_client_; |
| 80 std::unique_ptr<GpuService> gpu_service_; | 108 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; |
| 81 | 109 std::unique_ptr<ui::GpuService> gpu_service_; |
| 82 // Dummy screen required to be the screen instance. | 110 std::unique_ptr<ui::ContextFactory> context_factory_; |
| 111 std::unique_ptr<aura::Env> env_; |
| 83 std::unique_ptr<display::ScreenBase> screen_; | 112 std::unique_ptr<display::ScreenBase> screen_; |
| 84 | 113 |
| 85 // Used to send frames to mus. | 114 std::unique_ptr<aura::client::DefaultCaptureClient> capture_client_; |
| 86 std::unique_ptr<BitmapUploader> uploader_; | 115 std::unique_ptr<::wm::WMState> wm_state_; |
| 116 std::unique_ptr<aura::PropertyConverter> property_converter_; |
| 117 |
| 118 // Window to which we draw the bitmap. |
| 119 std::unique_ptr<aura::Window> bitmap_window_; |
| 120 |
| 121 // Destroys itself when the window gets destroyed. |
| 122 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; |
| 87 | 123 |
| 88 // Bitmap that is the same size as our client window area. | 124 // Bitmap that is the same size as our client window area. |
| 89 SkBitmap bitmap_; | 125 SkBitmap bitmap_; |
| 90 | 126 |
| 91 // Timer for calling DrawFrame(). | 127 // Timer for calling DrawFrame(). |
| 92 base::RepeatingTimer timer_; | 128 base::RepeatingTimer timer_; |
| 93 | 129 |
| 94 // Current rotation angle for drawing. | 130 // Current rotation angle for drawing. |
| 95 double angle_ = 0.0; | 131 double angle_ = 0.0; |
| 96 | 132 |
| 97 // Last time a frame was drawn. | 133 // Last time a frame was drawn. |
| 98 base::TimeTicks last_draw_frame_time_; | 134 base::TimeTicks last_draw_frame_time_; |
| 99 | 135 |
| 100 DISALLOW_COPY_AND_ASSIGN(MusDemo); | 136 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
| 101 }; | 137 }; |
| 102 | 138 |
| 103 } // namespace demo | 139 } // namespace demo |
| 104 } // namespace ui | 140 } // namespace aura |
| 105 | 141 |
| 106 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ | 142 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ |
| OLD | NEW |