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