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" | 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 { | |
|
rjkroege
2016/11/18 22:47:14
I think this is going to break the CrOS world.
I
| |
| 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, |
| 50 Window* target) override; | 52 Window* target) override; |
| 51 | 53 |
| 52 // WindowManagerDelegate: | 54 // Creates a new WindowTreeHost and adds its context to |window_tree_datas_|. |
| 53 void SetWindowManagerClient(WindowManagerClient* client) override; | 55 void AddWindowTree(); |
| 54 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; | |
| 55 bool OnWmSetProperty( | |
| 56 Window* window, | |
| 57 const std::string& name, | |
| 58 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | |
| 59 Window* OnWmCreateTopLevelWindow( | |
| 60 std::map<std::string, std::vector<uint8_t>>* properties) override; | |
| 61 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, | |
| 62 bool janky) override; | |
| 63 void OnWmNewDisplay(Window* window, const display::Display& display) override; | |
| 64 void OnWmDisplayRemoved(ui::Window* window) override; | |
| 65 void OnWmDisplayModified(const display::Display& display) override; | |
| 66 void OnWmPerformMoveLoop(Window* window, | |
| 67 mojom::MoveLoopSource source, | |
| 68 const gfx::Point& cursor_location, | |
| 69 const base::Callback<void(bool)>& on_done) override; | |
| 70 void OnWmCancelMoveLoop(Window* window) override; | |
| 71 | |
| 72 // Allocate a bitmap the same size as the window to draw into. | |
| 73 void AllocBitmap(); | |
| 74 | 56 |
| 75 // Draws one frame, incrementing the rotation angle. | 57 // Draws one frame, incrementing the rotation angle. |
| 76 void DrawFrame(); | 58 void DrawFrame(WindowTreeData* data); |
| 77 | 59 |
| 78 Window* window_ = nullptr; | |
| 79 std::unique_ptr<WindowTreeClient> window_tree_client_; | |
| 80 std::unique_ptr<GpuService> gpu_service_; | 60 std::unique_ptr<GpuService> gpu_service_; |
| 81 | 61 |
| 82 // Dummy screen required to be the screen instance. | 62 // Dummy screen required to be the screen instance. |
| 83 std::unique_ptr<display::ScreenBase> screen_; | 63 std::unique_ptr<display::ScreenBase> screen_; |
| 84 | 64 |
| 85 // Used to send frames to mus. | 65 std::vector<std::unique_ptr<WindowTreeData>> window_tree_datas_; |
| 86 std::unique_ptr<BitmapUploader> uploader_; | |
| 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 | 66 |
| 100 DISALLOW_COPY_AND_ASSIGN(MusDemo); | 67 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
| 101 }; | 68 }; |
| 102 | 69 |
| 103 } // namespace demo | 70 } // namespace demo |
| 104 } // namespace ui | 71 } // namespace ui |
| 105 | 72 |
| 106 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ | 73 #endif // SERVICES_UI_DEMO_MUS_DEMO_H_ |
| OLD | NEW |