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 #include "services/ui/demo/mus_demo.h" | 5 #include "services/ui/demo/mus_demo.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "services/service_manager/public/cpp/connector.h" | 9 #include "services/service_manager/public/cpp/connector.h" |
10 #include "services/service_manager/public/cpp/service_context.h" | 10 #include "services/service_manager/public/cpp/service_context.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 canvas->drawRect(rect, paint); | 65 canvas->drawRect(rect, paint); |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 class MusDemo::WindowTreeData { | 70 class MusDemo::WindowTreeData { |
71 public: | 71 public: |
72 explicit WindowTreeData( | 72 explicit WindowTreeData( |
73 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host); | 73 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 74 Init(std::move(window_tree_host)); |
| 75 } |
74 ~WindowTreeData(); | 76 ~WindowTreeData(); |
75 | 77 |
76 private: | 78 private: |
| 79 // Initializes the window tree host and start drawing frames. |
| 80 void Init(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host); |
| 81 |
77 // Draws one frame, incrementing the rotation angle. | 82 // Draws one frame, incrementing the rotation angle. |
78 void DrawFrame(); | 83 void DrawFrame(); |
79 | 84 |
80 // The Window tree host corresponding to this data. | 85 // The Window tree host corresponding to this data. |
81 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; | 86 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; |
82 | 87 |
83 // Root window of the window tree host. | 88 // Root window of the window tree host. |
84 aura::Window* root_window_ = nullptr; | 89 aura::Window* root_window_ = nullptr; |
85 | 90 |
86 // Window to which we draw the bitmap. | 91 // Window to which we draw the bitmap. |
87 std::unique_ptr<aura::Window> bitmap_window_; | 92 std::unique_ptr<aura::Window> bitmap_window_; |
88 | 93 |
89 // Destroys itself when the window gets destroyed. | 94 // Destroys itself when the window gets destroyed. |
90 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; | 95 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; |
91 | 96 |
92 // Timer for calling DrawFrame(). | 97 // Timer for calling DrawFrame(). |
93 base::RepeatingTimer timer_; | 98 base::RepeatingTimer timer_; |
94 | 99 |
95 // Current rotation angle for drawing. | 100 // Current rotation angle for drawing. |
96 double angle_ = 0.0; | 101 double angle_ = 0.0; |
97 | 102 |
98 // Last time a frame was drawn. | 103 // Last time a frame was drawn. |
99 base::TimeTicks last_draw_frame_time_; | 104 base::TimeTicks last_draw_frame_time_; |
100 }; | 105 }; |
101 | 106 |
| 107 MusDemo::WindowTreeData::~WindowTreeData() { |
| 108 timer_.Stop(); |
| 109 root_window_->RemoveChild(bitmap_window_.get()); |
| 110 bitmap_window_.reset(); |
| 111 } |
| 112 |
| 113 void MusDemo::WindowTreeData::Init( |
| 114 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 115 window_tree_host->InitHost(); |
| 116 window_tree_host->Show(); |
| 117 root_window_ = window_tree_host->window(); |
| 118 // Take ownership of the WTH. |
| 119 window_tree_host_ = std::move(window_tree_host); |
| 120 |
| 121 // Initialize the window for the bitmap. |
| 122 window_delegate_ = new aura_extra::ImageWindowDelegate(); |
| 123 bitmap_window_ = base::MakeUnique<aura::Window>(window_delegate_); |
| 124 bitmap_window_->Init(LAYER_TEXTURED); |
| 125 bitmap_window_->SetBounds(root_window_->bounds()); |
| 126 bitmap_window_->Show(); |
| 127 bitmap_window_->SetName("Bitmap"); |
| 128 |
| 129 root_window_->AddChild(bitmap_window_.get()); |
| 130 |
| 131 // Draw initial frame and start the timer to regularly draw frames. |
| 132 DrawFrame(); |
| 133 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), |
| 134 base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this))); |
| 135 } |
| 136 |
102 MusDemo::MusDemo() {} | 137 MusDemo::MusDemo() {} |
103 | 138 |
104 MusDemo::~MusDemo() { | 139 MusDemo::~MusDemo() { |
105 display::Screen::SetScreenInstance(nullptr); | 140 display::Screen::SetScreenInstance(nullptr); |
106 } | 141 } |
107 | 142 |
108 void MusDemo::OnStart() { | 143 void MusDemo::OnStart() { |
109 screen_ = base::MakeUnique<display::ScreenBase>(); | 144 screen_ = base::MakeUnique<display::ScreenBase>(); |
110 display::Screen::SetScreenInstance(screen_.get()); | 145 display::Screen::SetScreenInstance(screen_.get()); |
111 | 146 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 221 } |
187 | 222 |
188 void MusDemo::OnWmNewDisplay( | 223 void MusDemo::OnWmNewDisplay( |
189 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 224 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
190 const display::Display& display) { | 225 const display::Display& display) { |
191 DCHECK(!window_tree_data_); // Only support one display. | 226 DCHECK(!window_tree_data_); // Only support one display. |
192 window_tree_data_ = | 227 window_tree_data_ = |
193 base::MakeUnique<WindowTreeData>(std::move(window_tree_host)); | 228 base::MakeUnique<WindowTreeData>(std::move(window_tree_host)); |
194 } | 229 } |
195 | 230 |
196 MusDemo::WindowTreeData::WindowTreeData( | |
197 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | |
198 window_tree_host->InitHost(); | |
199 window_tree_host->Show(); | |
200 root_window_ = window_tree_host->window(); | |
201 // Take ownership of the WTH. | |
202 window_tree_host_ = std::move(window_tree_host); | |
203 | |
204 // Initialize the window for the bitmap. | |
205 window_delegate_ = new aura_extra::ImageWindowDelegate(); | |
206 bitmap_window_ = base::MakeUnique<aura::Window>(window_delegate_); | |
207 bitmap_window_->Init(LAYER_TEXTURED); | |
208 bitmap_window_->SetBounds(root_window_->bounds()); | |
209 bitmap_window_->Show(); | |
210 bitmap_window_->SetName("Bitmap"); | |
211 | |
212 root_window_->AddChild(bitmap_window_.get()); | |
213 | |
214 // Draw initial frame and start the timer to regularly draw frames. | |
215 DrawFrame(); | |
216 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), | |
217 base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this))); | |
218 } | |
219 | |
220 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { | 231 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { |
221 window_tree_data_.reset(); | 232 window_tree_data_.reset(); |
222 } | 233 } |
223 | 234 |
224 MusDemo::WindowTreeData::~WindowTreeData() { | |
225 timer_.Stop(); | |
226 root_window_->RemoveChild(bitmap_window_.get()); | |
227 bitmap_window_.reset(); | |
228 } | |
229 | |
230 void MusDemo::OnWmDisplayModified(const display::Display& display) {} | 235 void MusDemo::OnWmDisplayModified(const display::Display& display) {} |
231 | 236 |
232 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { | 237 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { |
233 return mojom::EventResult::UNHANDLED; | 238 return mojom::EventResult::UNHANDLED; |
234 } | 239 } |
235 | 240 |
236 void MusDemo::OnWmPerformMoveLoop(aura::Window* window, | 241 void MusDemo::OnWmPerformMoveLoop(aura::Window* window, |
237 mojom::MoveLoopSource source, | 242 mojom::MoveLoopSource source, |
238 const gfx::Point& cursor_location, | 243 const gfx::Point& cursor_location, |
239 const base::Callback<void(bool)>& on_done) { | 244 const base::Callback<void(bool)>& on_done) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 gfx::ImageSkiaRep image_skia_rep(bitmap, 1); | 285 gfx::ImageSkiaRep image_skia_rep(bitmap, 1); |
281 gfx::ImageSkia image_skia(image_skia_rep); | 286 gfx::ImageSkia image_skia(image_skia_rep); |
282 gfx::Image image(image_skia); | 287 gfx::Image image(image_skia); |
283 | 288 |
284 window_delegate_->SetImage(image); | 289 window_delegate_->SetImage(image); |
285 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds()); | 290 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds()); |
286 } | 291 } |
287 | 292 |
288 } // namespace demo | 293 } // namespace demo |
289 } // namespace aura | 294 } // namespace aura |
OLD | NEW |