| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ws/display.h" | 5 #include "services/ui/ws/display.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/debug/debugger.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 13 #include "mojo/common/common_type_converters.h" | 12 #include "mojo/common/common_type_converters.h" |
| 14 #include "services/service_manager/public/interfaces/connector.mojom.h" | 13 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 15 #include "services/ui/common/types.h" | 14 #include "services/ui/common/types.h" |
| 16 #include "services/ui/public/interfaces/cursor.mojom.h" | 15 #include "services/ui/public/interfaces/cursor.mojom.h" |
| 17 #include "services/ui/ws/display_binding.h" | 16 #include "services/ui/ws/display_binding.h" |
| 18 #include "services/ui/ws/display_manager.h" | 17 #include "services/ui/ws/display_manager.h" |
| 19 #include "services/ui/ws/focus_controller.h" | 18 #include "services/ui/ws/focus_controller.h" |
| 20 #include "services/ui/ws/platform_display.h" | 19 #include "services/ui/ws/platform_display.h" |
| 21 #include "services/ui/ws/platform_display_init_params.h" | 20 #include "services/ui/ws/platform_display_init_params.h" |
| 22 #include "services/ui/ws/user_activity_monitor.h" | 21 #include "services/ui/ws/user_activity_monitor.h" |
| 23 #include "services/ui/ws/window_manager_display_root.h" | 22 #include "services/ui/ws/window_manager_display_root.h" |
| 24 #include "services/ui/ws/window_manager_state.h" | 23 #include "services/ui/ws/window_manager_state.h" |
| 25 #include "services/ui/ws/window_manager_window_tree_factory.h" | 24 #include "services/ui/ws/window_manager_window_tree_factory.h" |
| 26 #include "services/ui/ws/window_server.h" | 25 #include "services/ui/ws/window_server.h" |
| 27 #include "services/ui/ws/window_server_delegate.h" | 26 #include "services/ui/ws/window_server_delegate.h" |
| 28 #include "services/ui/ws/window_tree.h" | 27 #include "services/ui/ws/window_tree.h" |
| 29 #include "services/ui/ws/window_tree_binding.h" | 28 #include "services/ui/ws/window_tree_binding.h" |
| 30 #include "ui/base/cursor/cursor.h" | 29 #include "ui/base/cursor/cursor.h" |
| 31 | 30 |
| 32 namespace ui { | 31 namespace ui { |
| 33 namespace ws { | 32 namespace ws { |
| 34 | 33 |
| 35 Display::Display(WindowServer* window_server, | 34 Display::Display(WindowServer* window_server) |
| 36 const PlatformDisplayInitParams& platform_display_init_params) | |
| 37 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { | 35 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { |
| 38 CreateRootWindow(platform_display_init_params.metrics.pixel_size); | |
| 39 | |
| 40 // Pass the display root ServerWindow to PlatformDisplay. | |
| 41 PlatformDisplayInitParams param_copy = platform_display_init_params; | |
| 42 param_copy.root_window = root_.get(); | |
| 43 platform_display_.reset(PlatformDisplay::Create(param_copy)); | |
| 44 platform_display_->Init(this); | |
| 45 | |
| 46 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); | 36 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); |
| 47 window_server_->user_id_tracker()->AddObserver(this); | 37 window_server_->user_id_tracker()->AddObserver(this); |
| 48 } | 38 } |
| 49 | 39 |
| 50 Display::~Display() { | 40 Display::~Display() { |
| 51 window_server_->user_id_tracker()->RemoveObserver(this); | 41 window_server_->user_id_tracker()->RemoveObserver(this); |
| 52 | 42 |
| 53 window_server_->window_manager_window_tree_factory_set()->RemoveObserver( | 43 window_server_->window_manager_window_tree_factory_set()->RemoveObserver( |
| 54 this); | 44 this); |
| 55 | 45 |
| 56 if (!focus_controller_) { | 46 if (!focus_controller_) { |
| 57 focus_controller_->RemoveObserver(this); | 47 focus_controller_->RemoveObserver(this); |
| 58 focus_controller_.reset(); | 48 focus_controller_.reset(); |
| 59 } | 49 } |
| 60 | 50 |
| 61 if (!binding_) { | 51 if (!binding_) { |
| 62 for (auto& pair : window_manager_display_root_map_) | 52 for (auto& pair : window_manager_display_root_map_) |
| 63 pair.second->window_manager_state()->OnDisplayDestroying(this); | 53 pair.second->window_manager_state()->OnDisplayDestroying(this); |
| 64 } else if (!window_manager_display_root_map_.empty()) { | 54 } else if (!window_manager_display_root_map_.empty()) { |
| 65 // If there is a |binding_| then the tree was created specifically for this | 55 // If there is a |binding_| then the tree was created specifically for this |
| 66 // display (which corresponds to a WindowTreeHost). | 56 // display (which corresponds to a WindowTreeHost). |
| 67 window_server_->DestroyTree(window_manager_display_root_map_.begin() | 57 window_server_->DestroyTree(window_manager_display_root_map_.begin() |
| 68 ->second->window_manager_state() | 58 ->second->window_manager_state() |
| 69 ->window_tree()); | 59 ->window_tree()); |
| 70 } | 60 } |
| 71 } | 61 } |
| 72 | 62 |
| 73 void Display::Init(std::unique_ptr<DisplayBinding> binding) { | 63 void Display::Init(const PlatformDisplayInitParams& init_params, |
| 74 init_called_ = true; | 64 std::unique_ptr<DisplayBinding> binding) { |
| 75 binding_ = std::move(binding); | 65 binding_ = std::move(binding); |
| 76 display_manager()->AddDisplay(this); | 66 display_manager()->AddDisplay(this); |
| 77 InitWindowManagerDisplayRootsIfNecessary(); | 67 |
| 68 CreateRootWindow(init_params.metrics.pixel_size); |
| 69 PlatformDisplayInitParams params_copy = init_params; |
| 70 params_copy.root_window = root_.get(); |
| 71 |
| 72 platform_display_ = PlatformDisplay::Create(params_copy); |
| 73 platform_display_->Init(this); |
| 78 } | 74 } |
| 79 | 75 |
| 80 int64_t Display::GetId() const { | 76 int64_t Display::GetId() const { |
| 81 return platform_display_->GetId(); | 77 return platform_display_->GetId(); |
| 82 } | 78 } |
| 83 | 79 |
| 84 DisplayManager* Display::display_manager() { | 80 DisplayManager* Display::display_manager() { |
| 85 return window_server_->display_manager(); | 81 return window_server_->display_manager(); |
| 86 } | 82 } |
| 87 | 83 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 display.set_work_area(metrics.work_area); | 95 display.set_work_area(metrics.work_area); |
| 100 display.set_device_scale_factor(metrics.device_scale_factor); | 96 display.set_device_scale_factor(metrics.device_scale_factor); |
| 101 display.set_rotation(metrics.rotation); | 97 display.set_rotation(metrics.rotation); |
| 102 display.set_touch_support( | 98 display.set_touch_support( |
| 103 display::Display::TouchSupport::TOUCH_SUPPORT_UNKNOWN); | 99 display::Display::TouchSupport::TOUCH_SUPPORT_UNKNOWN); |
| 104 | 100 |
| 105 return display; | 101 return display; |
| 106 } | 102 } |
| 107 | 103 |
| 108 gfx::Size Display::GetSize() const { | 104 gfx::Size Display::GetSize() const { |
| 109 return platform_display_->GetBounds().size(); | 105 DCHECK(root_); |
| 106 return root_->bounds().size(); |
| 110 } | 107 } |
| 111 | 108 |
| 112 ServerWindow* Display::GetRootWithId(const WindowId& id) { | 109 ServerWindow* Display::GetRootWithId(const WindowId& id) { |
| 113 if (id == root_->id()) | 110 if (id == root_->id()) |
| 114 return root_.get(); | 111 return root_.get(); |
| 115 for (auto& pair : window_manager_display_root_map_) { | 112 for (auto& pair : window_manager_display_root_map_) { |
| 116 if (pair.second->root()->id() == id) | 113 if (pair.second->root()->id() == id) |
| 117 return pair.second->root(); | 114 return pair.second->root(); |
| 118 } | 115 } |
| 119 return nullptr; | 116 return nullptr; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 197 } |
| 201 | 198 |
| 202 void Display::SetSize(const gfx::Size& size) { | 199 void Display::SetSize(const gfx::Size& size) { |
| 203 platform_display_->SetViewportSize(size); | 200 platform_display_->SetViewportSize(size); |
| 204 } | 201 } |
| 205 | 202 |
| 206 void Display::SetTitle(const mojo::String& title) { | 203 void Display::SetTitle(const mojo::String& title) { |
| 207 platform_display_->SetTitle(title.To<base::string16>()); | 204 platform_display_->SetTitle(title.To<base::string16>()); |
| 208 } | 205 } |
| 209 | 206 |
| 210 void Display::InitWindowManagerDisplayRootsIfNecessary() { | 207 void Display::InitWindowManagerDisplayRoots() { |
| 211 if (!init_called_ || !root_) | |
| 212 return; | |
| 213 | |
| 214 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | |
| 215 if (binding_) { | 208 if (binding_) { |
| 216 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( | 209 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( |
| 217 new WindowManagerDisplayRoot(this)); | 210 new WindowManagerDisplayRoot(this)); |
| 218 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); | 211 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); |
| 219 // For this case we never create additional displays roots, so any | 212 // For this case we never create additional displays roots, so any |
| 220 // id works. | 213 // id works. |
| 221 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = | 214 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = |
| 222 display_root_ptr.get(); | 215 display_root_ptr.get(); |
| 223 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); | 216 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); |
| 224 display_root->window_manager_state_ = window_tree->window_manager_state(); | 217 display_root->window_manager_state_ = window_tree->window_manager_state(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 void Display::CreateRootWindow(const gfx::Size& size) { | 253 void Display::CreateRootWindow(const gfx::Size& size) { |
| 261 DCHECK(!root_); | 254 DCHECK(!root_); |
| 262 | 255 |
| 263 root_.reset(window_server_->CreateServerWindow( | 256 root_.reset(window_server_->CreateServerWindow( |
| 264 display_manager()->GetAndAdvanceNextRootId(), | 257 display_manager()->GetAndAdvanceNextRootId(), |
| 265 ServerWindow::Properties())); | 258 ServerWindow::Properties())); |
| 266 root_->SetBounds(gfx::Rect(size)); | 259 root_->SetBounds(gfx::Rect(size)); |
| 267 root_->SetVisible(true); | 260 root_->SetVisible(true); |
| 268 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get()); | 261 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get()); |
| 269 focus_controller_->AddObserver(this); | 262 focus_controller_->AddObserver(this); |
| 270 InitWindowManagerDisplayRootsIfNecessary(); | |
| 271 } | 263 } |
| 272 | 264 |
| 273 ServerWindow* Display::GetRootWindow() { | 265 ServerWindow* Display::GetRootWindow() { |
| 274 return root_.get(); | 266 return root_.get(); |
| 275 } | 267 } |
| 276 | 268 |
| 269 void Display::OnAcceleratedWidgetAvailable() { |
| 270 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 271 InitWindowManagerDisplayRoots(); |
| 272 } |
| 273 |
| 277 bool Display::IsInHighContrastMode() { | 274 bool Display::IsInHighContrastMode() { |
| 278 return window_server_->IsActiveUserInHighContrastMode(); | 275 return window_server_->IsActiveUserInHighContrastMode(); |
| 279 } | 276 } |
| 280 | 277 |
| 281 void Display::OnEvent(const ui::Event& event) { | 278 void Display::OnEvent(const ui::Event& event) { |
| 282 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 279 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 283 if (display_root) | 280 if (display_root) |
| 284 display_root->window_manager_state()->ProcessEvent(event); | 281 display_root->window_manager_state()->ProcessEvent(event); |
| 285 window_server_ | 282 window_server_ |
| 286 ->GetUserActivityMonitorForUser( | 283 ->GetUserActivityMonitorForUser( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 380 } |
| 384 | 381 |
| 385 void Display::OnWindowManagerWindowTreeFactoryReady( | 382 void Display::OnWindowManagerWindowTreeFactoryReady( |
| 386 WindowManagerWindowTreeFactory* factory) { | 383 WindowManagerWindowTreeFactory* factory) { |
| 387 if (!binding_) | 384 if (!binding_) |
| 388 CreateWindowManagerDisplayRootFromFactory(factory); | 385 CreateWindowManagerDisplayRootFromFactory(factory); |
| 389 } | 386 } |
| 390 | 387 |
| 391 } // namespace ws | 388 } // namespace ws |
| 392 } // namespace ui | 389 } // namespace ui |
| OLD | NEW |