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 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
12 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/wm/coordinate_conversion.h" | 14 #include "ash/wm/coordinate_conversion.h" |
15 #include "ash/wm/property_util.h" | 15 #include "ash/wm/property_util.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/json/json_value_converter.h" | 18 #include "base/json/json_value_converter.h" |
19 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "ui/aura/client/screen_position_client.h" | 22 #include "ui/aura/client/screen_position_client.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_property.h" |
26 #include "ui/compositor/dip_util.h" | 27 #include "ui/compositor/dip_util.h" |
27 #include "ui/gfx/display.h" | 28 #include "ui/gfx/display.h" |
28 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
29 | 30 |
30 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
31 #include "ash/display/output_configurator_animation.h" | 32 #include "ash/display/output_configurator_animation.h" |
32 #include "base/chromeos/chromeos_version.h" | 33 #include "base/chromeos/chromeos_version.h" |
33 #include "base/string_number_conversions.h" | 34 #include "base/string_number_conversions.h" |
34 #include "base/time.h" | 35 #include "base/time.h" |
35 #include "chromeos/display/output_configurator.h" | 36 #include "chromeos/display/output_configurator.h" |
36 #include "ui/base/x/x11_util.h" | 37 #include "ui/base/x/x11_util.h" |
37 #endif // defined(OS_CHROMEOS) | 38 #endif // defined(OS_CHROMEOS) |
38 | 39 |
| 40 DECLARE_WINDOW_PROPERTY_TYPE(ash::internal::DisplayInfo::Rotation); |
39 | 41 |
40 namespace ash { | 42 namespace ash { |
41 namespace { | 43 namespace { |
42 | 44 |
| 45 DEFINE_WINDOW_PROPERTY_KEY(internal::DisplayInfo::Rotation, kRotationKey, |
| 46 internal::DisplayInfo::ROTATE_0); |
| 47 |
43 // Primary display stored in global object as it can be | 48 // Primary display stored in global object as it can be |
44 // accessed after Shell is deleted. A separate display instance is created | 49 // accessed after Shell is deleted. A separate display instance is created |
45 // during the shutdown instead of always keeping two display instances | 50 // during the shutdown instead of always keeping two display instances |
46 // (one here and another one in display_manager) in sync, which is error prone. | 51 // (one here and another one in display_manager) in sync, which is error prone. |
47 int64 primary_display_id = gfx::Display::kInvalidDisplayID; | 52 int64 primary_display_id = gfx::Display::kInvalidDisplayID; |
48 gfx::Display* primary_display_for_shutdown = NULL; | 53 gfx::Display* primary_display_for_shutdown = NULL; |
49 // Keeps the number of displays during the shutdown after | 54 // Keeps the number of displays during the shutdown after |
50 // ash::Shell:: is deleted. | 55 // ash::Shell:: is deleted. |
51 int num_displays_for_shutdown = -1; | 56 int num_displays_for_shutdown = -1; |
52 | 57 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 case DisplayLayout::LEFT: | 103 case DisplayLayout::LEFT: |
99 return std::string("left"); | 104 return std::string("left"); |
100 } | 105 } |
101 return std::string("unknown"); | 106 return std::string("unknown"); |
102 } | 107 } |
103 | 108 |
104 internal::DisplayManager* GetDisplayManager() { | 109 internal::DisplayManager* GetDisplayManager() { |
105 return Shell::GetInstance()->display_manager(); | 110 return Shell::GetInstance()->display_manager(); |
106 } | 111 } |
107 | 112 |
| 113 void RotateRootWindow(aura::RootWindow* root_window, |
| 114 const gfx::Display& display, |
| 115 const internal::DisplayInfo& info) { |
| 116 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) |
| 117 #if defined(OS_WIN) |
| 118 // Windows 8 bots refused to resize the host window, and |
| 119 // updating the transform results in incorrectly resizing |
| 120 // the root window. Don't apply the transform unless |
| 121 // necessary so that unit tests pass on win8 bots. |
| 122 if (info.rotation() == root_window->GetProperty(kRotationKey)) |
| 123 return; |
| 124 root_window->SetProperty(kRotationKey, info.rotation()); |
| 125 #endif |
| 126 gfx::Transform rotate; |
| 127 switch (info.rotation()) { |
| 128 case internal::DisplayInfo::ROTATE_0: |
| 129 break; |
| 130 case internal::DisplayInfo::ROTATE_90: |
| 131 rotate.Translate(display.bounds().height(), 0); |
| 132 rotate.Rotate(90); |
| 133 break; |
| 134 case internal::DisplayInfo::ROTATE_270: |
| 135 rotate.Translate(0, display.bounds().width()); |
| 136 rotate.Rotate(270); |
| 137 break; |
| 138 case internal::DisplayInfo::ROTATE_180: |
| 139 rotate.Translate(display.bounds().width(), display.bounds().height()); |
| 140 rotate.Rotate(180); |
| 141 break; |
| 142 } |
| 143 root_window->SetTransform(rotate); |
| 144 } |
| 145 |
108 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, | 146 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, |
109 const gfx::Display& display) { | 147 const gfx::Display& display) { |
| 148 internal::DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display); |
110 #if defined(OS_CHROMEOS) | 149 #if defined(OS_CHROMEOS) |
111 // Native window property (Atom in X11) that specifies the display's | 150 // Native window property (Atom in X11) that specifies the display's |
112 // rotation and scale factor. They are read and used by | 151 // rotation and scale factor. They are read and used by |
113 // touchpad/mouse driver directly on X (contact adlr@ for more | 152 // touchpad/mouse driver directly on X (contact adlr@ for more |
114 // details on touchpad/mouse driver side). The value of the rotation | 153 // details on touchpad/mouse driver side). The value of the rotation |
115 // is one of 0 (normal), 1 (90 degrees clockwise), 2 (180 degree) or | 154 // is one of 0 (normal), 1 (90 degrees clockwise), 2 (180 degree) or |
116 // 3 (270 degrees clockwise). The value of the scale factor is in | 155 // 3 (270 degrees clockwise). The value of the scale factor is in |
117 // percent (100, 140, 200 etc). | 156 // percent (100, 140, 200 etc). |
118 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; | 157 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; |
119 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; | 158 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; |
120 const char kCARDINAL[] = "CARDINAL"; | 159 const char kCARDINAL[] = "CARDINAL"; |
121 | 160 |
122 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 161 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
123 int rotation = 0; | 162 int rotation = static_cast<int>(info.rotation()); |
124 if (command_line->HasSwitch(switches::kAshOverrideDisplayOrientation)) { | 163 if (command_line->HasSwitch(switches::kAshOverrideDisplayOrientation)) { |
125 std::string value = command_line-> | 164 std::string value = command_line-> |
126 GetSwitchValueASCII(switches::kAshOverrideDisplayOrientation); | 165 GetSwitchValueASCII(switches::kAshOverrideDisplayOrientation); |
127 DCHECK(base::StringToInt(value, &rotation)); | 166 DCHECK(base::StringToInt(value, &rotation)); |
128 DCHECK(0 <= rotation && rotation <= 3) << "Invalid rotation value=" | 167 DCHECK(0 <= rotation && rotation <= 3) << "Invalid rotation value=" |
129 << rotation; | 168 << rotation; |
130 if (rotation < 0 || rotation > 3) | 169 if (rotation < 0 || rotation > 3) |
131 rotation = 0; | 170 rotation = 0; |
132 } | 171 } |
133 gfx::AcceleratedWidget xwindow = root->GetAcceleratedWidget(); | 172 gfx::AcceleratedWidget xwindow = root->GetAcceleratedWidget(); |
134 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, rotation); | 173 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, rotation); |
135 ui::SetIntProperty(xwindow, | 174 ui::SetIntProperty(xwindow, |
136 kScaleFactorProp, | 175 kScaleFactorProp, |
137 kCARDINAL, | 176 kCARDINAL, |
138 100 * display.device_scale_factor()); | 177 100 * display.device_scale_factor()); |
139 #endif | 178 #endif |
| 179 RotateRootWindow(root, display, info); |
140 } | 180 } |
141 | 181 |
142 } // namespace | 182 } // namespace |
143 | 183 |
144 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
145 // DisplayLayout | 185 // DisplayLayout |
146 | 186 |
147 DisplayLayout::DisplayLayout() | 187 DisplayLayout::DisplayLayout() |
148 : position(RIGHT), | 188 : position(RIGHT), |
149 offset(0) {} | 189 offset(0) {} |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { | 270 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { |
231 return base::Time::Now() < throttle_timeout_; | 271 return base::Time::Now() < throttle_timeout_; |
232 } | 272 } |
233 | 273 |
234 //////////////////////////////////////////////////////////////////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// |
235 // DisplayController | 275 // DisplayController |
236 | 276 |
237 DisplayController::DisplayController() | 277 DisplayController::DisplayController() |
238 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID), | 278 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID), |
239 primary_root_window_for_replace_(NULL) { | 279 primary_root_window_for_replace_(NULL) { |
| 280 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
240 #if defined(OS_CHROMEOS) | 281 #if defined(OS_CHROMEOS) |
241 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
242 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && | 282 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && |
243 base::chromeos::IsRunningOnChromeOS()) | 283 base::chromeos::IsRunningOnChromeOS()) |
244 limiter_.reset(new DisplayChangeLimiter); | 284 limiter_.reset(new DisplayChangeLimiter); |
245 #endif | 285 #endif |
| 286 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { |
| 287 std::string value = command_line->GetSwitchValueASCII( |
| 288 switches::kAshSecondaryDisplayLayout); |
| 289 char layout; |
| 290 int offset = 0; |
| 291 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { |
| 292 if (layout == 't') |
| 293 default_display_layout_.position = DisplayLayout::TOP; |
| 294 else if (layout == 'b') |
| 295 default_display_layout_.position = DisplayLayout::BOTTOM; |
| 296 else if (layout == 'r') |
| 297 default_display_layout_.position = DisplayLayout::RIGHT; |
| 298 else if (layout == 'l') |
| 299 default_display_layout_.position = DisplayLayout::LEFT; |
| 300 default_display_layout_.offset = offset; |
| 301 } |
| 302 } |
246 // Reset primary display to make sure that tests don't use | 303 // Reset primary display to make sure that tests don't use |
247 // stale display info from previous tests. | 304 // stale display info from previous tests. |
248 primary_display_id = gfx::Display::kInvalidDisplayID; | 305 primary_display_id = gfx::Display::kInvalidDisplayID; |
249 delete primary_display_for_shutdown; | 306 delete primary_display_for_shutdown; |
250 primary_display_for_shutdown = NULL; | 307 primary_display_for_shutdown = NULL; |
251 num_displays_for_shutdown = -1; | 308 num_displays_for_shutdown = -1; |
252 | 309 |
253 Shell::GetScreen()->AddObserver(this); | 310 Shell::GetScreen()->AddObserver(this); |
254 } | 311 } |
255 | 312 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 362 |
306 void DisplayController::InitSecondaryDisplays() { | 363 void DisplayController::InitSecondaryDisplays() { |
307 internal::DisplayManager* display_manager = GetDisplayManager(); | 364 internal::DisplayManager* display_manager = GetDisplayManager(); |
308 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 365 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
309 const gfx::Display* display = display_manager->GetDisplayAt(i); | 366 const gfx::Display* display = display_manager->GetDisplayAt(i); |
310 if (primary_display_id != display->id()) { | 367 if (primary_display_id != display->id()) { |
311 aura::RootWindow* root = AddRootWindowForDisplay(*display); | 368 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
312 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 369 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
313 } | 370 } |
314 } | 371 } |
315 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
316 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { | |
317 std::string value = command_line->GetSwitchValueASCII( | |
318 switches::kAshSecondaryDisplayLayout); | |
319 char layout; | |
320 int offset; | |
321 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { | |
322 if (layout == 't') | |
323 default_display_layout_.position = DisplayLayout::TOP; | |
324 else if (layout == 'b') | |
325 default_display_layout_.position = DisplayLayout::BOTTOM; | |
326 else if (layout == 'r') | |
327 default_display_layout_.position = DisplayLayout::RIGHT; | |
328 else if (layout == 'l') | |
329 default_display_layout_.position = DisplayLayout::LEFT; | |
330 default_display_layout_.offset = offset; | |
331 } | |
332 } | |
333 UpdateDisplayBoundsForLayout(); | 372 UpdateDisplayBoundsForLayout(); |
334 } | 373 } |
335 | 374 |
336 void DisplayController::AddObserver(Observer* observer) { | 375 void DisplayController::AddObserver(Observer* observer) { |
337 observers_.AddObserver(observer); | 376 observers_.AddObserver(observer); |
338 } | 377 } |
339 | 378 |
340 void DisplayController::RemoveObserver(Observer* observer) { | 379 void DisplayController::RemoveObserver(Observer* observer) { |
341 observers_.RemoveObserver(observer); | 380 observers_.RemoveObserver(observer); |
342 } | 381 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 gfx::Display* DisplayController::GetSecondaryDisplay() { | 640 gfx::Display* DisplayController::GetSecondaryDisplay() { |
602 internal::DisplayManager* display_manager = GetDisplayManager(); | 641 internal::DisplayManager* display_manager = GetDisplayManager(); |
603 CHECK_EQ(2U, display_manager->GetNumDisplays()); | 642 CHECK_EQ(2U, display_manager->GetNumDisplays()); |
604 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? | 643 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? |
605 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); | 644 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); |
606 } | 645 } |
607 | 646 |
608 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 647 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
609 if (limiter_.get()) | 648 if (limiter_.get()) |
610 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 649 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
611 DCHECK(!GetDisplayManager()->GetDisplayInfo(display). | 650 const internal::DisplayInfo& display_info = |
612 bounds_in_pixel().IsEmpty()); | 651 GetDisplayManager()->GetDisplayInfo(display); |
| 652 DCHECK(!display_info.bounds_in_pixel().IsEmpty()); |
613 | 653 |
614 NotifyDisplayConfigurationChanging(); | 654 NotifyDisplayConfigurationChanging(); |
615 UpdateDisplayBoundsForLayout(); | 655 UpdateDisplayBoundsForLayout(); |
616 aura::RootWindow* root = root_windows_[display.id()]; | 656 aura::RootWindow* root = root_windows_[display.id()]; |
| 657 root->SetHostBoundsAndInsets(display_info.bounds_in_pixel(), |
| 658 display_info.GetOverscanInsetsInPixel()); |
617 SetDisplayPropertiesOnHostWindow(root, display); | 659 SetDisplayPropertiesOnHostWindow(root, display); |
618 root->SetHostBounds( | |
619 GetDisplayManager()->GetDisplayInfo(display).bounds_in_pixel()); | |
620 } | 660 } |
621 | 661 |
622 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 662 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
623 if (limiter_.get()) | 663 if (limiter_.get()) |
624 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 664 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
625 | 665 |
626 NotifyDisplayConfigurationChanging(); | 666 NotifyDisplayConfigurationChanging(); |
627 if (primary_root_window_for_replace_) { | 667 if (primary_root_window_for_replace_) { |
628 DCHECK(root_windows_.empty()); | 668 DCHECK(root_windows_.empty()); |
629 primary_display_id = display.id(); | 669 primary_display_id = display.id(); |
630 root_windows_[display.id()] = primary_root_window_for_replace_; | 670 root_windows_[display.id()] = primary_root_window_for_replace_; |
631 primary_root_window_for_replace_->SetProperty( | 671 primary_root_window_for_replace_->SetProperty( |
632 internal::kDisplayIdKey, display.id()); | 672 internal::kDisplayIdKey, display.id()); |
633 primary_root_window_for_replace_ = NULL; | 673 primary_root_window_for_replace_ = NULL; |
634 UpdateDisplayBoundsForLayout(); | 674 UpdateDisplayBoundsForLayout(); |
635 root_windows_[display.id()]->SetHostBounds( | 675 const internal::DisplayInfo& display_info = |
636 GetDisplayManager()->GetDisplayInfo(display).bounds_in_pixel()); | 676 GetDisplayManager()->GetDisplayInfo(display); |
| 677 root_windows_[display.id()]->SetHostBoundsAndInsets( |
| 678 display_info.bounds_in_pixel(), |
| 679 display_info.GetOverscanInsetsInPixel()); |
637 } else { | 680 } else { |
638 DCHECK(!root_windows_.empty()); | 681 DCHECK(!root_windows_.empty()); |
639 aura::RootWindow* root = AddRootWindowForDisplay(display); | 682 aura::RootWindow* root = AddRootWindowForDisplay(display); |
640 UpdateDisplayBoundsForLayout(); | 683 UpdateDisplayBoundsForLayout(); |
641 if (desired_primary_display_id_ == display.id()) | 684 if (desired_primary_display_id_ == display.id()) |
642 SetPrimaryDisplay(display); | 685 SetPrimaryDisplay(display); |
643 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 686 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
644 } | 687 } |
645 } | 688 } |
646 | 689 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 const DisplayLayout& layout, | 809 const DisplayLayout& layout, |
767 bool override) { | 810 bool override) { |
768 DisplayIdPair pair; | 811 DisplayIdPair pair; |
769 pair.first = id1; | 812 pair.first = id1; |
770 pair.second = id2; | 813 pair.second = id2; |
771 if (override || paired_layouts_.find(pair) == paired_layouts_.end()) | 814 if (override || paired_layouts_.find(pair) == paired_layouts_.end()) |
772 paired_layouts_[pair] = layout; | 815 paired_layouts_[pair] = layout; |
773 } | 816 } |
774 | 817 |
775 } // namespace ash | 818 } // namespace ash |
OLD | NEW |