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