| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_MUS_DEMO_MUS_DEMO_H_ |
| 6 #define COMPONENTS_MUS_DEMO_MUS_DEMO_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/timer/timer.h" |
| 16 #include "components/mus/public/cpp/window.h" |
| 17 #include "components/mus/public/cpp/window_manager_delegate.h" |
| 18 #include "components/mus/public/cpp/window_tree_delegate.h" |
| 19 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
| 20 #include "mojo/public/cpp/bindings/binding_set.h" |
| 21 #include "mojo/shell/public/cpp/connector.h" |
| 22 #include "mojo/shell/public/cpp/shell_client.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 |
| 25 namespace bitmap_uploader { |
| 26 class BitmapUploader; |
| 27 } |
| 28 |
| 29 namespace mus_demo { |
| 30 |
| 31 // A simple MUS Demo mojo app. This app connects to the mojo:mus, creates a new |
| 32 // window and draws a spinning square in the center of the window. Provides a |
| 33 // simple way to demonstrate that the graphic stack works as intended. |
| 34 class MusDemo : public mojo::ShellClient, |
| 35 public mus::WindowTreeDelegate, |
| 36 public mus::WindowManagerDelegate { |
| 37 public: |
| 38 MusDemo(); |
| 39 ~MusDemo() override; |
| 40 |
| 41 private: |
| 42 // mojo::ShellClient: |
| 43 void Initialize(mojo::Connector* connector, |
| 44 const mojo::Identity& identity, |
| 45 uint32_t id) override; |
| 46 bool AcceptConnection(mojo::Connection* connection) override; |
| 47 |
| 48 // WindowTreeDelegate: |
| 49 void OnEmbed(mus::Window* root) override; |
| 50 void OnUnembed(mus::Window* root) override; |
| 51 void OnConnectionLost(mus::WindowTreeConnection* connection) override; |
| 52 |
| 53 // WindowManagerDelegate: |
| 54 void SetWindowManagerClient(mus::WindowManagerClient* client) override; |
| 55 bool OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) override; |
| 56 bool OnWmSetProperty(mus::Window* window, |
| 57 const std::string& name, |
| 58 scoped_ptr<std::vector<uint8_t>>* new_data) override; |
| 59 mus::Window* OnWmCreateTopLevelWindow( |
| 60 std::map<std::string, std::vector<uint8_t>>* properties) override; |
| 61 void OnAccelerator(uint32_t id, const ui::Event& event) override; |
| 62 |
| 63 // Allocate a bitmap the same size as the window to draw into. |
| 64 void AllocBitmap(); |
| 65 |
| 66 // Draws one frame, incrementing the rotation angle. |
| 67 void DrawFrame(); |
| 68 |
| 69 mojo::Connector* connector_ = nullptr; |
| 70 |
| 71 mus::Window* window_ = nullptr; |
| 72 mus::mojom::WindowTreeHostPtr window_tree_host_; |
| 73 |
| 74 // Used to send frames to mus. |
| 75 scoped_ptr<bitmap_uploader::BitmapUploader> uploader_; |
| 76 |
| 77 // Bitmap that is the same size as our client window area. |
| 78 SkBitmap bitmap_; |
| 79 |
| 80 // Timer for calling DrawFrame(). |
| 81 base::RepeatingTimer timer_; |
| 82 |
| 83 // Current rotation angle for drawing. |
| 84 double angle_ = 0.0; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(MusDemo); |
| 87 }; |
| 88 |
| 89 } // namespace mus_demo |
| 90 |
| 91 #endif // COMPONENTS_MUS_DEMO_MUS_DEMO_H_ |
| OLD | NEW |