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

Side by Side Diff: ash/display/display_controller.cc

Issue 23496024: Introduce RootWindowProperty for RootWindow's properties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/ash.gyp ('k') | ash/display/mirror_window_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (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/display_layout_store.h" 12 #include "ash/display/display_layout_store.h"
13 #include "ash/display/display_manager.h" 13 #include "ash/display/display_manager.h"
14 #include "ash/display/mirror_window_controller.h" 14 #include "ash/display/mirror_window_controller.h"
15 #include "ash/display/root_window_transformers.h" 15 #include "ash/display/root_window_transformers.h"
16 #include "ash/host/root_window_host_factory.h" 16 #include "ash/host/root_window_host_factory.h"
17 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
18 #include "ash/root_window_settings.h"
18 #include "ash/screen_ash.h" 19 #include "ash/screen_ash.h"
19 #include "ash/shell.h" 20 #include "ash/shell.h"
20 #include "ash/wm/coordinate_conversion.h" 21 #include "ash/wm/coordinate_conversion.h"
21 #include "ash/wm/property_util.h" 22 #include "ash/wm/property_util.h"
22 #include "ash/wm/window_properties.h"
23 #include "ash/wm/window_util.h"
24 #include "base/command_line.h" 23 #include "base/command_line.h"
25 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
26 #include "third_party/skia/include/utils/SkMatrix44.h" 25 #include "third_party/skia/include/utils/SkMatrix44.h"
27 #include "ui/aura/client/activation_client.h" 26 #include "ui/aura/client/activation_client.h"
28 #include "ui/aura/client/capture_client.h" 27 #include "ui/aura/client/capture_client.h"
29 #include "ui/aura/client/cursor_client.h" 28 #include "ui/aura/client/cursor_client.h"
30 #include "ui/aura/client/focus_client.h" 29 #include "ui/aura/client/focus_client.h"
31 #include "ui/aura/client/screen_position_client.h" 30 #include "ui/aura/client/screen_position_client.h"
32 #include "ui/aura/root_window.h" 31 #include "ui/aura/root_window.h"
33 #include "ui/aura/root_window_transformer.h" 32 #include "ui/aura/root_window_transformer.h"
(...skipping 13 matching lines...) Expand all
47 #include "chromeos/display/output_configurator.h" 46 #include "chromeos/display/output_configurator.h"
48 #include "ui/base/x/x11_util.h" 47 #include "ui/base/x/x11_util.h"
49 48
50 // Including this at the bottom to avoid other 49 // Including this at the bottom to avoid other
51 // potential conflict with chrome headers. 50 // potential conflict with chrome headers.
52 #include <X11/extensions/Xrandr.h> 51 #include <X11/extensions/Xrandr.h>
53 #undef RootWindow 52 #undef RootWindow
54 #endif // defined(USE_X11) 53 #endif // defined(USE_X11)
55 #endif // defined(OS_CHROMEOS) 54 #endif // defined(OS_CHROMEOS)
56 55
57 DECLARE_WINDOW_PROPERTY_TYPE(int64);
58
59 namespace ash { 56 namespace ash {
60 namespace { 57 namespace {
61 58
62 // Primary display stored in global object as it can be 59 // Primary display stored in global object as it can be
63 // accessed after Shell is deleted. A separate display instance is created 60 // accessed after Shell is deleted. A separate display instance is created
64 // during the shutdown instead of always keeping two display instances 61 // during the shutdown instead of always keeping two display instances
65 // (one here and another one in display_manager) in sync, which is error prone. 62 // (one here and another one in display_manager) in sync, which is error prone.
66 int64 primary_display_id = gfx::Display::kInvalidDisplayID; 63 int64 primary_display_id = gfx::Display::kInvalidDisplayID;
67 gfx::Display* primary_display_for_shutdown = NULL; 64 gfx::Display* primary_display_for_shutdown = NULL;
68 // Keeps the number of displays during the shutdown after 65 // Keeps the number of displays during the shutdown after
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 #endif 123 #endif
127 scoped_ptr<aura::RootWindowTransformer> transformer( 124 scoped_ptr<aura::RootWindowTransformer> transformer(
128 internal::CreateRootWindowTransformerForDisplay(root, display)); 125 internal::CreateRootWindowTransformerForDisplay(root, display));
129 root->SetRootWindowTransformer(transformer.Pass()); 126 root->SetRootWindowTransformer(transformer.Pass());
130 } 127 }
131 128
132 } // namespace 129 } // namespace
133 130
134 namespace internal { 131 namespace internal {
135 132
136 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey,
137 gfx::Display::kInvalidDisplayID);
138
139 // A utility class to store/restore focused/active window 133 // A utility class to store/restore focused/active window
140 // when the display configuration has changed. 134 // when the display configuration has changed.
141 class FocusActivationStore { 135 class FocusActivationStore {
142 public: 136 public:
143 FocusActivationStore() 137 FocusActivationStore()
144 : activation_client_(NULL), 138 : activation_client_(NULL),
145 capture_client_(NULL), 139 capture_client_(NULL),
146 focus_client_(NULL), 140 focus_client_(NULL),
147 focused_(NULL), 141 focused_(NULL),
148 active_(NULL) { 142 active_(NULL) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return; 479 return;
486 480
487 gfx::Display old_primary_display = GetPrimaryDisplay(); 481 gfx::Display old_primary_display = GetPrimaryDisplay();
488 482
489 // Swap root windows between current and new primary display. 483 // Swap root windows between current and new primary display.
490 aura::RootWindow* primary_root = root_windows_[primary_display_id]; 484 aura::RootWindow* primary_root = root_windows_[primary_display_id];
491 DCHECK(primary_root); 485 DCHECK(primary_root);
492 DCHECK_NE(primary_root, non_primary_root); 486 DCHECK_NE(primary_root, non_primary_root);
493 487
494 root_windows_[new_primary_display.id()] = primary_root; 488 root_windows_[new_primary_display.id()] = primary_root;
495 primary_root->SetProperty(internal::kDisplayIdKey, new_primary_display.id()); 489 internal::GetRootWindowSettings(primary_root)->display_id =
490 new_primary_display.id();
496 491
497 root_windows_[old_primary_display.id()] = non_primary_root; 492 root_windows_[old_primary_display.id()] = non_primary_root;
498 non_primary_root->SetProperty(internal::kDisplayIdKey, 493 internal::GetRootWindowSettings(non_primary_root)->display_id =
499 old_primary_display.id()); 494 old_primary_display.id();
500 495
501 primary_display_id = new_primary_display.id(); 496 primary_display_id = new_primary_display.id();
502 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( 497 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId(
503 display_manager->GetCurrentDisplayIdPair(), primary_display_id); 498 display_manager->GetCurrentDisplayIdPair(), primary_display_id);
504 499
505 UpdateWorkAreaOfDisplayNearestWindow( 500 UpdateWorkAreaOfDisplayNearestWindow(
506 primary_root, old_primary_display.GetWorkAreaInsets()); 501 primary_root, old_primary_display.GetWorkAreaInsets());
507 UpdateWorkAreaOfDisplayNearestWindow( 502 UpdateWorkAreaOfDisplayNearestWindow(
508 non_primary_root, new_primary_display.GetWorkAreaInsets()); 503 non_primary_root, new_primary_display.GetWorkAreaInsets());
509 504
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 556 }
562 } 557 }
563 dst_root_window->ConvertPointFromNativeScreen(&target_location_in_native); 558 dst_root_window->ConvertPointFromNativeScreen(&target_location_in_native);
564 dst_root_window->MoveCursorTo(target_location_in_native); 559 dst_root_window->MoveCursorTo(target_location_in_native);
565 } 560 }
566 561
567 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( 562 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow(
568 const aura::Window* window, 563 const aura::Window* window,
569 const gfx::Insets& insets) { 564 const gfx::Insets& insets) {
570 const aura::RootWindow* root_window = window->GetRootWindow(); 565 const aura::RootWindow* root_window = window->GetRootWindow();
571 int64 id = root_window->GetProperty(internal::kDisplayIdKey); 566 int64 id = internal::GetRootWindowSettings(root_window)->display_id;
572 // if id is |kInvaildDisplayID|, it's being deleted. 567 // if id is |kInvaildDisplayID|, it's being deleted.
573 DCHECK(id != gfx::Display::kInvalidDisplayID); 568 DCHECK(id != gfx::Display::kInvalidDisplayID);
574 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); 569 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets);
575 } 570 }
576 571
577 const gfx::Display& DisplayController::GetDisplayNearestWindow( 572 const gfx::Display& DisplayController::GetDisplayNearestWindow(
578 const aura::Window* window) const { 573 const aura::Window* window) const {
579 if (!window) 574 if (!window)
580 return GetPrimaryDisplay(); 575 return GetPrimaryDisplay();
581 const aura::RootWindow* root_window = window->GetRootWindow(); 576 const aura::RootWindow* root_window = window->GetRootWindow();
582 if (!root_window) 577 if (!root_window)
583 return GetPrimaryDisplay(); 578 return GetPrimaryDisplay();
584 int64 id = root_window->GetProperty(internal::kDisplayIdKey); 579 int64 id = internal::GetRootWindowSettings(root_window)->display_id;
585 // if id is |kInvaildDisplayID|, it's being deleted. 580 // if id is |kInvaildDisplayID|, it's being deleted.
586 DCHECK(id != gfx::Display::kInvalidDisplayID); 581 DCHECK(id != gfx::Display::kInvalidDisplayID);
587 582
588 internal::DisplayManager* display_manager = GetDisplayManager(); 583 internal::DisplayManager* display_manager = GetDisplayManager();
589 // RootWindow needs Display to determine its device scale factor. 584 // RootWindow needs Display to determine its device scale factor.
590 // TODO(oshima): We don't need full display info for mirror 585 // TODO(oshima): We don't need full display info for mirror
591 // window. Refactor so that RootWindow doesn't use it. 586 // window. Refactor so that RootWindow doesn't use it.
592 if (display_manager->mirrored_display().id() == id) 587 if (display_manager->mirrored_display().id() == id)
593 return display_manager->mirrored_display(); 588 return display_manager->mirrored_display();
594 589
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 aura::RootWindow* root = root_windows_[display.id()]; 626 aura::RootWindow* root = root_windows_[display.id()];
632 root->SetHostBounds(display_info.bounds_in_pixel()); 627 root->SetHostBounds(display_info.bounds_in_pixel());
633 SetDisplayPropertiesOnHostWindow(root, display); 628 SetDisplayPropertiesOnHostWindow(root, display);
634 } 629 }
635 630
636 void DisplayController::OnDisplayAdded(const gfx::Display& display) { 631 void DisplayController::OnDisplayAdded(const gfx::Display& display) {
637 if (primary_root_window_for_replace_) { 632 if (primary_root_window_for_replace_) {
638 DCHECK(root_windows_.empty()); 633 DCHECK(root_windows_.empty());
639 primary_display_id = display.id(); 634 primary_display_id = display.id();
640 root_windows_[display.id()] = primary_root_window_for_replace_; 635 root_windows_[display.id()] = primary_root_window_for_replace_;
641 primary_root_window_for_replace_->SetProperty( 636 internal::GetRootWindowSettings(primary_root_window_for_replace_)->
642 internal::kDisplayIdKey, display.id()); 637 display_id = display.id();
643 primary_root_window_for_replace_ = NULL; 638 primary_root_window_for_replace_ = NULL;
644 const internal::DisplayInfo& display_info = 639 const internal::DisplayInfo& display_info =
645 GetDisplayManager()->GetDisplayInfo(display.id()); 640 GetDisplayManager()->GetDisplayInfo(display.id());
646 root_windows_[display.id()]->SetHostBounds( 641 root_windows_[display.id()]->SetHostBounds(
647 display_info.bounds_in_pixel()); 642 display_info.bounds_in_pixel());
648 } else { 643 } else {
649 if (primary_display_id == gfx::Display::kInvalidDisplayID) 644 if (primary_display_id == gfx::Display::kInvalidDisplayID)
650 primary_display_id = display.id(); 645 primary_display_id = display.id();
651 DCHECK(!root_windows_.empty()); 646 DCHECK(!root_windows_.empty());
652 aura::RootWindow* root = AddRootWindowForDisplay(display); 647 aura::RootWindow* root = AddRootWindowForDisplay(display);
(...skipping 18 matching lines...) Expand all
671 primary_display_id = gfx::Display::kInvalidDisplayID; 666 primary_display_id = gfx::Display::kInvalidDisplayID;
672 primary_root_window_for_replace_ = root_to_delete; 667 primary_root_window_for_replace_ = root_to_delete;
673 return; 668 return;
674 } 669 }
675 DCHECK_EQ(1U, root_windows_.size()); 670 DCHECK_EQ(1U, root_windows_.size());
676 primary_display_id = ScreenAsh::GetSecondaryDisplay().id(); 671 primary_display_id = ScreenAsh::GetSecondaryDisplay().id();
677 aura::RootWindow* primary_root = root_to_delete; 672 aura::RootWindow* primary_root = root_to_delete;
678 673
679 // Delete the other root instead. 674 // Delete the other root instead.
680 root_to_delete = root_windows_[primary_display_id]; 675 root_to_delete = root_windows_[primary_display_id];
681 root_to_delete->SetProperty(internal::kDisplayIdKey, display.id()); 676 internal::GetRootWindowSettings(root_to_delete)->display_id = display.id();
682 677
683 // Setup primary root. 678 // Setup primary root.
684 root_windows_[primary_display_id] = primary_root; 679 root_windows_[primary_display_id] = primary_root;
685 primary_root->SetProperty(internal::kDisplayIdKey, primary_display_id); 680 internal::GetRootWindowSettings(primary_root)->display_id =
681 primary_display_id;
686 682
687 OnDisplayBoundsChanged( 683 OnDisplayBoundsChanged(
688 GetDisplayManager()->GetDisplayForId(primary_display_id)); 684 GetDisplayManager()->GetDisplayForId(primary_display_id));
689 } 685 }
690 internal::RootWindowController* controller = 686 internal::RootWindowController* controller =
691 GetRootWindowController(root_to_delete); 687 GetRootWindowController(root_to_delete);
692 DCHECK(controller); 688 DCHECK(controller);
693 controller->MoveWindowsTo(GetPrimaryRootWindow()); 689 controller->MoveWindowsTo(GetPrimaryRootWindow());
694 // Delete most of root window related objects, but don't delete 690 // Delete most of root window related objects, but don't delete
695 // root window itself yet because the stack may be using it. 691 // root window itself yet because the stack may be using it.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 aura::RootWindow::CreateParams params(bounds_in_pixel); 767 aura::RootWindow::CreateParams params(bounds_in_pixel);
772 params.host = Shell::GetInstance()->root_window_host_factory()-> 768 params.host = Shell::GetInstance()->root_window_host_factory()->
773 CreateRootWindowHost(bounds_in_pixel); 769 CreateRootWindowHost(bounds_in_pixel);
774 aura::RootWindow* root_window = new aura::RootWindow(params); 770 aura::RootWindow* root_window = new aura::RootWindow(params);
775 root_window->SetName( 771 root_window->SetName(
776 base::StringPrintf("RootWindow-%d", root_window_count++)); 772 base::StringPrintf("RootWindow-%d", root_window_count++));
777 root_window->compositor()->SetBackgroundColor(SK_ColorBLACK); 773 root_window->compositor()->SetBackgroundColor(SK_ColorBLACK);
778 // No need to remove RootWindowObserver because 774 // No need to remove RootWindowObserver because
779 // the DisplayController object outlives RootWindow objects. 775 // the DisplayController object outlives RootWindow objects.
780 root_window->AddRootWindowObserver(this); 776 root_window->AddRootWindowObserver(this);
781 root_window->SetProperty(internal::kDisplayIdKey, display.id()); 777 internal::InitRootWindowSettings(root_window)->display_id = display.id();
782 root_window->Init(); 778 root_window->Init();
783 779
784 root_windows_[display.id()] = root_window; 780 root_windows_[display.id()] = root_window;
785 SetDisplayPropertiesOnHostWindow(root_window, display); 781 SetDisplayPropertiesOnHostWindow(root_window, display);
786 782
787 #if defined(OS_CHROMEOS) 783 #if defined(OS_CHROMEOS)
788 static bool force_constrain_pointer_to_root = 784 static bool force_constrain_pointer_to_root =
789 CommandLine::ForCurrentProcess()->HasSwitch( 785 CommandLine::ForCurrentProcess()->HasSwitch(
790 switches::kAshConstrainPointerToRoot); 786 switches::kAshConstrainPointerToRoot);
791 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) 787 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 for (size_t i = 0; i < root_windows.size(); ++i) { 821 for (size_t i = 0; i < root_windows.size(); ++i) {
826 std::string name = 822 std::string name =
827 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; 823 root_windows[i] == primary ? "aura_root_0" : "aura_root_x";
828 gfx::AcceleratedWidget xwindow = root_windows[i]->GetAcceleratedWidget(); 824 gfx::AcceleratedWidget xwindow = root_windows[i]->GetAcceleratedWidget();
829 XStoreName(ui::GetXDisplay(), xwindow, name.c_str()); 825 XStoreName(ui::GetXDisplay(), xwindow, name.c_str());
830 } 826 }
831 #endif 827 #endif
832 } 828 }
833 829
834 } // namespace ash 830 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash.gyp ('k') | ash/display/mirror_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698