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 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 host->compositor()->vsync_manager()->SetAuthoritativeVSyncInterval( | 153 host->compositor()->vsync_manager()->SetAuthoritativeVSyncInterval( |
154 base::TimeDelta::FromMicroseconds( | 154 base::TimeDelta::FromMicroseconds( |
155 base::Time::kMicrosecondsPerSecond / mode.refresh_rate)); | 155 base::Time::kMicrosecondsPerSecond / mode.refresh_rate)); |
156 } | 156 } |
157 | 157 |
158 // Just movnig the display requires the full redraw. | 158 // Just movnig the display requires the full redraw. |
159 // chrome-os-partner:33558. | 159 // chrome-os-partner:33558. |
160 host->compositor()->ScheduleFullRedraw(); | 160 host->compositor()->ScheduleFullRedraw(); |
161 } | 161 } |
162 | 162 |
163 void ClearDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, | 163 void ClearDisplayPropertiesOnHost(AshWindowTreeHost* ash_host) { |
164 const gfx::Display& display) { | |
165 #if defined(OS_CHROMEOS) && defined(USE_OZONE) | 164 #if defined(OS_CHROMEOS) && defined(USE_OZONE) |
166 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 165 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
167 ui::CursorController::GetInstance()->ClearCursorConfigForWindow( | 166 ui::CursorController::GetInstance()->ClearCursorConfigForWindow( |
168 host->GetAcceleratedWidget()); | 167 host->GetAcceleratedWidget()); |
169 #endif | 168 #endif |
170 } | 169 } |
171 | 170 |
172 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { | 171 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { |
173 CHECK(ash_host->AsWindowTreeHost()); | 172 CHECK(ash_host->AsWindowTreeHost()); |
174 return ash_host->AsWindowTreeHost()->window(); | 173 return ash_host->AsWindowTreeHost()->window(); |
175 } | 174 } |
176 | 175 |
177 } // namespace | 176 } // namespace |
178 | 177 |
179 // A utility class to store/restore focused/active window | 178 // A utility class to store/restore focused/active window |
180 // when the display configuration has changed. | 179 // when the display configuration has changed. |
181 class FocusActivationStore { | 180 class FocusActivationStore { |
182 public: | 181 public: |
183 FocusActivationStore() | 182 FocusActivationStore() |
184 : activation_client_(NULL), | 183 : activation_client_(nullptr), |
185 capture_client_(NULL), | 184 capture_client_(nullptr), |
186 focus_client_(NULL), | 185 focus_client_(nullptr), |
187 focused_(NULL), | 186 focused_(nullptr), |
188 active_(NULL) { | 187 active_(nullptr) {} |
189 } | |
190 | 188 |
191 void Store(bool clear_focus) { | 189 void Store(bool clear_focus) { |
192 if (!activation_client_) { | 190 if (!activation_client_) { |
193 aura::Window* root = Shell::GetPrimaryRootWindow(); | 191 aura::Window* root = Shell::GetPrimaryRootWindow(); |
194 activation_client_ = aura::client::GetActivationClient(root); | 192 activation_client_ = aura::client::GetActivationClient(root); |
195 capture_client_ = aura::client::GetCaptureClient(root); | 193 capture_client_ = aura::client::GetCaptureClient(root); |
196 focus_client_ = aura::client::GetFocusClient(root); | 194 focus_client_ = aura::client::GetFocusClient(root); |
197 } | 195 } |
198 focused_ = focus_client_->GetFocusedWindow(); | 196 focused_ = focus_client_->GetFocusedWindow(); |
199 if (focused_) | 197 if (focused_) |
200 tracker_.Add(focused_); | 198 tracker_.Add(focused_); |
201 active_ = activation_client_->GetActiveWindow(); | 199 active_ = activation_client_->GetActiveWindow(); |
202 if (active_ && focused_ != active_) | 200 if (active_ && focused_ != active_) |
203 tracker_.Add(active_); | 201 tracker_.Add(active_); |
204 | 202 |
205 // Deactivate the window to close menu / bubble windows. | 203 // Deactivate the window to close menu / bubble windows. |
206 if (clear_focus) | 204 if (clear_focus) |
207 activation_client_->DeactivateWindow(active_); | 205 activation_client_->DeactivateWindow(active_); |
208 | 206 |
209 // Release capture if any. | 207 // Release capture if any. |
210 capture_client_->SetCapture(NULL); | 208 capture_client_->SetCapture(nullptr); |
211 // Clear the focused window if any. This is necessary because a | 209 // Clear the focused window if any. This is necessary because a |
212 // window may be deleted when losing focus (fullscreen flash for | 210 // window may be deleted when losing focus (fullscreen flash for |
213 // example). If the focused window is still alive after move, it'll | 211 // example). If the focused window is still alive after move, it'll |
214 // be re-focused below. | 212 // be re-focused below. |
215 if (clear_focus) | 213 if (clear_focus) |
216 focus_client_->FocusWindow(NULL); | 214 focus_client_->FocusWindow(nullptr); |
217 } | 215 } |
218 | 216 |
219 void Restore() { | 217 void Restore() { |
220 // Restore focused or active window if it's still alive. | 218 // Restore focused or active window if it's still alive. |
221 if (focused_ && tracker_.Contains(focused_)) { | 219 if (focused_ && tracker_.Contains(focused_)) { |
222 focus_client_->FocusWindow(focused_); | 220 focus_client_->FocusWindow(focused_); |
223 } else if (active_ && tracker_.Contains(active_)) { | 221 } else if (active_ && tracker_.Contains(active_)) { |
224 activation_client_->ActivateWindow(active_); | 222 activation_client_->ActivateWindow(active_); |
225 } | 223 } |
226 if (focused_) | 224 if (focused_) |
227 tracker_.Remove(focused_); | 225 tracker_.Remove(focused_); |
228 if (active_) | 226 if (active_) |
229 tracker_.Remove(active_); | 227 tracker_.Remove(active_); |
230 focused_ = NULL; | 228 focused_ = nullptr; |
231 active_ = NULL; | 229 active_ = nullptr; |
232 } | 230 } |
233 | 231 |
234 private: | 232 private: |
235 aura::client::ActivationClient* activation_client_; | 233 aura::client::ActivationClient* activation_client_; |
236 aura::client::CaptureClient* capture_client_; | 234 aura::client::CaptureClient* capture_client_; |
237 aura::client::FocusClient* focus_client_; | 235 aura::client::FocusClient* focus_client_; |
238 aura::WindowTracker tracker_; | 236 aura::WindowTracker tracker_; |
239 aura::Window* focused_; | 237 aura::Window* focused_; |
240 aura::Window* active_; | 238 aura::Window* active_; |
241 | 239 |
(...skipping 14 matching lines...) Expand all Loading... |
256 } | 254 } |
257 | 255 |
258 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { | 256 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { |
259 return base::Time::Now() < throttle_timeout_; | 257 return base::Time::Now() < throttle_timeout_; |
260 } | 258 } |
261 | 259 |
262 //////////////////////////////////////////////////////////////////////////////// | 260 //////////////////////////////////////////////////////////////////////////////// |
263 // DisplayController | 261 // DisplayController |
264 | 262 |
265 DisplayController::DisplayController() | 263 DisplayController::DisplayController() |
266 : primary_tree_host_for_replace_(NULL), | 264 : primary_tree_host_for_replace_(nullptr), |
267 focus_activation_store_(new FocusActivationStore()), | 265 focus_activation_store_(new FocusActivationStore()), |
268 cursor_window_controller_(new CursorWindowController()), | 266 cursor_window_controller_(new CursorWindowController()), |
269 mirror_window_controller_(new MirrorWindowController()), | 267 mirror_window_controller_(new MirrorWindowController()), |
270 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), | 268 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), |
271 weak_ptr_factory_(this) { | 269 weak_ptr_factory_(this) { |
272 #if defined(OS_CHROMEOS) | 270 #if defined(OS_CHROMEOS) |
273 if (base::SysInfo::IsRunningOnChromeOS()) | 271 if (base::SysInfo::IsRunningOnChromeOS()) |
274 limiter_.reset(new DisplayChangeLimiter); | 272 limiter_.reset(new DisplayChangeLimiter); |
275 #endif | 273 #endif |
276 // Reset primary display to make sure that tests don't use | 274 // Reset primary display to make sure that tests don't use |
277 // stale display info from previous tests. | 275 // stale display info from previous tests. |
278 primary_display_id = gfx::Display::kInvalidDisplayID; | 276 primary_display_id = gfx::Display::kInvalidDisplayID; |
279 } | 277 } |
280 | 278 |
281 DisplayController::~DisplayController() { | 279 DisplayController::~DisplayController() { |
282 } | 280 } |
283 | 281 |
284 void DisplayController::Start() { | 282 void DisplayController::Start() { |
285 Shell::GetScreen()->AddObserver(this); | 283 Shell::GetScreen()->AddObserver(this); |
286 Shell::GetInstance()->display_manager()->set_delegate(this); | 284 Shell::GetInstance()->display_manager()->set_delegate(this); |
287 } | 285 } |
288 | 286 |
289 void DisplayController::Shutdown() { | 287 void DisplayController::Shutdown() { |
290 // Unset the display manager's delegate here because | 288 // Unset the display manager's delegate here because |
291 // DisplayManager outlives DisplayController. | 289 // DisplayManager outlives DisplayController. |
292 Shell::GetInstance()->display_manager()->set_delegate(NULL); | 290 Shell::GetInstance()->display_manager()->set_delegate(nullptr); |
293 | 291 |
294 cursor_window_controller_.reset(); | 292 cursor_window_controller_.reset(); |
295 mirror_window_controller_.reset(); | 293 mirror_window_controller_.reset(); |
296 | 294 |
297 Shell::GetScreen()->RemoveObserver(this); | 295 Shell::GetScreen()->RemoveObserver(this); |
298 | 296 |
299 int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); | 297 int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); |
300 | 298 |
301 // Delete non primary root window controllers first, then | 299 // Delete non primary root window controllers first, then |
302 // delete the primary root window controller. | 300 // delete the primary root window controller. |
303 aura::Window::Windows root_windows = DisplayController::GetAllRootWindows(); | 301 aura::Window::Windows root_windows = DisplayController::GetAllRootWindows(); |
304 std::vector<RootWindowController*> to_delete; | 302 std::vector<RootWindowController*> to_delete; |
305 RootWindowController* primary_rwc = NULL; | 303 RootWindowController* primary_rwc = nullptr; |
306 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 304 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
307 iter != root_windows.end(); | 305 iter != root_windows.end(); |
308 ++iter) { | 306 ++iter) { |
309 RootWindowController* rwc = GetRootWindowController(*iter); | 307 RootWindowController* rwc = GetRootWindowController(*iter); |
310 if (GetRootWindowSettings(*iter)->display_id == primary_id) | 308 if (GetRootWindowSettings(*iter)->display_id == primary_id) |
311 primary_rwc = rwc; | 309 primary_rwc = rwc; |
312 else | 310 else |
313 to_delete.push_back(rwc); | 311 to_delete.push_back(rwc); |
314 } | 312 } |
315 CHECK(primary_rwc); | 313 CHECK(primary_rwc); |
316 | 314 |
317 STLDeleteElements(&to_delete); | 315 STLDeleteElements(&to_delete); |
318 delete primary_rwc; | 316 delete primary_rwc; |
319 } | 317 } |
320 | 318 |
321 void DisplayController::CreatePrimaryHost( | 319 void DisplayController::CreatePrimaryHost( |
322 const AshWindowTreeHostInitParams& init_params) { | 320 const AshWindowTreeHostInitParams& init_params) { |
323 const gfx::Display& primary_candidate = | 321 const gfx::Display& primary_candidate = |
324 GetDisplayManager()->GetPrimaryDisplayCandidate(); | 322 GetDisplayManager()->GetPrimaryDisplayCandidate(); |
325 primary_display_id = primary_candidate.id(); | 323 primary_display_id = primary_candidate.id(); |
326 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); | 324 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); |
327 AddWindowTreeHostForDisplay(primary_candidate, init_params); | 325 AddWindowTreeHostForDisplay(primary_candidate, init_params); |
328 } | 326 } |
329 | 327 |
330 void DisplayController::InitDisplays() { | 328 void DisplayController::InitDisplays() { |
331 RootWindowController::CreateForPrimaryDisplay( | 329 RootWindowController::CreateForPrimaryDisplay( |
332 window_tree_hosts_[primary_display_id]); | 330 window_tree_hosts_[primary_display_id]); |
333 | |
334 DisplayManager* display_manager = GetDisplayManager(); | 331 DisplayManager* display_manager = GetDisplayManager(); |
335 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 332 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
336 const gfx::Display& display = display_manager->GetDisplayAt(i); | 333 const gfx::Display& display = display_manager->GetDisplayAt(i); |
337 if (primary_display_id != display.id()) { | 334 if (primary_display_id != display.id()) { |
338 AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay( | 335 AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay( |
339 display, AshWindowTreeHostInitParams()); | 336 display, AshWindowTreeHostInitParams()); |
340 RootWindowController::CreateForSecondaryDisplay(ash_host); | 337 RootWindowController::CreateForSecondaryDisplay(ash_host); |
341 } | 338 } |
342 } | 339 } |
343 | 340 |
(...skipping 12 matching lines...) Expand all Loading... |
356 int64 DisplayController::GetPrimaryDisplayId() { | 353 int64 DisplayController::GetPrimaryDisplayId() { |
357 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); | 354 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); |
358 return primary_display_id; | 355 return primary_display_id; |
359 } | 356 } |
360 | 357 |
361 aura::Window* DisplayController::GetPrimaryRootWindow() { | 358 aura::Window* DisplayController::GetPrimaryRootWindow() { |
362 return GetRootWindowForDisplayId(primary_display_id); | 359 return GetRootWindowForDisplayId(primary_display_id); |
363 } | 360 } |
364 | 361 |
365 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { | 362 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { |
366 CHECK_EQ(1u, window_tree_hosts_.count(id)); | 363 AshWindowTreeHost* host = GetAshWindowTreeHostForDisplayId(id); |
367 AshWindowTreeHost* host = window_tree_hosts_[id]; | |
368 CHECK(host); | 364 CHECK(host); |
369 return GetWindow(host); | 365 return GetWindow(host); |
370 } | 366 } |
371 | 367 |
| 368 AshWindowTreeHost* DisplayController::GetAshWindowTreeHostForDisplayId( |
| 369 int64 id) { |
| 370 CHECK_EQ(1u, window_tree_hosts_.count(id)); |
| 371 return window_tree_hosts_[id]; |
| 372 } |
| 373 |
372 void DisplayController::CloseChildWindows() { | 374 void DisplayController::CloseChildWindows() { |
373 for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); | 375 for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); |
374 it != window_tree_hosts_.end(); | 376 it != window_tree_hosts_.end(); |
375 ++it) { | 377 ++it) { |
376 aura::Window* root_window = GetWindow(it->second); | 378 aura::Window* root_window = GetWindow(it->second); |
377 RootWindowController* controller = GetRootWindowController(root_window); | 379 RootWindowController* controller = GetRootWindowController(root_window); |
378 if (controller) { | 380 if (controller) { |
379 controller->CloseChildWindows(); | 381 controller->CloseChildWindows(); |
380 } else { | 382 } else { |
381 while (!root_window->children().empty()) { | 383 while (!root_window->children().empty()) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 void DisplayController::UpdateMouseLocationAfterDisplayChange() { | 541 void DisplayController::UpdateMouseLocationAfterDisplayChange() { |
540 // If the mouse is currently on a display in native location, | 542 // If the mouse is currently on a display in native location, |
541 // use the same native location. Otherwise find the display closest | 543 // use the same native location. Otherwise find the display closest |
542 // to the current cursor location in screen coordinates. | 544 // to the current cursor location in screen coordinates. |
543 | 545 |
544 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 546 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); |
545 gfx::Point target_location_in_native; | 547 gfx::Point target_location_in_native; |
546 int64 closest_distance_squared = -1; | 548 int64 closest_distance_squared = -1; |
547 DisplayManager* display_manager = GetDisplayManager(); | 549 DisplayManager* display_manager = GetDisplayManager(); |
548 | 550 |
549 aura::Window* dst_root_window = NULL; | 551 aura::Window* dst_root_window = nullptr; |
550 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 552 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
551 const gfx::Display& display = display_manager->GetDisplayAt(i); | 553 const gfx::Display& display = display_manager->GetDisplayAt(i); |
552 const DisplayInfo display_info = | 554 const DisplayInfo display_info = |
553 display_manager->GetDisplayInfo(display.id()); | 555 display_manager->GetDisplayInfo(display.id()); |
554 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 556 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
555 if (display_info.bounds_in_native().Contains( | 557 if (display_info.bounds_in_native().Contains( |
556 cursor_location_in_native_coords_for_restore_)) { | 558 cursor_location_in_native_coords_for_restore_)) { |
557 dst_root_window = root_window; | 559 dst_root_window = root_window; |
558 target_location_in_native = cursor_location_in_native_coords_for_restore_; | 560 target_location_in_native = cursor_location_in_native_coords_for_restore_; |
559 break; | 561 break; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 const aura::Window* window, | 624 const aura::Window* window, |
623 const gfx::Insets& insets) { | 625 const gfx::Insets& insets) { |
624 const aura::Window* root_window = window->GetRootWindow(); | 626 const aura::Window* root_window = window->GetRootWindow(); |
625 int64 id = GetRootWindowSettings(root_window)->display_id; | 627 int64 id = GetRootWindowSettings(root_window)->display_id; |
626 // if id is |kInvaildDisplayID|, it's being deleted. | 628 // if id is |kInvaildDisplayID|, it's being deleted. |
627 DCHECK(id != gfx::Display::kInvalidDisplayID); | 629 DCHECK(id != gfx::Display::kInvalidDisplayID); |
628 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 630 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
629 } | 631 } |
630 | 632 |
631 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 633 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
632 if (primary_tree_host_for_replace_) { | 634 if (GetDisplayManager()->IsInUnifiedMode()) { |
| 635 if (primary_display_id == gfx::Display::kInvalidDisplayID) |
| 636 primary_display_id = display.id(); |
| 637 AshWindowTreeHost* ash_host = |
| 638 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
| 639 RootWindowController::CreateForSecondaryDisplay(ash_host); |
| 640 |
| 641 if (primary_tree_host_for_replace_) { |
| 642 AshWindowTreeHost* to_delete = primary_tree_host_for_replace_; |
| 643 primary_tree_host_for_replace_ = nullptr; |
| 644 DeleteHost(to_delete); |
| 645 // the host has already been removed from the window_tree_host_. |
| 646 } |
| 647 } |
| 648 // TODO(oshima): It should be possible to consolidate logic for |
| 649 // unified and non unified, but I'm keeping them separated to minimize |
| 650 // the risk in M44. I'll consolidate this in M45. |
| 651 else if (primary_tree_host_for_replace_) { |
633 DCHECK(window_tree_hosts_.empty()); | 652 DCHECK(window_tree_hosts_.empty()); |
634 primary_display_id = display.id(); | 653 primary_display_id = display.id(); |
635 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; | 654 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
636 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 655 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
637 ->display_id = display.id(); | 656 ->display_id = display.id(); |
638 primary_tree_host_for_replace_ = NULL; | 657 primary_tree_host_for_replace_ = nullptr; |
639 const DisplayInfo& display_info = | 658 const DisplayInfo& display_info = |
640 GetDisplayManager()->GetDisplayInfo(display.id()); | 659 GetDisplayManager()->GetDisplayInfo(display.id()); |
641 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 660 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
642 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 661 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
643 SetDisplayPropertiesOnHost(ash_host, display); | 662 SetDisplayPropertiesOnHost(ash_host, display); |
644 } else { | 663 } else { |
645 if (primary_display_id == gfx::Display::kInvalidDisplayID) | 664 if (primary_display_id == gfx::Display::kInvalidDisplayID) |
646 primary_display_id = display.id(); | 665 primary_display_id = display.id(); |
647 DCHECK(!window_tree_hosts_.empty()); | 666 DCHECK(!window_tree_hosts_.empty()); |
648 AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay( | 667 AshWindowTreeHost* ash_host = |
649 display, AshWindowTreeHostInitParams()); | 668 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
650 RootWindowController::CreateForSecondaryDisplay(ash_host); | 669 RootWindowController::CreateForSecondaryDisplay(ash_host); |
651 } | 670 } |
652 } | 671 } |
653 | 672 |
| 673 void DisplayController::DeleteHost(AshWindowTreeHost* host_to_delete) { |
| 674 ClearDisplayPropertiesOnHost(host_to_delete); |
| 675 RootWindowController* controller = |
| 676 GetRootWindowController(GetWindow(host_to_delete)); |
| 677 DCHECK(controller); |
| 678 controller->MoveWindowsTo(GetPrimaryRootWindow()); |
| 679 // Delete most of root window related objects, but don't delete |
| 680 // root window itself yet because the stack may be using it. |
| 681 controller->Shutdown(); |
| 682 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); |
| 683 } |
| 684 |
654 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { | 685 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { |
655 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; | 686 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; |
656 CHECK(host_to_delete) << display.ToString(); | 687 CHECK(host_to_delete) << display.ToString(); |
657 | 688 |
658 // When the primary root window's display is removed, move the primary | 689 // When the primary root window's display is removed, move the primary |
659 // root to the other display. | 690 // root to the other display. |
660 if (primary_display_id == display.id()) { | 691 if (primary_display_id == display.id()) { |
661 // Temporarily store the primary root window in | 692 // Temporarily store the primary root window in |
662 // |primary_root_window_for_replace_| when replacing the display. | 693 // |primary_root_window_for_replace_| when replacing the display. |
663 if (window_tree_hosts_.size() == 1) { | 694 if (window_tree_hosts_.size() == 1) { |
(...skipping 19 matching lines...) Expand all Loading... |
683 | 714 |
684 // Setup primary root. | 715 // Setup primary root. |
685 window_tree_hosts_[primary_display_id] = primary_host; | 716 window_tree_hosts_[primary_display_id] = primary_host; |
686 GetRootWindowSettings(GetWindow(primary_host))->display_id = | 717 GetRootWindowSettings(GetWindow(primary_host))->display_id = |
687 primary_display_id; | 718 primary_display_id; |
688 | 719 |
689 OnDisplayMetricsChanged( | 720 OnDisplayMetricsChanged( |
690 GetDisplayManager()->GetDisplayForId(primary_display_id), | 721 GetDisplayManager()->GetDisplayForId(primary_display_id), |
691 DISPLAY_METRIC_BOUNDS); | 722 DISPLAY_METRIC_BOUNDS); |
692 } | 723 } |
693 ClearDisplayPropertiesOnHost(host_to_delete, display); | 724 |
694 RootWindowController* controller = | 725 DeleteHost(host_to_delete); |
695 GetRootWindowController(GetWindow(host_to_delete)); | |
696 DCHECK(controller); | |
697 controller->MoveWindowsTo(GetPrimaryRootWindow()); | |
698 // Delete most of root window related objects, but don't delete | |
699 // root window itself yet because the stack may be using it. | |
700 controller->Shutdown(); | |
701 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); | |
702 | 726 |
703 // The window tree host should be erased at last because some handlers can | 727 // The window tree host should be erased at last because some handlers can |
704 // access to the host through GetRootWindowForDisplayId() during | 728 // access to the host through GetRootWindowForDisplayId() during |
705 // MoveWindowsTo(). See http://crbug.com/415222 | 729 // MoveWindowsTo(). See http://crbug.com/415222 |
706 window_tree_hosts_.erase(display.id()); | 730 window_tree_hosts_.erase(display.id()); |
707 } | 731 } |
708 | 732 |
709 void DisplayController::OnDisplayMetricsChanged(const gfx::Display& display, | 733 void DisplayController::OnDisplayMetricsChanged(const gfx::Display& display, |
710 uint32_t metrics) { | 734 uint32_t metrics) { |
711 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | | 735 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | |
(...skipping 12 matching lines...) Expand all Loading... |
724 const_cast<aura::Window*>(host->window())); | 748 const_cast<aura::Window*>(host->window())); |
725 | 749 |
726 DisplayManager* display_manager = GetDisplayManager(); | 750 DisplayManager* display_manager = GetDisplayManager(); |
727 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { | 751 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { |
728 mirror_window_controller_->UpdateWindow(); | 752 mirror_window_controller_->UpdateWindow(); |
729 cursor_window_controller_->UpdateContainer(); | 753 cursor_window_controller_->UpdateContainer(); |
730 } | 754 } |
731 } | 755 } |
732 | 756 |
733 void DisplayController::CreateOrUpdateMirroringDisplay( | 757 void DisplayController::CreateOrUpdateMirroringDisplay( |
734 const DisplayInfo& info) { | 758 const DisplayInfoList& info_list) { |
735 switch (GetDisplayManager()->second_display_mode()) { | 759 switch (GetDisplayManager()->multi_display_mode()) { |
736 case DisplayManager::MIRRORING: | 760 case DisplayManager::MIRRORING: |
737 mirror_window_controller_->UpdateWindow(info); | 761 case DisplayManager::UNIFIED: |
| 762 mirror_window_controller_->UpdateWindow(info_list); |
738 cursor_window_controller_->UpdateContainer(); | 763 cursor_window_controller_->UpdateContainer(); |
739 break; | 764 break; |
740 case DisplayManager::EXTENDED: | 765 case DisplayManager::EXTENDED: |
741 NOTREACHED(); | 766 NOTREACHED(); |
742 } | 767 } |
743 } | 768 } |
744 | 769 |
745 void DisplayController::CloseMirroringDisplay() { | 770 void DisplayController::CloseMirroringDisplay() { |
746 mirror_window_controller_->Close(); | 771 mirror_window_controller_->Close(); |
747 // If cursor_compositing is enabled for large cursor, the cursor window is | 772 // If cursor_compositing is enabled for large cursor, the cursor window is |
(...skipping 25 matching lines...) Expand all Loading... |
773 if (limiter_) | 798 if (limiter_) |
774 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 799 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
775 | 800 |
776 focus_activation_store_->Restore(); | 801 focus_activation_store_->Restore(); |
777 | 802 |
778 DisplayManager* display_manager = GetDisplayManager(); | 803 DisplayManager* display_manager = GetDisplayManager(); |
779 DisplayLayoutStore* layout_store = display_manager->layout_store(); | 804 DisplayLayoutStore* layout_store = display_manager->layout_store(); |
780 if (display_manager->num_connected_displays() > 1) { | 805 if (display_manager->num_connected_displays() > 1) { |
781 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); | 806 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
782 layout_store->UpdateMirrorStatus(pair, display_manager->IsInMirrorMode()); | 807 layout_store->UpdateMirrorStatus(pair, display_manager->IsInMirrorMode()); |
783 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); | |
784 | 808 |
785 if (Shell::GetScreen()->GetNumDisplays() > 1 ) { | 809 if (Shell::GetScreen()->GetNumDisplays() > 1 ) { |
| 810 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); |
786 int64 primary_id = layout.primary_id; | 811 int64 primary_id = layout.primary_id; |
787 SetPrimaryDisplayId( | 812 SetPrimaryDisplayId( |
788 primary_id == gfx::Display::kInvalidDisplayID ? | 813 primary_id == gfx::Display::kInvalidDisplayID ? |
789 pair.first : primary_id); | 814 pair.first : primary_id); |
790 // Update the primary_id in case the above call is | 815 // Update the primary_id in case the above call is |
791 // ignored. Happens when a) default layout's primary id | 816 // ignored. Happens when a) default layout's primary id |
792 // doesn't exist, or b) the primary_id has already been | 817 // doesn't exist, or b) the primary_id has already been |
793 // set to the same and didn't update it. | 818 // set to the same and didn't update it. |
794 layout_store->UpdatePrimaryDisplayId( | 819 layout_store->UpdatePrimaryDisplayId( |
795 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); | 820 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); |
796 } | 821 } |
797 } | 822 } |
798 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 823 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
799 UpdateMouseLocationAfterDisplayChange(); | 824 UpdateMouseLocationAfterDisplayChange(); |
800 } | 825 } |
801 | 826 |
802 AshWindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( | 827 AshWindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( |
803 const gfx::Display& display, | 828 const gfx::Display& display, |
804 const AshWindowTreeHostInitParams& init_params) { | 829 const AshWindowTreeHostInitParams& init_params) { |
805 static int host_count = 0; | 830 static int host_count = 0; |
806 const DisplayInfo& display_info = | 831 const DisplayInfo& display_info = |
807 GetDisplayManager()->GetDisplayInfo(display.id()); | 832 GetDisplayManager()->GetDisplayInfo(display.id()); |
808 AshWindowTreeHostInitParams params_with_bounds(init_params); | 833 AshWindowTreeHostInitParams params_with_bounds(init_params); |
809 params_with_bounds.initial_bounds = display_info.bounds_in_native(); | 834 params_with_bounds.initial_bounds = display_info.bounds_in_native(); |
| 835 params_with_bounds.offscreen = |
| 836 display.id() == DisplayManager::kUnifiedDisplayId; |
810 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); | 837 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); |
811 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 838 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
812 | 839 |
813 host->window()->SetName(base::StringPrintf("RootWindow-%d", host_count++)); | 840 host->window()->SetName(base::StringPrintf( |
| 841 "%sRootWindow-%d", params_with_bounds.offscreen ? "Offscreen" : "", |
| 842 host_count++)); |
814 host->window()->SetTitle(base::UTF8ToUTF16(display_info.name())); | 843 host->window()->SetTitle(base::UTF8ToUTF16(display_info.name())); |
815 host->compositor()->SetBackgroundColor(SK_ColorBLACK); | 844 host->compositor()->SetBackgroundColor(SK_ColorBLACK); |
816 // No need to remove our observer observer because the DisplayController | 845 // No need to remove our observer observer because the DisplayController |
817 // outlives the host. | 846 // outlives the host. |
818 host->AddObserver(this); | 847 host->AddObserver(this); |
819 InitRootWindowSettings(host->window())->display_id = display.id(); | 848 InitRootWindowSettings(host->window())->display_id = display.id(); |
820 host->InitHost(); | 849 host->InitHost(); |
821 | 850 |
822 window_tree_hosts_[display.id()] = ash_host; | 851 window_tree_hosts_[display.id()] = ash_host; |
823 SetDisplayPropertiesOnHost(ash_host, display); | 852 SetDisplayPropertiesOnHost(ash_host, display); |
824 | 853 |
825 #if defined(OS_CHROMEOS) | 854 #if defined(OS_CHROMEOS) |
826 static bool force_constrain_pointer_to_root = | 855 if (switches::ConstrainPointerToRoot()) |
827 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
828 switches::kAshConstrainPointerToRoot); | |
829 if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) | |
830 ash_host->ConfineCursorToRootWindow(); | 856 ash_host->ConfineCursorToRootWindow(); |
831 #endif | 857 #endif |
832 return ash_host; | 858 return ash_host; |
833 } | 859 } |
834 | 860 |
835 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 861 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
836 #if defined(OS_CHROMEOS) | 862 #if defined(OS_CHROMEOS) |
837 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 863 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
838 Shell::GetInstance()->display_configurator_animation() | 864 Shell::GetInstance()->display_configurator_animation() |
839 ->StartFadeInAnimation(); | 865 ->StartFadeInAnimation(); |
840 #endif | 866 #endif |
841 } | 867 } |
842 | 868 |
843 void DisplayController::SetMirrorModeAfterAnimation(bool mirror) { | 869 void DisplayController::SetMirrorModeAfterAnimation(bool mirror) { |
844 GetDisplayManager()->SetMirrorMode(mirror); | 870 GetDisplayManager()->SetMirrorMode(mirror); |
845 } | 871 } |
846 | 872 |
847 } // namespace ash | 873 } // namespace ash |
OLD | NEW |