Merge ozone-mir:implement-create-platform-window into ozone-mir:ozone-mir
- Git
- lp:ozone-mir
- implement-create-platform-window
- Merge into ozone-mir
Proposed by
Andrea Azzarone
Status: | Merged |
---|---|
Merge reported by: | Andrea Azzarone |
Merged at revision: | not available |
Proposed branch: | ozone-mir:implement-create-platform-window |
Merge into: | ozone-mir:ozone-mir |
Diff against target: |
506 lines (+300/-37) 10 files modified
ui/ozone/BUILD.gn (+1/-0) ui/ozone/platform/mir/BUILD.gn (+18/-1) ui/ozone/platform/mir/mir_connection_wrapper.cc (+0/-27) ui/ozone/platform/mir/mir_connection_wrapper.h (+0/-5) ui/ozone/platform/mir/mir_platform_window.cc (+77/-2) ui/ozone/platform/mir/mir_platform_window.h (+15/-1) ui/ozone/platform/mir/mir_platform_window_manager.cc (+85/-0) ui/ozone/platform/mir/mir_platform_window_manager.h (+47/-0) ui/ozone/platform/mir/mir_platform_window_manager_unittest.cc (+46/-0) ui/ozone/platform/mir/ozone_platform_mir.cc (+11/-1) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+317378@code.launchpad.net |
Commit message
Move the AddWindow/
Add tests for MirPlatformWind
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/ui/ozone/BUILD.gn b/ui/ozone/BUILD.gn |
2 | index e24b0f8..b84363d 100644 |
3 | --- a/ui/ozone/BUILD.gn |
4 | +++ b/ui/ozone/BUILD.gn |
5 | @@ -45,6 +45,7 @@ if (ozone_platform_wayland) { |
6 | if (ozone_platform_mir) { |
7 | ozone_platforms += [ "mir" ] |
8 | ozone_platform_deps += [ "platform/mir" ] |
9 | + ozone_platform_test_deps += [ "platform/mir:mir_unittests" ] |
10 | } |
11 | |
12 | if (ozone_platform_x11) { |
13 | diff --git a/ui/ozone/platform/mir/BUILD.gn b/ui/ozone/platform/mir/BUILD.gn |
14 | index d54565e..48cc432 100644 |
15 | --- a/ui/ozone/platform/mir/BUILD.gn |
16 | +++ b/ui/ozone/platform/mir/BUILD.gn |
17 | @@ -18,7 +18,9 @@ source_set("mir") { |
18 | "mir_connection_wrapper.cc", |
19 | "mir_connection_wrapper.h", |
20 | "mir_platform_window.cc", |
21 | - "mir_platoform_window.h", |
22 | + "mir_platform_window.h", |
23 | + "mir_platform_window_manager.cc", |
24 | + "mir_platform_window_manager.h", |
25 | "ozone_platform_mir.cc", |
26 | "ozone_platform_mir.h" |
27 | ] |
28 | @@ -43,3 +45,18 @@ source_set("mir") { |
29 | "//third_party/khronos:khronos_headers" |
30 | ] |
31 | } |
32 | + |
33 | +source_set("mir_unittests") { |
34 | + testonly = true |
35 | + |
36 | + sources = [ |
37 | + "mir_platform_window_manager_unittest.cc" |
38 | + ] |
39 | + |
40 | + deps = [ |
41 | + ":mir", |
42 | + "//testing/gmock", |
43 | + "//testing/gtest", |
44 | + ] |
45 | +} |
46 | + |
47 | diff --git a/ui/ozone/platform/mir/mir_connection_wrapper.cc b/ui/ozone/platform/mir/mir_connection_wrapper.cc |
48 | index 42cbf60..54e24ce 100644 |
49 | --- a/ui/ozone/platform/mir/mir_connection_wrapper.cc |
50 | +++ b/ui/ozone/platform/mir/mir_connection_wrapper.cc |
51 | @@ -4,7 +4,6 @@ |
52 | |
53 | #include "ui/ozone/platform/mir/mir_connection_wrapper.h" |
54 | |
55 | -#include <map> |
56 | #include <mir_toolkit/mir_connection.h> |
57 | |
58 | #include "ui/ozone/platform/mir/mir_platform_window.h" |
59 | @@ -35,22 +34,8 @@ public: |
60 | return connection_; |
61 | } |
62 | |
63 | - MirPlatformWindow* GetWindow(gfx::AcceleratedWidget widget) { |
64 | - auto it = window_map_.find(widget); |
65 | - return it == window_map_.end() ? nullptr : it->second; |
66 | - } |
67 | - |
68 | - void AddWindow(gfx::AcceleratedWidget widget, MirPlatformWindow* window) { |
69 | - window_map_[widget] = window; |
70 | - } |
71 | - |
72 | - void RemoveWindow(gfx::AcceleratedWidget widget) { |
73 | - window_map_.erase(widget); |
74 | - } |
75 | - |
76 | private: |
77 | MirConnection* connection_; |
78 | - std::map<gfx::AcceleratedWidget, MirPlatformWindow*> window_map_; |
79 | }; |
80 | |
81 | // |
82 | @@ -72,16 +57,4 @@ MirConnection* MirConnectionWrapper::GetMirConnection() { |
83 | return pimpl_->GetMirConnection(); |
84 | } |
85 | |
86 | -MirPlatformWindow* MirConnectionWrapper::GetWindow(gfx::AcceleratedWidget widget) { |
87 | - return pimpl_->GetWindow(widget); |
88 | -} |
89 | - |
90 | -void MirConnectionWrapper::AddWindow(gfx::AcceleratedWidget widget, MirPlatformWindow* window) { |
91 | - pimpl_->AddWindow(widget, window); |
92 | -} |
93 | - |
94 | -void MirConnectionWrapper::RemoveWindow(gfx::AcceleratedWidget widget) { |
95 | - pimpl_->RemoveWindow(widget); |
96 | -} |
97 | - |
98 | } // namespace ui |
99 | diff --git a/ui/ozone/platform/mir/mir_connection_wrapper.h b/ui/ozone/platform/mir/mir_connection_wrapper.h |
100 | index e6ce590..4f41864 100644 |
101 | --- a/ui/ozone/platform/mir/mir_connection_wrapper.h |
102 | +++ b/ui/ozone/platform/mir/mir_connection_wrapper.h |
103 | @@ -8,7 +8,6 @@ |
104 | #include <memory> |
105 | |
106 | #include "base/macros.h" |
107 | -#include "ui/gfx/native_widget_types.h" |
108 | |
109 | struct MirConnection; |
110 | |
111 | @@ -25,10 +24,6 @@ public: |
112 | |
113 | MirConnection* GetMirConnection(); |
114 | |
115 | - MirPlatformWindow* GetWindow(gfx::AcceleratedWidget widget); |
116 | - void AddWindow(gfx::AcceleratedWidget widget, MirPlatformWindow* window); |
117 | - void RemoveWindow(gfx::AcceleratedWidget widget); |
118 | - |
119 | private: |
120 | class Impl; |
121 | std::unique_ptr<Impl> pimpl_; |
122 | diff --git a/ui/ozone/platform/mir/mir_platform_window.cc b/ui/ozone/platform/mir/mir_platform_window.cc |
123 | index 44f0582..5195491 100644 |
124 | --- a/ui/ozone/platform/mir/mir_platform_window.cc |
125 | +++ b/ui/ozone/platform/mir/mir_platform_window.cc |
126 | @@ -4,17 +4,92 @@ |
127 | |
128 | #include "ui/ozone/platform/mir/mir_platform_window.h" |
129 | |
130 | +#include <mir_toolkit/mir_window.h> |
131 | + |
132 | #include "base/logging.h" |
133 | +#include "ui/ozone/platform/mir/mir_connection_wrapper.h" |
134 | +#include "ui/ozone/platform/mir/mir_platform_window_manager.h" |
135 | +#include "ui/platform_window/platform_window_delegate.h" |
136 | |
137 | namespace ui { |
138 | |
139 | - |
140 | -MirPlatformWindow::MirPlatformWindow() { |
141 | +// |
142 | +// Start Private Implementation |
143 | +// |
144 | + |
145 | +class MirPlatformWindow::Impl { |
146 | +public: |
147 | + Impl(PlatformWindowDelegate* delegate, |
148 | + MirConnectionWrapper* connection, |
149 | + const gfx::Rect& bounds, |
150 | + MirPlatformWindowManager* window_manager, |
151 | + MirPlatformWindow* parent) |
152 | + : parent_(parent), |
153 | + delegate_(delegate), |
154 | + connection_(connection), |
155 | + window_manager_(window_manager), |
156 | + window_(nullptr), |
157 | + bounds_(bounds), |
158 | + widget_(0) { |
159 | + } |
160 | + |
161 | + ~Impl() { |
162 | + if (widget_) |
163 | + window_manager_->RemoveWindow(widget_); |
164 | + if (mir_window_is_valid(window_)) |
165 | + mir_window_release_sync(window_); |
166 | + } |
167 | + |
168 | + bool Initialize() { |
169 | + auto connection = connection_->GetMirConnection(); |
170 | + |
171 | + auto spec = mir_create_normal_window_spec(connection, 0, 0); |
172 | + window_ = mir_create_window_sync(spec); |
173 | + mir_window_spec_release(spec); |
174 | + |
175 | + if (!mir_window_is_valid(window_)) { |
176 | + LOG(ERROR) << "Failed to create mir window"; |
177 | + return false; |
178 | + } |
179 | + |
180 | + widget_ = window_manager_->NextAcceleratedWidget(); |
181 | + window_manager_->AddWindow(widget_, parent_); |
182 | + delegate_->OnAcceleratedWidgetAvailable(widget_, 1.f); |
183 | + |
184 | + return true; |
185 | + } |
186 | + |
187 | +private: |
188 | + MirPlatformWindow* parent_; |
189 | + |
190 | + PlatformWindowDelegate* delegate_; |
191 | + MirConnectionWrapper* connection_; |
192 | + MirPlatformWindowManager* window_manager_; |
193 | + |
194 | + MirWindow* window_; |
195 | + |
196 | + gfx::Rect bounds_; |
197 | + gfx::AcceleratedWidget widget_; |
198 | +}; |
199 | + |
200 | +// |
201 | +// End Private Implementation |
202 | +// |
203 | + |
204 | +MirPlatformWindow::MirPlatformWindow(PlatformWindowDelegate* delegate, |
205 | + MirConnectionWrapper* connection, |
206 | + const gfx::Rect& bound, |
207 | + MirPlatformWindowManager* window_manager) |
208 | + : pimpl_(new Impl(delegate, connection, bound, window_manager, this)) { |
209 | } |
210 | |
211 | MirPlatformWindow::~MirPlatformWindow() { |
212 | } |
213 | |
214 | +bool MirPlatformWindow::Initialize() { |
215 | + return pimpl_->Initialize(); |
216 | +} |
217 | + |
218 | void MirPlatformWindow::Show() { |
219 | NOTIMPLEMENTED(); |
220 | } |
221 | diff --git a/ui/ozone/platform/mir/mir_platform_window.h b/ui/ozone/platform/mir/mir_platform_window.h |
222 | index 5cd7487..3b94368 100644 |
223 | --- a/ui/ozone/platform/mir/mir_platform_window.h |
224 | +++ b/ui/ozone/platform/mir/mir_platform_window.h |
225 | @@ -5,17 +5,28 @@ |
226 | #ifndef UI_OZONE_PLATFORM_MIR_MIR_PLATFORM_WINDOW_H_ |
227 | #define UI_OZONE_PLATFORM_MIR_MIR_PLATFORM_WINDOW_H_ |
228 | |
229 | +#include <memory> |
230 | + |
231 | #include "ui/gfx/geometry/rect.h" |
232 | #include "ui/gfx/native_widget_types.h" |
233 | #include "ui/platform_window/platform_window.h" |
234 | |
235 | namespace ui { |
236 | |
237 | +class MirConnectionWrapper; |
238 | +class MirPlatformWindowManager; |
239 | +class PlatformWindowDelegate; |
240 | + |
241 | class MirPlatformWindow : public PlatformWindow { |
242 | public: |
243 | - MirPlatformWindow(); |
244 | + MirPlatformWindow(PlatformWindowDelegate* delegate, |
245 | + MirConnectionWrapper* connection, |
246 | + const gfx::Rect& bounds, |
247 | + MirPlatformWindowManager* window_manager); |
248 | ~MirPlatformWindow() override; |
249 | |
250 | + bool Initialize(); |
251 | + |
252 | void Show() override; |
253 | void Hide() override; |
254 | void Close() override; |
255 | @@ -40,6 +51,9 @@ class MirPlatformWindow : public PlatformWindow { |
256 | PlatformImeController* GetPlatformImeController() override; |
257 | |
258 | private: |
259 | + class Impl; |
260 | + std::unique_ptr<Impl> pimpl_; |
261 | + |
262 | DISALLOW_COPY_AND_ASSIGN(MirPlatformWindow); |
263 | }; |
264 | |
265 | diff --git a/ui/ozone/platform/mir/mir_platform_window_manager.cc b/ui/ozone/platform/mir/mir_platform_window_manager.cc |
266 | new file mode 100644 |
267 | index 0000000..884644a |
268 | --- /dev/null |
269 | +++ b/ui/ozone/platform/mir/mir_platform_window_manager.cc |
270 | @@ -0,0 +1,85 @@ |
271 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
272 | +// Use of this source code is governed by a BSD-style license that can be |
273 | +// found in the LICENSE file. |
274 | + |
275 | +#include "ui/ozone/platform/mir/mir_platform_window_manager.h" |
276 | + |
277 | +#include <map> |
278 | +#include <utility> |
279 | + |
280 | +#include "base/logging.h" |
281 | +#include "ui/ozone/platform/mir/mir_platform_window.h" |
282 | + |
283 | +namespace ui { |
284 | + |
285 | +// |
286 | +// Start private implementation |
287 | +// |
288 | + |
289 | +class MirPlatformWindowManager::Impl { |
290 | +public: |
291 | + gfx::AcceleratedWidget NextAcceleratedWidget() { |
292 | + // We're not using 0 since other code assumes that a 0 AcceleratedWidget is |
293 | + // an invalid widget. |
294 | + return ++last_allocated_widget_; |
295 | + } |
296 | + |
297 | + void AddWindow(gfx::AcceleratedWidget widget, |
298 | + MirPlatformWindow* window) { |
299 | + auto result = window_map_.insert(std::make_pair(widget, window)); |
300 | + DCHECK(result.second) << "Window for " << widget << " already added."; |
301 | + } |
302 | + |
303 | + void RemoveWindow(gfx::AcceleratedWidget widget) { |
304 | + auto it = window_map_.find(widget); |
305 | + if (it != end(window_map_)) |
306 | + window_map_.erase(it); |
307 | + else |
308 | + NOTREACHED() << "Attempting to remove non-existing window " << widget; |
309 | + } |
310 | + |
311 | + MirPlatformWindow* GetWindow(gfx::AcceleratedWidget widget) { |
312 | + auto it = window_map_.find(widget); |
313 | + if (it != end(window_map_)) |
314 | + return it->second; |
315 | + |
316 | + NOTREACHED() << "Attempting to get non-existing window " << widget; |
317 | + return nullptr; |
318 | + } |
319 | + |
320 | +private: |
321 | + typedef std::map<gfx::AcceleratedWidget, MirPlatformWindow*> WidgetToWindowMap; |
322 | + |
323 | + gfx::AcceleratedWidget last_allocated_widget_ = 0; |
324 | + WidgetToWindowMap window_map_; |
325 | +}; |
326 | + |
327 | +// |
328 | +// End private implementation |
329 | +// |
330 | + |
331 | +MirPlatformWindowManager::MirPlatformWindowManager() |
332 | + : pimpl_(new Impl) { |
333 | +} |
334 | + |
335 | +MirPlatformWindowManager::~MirPlatformWindowManager() { |
336 | +} |
337 | + |
338 | +gfx::AcceleratedWidget MirPlatformWindowManager::NextAcceleratedWidget() { |
339 | + return pimpl_->NextAcceleratedWidget(); |
340 | +} |
341 | + |
342 | +void MirPlatformWindowManager::AddWindow(gfx::AcceleratedWidget widget, |
343 | + MirPlatformWindow* window) { |
344 | + pimpl_->AddWindow(widget, window); |
345 | +} |
346 | + |
347 | +void MirPlatformWindowManager::RemoveWindow(gfx::AcceleratedWidget widget) { |
348 | + pimpl_->RemoveWindow(widget); |
349 | +} |
350 | + |
351 | +MirPlatformWindow* MirPlatformWindowManager::GetWindow(gfx::AcceleratedWidget widget) { |
352 | + return pimpl_->GetWindow(widget); |
353 | +} |
354 | + |
355 | +} // namespace ui |
356 | diff --git a/ui/ozone/platform/mir/mir_platform_window_manager.h b/ui/ozone/platform/mir/mir_platform_window_manager.h |
357 | new file mode 100644 |
358 | index 0000000..3af5934 |
359 | --- /dev/null |
360 | +++ b/ui/ozone/platform/mir/mir_platform_window_manager.h |
361 | @@ -0,0 +1,47 @@ |
362 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
363 | +// Use of this source code is governed by a BSD-style license that can be |
364 | +// found in the LICENSE file. |
365 | + |
366 | +#ifndef UI_OZONE_PLATFORM_MIR_MIR_PLATFORM_WINDOW_MANAGER_H_ |
367 | +#define UI_OZONE_PLATFORM_MIR_MIR_PLATFORM_WINDOW_MANAGER_H_ |
368 | + |
369 | +#include <memory> |
370 | + |
371 | +#include "base/macros.h" |
372 | +#include "ui/gfx/native_widget_types.h" |
373 | + |
374 | +namespace ui { |
375 | + |
376 | +class MirPlatformWindow; |
377 | + |
378 | +// Responsible for keeping the mapping between the allocated widgets and |
379 | +// windows. |
380 | +class MirPlatformWindowManager { |
381 | + public: |
382 | + MirPlatformWindowManager(); |
383 | + ~MirPlatformWindowManager(); |
384 | + |
385 | + gfx::AcceleratedWidget NextAcceleratedWidget(); |
386 | + |
387 | + // Adds a window for |widget|. Note: |widget| should not be associated when |
388 | + // calling this function. |
389 | + void AddWindow(gfx::AcceleratedWidget widget, MirPlatformWindow* window); |
390 | + |
391 | + // Removes the window association for |widget|. Note: |widget| must be |
392 | + // associated with a window when calling this function. |
393 | + void RemoveWindow(gfx::AcceleratedWidget widget); |
394 | + |
395 | + // Returns the window associated with |widget|. Note: This function should |
396 | + // only be called if a valid window has been associated. |
397 | + MirPlatformWindow* GetWindow(gfx::AcceleratedWidget widget); |
398 | + |
399 | + private: |
400 | + class Impl; |
401 | + std::unique_ptr<Impl> pimpl_; |
402 | + |
403 | + DISALLOW_COPY_AND_ASSIGN(MirPlatformWindowManager); |
404 | +}; |
405 | + |
406 | +} // namespace ui |
407 | + |
408 | +#endif // UI_OZONE_PLATFORM_MIR_MIR_PLATFORM_WINDOW_MANAGER_H_ |
409 | diff --git a/ui/ozone/platform/mir/mir_platform_window_manager_unittest.cc b/ui/ozone/platform/mir/mir_platform_window_manager_unittest.cc |
410 | new file mode 100644 |
411 | index 0000000..0caae34 |
412 | --- /dev/null |
413 | +++ b/ui/ozone/platform/mir/mir_platform_window_manager_unittest.cc |
414 | @@ -0,0 +1,46 @@ |
415 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
416 | +// Use of this source code is governed by a BSD-style license that can be |
417 | +// found in the LICENSE file. |
418 | + |
419 | +#include <memory> |
420 | + |
421 | +#include "testing/gtest/include/gtest/gtest.h" |
422 | +#include "ui/ozone/platform/mir/mir_platform_window_manager.h" |
423 | + |
424 | +class MirPlatformWindowManagerTest : public testing::Test { |
425 | + public: |
426 | + MirPlatformWindowManagerTest() { |
427 | + } |
428 | + |
429 | + void SetUp() override { |
430 | + wm_.reset(new ui::MirPlatformWindowManager); |
431 | + } |
432 | + |
433 | + protected: |
434 | + std::unique_ptr<ui::MirPlatformWindowManager> wm_; |
435 | + |
436 | + private: |
437 | + DISALLOW_COPY_AND_ASSIGN(MirPlatformWindowManagerTest); |
438 | +}; |
439 | + |
440 | +TEST_F(MirPlatformWindowManagerTest, NextAcceleratedWidget) { |
441 | + EXPECT_EQ(1, wm_->NextAcceleratedWidget()); |
442 | + EXPECT_EQ(2, wm_->NextAcceleratedWidget()); |
443 | + EXPECT_EQ(3, wm_->NextAcceleratedWidget()); |
444 | +} |
445 | + |
446 | +TEST_F(MirPlatformWindowManagerTest, AddAndRemoveWindow) { |
447 | + auto widget1 = wm_->NextAcceleratedWidget(); |
448 | + auto window1 = reinterpret_cast<ui::MirPlatformWindow*>(0x1234); |
449 | + wm_->AddWindow(widget1, window1); |
450 | + |
451 | + auto widget2 = wm_->NextAcceleratedWidget(); |
452 | + auto window2 = reinterpret_cast<ui::MirPlatformWindow*>(0x6789); |
453 | + wm_->AddWindow(widget2, window2); |
454 | + |
455 | + EXPECT_EQ(window1, wm_->GetWindow(widget1)); |
456 | + EXPECT_EQ(window2, wm_->GetWindow(widget2)); |
457 | + |
458 | + wm_->RemoveWindow(widget1); |
459 | + EXPECT_DEATH(wm_->GetWindow(widget1), ""); |
460 | +} |
461 | diff --git a/ui/ozone/platform/mir/ozone_platform_mir.cc b/ui/ozone/platform/mir/ozone_platform_mir.cc |
462 | index 3ce6d53..3157f55 100644 |
463 | --- a/ui/ozone/platform/mir/ozone_platform_mir.cc |
464 | +++ b/ui/ozone/platform/mir/ozone_platform_mir.cc |
465 | @@ -10,6 +10,7 @@ |
466 | #include "ui/ozone/common/stub_overlay_manager.h" |
467 | #include "ui/ozone/platform/mir/mir_connection_wrapper.h" |
468 | #include "ui/ozone/platform/mir/mir_platform_window.h" |
469 | +#include "ui/ozone/platform/mir/mir_platform_window_manager.h" |
470 | #include "ui/ozone/public/cursor_factory_ozone.h" |
471 | #include "ui/ozone/public/gpu_platform_support_host.h" |
472 | #include "ui/ozone/public/input_controller.h" |
473 | @@ -59,7 +60,12 @@ class OzonePlatformMir : public OzonePlatform { |
474 | std::unique_ptr<PlatformWindow> CreatePlatformWindow( |
475 | PlatformWindowDelegate* delegate, |
476 | const gfx::Rect& bounds) override { |
477 | - NOTIMPLEMENTED(); |
478 | + auto window = |
479 | + base::MakeUnique<MirPlatformWindow>(delegate, connection_.get(), bounds, |
480 | + window_manager_.get()); |
481 | + if (!window->Initialize()) |
482 | + return nullptr; |
483 | + return std::move(window); |
484 | return nullptr; |
485 | } |
486 | |
487 | @@ -75,8 +81,11 @@ class OzonePlatformMir : public OzonePlatform { |
488 | |
489 | void InitializeUI(const InitParams& args) override { |
490 | connection_.reset(new MirConnectionWrapper); |
491 | + |
492 | if (!connection_->Initialize()) |
493 | LOG(FATAL) << "Failed to initialize Mir platform"; |
494 | + |
495 | + window_manager_.reset(new MirPlatformWindowManager); |
496 | } |
497 | |
498 | void InitializeGPU() override { |
499 | @@ -90,6 +99,7 @@ class OzonePlatformMir : public OzonePlatform { |
500 | |
501 | private: |
502 | std::unique_ptr<MirConnectionWrapper> connection_; |
503 | + std::unique_ptr<MirPlatformWindowManager> window_manager_; |
504 | |
505 | DISALLOW_COPY_AND_ASSIGN(OzonePlatformMir); |
506 | }; |