| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/display/cursor_window_controller.h" | 12 #include "ash/display/cursor_window_controller.h" |
| 13 #include "ash/display/display_layout_store.h" | 13 #include "ash/display/display_layout_store.h" |
| 14 #include "ash/display/display_manager.h" | 14 #include "ash/display/display_manager.h" |
| 15 #include "ash/display/mirror_window_controller.h" | 15 #include "ash/display/mirror_window_controller.h" |
| 16 #include "ash/display/root_window_transformers.h" | 16 #include "ash/display/root_window_transformers.h" |
| 17 #include "ash/display/virtual_keyboard_window_controller.h" | 17 #include "ash/display/virtual_keyboard_window_controller.h" |
| 18 #include "ash/host/window_tree_host_factory.h" | 18 #include "ash/host/ash_window_tree_host.h" |
| 19 #include "ash/host/root_window_transformer.h" |
| 19 #include "ash/root_window_controller.h" | 20 #include "ash/root_window_controller.h" |
| 20 #include "ash/root_window_settings.h" | 21 #include "ash/root_window_settings.h" |
| 21 #include "ash/screen_util.h" | 22 #include "ash/screen_util.h" |
| 22 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 23 #include "ash/shell_delegate.h" | 24 #include "ash/shell_delegate.h" |
| 24 #include "ash/wm/coordinate_conversion.h" | 25 #include "ash/wm/coordinate_conversion.h" |
| 25 #include "base/command_line.h" | 26 #include "base/command_line.h" |
| 26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 27 #include "ui/aura/client/capture_client.h" | 28 #include "ui/aura/client/capture_client.h" |
| 28 #include "ui/aura/client/focus_client.h" | 29 #include "ui/aura/client/focus_client.h" |
| 29 #include "ui/aura/client/screen_position_client.h" | 30 #include "ui/aura/client/screen_position_client.h" |
| 30 #include "ui/aura/root_window_transformer.h" | |
| 31 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 32 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
| 33 #include "ui/aura/window_property.h" | 33 #include "ui/aura/window_property.h" |
| 34 #include "ui/aura/window_tracker.h" | 34 #include "ui/aura/window_tracker.h" |
| 35 #include "ui/compositor/compositor.h" | 35 #include "ui/compositor/compositor.h" |
| 36 #include "ui/compositor/compositor_vsync_manager.h" | 36 #include "ui/compositor/compositor_vsync_manager.h" |
| 37 #include "ui/gfx/display.h" | 37 #include "ui/gfx/display.h" |
| 38 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
| 39 #include "ui/wm/public/activation_client.h" | 39 #include "ui/wm/public/activation_client.h" |
| 40 | 40 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 69 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| | 69 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| |
| 70 // when the display change happens, so the actual timeout is much shorter. | 70 // when the display change happens, so the actual timeout is much shorter. |
| 71 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; | 71 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; |
| 72 const int64 kCycleDisplayThrottleTimeoutMs = 4000; | 72 const int64 kCycleDisplayThrottleTimeoutMs = 4000; |
| 73 const int64 kSwapDisplayThrottleTimeoutMs = 500; | 73 const int64 kSwapDisplayThrottleTimeoutMs = 500; |
| 74 | 74 |
| 75 internal::DisplayManager* GetDisplayManager() { | 75 internal::DisplayManager* GetDisplayManager() { |
| 76 return Shell::GetInstance()->display_manager(); | 76 return Shell::GetInstance()->display_manager(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SetDisplayPropertiesOnHost(aura::WindowTreeHost* host, | 79 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, |
| 80 const gfx::Display& display) { | 80 const gfx::Display& display) { |
| 81 internal::DisplayInfo info = | 81 internal::DisplayInfo info = |
| 82 GetDisplayManager()->GetDisplayInfo(display.id()); | 82 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 83 #if defined(OS_CHROMEOS) && defined(USE_X11) | 83 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 84 // Native window property (Atom in X11) that specifies the display's | 84 // Native window property (Atom in X11) that specifies the display's |
| 85 // rotation, scale factor and if it's internal display. They are | 85 // rotation, scale factor and if it's internal display. They are |
| 86 // read and used by touchpad/mouse driver directly on X (contact | 86 // read and used by touchpad/mouse driver directly on X (contact |
| 87 // adlr@ for more details on touchpad/mouse driver side). The value | 87 // adlr@ for more details on touchpad/mouse driver side). The value |
| 88 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2 | 88 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2 |
| 89 // (180 degree) or 3 (270 degrees clockwise). The value of the | 89 // (180 degree) or 3 (270 degrees clockwise). The value of the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 break; | 102 break; |
| 103 case gfx::Display::ROTATE_180: | 103 case gfx::Display::ROTATE_180: |
| 104 xrandr_rotation = RR_Rotate_180; | 104 xrandr_rotation = RR_Rotate_180; |
| 105 break; | 105 break; |
| 106 case gfx::Display::ROTATE_270: | 106 case gfx::Display::ROTATE_270: |
| 107 xrandr_rotation = RR_Rotate_270; | 107 xrandr_rotation = RR_Rotate_270; |
| 108 break; | 108 break; |
| 109 } | 109 } |
| 110 | 110 |
| 111 int internal = display.IsInternal() ? 1 : 0; | 111 int internal = display.IsInternal() ? 1 : 0; |
| 112 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
| 112 gfx::AcceleratedWidget xwindow = host->GetAcceleratedWidget(); | 113 gfx::AcceleratedWidget xwindow = host->GetAcceleratedWidget(); |
| 113 ui::SetIntProperty(xwindow, kInternalProp, kCARDINAL, internal); | 114 ui::SetIntProperty(xwindow, kInternalProp, kCARDINAL, internal); |
| 114 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, xrandr_rotation); | 115 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, xrandr_rotation); |
| 115 ui::SetIntProperty(xwindow, | 116 ui::SetIntProperty(xwindow, |
| 116 kScaleFactorProp, | 117 kScaleFactorProp, |
| 117 kCARDINAL, | 118 kCARDINAL, |
| 118 100 * display.device_scale_factor()); | 119 100 * display.device_scale_factor()); |
| 119 #endif | 120 #endif |
| 120 scoped_ptr<aura::RootWindowTransformer> transformer( | 121 scoped_ptr<RootWindowTransformer> transformer( |
| 121 internal::CreateRootWindowTransformerForDisplay(host->window(), | 122 internal::CreateRootWindowTransformerForDisplay(host->window(), |
| 122 display)); | 123 display)); |
| 123 host->SetRootWindowTransformer(transformer.Pass()); | 124 ash_host->SetRootWindowTransformer(transformer.Pass()); |
| 124 | 125 |
| 125 internal::DisplayMode mode; | 126 internal::DisplayMode mode; |
| 126 if (GetDisplayManager()->GetSelectedModeForDisplayId(display.id(), &mode) && | 127 if (GetDisplayManager()->GetSelectedModeForDisplayId(display.id(), &mode) && |
| 127 mode.refresh_rate > 0.0f) { | 128 mode.refresh_rate > 0.0f) { |
| 128 host->compositor()->vsync_manager()->SetAuthoritativeVSyncInterval( | 129 host->compositor()->vsync_manager()->SetAuthoritativeVSyncInterval( |
| 129 base::TimeDelta::FromMicroseconds( | 130 base::TimeDelta::FromMicroseconds( |
| 130 base::Time::kMicrosecondsPerSecond / mode.refresh_rate)); | 131 base::Time::kMicrosecondsPerSecond / mode.refresh_rate)); |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 135 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { |
| 136 return ash_host->AsWindowTreeHost()->window(); |
| 137 } |
| 138 |
| 139 internal::RootWindowController* GetRootWindowControllerFromHost( |
| 140 AshWindowTreeHost* host) { |
| 141 return internal::GetRootWindowController(GetWindow(host)); |
| 142 } |
| 143 |
| 134 } // namespace | 144 } // namespace |
| 135 | 145 |
| 136 namespace internal { | 146 namespace internal { |
| 137 | 147 |
| 138 // A utility class to store/restore focused/active window | 148 // A utility class to store/restore focused/active window |
| 139 // when the display configuration has changed. | 149 // when the display configuration has changed. |
| 140 class FocusActivationStore { | 150 class FocusActivationStore { |
| 141 public: | 151 public: |
| 142 FocusActivationStore() | 152 FocusActivationStore() |
| 143 : activation_client_(NULL), | 153 : activation_client_(NULL), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 227 } |
| 218 | 228 |
| 219 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { | 229 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { |
| 220 return base::Time::Now() < throttle_timeout_; | 230 return base::Time::Now() < throttle_timeout_; |
| 221 } | 231 } |
| 222 | 232 |
| 223 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 224 // DisplayController | 234 // DisplayController |
| 225 | 235 |
| 226 DisplayController::DisplayController() | 236 DisplayController::DisplayController() |
| 227 : primary_root_window_for_replace_(NULL), | 237 : primary_tree_host_for_replace_(NULL), |
| 228 focus_activation_store_(new internal::FocusActivationStore()), | 238 focus_activation_store_(new internal::FocusActivationStore()), |
| 229 cursor_window_controller_(new internal::CursorWindowController()), | 239 cursor_window_controller_(new internal::CursorWindowController()), |
| 230 mirror_window_controller_(new internal::MirrorWindowController()) { | 240 mirror_window_controller_(new internal::MirrorWindowController()) { |
| 231 #if defined(OS_CHROMEOS) | 241 #if defined(OS_CHROMEOS) |
| 232 if (base::SysInfo::IsRunningOnChromeOS()) | 242 if (base::SysInfo::IsRunningOnChromeOS()) |
| 233 limiter_.reset(new DisplayChangeLimiter); | 243 limiter_.reset(new DisplayChangeLimiter); |
| 234 #endif | 244 #endif |
| 235 // Reset primary display to make sure that tests don't use | 245 // Reset primary display to make sure that tests don't use |
| 236 // stale display info from previous tests. | 246 // stale display info from previous tests. |
| 237 primary_display_id = gfx::Display::kInvalidDisplayID; | 247 primary_display_id = gfx::Display::kInvalidDisplayID; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 256 // DisplayManager outlives DisplayController. | 266 // DisplayManager outlives DisplayController. |
| 257 Shell::GetInstance()->display_manager()->set_delegate(NULL); | 267 Shell::GetInstance()->display_manager()->set_delegate(NULL); |
| 258 | 268 |
| 259 cursor_window_controller_.reset(); | 269 cursor_window_controller_.reset(); |
| 260 mirror_window_controller_.reset(); | 270 mirror_window_controller_.reset(); |
| 261 virtual_keyboard_window_controller_.reset(); | 271 virtual_keyboard_window_controller_.reset(); |
| 262 | 272 |
| 263 Shell::GetScreen()->RemoveObserver(this); | 273 Shell::GetScreen()->RemoveObserver(this); |
| 264 // Delete all root window controllers, which deletes root window | 274 // Delete all root window controllers, which deletes root window |
| 265 // from the last so that the primary root window gets deleted last. | 275 // from the last so that the primary root window gets deleted last. |
| 266 for (std::map<int64, aura::Window*>::const_reverse_iterator it = | 276 for (WindowTreeHostMap::const_reverse_iterator it = |
| 267 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 277 window_tree_hosts_.rbegin(); it != window_tree_hosts_.rend(); ++it) { |
| 268 internal::RootWindowController* controller = | 278 internal::RootWindowController* controller = |
| 269 internal::GetRootWindowController(it->second); | 279 internal::GetRootWindowController(GetWindow(it->second)); |
| 270 DCHECK(controller); | 280 DCHECK(controller); |
| 271 delete controller; | 281 delete controller; |
| 272 } | 282 } |
| 273 } | 283 } |
| 274 | 284 |
| 275 void DisplayController::InitPrimaryDisplay() { | 285 void DisplayController::CreatePrimaryHost() { |
| 276 const gfx::Display& primary_candidate = | 286 const gfx::Display& primary_candidate = |
| 277 GetDisplayManager()->GetPrimaryDisplayCandidate(); | 287 GetDisplayManager()->GetPrimaryDisplayCandidate(); |
| 278 primary_display_id = primary_candidate.id(); | 288 primary_display_id = primary_candidate.id(); |
| 279 AddWindowTreeHostForDisplay(primary_candidate); | 289 AddWindowTreeHostForDisplay(primary_candidate); |
| 280 } | 290 } |
| 281 | 291 |
| 282 void DisplayController::InitSecondaryDisplays() { | 292 void DisplayController::InitDisplays() { |
| 293 internal::RootWindowController::CreateForPrimaryDisplay( |
| 294 window_tree_hosts_[primary_display_id]); |
| 295 |
| 283 internal::DisplayManager* display_manager = GetDisplayManager(); | 296 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 284 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 297 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 285 const gfx::Display& display = display_manager->GetDisplayAt(i); | 298 const gfx::Display& display = display_manager->GetDisplayAt(i); |
| 286 if (primary_display_id != display.id()) { | 299 if (primary_display_id != display.id()) { |
| 287 aura::WindowTreeHost* host = AddWindowTreeHostForDisplay(display); | 300 AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); |
| 288 internal::RootWindowController::CreateForSecondaryDisplay(host); | 301 internal::RootWindowController::CreateForSecondaryDisplay(ash_host); |
| 289 } | 302 } |
| 290 } | 303 } |
| 291 UpdateHostWindowNames(); | 304 UpdateHostWindowNames(); |
| 292 } | 305 } |
| 293 | 306 |
| 294 void DisplayController::AddObserver(Observer* observer) { | 307 void DisplayController::AddObserver(Observer* observer) { |
| 295 observers_.AddObserver(observer); | 308 observers_.AddObserver(observer); |
| 296 } | 309 } |
| 297 | 310 |
| 298 void DisplayController::RemoveObserver(Observer* observer) { | 311 void DisplayController::RemoveObserver(Observer* observer) { |
| 299 observers_.RemoveObserver(observer); | 312 observers_.RemoveObserver(observer); |
| 300 } | 313 } |
| 301 | 314 |
| 302 // static | 315 // static |
| 303 int64 DisplayController::GetPrimaryDisplayId() { | 316 int64 DisplayController::GetPrimaryDisplayId() { |
| 304 return primary_display_id; | 317 return primary_display_id; |
| 305 } | 318 } |
| 306 | 319 |
| 307 aura::Window* DisplayController::GetPrimaryRootWindow() { | 320 aura::Window* DisplayController::GetPrimaryRootWindow() { |
| 308 DCHECK(!root_windows_.empty()); | 321 return GetRootWindowForDisplayId(primary_display_id); |
| 309 return root_windows_[primary_display_id]; | |
| 310 } | 322 } |
| 311 | 323 |
| 312 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { | 324 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { |
| 313 return root_windows_[id]; | 325 return GetWindow(window_tree_hosts_[id]); |
| 314 } | 326 } |
| 315 | 327 |
| 316 void DisplayController::CloseChildWindows() { | 328 void DisplayController::CloseChildWindows() { |
| 317 for (std::map<int64, aura::Window*>::const_iterator it = | 329 for (WindowTreeHostMap::const_iterator it = |
| 318 root_windows_.begin(); it != root_windows_.end(); ++it) { | 330 window_tree_hosts_.begin(); it != window_tree_hosts_.end(); ++it) { |
| 319 aura::Window* root_window = it->second; | 331 aura::Window* root_window = GetWindow(it->second); |
| 320 internal::RootWindowController* controller = | 332 internal::RootWindowController* controller = |
| 321 internal::GetRootWindowController(root_window); | 333 internal::GetRootWindowController(root_window); |
| 322 if (controller) { | 334 if (controller) { |
| 323 controller->CloseChildWindows(); | 335 controller->CloseChildWindows(); |
| 324 } else { | 336 } else { |
| 325 while (!root_window->children().empty()) { | 337 while (!root_window->children().empty()) { |
| 326 aura::Window* child = root_window->children()[0]; | 338 aura::Window* child = root_window->children()[0]; |
| 327 delete child; | 339 delete child; |
| 328 } | 340 } |
| 329 } | 341 } |
| 330 } | 342 } |
| 331 } | 343 } |
| 332 | 344 |
| 333 aura::Window::Windows DisplayController::GetAllRootWindows() { | 345 aura::Window::Windows DisplayController::GetAllRootWindows() { |
| 334 aura::Window::Windows windows; | 346 aura::Window::Windows windows; |
| 335 for (std::map<int64, aura::Window*>::const_iterator it = | 347 for (WindowTreeHostMap::const_iterator it = |
| 336 root_windows_.begin(); it != root_windows_.end(); ++it) { | 348 window_tree_hosts_.begin(); it != window_tree_hosts_.end(); ++it) { |
| 337 DCHECK(it->second); | 349 DCHECK(it->second); |
| 338 if (internal::GetRootWindowController(it->second)) | 350 if (GetRootWindowControllerFromHost(it->second)) |
| 339 windows.push_back(it->second); | 351 windows.push_back(GetWindow(it->second)); |
| 340 } | 352 } |
| 341 return windows; | 353 return windows; |
| 342 } | 354 } |
| 343 | 355 |
| 344 gfx::Insets DisplayController::GetOverscanInsets(int64 display_id) const { | 356 gfx::Insets DisplayController::GetOverscanInsets(int64 display_id) const { |
| 345 return GetDisplayManager()->GetOverscanInsets(display_id); | 357 return GetDisplayManager()->GetOverscanInsets(display_id); |
| 346 } | 358 } |
| 347 | 359 |
| 348 void DisplayController::SetOverscanInsets(int64 display_id, | 360 void DisplayController::SetOverscanInsets(int64 display_id, |
| 349 const gfx::Insets& insets_in_dip) { | 361 const gfx::Insets& insets_in_dip) { |
| 350 GetDisplayManager()->SetOverscanInsets(display_id, insets_in_dip); | 362 GetDisplayManager()->SetOverscanInsets(display_id, insets_in_dip); |
| 351 } | 363 } |
| 352 | 364 |
| 353 std::vector<internal::RootWindowController*> | 365 std::vector<internal::RootWindowController*> |
| 354 DisplayController::GetAllRootWindowControllers() { | 366 DisplayController::GetAllRootWindowControllers() { |
| 355 std::vector<internal::RootWindowController*> controllers; | 367 std::vector<internal::RootWindowController*> controllers; |
| 356 for (std::map<int64, aura::Window*>::const_iterator it = | 368 for (WindowTreeHostMap::const_iterator it = |
| 357 root_windows_.begin(); it != root_windows_.end(); ++it) { | 369 window_tree_hosts_.begin(); it != window_tree_hosts_.end(); ++it) { |
| 358 internal::RootWindowController* controller = | 370 internal::RootWindowController* controller = |
| 359 internal::GetRootWindowController(it->second); | 371 GetRootWindowControllerFromHost(it->second); |
| 360 if (controller) | 372 if (controller) |
| 361 controllers.push_back(controller); | 373 controllers.push_back(controller); |
| 362 } | 374 } |
| 363 return controllers; | 375 return controllers; |
| 364 } | 376 } |
| 365 | 377 |
| 366 void DisplayController::ToggleMirrorMode() { | 378 void DisplayController::ToggleMirrorMode() { |
| 367 internal::DisplayManager* display_manager = GetDisplayManager(); | 379 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 368 if (display_manager->num_connected_displays() <= 1) | 380 if (display_manager->num_connected_displays() <= 1) |
| 369 return; | 381 return; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 DCHECK(display_manager->IsActiveDisplay(new_primary_display)); | 437 DCHECK(display_manager->IsActiveDisplay(new_primary_display)); |
| 426 | 438 |
| 427 if (!new_primary_display.is_valid() || | 439 if (!new_primary_display.is_valid() || |
| 428 !display_manager->IsActiveDisplay(new_primary_display)) { | 440 !display_manager->IsActiveDisplay(new_primary_display)) { |
| 429 LOG(ERROR) << "Invalid or non-existent display is requested:" | 441 LOG(ERROR) << "Invalid or non-existent display is requested:" |
| 430 << new_primary_display.ToString(); | 442 << new_primary_display.ToString(); |
| 431 return; | 443 return; |
| 432 } | 444 } |
| 433 | 445 |
| 434 if (primary_display_id == new_primary_display.id() || | 446 if (primary_display_id == new_primary_display.id() || |
| 435 root_windows_.size() < 2) { | 447 window_tree_hosts_.size() < 2) { |
| 436 return; | 448 return; |
| 437 } | 449 } |
| 438 | 450 |
| 439 aura::Window* non_primary_root = root_windows_[new_primary_display.id()]; | 451 AshWindowTreeHost* non_primary_host = window_tree_hosts_[new_primary_display.i
d()]; |
| 440 LOG_IF(ERROR, !non_primary_root) | 452 LOG_IF(ERROR, !non_primary_host) |
| 441 << "Unknown display is requested in SetPrimaryDisplay: id=" | 453 << "Unknown display is requested in SetPrimaryDisplay: id=" |
| 442 << new_primary_display.id(); | 454 << new_primary_display.id(); |
| 443 if (!non_primary_root) | 455 if (!non_primary_host) |
| 444 return; | 456 return; |
| 445 | 457 |
| 446 gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 458 gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 447 | 459 |
| 448 // Swap root windows between current and new primary display. | 460 // Swap root windows between current and new primary display. |
| 449 aura::Window* primary_root = root_windows_[primary_display_id]; | 461 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; |
| 450 DCHECK(primary_root); | 462 DCHECK(primary_host); |
| 451 DCHECK_NE(primary_root, non_primary_root); | 463 DCHECK_NE(primary_host, non_primary_host); |
| 452 | 464 |
| 453 root_windows_[new_primary_display.id()] = primary_root; | 465 window_tree_hosts_[new_primary_display.id()] = primary_host; |
| 454 internal::GetRootWindowSettings(primary_root)->display_id = | 466 internal::GetRootWindowSettings(GetWindow(primary_host))->display_id = |
| 455 new_primary_display.id(); | 467 new_primary_display.id(); |
| 456 | 468 |
| 457 root_windows_[old_primary_display.id()] = non_primary_root; | 469 window_tree_hosts_[old_primary_display.id()] = non_primary_host; |
| 458 internal::GetRootWindowSettings(non_primary_root)->display_id = | 470 internal::GetRootWindowSettings(GetWindow(non_primary_host))->display_id = |
| 459 old_primary_display.id(); | 471 old_primary_display.id(); |
| 460 | 472 |
| 461 primary_display_id = new_primary_display.id(); | 473 primary_display_id = new_primary_display.id(); |
| 462 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( | 474 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( |
| 463 display_manager->GetCurrentDisplayIdPair(), primary_display_id); | 475 display_manager->GetCurrentDisplayIdPair(), primary_display_id); |
| 464 | 476 |
| 465 UpdateWorkAreaOfDisplayNearestWindow( | 477 UpdateWorkAreaOfDisplayNearestWindow( |
| 466 primary_root, old_primary_display.GetWorkAreaInsets()); | 478 GetWindow(primary_host), old_primary_display.GetWorkAreaInsets()); |
| 467 UpdateWorkAreaOfDisplayNearestWindow( | 479 UpdateWorkAreaOfDisplayNearestWindow( |
| 468 non_primary_root, new_primary_display.GetWorkAreaInsets()); | 480 GetWindow(non_primary_host), new_primary_display.GetWorkAreaInsets()); |
| 469 | 481 |
| 470 // Update the dispay manager with new display info. | 482 // Update the dispay manager with new display info. |
| 471 std::vector<internal::DisplayInfo> display_info_list; | 483 std::vector<internal::DisplayInfo> display_info_list; |
| 472 display_info_list.push_back(display_manager->GetDisplayInfo( | 484 display_info_list.push_back(display_manager->GetDisplayInfo( |
| 473 primary_display_id)); | 485 primary_display_id)); |
| 474 display_info_list.push_back(display_manager->GetDisplayInfo( | 486 display_info_list.push_back(display_manager->GetDisplayInfo( |
| 475 ScreenUtil::GetSecondaryDisplay().id())); | 487 ScreenUtil::GetSecondaryDisplay().id())); |
| 476 GetDisplayManager()->set_force_bounds_changed(true); | 488 GetDisplayManager()->set_force_bounds_changed(true); |
| 477 GetDisplayManager()->UpdateDisplays(display_info_list); | 489 GetDisplayManager()->UpdateDisplays(display_info_list); |
| 478 GetDisplayManager()->set_force_bounds_changed(false); | 490 GetDisplayManager()->set_force_bounds_changed(false); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 int64 id = internal::GetRootWindowSettings(root_window)->display_id; | 544 int64 id = internal::GetRootWindowSettings(root_window)->display_id; |
| 533 // if id is |kInvaildDisplayID|, it's being deleted. | 545 // if id is |kInvaildDisplayID|, it's being deleted. |
| 534 DCHECK(id != gfx::Display::kInvalidDisplayID); | 546 DCHECK(id != gfx::Display::kInvalidDisplayID); |
| 535 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 547 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
| 536 } | 548 } |
| 537 | 549 |
| 538 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 550 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 539 const internal::DisplayInfo& display_info = | 551 const internal::DisplayInfo& display_info = |
| 540 GetDisplayManager()->GetDisplayInfo(display.id()); | 552 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 541 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 553 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
| 542 aura::WindowTreeHost* host = root_windows_[display.id()]->GetHost(); | 554 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
| 543 host->SetBounds(display_info.bounds_in_native()); | 555 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
| 544 SetDisplayPropertiesOnHost(host, display); | 556 SetDisplayPropertiesOnHost(ash_host, display); |
| 545 } | 557 } |
| 546 | 558 |
| 547 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 559 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
| 548 if (primary_root_window_for_replace_) { | 560 if (primary_tree_host_for_replace_) { |
| 549 DCHECK(root_windows_.empty()); | 561 DCHECK(window_tree_hosts_.empty()); |
| 550 primary_display_id = display.id(); | 562 primary_display_id = display.id(); |
| 551 root_windows_[display.id()] = primary_root_window_for_replace_; | 563 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
| 552 internal::GetRootWindowSettings(primary_root_window_for_replace_)-> | 564 internal::GetRootWindowSettings( |
| 565 primary_tree_host_for_replace_->AsWindowTreeHost()->window())-> |
| 553 display_id = display.id(); | 566 display_id = display.id(); |
| 554 primary_root_window_for_replace_ = NULL; | 567 primary_tree_host_for_replace_ = NULL; |
| 555 const internal::DisplayInfo& display_info = | 568 const internal::DisplayInfo& display_info = |
| 556 GetDisplayManager()->GetDisplayInfo(display.id()); | 569 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 557 aura::WindowTreeHost* host = root_windows_[display.id()]->GetHost(); | 570 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
| 558 host->SetBounds(display_info.bounds_in_native()); | 571 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
| 559 SetDisplayPropertiesOnHost(host, display); | 572 SetDisplayPropertiesOnHost(ash_host, display); |
| 560 } else { | 573 } else { |
| 561 if (primary_display_id == gfx::Display::kInvalidDisplayID) | 574 if (primary_display_id == gfx::Display::kInvalidDisplayID) |
| 562 primary_display_id = display.id(); | 575 primary_display_id = display.id(); |
| 563 DCHECK(!root_windows_.empty()); | 576 DCHECK(!window_tree_hosts_.empty()); |
| 564 aura::WindowTreeHost* host = AddWindowTreeHostForDisplay(display); | 577 AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); |
| 565 internal::RootWindowController::CreateForSecondaryDisplay(host); | 578 internal::RootWindowController::CreateForSecondaryDisplay(ash_host); |
| 566 } | 579 } |
| 567 } | 580 } |
| 568 | 581 |
| 569 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { | 582 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { |
| 570 aura::Window* root_to_delete = root_windows_[display.id()]; | 583 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; |
| 571 DCHECK(root_to_delete) << display.ToString(); | 584 DCHECK(host_to_delete) << display.ToString(); |
| 572 | 585 |
| 573 // Display for root window will be deleted when the Primary RootWindow | 586 // Display for root window will be deleted when the Primary RootWindow |
| 574 // is deleted by the Shell. | 587 // is deleted by the Shell. |
| 575 root_windows_.erase(display.id()); | 588 window_tree_hosts_.erase(display.id()); |
| 576 | 589 |
| 577 // When the primary root window's display is removed, move the primary | 590 // When the primary root window's display is removed, move the primary |
| 578 // root to the other display. | 591 // root to the other display. |
| 579 if (primary_display_id == display.id()) { | 592 if (primary_display_id == display.id()) { |
| 580 // Temporarily store the primary root window in | 593 // Temporarily store the primary root window in |
| 581 // |primary_root_window_for_replace_| when replacing the display. | 594 // |primary_root_window_for_replace_| when replacing the display. |
| 582 if (root_windows_.size() == 0) { | 595 if (window_tree_hosts_.size() == 0) { |
| 583 primary_display_id = gfx::Display::kInvalidDisplayID; | 596 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 584 primary_root_window_for_replace_ = root_to_delete; | 597 primary_tree_host_for_replace_ = host_to_delete; |
| 585 return; | 598 return; |
| 586 } | 599 } |
| 587 DCHECK_EQ(1U, root_windows_.size()); | 600 DCHECK_EQ(1U, window_tree_hosts_.size()); |
| 588 primary_display_id = ScreenUtil::GetSecondaryDisplay().id(); | 601 primary_display_id = ScreenUtil::GetSecondaryDisplay().id(); |
| 589 aura::Window* primary_root = root_to_delete; | 602 AshWindowTreeHost* primary_host = host_to_delete; |
| 590 | 603 |
| 591 // Delete the other root instead. | 604 // Delete the other host instead. |
| 592 root_to_delete = root_windows_[primary_display_id]; | 605 host_to_delete = window_tree_hosts_[primary_display_id]; |
| 593 internal::GetRootWindowSettings(root_to_delete)->display_id = display.id(); | 606 internal::GetRootWindowSettings(host_to_delete->AsWindowTreeHost()->window()
)-> |
| 607 display_id = display.id(); |
| 594 | 608 |
| 595 // Setup primary root. | 609 // Setup primary root. |
| 596 root_windows_[primary_display_id] = primary_root; | 610 window_tree_hosts_[primary_display_id] = primary_host; |
| 597 internal::GetRootWindowSettings(primary_root)->display_id = | 611 internal::GetRootWindowSettings(GetWindow(primary_host))->display_id = |
| 598 primary_display_id; | 612 primary_display_id; |
| 599 | 613 |
| 600 OnDisplayBoundsChanged( | 614 OnDisplayBoundsChanged( |
| 601 GetDisplayManager()->GetDisplayForId(primary_display_id)); | 615 GetDisplayManager()->GetDisplayForId(primary_display_id)); |
| 602 } | 616 } |
| 603 internal::RootWindowController* controller = | 617 internal::RootWindowController* controller = |
| 604 internal::GetRootWindowController(root_to_delete); | 618 internal::GetRootWindowController(host_to_delete->AsWindowTreeHost()->wind
ow()); |
| 605 DCHECK(controller); | 619 DCHECK(controller); |
| 606 controller->MoveWindowsTo(GetPrimaryRootWindow()); | 620 controller->MoveWindowsTo(GetPrimaryRootWindow()); |
| 607 // Delete most of root window related objects, but don't delete | 621 // Delete most of root window related objects, but don't delete |
| 608 // root window itself yet because the stack may be using it. | 622 // root window itself yet because the stack may be using it. |
| 609 controller->Shutdown(); | 623 controller->Shutdown(); |
| 610 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); | 624 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); |
| 611 } | 625 } |
| 612 | 626 |
| 613 void DisplayController::OnHostResized(const aura::WindowTreeHost* host) { | 627 void DisplayController::OnHostResized(const aura::WindowTreeHost* host) { |
| 614 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 628 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 // set to the same and didn't update it. | 698 // set to the same and didn't update it. |
| 685 layout_store->UpdatePrimaryDisplayId( | 699 layout_store->UpdatePrimaryDisplayId( |
| 686 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); | 700 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 687 } | 701 } |
| 688 } | 702 } |
| 689 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 703 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
| 690 UpdateHostWindowNames(); | 704 UpdateHostWindowNames(); |
| 691 EnsurePointerInDisplays(); | 705 EnsurePointerInDisplays(); |
| 692 } | 706 } |
| 693 | 707 |
| 694 aura::WindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( | 708 AshWindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( |
| 695 const gfx::Display& display) { | 709 const gfx::Display& display) { |
| 696 static int host_count = 0; | 710 static int host_count = 0; |
| 697 const internal::DisplayInfo& display_info = | 711 const internal::DisplayInfo& display_info = |
| 698 GetDisplayManager()->GetDisplayInfo(display.id()); | 712 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 699 const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); | 713 const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); |
| 700 aura::WindowTreeHost* host = | 714 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(bounds_in_native); |
| 701 Shell::GetInstance()->window_tree_host_factory()->CreateWindowTreeHost( | 715 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
| 702 bounds_in_native); | 716 |
| 703 host->window()->SetName(base::StringPrintf("RootWindow-%d", host_count++)); | 717 host->window()->SetName(base::StringPrintf("RootWindow-%d", host_count++)); |
| 704 host->compositor()->SetBackgroundColor(SK_ColorBLACK); | 718 host->compositor()->SetBackgroundColor(SK_ColorBLACK); |
| 705 // No need to remove our observer observer because the DisplayController | 719 // No need to remove our observer observer because the DisplayController |
| 706 // outlives the host. | 720 // outlives the host. |
| 707 host->AddObserver(this); | 721 host->AddObserver(this); |
| 708 internal::InitRootWindowSettings(host->window())->display_id = display.id(); | 722 internal::InitRootWindowSettings(host->window())->display_id = display.id(); |
| 709 host->InitHost(); | 723 host->InitHost(); |
| 710 | 724 |
| 711 root_windows_[display.id()] = host->window(); | 725 window_tree_hosts_[display.id()] = ash_host; |
| 712 SetDisplayPropertiesOnHost(host, display); | 726 SetDisplayPropertiesOnHost(ash_host, display); |
| 713 | 727 |
| 714 #if defined(OS_CHROMEOS) | 728 #if defined(OS_CHROMEOS) |
| 715 static bool force_constrain_pointer_to_root = | 729 static bool force_constrain_pointer_to_root = |
| 716 CommandLine::ForCurrentProcess()->HasSwitch( | 730 CommandLine::ForCurrentProcess()->HasSwitch( |
| 717 switches::kAshConstrainPointerToRoot); | 731 switches::kAshConstrainPointerToRoot); |
| 718 if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) | 732 if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) |
| 719 host->ConfineCursorToRootWindow(); | 733 ash_host->ConfineCursorToRootWindow(); |
| 720 #endif | 734 #endif |
| 721 return host; | 735 return ash_host; |
| 722 } | 736 } |
| 723 | 737 |
| 724 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 738 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
| 725 #if defined(OS_CHROMEOS) && defined(USE_X11) | 739 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 726 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 740 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 727 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 741 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
| 728 #endif | 742 #endif |
| 729 } | 743 } |
| 730 | 744 |
| 731 void DisplayController::UpdateHostWindowNames() { | 745 void DisplayController::UpdateHostWindowNames() { |
| 732 #if defined(USE_X11) | 746 #if defined(USE_X11) |
| 733 // crbug.com/120229 - set the window title for the primary dislpay | 747 // crbug.com/120229 - set the window title for the primary dislpay |
| 734 // to "aura_root_0" so gtalk can find the primary root window to broadcast. | 748 // to "aura_root_0" so gtalk can find the primary root window to broadcast. |
| 735 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. | 749 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. |
| 736 aura::Window* primary = Shell::GetPrimaryRootWindow(); | 750 aura::Window* primary = Shell::GetPrimaryRootWindow(); |
| 737 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 751 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 738 for (size_t i = 0; i < root_windows.size(); ++i) { | 752 for (size_t i = 0; i < root_windows.size(); ++i) { |
| 739 std::string name = | 753 std::string name = |
| 740 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 754 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
| 741 gfx::AcceleratedWidget xwindow = | 755 gfx::AcceleratedWidget xwindow = |
| 742 root_windows[i]->GetHost()->GetAcceleratedWidget(); | 756 root_windows[i]->GetHost()->GetAcceleratedWidget(); |
| 743 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 757 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
| 744 } | 758 } |
| 745 #endif | 759 #endif |
| 746 } | 760 } |
| 747 | 761 |
| 748 } // namespace ash | 762 } // namespace ash |
| OLD | NEW |