Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: ash/mus/bridge/shell_port_mash.cc

Issue 2833093002: WIP: simplified display management in ash (Closed)
Patch Set: merge and more fixs Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/bridge/shell_port_mash.h ('k') | ash/mus/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/mus/bridge/shell_port_mash.h" 5 #include "ash/mus/bridge/shell_port_mash.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/accelerators/accelerator_controller.h" 9 #include "ash/accelerators/accelerator_controller.h"
10 #include "ash/accelerators/accelerator_controller_delegate_aura.h" 10 #include "ash/accelerators/accelerator_controller_delegate_aura.h"
11 #include "ash/aura/key_event_watcher_aura.h" 11 #include "ash/aura/key_event_watcher_aura.h"
12 #include "ash/aura/pointer_watcher_adapter.h" 12 #include "ash/aura/pointer_watcher_adapter.h"
13 #include "ash/host/ash_window_tree_host.h" 13 #include "ash/display/window_tree_host_manager.h"
14 #include "ash/host/ash_window_tree_host_init_params.h"
14 #include "ash/key_event_watcher.h" 15 #include "ash/key_event_watcher.h"
15 #include "ash/laser/laser_pointer_controller.h" 16 #include "ash/laser/laser_pointer_controller.h"
16 #include "ash/magnifier/partial_magnification_controller.h" 17 #include "ash/magnifier/partial_magnification_controller.h"
17 #include "ash/mus/accelerators/accelerator_controller_delegate_mus.h" 18 #include "ash/mus/accelerators/accelerator_controller_delegate_mus.h"
18 #include "ash/mus/accelerators/accelerator_controller_registrar.h" 19 #include "ash/mus/accelerators/accelerator_controller_registrar.h"
20 #include "ash/mus/ash_window_tree_host_mus.h"
19 #include "ash/mus/bridge/immersive_handler_factory_mus.h" 21 #include "ash/mus/bridge/immersive_handler_factory_mus.h"
20 #include "ash/mus/bridge/workspace_event_handler_mus.h" 22 #include "ash/mus/bridge/workspace_event_handler_mus.h"
21 #include "ash/mus/drag_window_resizer.h" 23 #include "ash/mus/drag_window_resizer.h"
22 #include "ash/mus/keyboard_ui_mus.h" 24 #include "ash/mus/keyboard_ui_mus.h"
23 #include "ash/mus/screen_mus.h" 25 #include "ash/mus/screen_mus.h"
24 #include "ash/mus/window_manager.h" 26 #include "ash/mus/window_manager.h"
25 #include "ash/public/cpp/config.h" 27 #include "ash/public/cpp/config.h"
26 #include "ash/root_window_controller.h" 28 #include "ash/root_window_controller.h"
27 #include "ash/root_window_settings.h" 29 #include "ash/root_window_settings.h"
28 #include "ash/session/session_state_delegate.h" 30 #include "ash/session/session_state_delegate.h"
(...skipping 13 matching lines...) Expand all
42 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone. h" 44 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone. h"
43 #include "ash/wm/mru_window_tracker.h" 45 #include "ash/wm/mru_window_tracker.h"
44 #include "ash/wm/window_cycle_event_filter.h" 46 #include "ash/wm/window_cycle_event_filter.h"
45 #include "ash/wm/window_cycle_event_filter_aura.h" 47 #include "ash/wm/window_cycle_event_filter_aura.h"
46 #include "ash/wm/window_resizer.h" 48 #include "ash/wm/window_resizer.h"
47 #include "ash/wm/window_util.h" 49 #include "ash/wm/window_util.h"
48 #include "ash/wm/workspace/workspace_event_handler_aura.h" 50 #include "ash/wm/workspace/workspace_event_handler_aura.h"
49 #include "ash/wm_window.h" 51 #include "ash/wm_window.h"
50 #include "base/memory/ptr_util.h" 52 #include "base/memory/ptr_util.h"
51 #include "components/user_manager/user_info_impl.h" 53 #include "components/user_manager/user_info_impl.h"
54 #include "services/ui/public/interfaces/constants.mojom.h"
52 #include "ui/aura/env.h" 55 #include "ui/aura/env.h"
56 #include "ui/aura/mus/window_manager_delegate.h"
53 #include "ui/aura/mus/window_tree_client.h" 57 #include "ui/aura/mus/window_tree_client.h"
54 #include "ui/aura/mus/window_tree_host_mus.h" 58 #include "ui/aura/mus/window_tree_host_mus.h"
59 #include "ui/aura/mus/window_tree_host_mus_init_params.h"
55 #include "ui/aura/window.h" 60 #include "ui/aura/window.h"
61 #include "ui/display/manager/display_manager.h"
56 #include "ui/display/manager/managed_display_info.h" 62 #include "ui/display/manager/managed_display_info.h"
57 #include "ui/display/screen.h" 63 #include "ui/display/screen.h"
58 #include "ui/display/types/native_display_delegate.h" 64 #include "ui/display/types/native_display_delegate.h"
59 #include "ui/views/mus/pointer_watcher_event_router.h" 65 #include "ui/views/mus/pointer_watcher_event_router.h"
60 66
67 #if defined(USE_OZONE)
68 #include "ui/display/manager/forwarding_display_delegate.h"
69 #endif
70
61 namespace ash { 71 namespace ash {
62 namespace mus { 72 namespace mus {
63 73
64 namespace { 74 namespace {
65 75
66 // TODO(jamescook): After ShellDelegate is ported to ash/common use 76 // TODO(jamescook): After ShellDelegate is ported to ash/common use
67 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version 77 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version
68 // of SessionStateDelegate. 78 // of SessionStateDelegate.
69 class SessionStateDelegateStub : public SessionStateDelegate { 79 class SessionStateDelegateStub : public SessionStateDelegate {
70 public: 80 public:
(...skipping 30 matching lines...) Expand all
101 111
102 ShellPortMash::ShellPortMash( 112 ShellPortMash::ShellPortMash(
103 WmWindow* primary_root_window, 113 WmWindow* primary_root_window,
104 WindowManager* window_manager, 114 WindowManager* window_manager,
105 views::PointerWatcherEventRouter* pointer_watcher_event_router, 115 views::PointerWatcherEventRouter* pointer_watcher_event_router,
106 bool create_session_state_delegate_stub) 116 bool create_session_state_delegate_stub)
107 : window_manager_(window_manager), 117 : window_manager_(window_manager),
108 primary_root_window_(primary_root_window) { 118 primary_root_window_(primary_root_window) {
109 if (create_session_state_delegate_stub) 119 if (create_session_state_delegate_stub)
110 session_state_delegate_ = base::MakeUnique<SessionStateDelegateStub>(); 120 session_state_delegate_ = base::MakeUnique<SessionStateDelegateStub>();
111 DCHECK(primary_root_window_); 121 // DCHECK(primary_root_window_);
112 122
113 if (GetAshConfig() == Config::MASH) { 123 if (GetAshConfig() == Config::MASH) {
114 mash_state_ = base::MakeUnique<MashSpecificState>(); 124 mash_state_ = base::MakeUnique<MashSpecificState>();
115 mash_state_->pointer_watcher_event_router = pointer_watcher_event_router; 125 mash_state_->pointer_watcher_event_router = pointer_watcher_event_router;
116 mash_state_->immersive_handler_factory = 126 mash_state_->immersive_handler_factory =
117 base::MakeUnique<ImmersiveHandlerFactoryMus>(); 127 base::MakeUnique<ImmersiveHandlerFactoryMus>();
118 } else { 128 } else {
119 DCHECK_EQ(Config::MUS, GetAshConfig()); 129 DCHECK_EQ(Config::MUS, GetAshConfig());
120 mus_state_ = base::MakeUnique<MusSpecificState>(); 130 mus_state_ = base::MakeUnique<MusSpecificState>();
121 } 131 }
(...skipping 24 matching lines...) Expand all
146 aura::WindowTreeClient* ShellPortMash::window_tree_client() { 156 aura::WindowTreeClient* ShellPortMash::window_tree_client() {
147 return window_manager_->window_tree_client(); 157 return window_manager_->window_tree_client();
148 } 158 }
149 159
150 void ShellPortMash::Shutdown() { 160 void ShellPortMash::Shutdown() {
151 if (mus_state_) 161 if (mus_state_)
152 mus_state_->pointer_watcher_adapter.reset(); 162 mus_state_->pointer_watcher_adapter.reset();
153 163
154 ShellPort::Shutdown(); 164 ShellPort::Shutdown();
155 165
156 window_manager_->DeleteAllRootWindowControllers(); 166 // TODO(sky): Config::MASH should use WindowTreeHostManager too.
167 if (GetAshConfig() == Config::MUS)
168 Shell::Get()->window_tree_host_manager()->Shutdown();
169 else
170 window_manager_->DeleteAllRootWindowControllers();
157 } 171 }
158 172
159 Config ShellPortMash::GetAshConfig() const { 173 Config ShellPortMash::GetAshConfig() const {
160 return window_manager_->config(); 174 return window_manager_->config();
161 } 175 }
162 176
163 WmWindow* ShellPortMash::GetPrimaryRootWindow() { 177 WmWindow* ShellPortMash::GetPrimaryRootWindow() {
178 if (GetAshConfig() == Config::MUS) {
179 return WmWindow::Get(
180 Shell::Get()->window_tree_host_manager()->GetPrimaryRootWindow());
181 }
164 // NOTE: This is called before the RootWindowController has been created, so 182 // NOTE: This is called before the RootWindowController has been created, so
165 // it can't call through to RootWindowController to get all windows. 183 // it can't call through to RootWindowController to get all windows.
166 return primary_root_window_; 184 return primary_root_window_;
167 } 185 }
168 186
169 WmWindow* ShellPortMash::GetRootWindowForDisplayId(int64_t display_id) { 187 WmWindow* ShellPortMash::GetRootWindowForDisplayId(int64_t display_id) {
188 if (GetAshConfig() == Config::MUS) {
189 return WmWindow::Get(
190 Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId(
191 display_id));
192 }
170 RootWindowController* root_window_controller = 193 RootWindowController* root_window_controller =
171 GetRootWindowControllerWithDisplayId(display_id); 194 GetRootWindowControllerWithDisplayId(display_id);
172 return root_window_controller 195 return root_window_controller
173 ? WmWindow::Get(root_window_controller->GetRootWindow()) 196 ? WmWindow::Get(root_window_controller->GetRootWindow())
174 : nullptr; 197 : nullptr;
175 } 198 }
176 199
177 const display::ManagedDisplayInfo& ShellPortMash::GetDisplayInfo( 200 const display::ManagedDisplayInfo& ShellPortMash::GetDisplayInfo(
178 int64_t display_id) const { 201 int64_t display_id) const {
179 // TODO(mash): implement http://crbug.com/622480. 202 // TODO(mash): implement http://crbug.com/622480.
(...skipping 21 matching lines...) Expand all
201 } 224 }
202 225
203 bool ShellPortMash::IsInUnifiedModeIgnoreMirroring() const { 226 bool ShellPortMash::IsInUnifiedModeIgnoreMirroring() const {
204 // TODO(mash): implement http://crbug.com/622480. 227 // TODO(mash): implement http://crbug.com/622480.
205 NOTIMPLEMENTED(); 228 NOTIMPLEMENTED();
206 return false; 229 return false;
207 } 230 }
208 231
209 void ShellPortMash::SetDisplayWorkAreaInsets(WmWindow* window, 232 void ShellPortMash::SetDisplayWorkAreaInsets(WmWindow* window,
210 const gfx::Insets& insets) { 233 const gfx::Insets& insets) {
234 if (GetAshConfig() == Config::MUS) {
235 Shell::Get()
236 ->window_tree_host_manager()
237 ->UpdateWorkAreaOfDisplayNearestWindow(window->aura_window(), insets);
238 return;
239 }
211 window_manager_->screen()->SetWorkAreaInsets(window->aura_window(), insets); 240 window_manager_->screen()->SetWorkAreaInsets(window->aura_window(), insets);
212 } 241 }
213 242
214 void ShellPortMash::LockCursor() { 243 void ShellPortMash::LockCursor() {
215 // TODO: http://crbug.com/637853 244 // TODO: http://crbug.com/637853
216 NOTIMPLEMENTED(); 245 NOTIMPLEMENTED();
217 } 246 }
218 247
219 void ShellPortMash::UnlockCursor() { 248 void ShellPortMash::UnlockCursor() {
220 // TODO: http://crbug.com/637853 249 // TODO: http://crbug.com/637853
221 NOTIMPLEMENTED(); 250 NOTIMPLEMENTED();
222 } 251 }
223 252
224 bool ShellPortMash::IsMouseEventsEnabled() { 253 bool ShellPortMash::IsMouseEventsEnabled() {
225 // TODO: http://crbug.com/637853 254 // TODO: http://crbug.com/637853
226 NOTIMPLEMENTED(); 255 NOTIMPLEMENTED();
227 return true; 256 return true;
228 } 257 }
229 258
230 std::vector<WmWindow*> ShellPortMash::GetAllRootWindows() { 259 std::vector<WmWindow*> ShellPortMash::GetAllRootWindows() {
260 if (GetAshConfig() == Config::MUS) {
261 aura::Window::Windows root_windows =
262 Shell::Get()->window_tree_host_manager()->GetAllRootWindows();
263 std::vector<WmWindow*> wm_windows(root_windows.size());
264 for (size_t i = 0; i < root_windows.size(); ++i)
265 wm_windows[i] = WmWindow::Get(root_windows[i]);
266 return wm_windows;
267 }
231 std::vector<WmWindow*> root_windows; 268 std::vector<WmWindow*> root_windows;
232 for (RootWindowController* root_window_controller : 269 for (RootWindowController* root_window_controller :
233 RootWindowController::root_window_controllers()) { 270 RootWindowController::root_window_controllers()) {
234 root_windows.push_back(root_window_controller->GetWindow()); 271 root_windows.push_back(root_window_controller->GetWindow());
235 } 272 }
236 return root_windows; 273 return root_windows;
237 } 274 }
238 275
239 void ShellPortMash::RecordGestureAction(GestureActionType action) { 276 void ShellPortMash::RecordGestureAction(GestureActionType action) {
240 if (GetAshConfig() == Config::MUS) { 277 if (GetAshConfig() == Config::MUS) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // In Config::MUS PointerWatcherAdapter must be created when this function is 457 // In Config::MUS PointerWatcherAdapter must be created when this function is
421 // called (it is order dependent), that is not the case with Config::MASH. 458 // called (it is order dependent), that is not the case with Config::MASH.
422 if (GetAshConfig() == Config::MUS) { 459 if (GetAshConfig() == Config::MUS) {
423 mus_state_->pointer_watcher_adapter = 460 mus_state_->pointer_watcher_adapter =
424 base::MakeUnique<PointerWatcherAdapter>(); 461 base::MakeUnique<PointerWatcherAdapter>();
425 } 462 }
426 } 463 }
427 464
428 std::unique_ptr<AshWindowTreeHost> ShellPortMash::CreateAshWindowTreeHost( 465 std::unique_ptr<AshWindowTreeHost> ShellPortMash::CreateAshWindowTreeHost(
429 const AshWindowTreeHostInitParams& init_params) { 466 const AshWindowTreeHostInitParams& init_params) {
430 return nullptr; 467 // TODO(sky): make this work for mash too.
468 if (GetAshConfig() != Config::MUS)
469 return nullptr;
470
471 aura::WindowTreeHostMusInitParams aura_init_params =
472 window_manager_->window_manager_client()->CreateInitParamsForNewDisplay();
473 aura_init_params.display_id = init_params.display_id;
474 aura_init_params.viewport_metrics.bounds_in_pixels =
475 init_params.initial_bounds;
476 aura_init_params.viewport_metrics.device_scale_factor =
477 init_params.device_scale_factor;
478 aura_init_params.viewport_metrics.ui_scale_factor =
479 init_params.ui_scale_factor;
480 display::Display mirrored_display =
481 Shell::Get()->display_manager()->GetMirroringDisplayById(
482 init_params.display_id);
483 if (mirrored_display.is_valid()) {
484 aura_init_params.display =
485 base::MakeUnique<display::Display>(mirrored_display);
486 }
487 return base::MakeUnique<AshWindowTreeHostMus>(std::move(aura_init_params));
431 } 488 }
432 489
433 void ShellPortMash::CreatePrimaryHost() {} 490 void ShellPortMash::CreatePrimaryHost() {
491 if (GetAshConfig() == Config::MASH)
492 return;
493
494 DCHECK_EQ(Config::MUS, GetAshConfig());
495 Shell::Get()->window_tree_host_manager()->Start();
496 AshWindowTreeHostInitParams ash_init_params;
497 Shell::Get()->window_tree_host_manager()->CreatePrimaryHost(ash_init_params);
498 }
434 499
435 void ShellPortMash::InitHosts(const ShellInitParams& init_params) { 500 void ShellPortMash::InitHosts(const ShellInitParams& init_params) {
436 window_manager_->CreatePrimaryRootWindowController( 501 if (GetAshConfig() == Config::MUS) {
437 base::WrapUnique(init_params.primary_window_tree_host)); 502 Shell::Get()->window_tree_host_manager()->InitHosts();
503 } else {
504 window_manager_->CreatePrimaryRootWindowController(
505 base::WrapUnique(init_params.primary_window_tree_host));
506 }
438 } 507 }
439 508
440 std::unique_ptr<display::NativeDisplayDelegate> 509 std::unique_ptr<display::NativeDisplayDelegate>
441 ShellPortMash::CreateNativeDisplayDelegate() { 510 ShellPortMash::CreateNativeDisplayDelegate() {
511 #if defined(USE_OZONE)
512 display::mojom::NativeDisplayDelegatePtr native_display_delegate;
513 if (window_manager_->connector()) {
514 window_manager_->connector()->BindInterface(ui::mojom::kServiceName,
515 &native_display_delegate);
516 }
517 return base::MakeUnique<display::ForwardingDisplayDelegate>(
518 std::move(native_display_delegate));
519 #else
520 // The bots compile this config, but it is never run.
521 CHECK(false);
442 return nullptr; 522 return nullptr;
523 #endif
443 } 524 }
444 525
445 std::unique_ptr<AcceleratorController> 526 std::unique_ptr<AcceleratorController>
446 ShellPortMash::CreateAcceleratorController() { 527 ShellPortMash::CreateAcceleratorController() {
447 if (GetAshConfig() == Config::MUS) { 528 if (GetAshConfig() == Config::MUS) {
448 DCHECK(!mus_state_->accelerator_controller_delegate); 529 DCHECK(!mus_state_->accelerator_controller_delegate);
449 mus_state_->accelerator_controller_delegate = 530 mus_state_->accelerator_controller_delegate =
450 base::MakeUnique<AcceleratorControllerDelegateAura>(); 531 base::MakeUnique<AcceleratorControllerDelegateAura>();
451 return base::MakeUnique<AcceleratorController>( 532 return base::MakeUnique<AcceleratorController>(
452 mus_state_->accelerator_controller_delegate.get(), nullptr); 533 mus_state_->accelerator_controller_delegate.get(), nullptr);
(...skipping 13 matching lines...) Expand all
466 mash_state_->accelerator_controller_registrar = 547 mash_state_->accelerator_controller_registrar =
467 base ::MakeUnique<AcceleratorControllerRegistrar>( 548 base ::MakeUnique<AcceleratorControllerRegistrar>(
468 window_manager_, accelerator_namespace_id); 549 window_manager_, accelerator_namespace_id);
469 return base::MakeUnique<AcceleratorController>( 550 return base::MakeUnique<AcceleratorController>(
470 mash_state_->accelerator_controller_delegate.get(), 551 mash_state_->accelerator_controller_delegate.get(),
471 mash_state_->accelerator_controller_registrar.get()); 552 mash_state_->accelerator_controller_registrar.get());
472 } 553 }
473 554
474 } // namespace mus 555 } // namespace mus
475 } // namespace ash 556 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/bridge/shell_port_mash.h ('k') | ash/mus/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698