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

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

Issue 12047111: Set scale/orientation property to aura root window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 7 years, 10 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_switches.cc ('k') | no next file » | 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 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"
(...skipping 12 matching lines...) Expand all
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/compositor/dip_util.h" 26 #include "ui/compositor/dip_util.h"
27 #include "ui/gfx/display.h" 27 #include "ui/gfx/display.h"
28 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
29 29
30 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
31 #include "ash/display/output_configurator_animation.h" 31 #include "ash/display/output_configurator_animation.h"
32 #include "base/chromeos/chromeos_version.h" 32 #include "base/chromeos/chromeos_version.h"
33 #include "base/string_number_conversions.h"
33 #include "base/time.h" 34 #include "base/time.h"
34 #include "chromeos/display/output_configurator.h" 35 #include "chromeos/display/output_configurator.h"
36 #include "ui/base/x/x11_util.h"
35 #endif // defined(OS_CHROMEOS) 37 #endif // defined(OS_CHROMEOS)
36 38
37 39
38 namespace ash { 40 namespace ash {
39 namespace { 41 namespace {
40 42
41 // Primary display stored in global object as it can be 43 // Primary display stored in global object as it can be
42 // accessed after Shell is deleted. A separate display instance is created 44 // accessed after Shell is deleted. A separate display instance is created
43 // during the shutdown instead of always keeping two display instances 45 // during the shutdown instead of always keeping two display instances
44 // (one here and another one in display_manager) in sync, which is error prone. 46 // (one here and another one in display_manager) in sync, which is error prone.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 case DisplayLayout::LEFT: 98 case DisplayLayout::LEFT:
97 return std::string("left"); 99 return std::string("left");
98 } 100 }
99 return std::string("unknown"); 101 return std::string("unknown");
100 } 102 }
101 103
102 internal::DisplayManager* GetDisplayManager() { 104 internal::DisplayManager* GetDisplayManager() {
103 return Shell::GetInstance()->display_manager(); 105 return Shell::GetInstance()->display_manager();
104 } 106 }
105 107
108 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root,
109 const gfx::Display& display) {
110 #if defined(OS_CHROMEOS)
111 // Native window property (Atom in X11) that specifies the display's
112 // rotation and scale factor. They are read and used by
113 // touchpad/mouse driver directly on X (contact adlr@ for more
114 // 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
116 // 3 (270 degrees clockwise). The value of the scale factor is in
117 // percent (100, 140, 200 etc).
118 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION";
119 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR";
120 const char kCARDINAL[] = "CARDINAL";
121
122 CommandLine* command_line = CommandLine::ForCurrentProcess();
123 int rotation = 0;
124 if (command_line->HasSwitch(switches::kAshOverrideDisplayOrientation)) {
125 std::string value = command_line->
126 GetSwitchValueASCII(switches::kAshOverrideDisplayOrientation);
127 DCHECK(base::StringToInt(value, &rotation));
128 DCHECK(0 <= rotation && rotation <= 3) << "Invalid rotation value="
129 << rotation;
130 if (rotation < 0 || rotation > 3)
131 rotation = 0;
132 }
133 gfx::AcceleratedWidget xwindow = root->GetAcceleratedWidget();
134 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, rotation);
135 ui::SetIntProperty(xwindow,
136 kScaleFactorProp,
137 kCARDINAL,
138 100 * display.device_scale_factor());
139 #endif
140 }
141
106 } // namespace 142 } // namespace
107 143
108 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
109 // DisplayLayout 145 // DisplayLayout
110 146
111 DisplayLayout::DisplayLayout() 147 DisplayLayout::DisplayLayout()
112 : position(RIGHT), 148 : position(RIGHT),
113 offset(0) {} 149 offset(0) {}
114 150
115 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) 151 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 primary_candidate = display; 305 primary_candidate = display;
270 break; 306 break;
271 } else if (display->bounds_in_pixel().y() < y) { 307 } else if (display->bounds_in_pixel().y() < y) {
272 primary_candidate = display; 308 primary_candidate = display;
273 y = display->bounds_in_pixel().y(); 309 y = display->bounds_in_pixel().y();
274 } 310 }
275 } 311 }
276 } 312 }
277 #endif 313 #endif
278 primary_display_id = primary_candidate->id(); 314 primary_display_id = primary_candidate->id();
279 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); 315 AddRootWindowForDisplay(*primary_candidate);
280 root->SetHostBounds(primary_candidate->bounds_in_pixel());
281 UpdateDisplayBoundsForLayout(); 316 UpdateDisplayBoundsForLayout();
282 } 317 }
283 318
284 void DisplayController::InitSecondaryDisplays() { 319 void DisplayController::InitSecondaryDisplays() {
285 internal::DisplayManager* display_manager = GetDisplayManager(); 320 internal::DisplayManager* display_manager = GetDisplayManager();
286 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 321 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
287 const gfx::Display* display = display_manager->GetDisplayAt(i); 322 const gfx::Display* display = display_manager->GetDisplayAt(i);
288 if (primary_display_id != display->id()) { 323 if (primary_display_id != display->id()) {
289 aura::RootWindow* root = AddRootWindowForDisplay(*display); 324 aura::RootWindow* root = AddRootWindowForDisplay(*display);
290 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); 325 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? 568 return display_manager->GetDisplayAt(0)->id() == primary_display_id ?
534 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); 569 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
535 } 570 }
536 571
537 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { 572 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
538 if (limiter_.get()) 573 if (limiter_.get())
539 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); 574 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs);
540 575
541 NotifyDisplayConfigurationChanging(); 576 NotifyDisplayConfigurationChanging();
542 UpdateDisplayBoundsForLayout(); 577 UpdateDisplayBoundsForLayout();
543 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); 578 aura::RootWindow* root = root_windows_[display.id()];
579 SetDisplayPropertiesOnHostWindow(root, display);
580 root->SetHostBounds(display.bounds_in_pixel());
544 } 581 }
545 582
546 void DisplayController::OnDisplayAdded(const gfx::Display& display) { 583 void DisplayController::OnDisplayAdded(const gfx::Display& display) {
547 if (limiter_.get()) 584 if (limiter_.get())
548 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); 585 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs);
549 586
550 NotifyDisplayConfigurationChanging(); 587 NotifyDisplayConfigurationChanging();
551 if (primary_root_window_for_replace_) { 588 if (primary_root_window_for_replace_) {
552 DCHECK(root_windows_.empty()); 589 DCHECK(root_windows_.empty());
553 primary_display_id = display.id(); 590 primary_display_id = display.id();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // root window itself yet because the stack may be using it. 649 // root window itself yet because the stack may be using it.
613 controller->Shutdown(); 650 controller->Shutdown();
614 MessageLoop::current()->DeleteSoon(FROM_HERE, controller); 651 MessageLoop::current()->DeleteSoon(FROM_HERE, controller);
615 } 652 }
616 653
617 aura::RootWindow* DisplayController::AddRootWindowForDisplay( 654 aura::RootWindow* DisplayController::AddRootWindowForDisplay(
618 const gfx::Display& display) { 655 const gfx::Display& display) {
619 aura::RootWindow* root = 656 aura::RootWindow* root =
620 GetDisplayManager()->CreateRootWindowForDisplay(display); 657 GetDisplayManager()->CreateRootWindowForDisplay(display);
621 root_windows_[display.id()] = root; 658 root_windows_[display.id()] = root;
659 SetDisplayPropertiesOnHostWindow(root, display);
622 660
623 #if defined(OS_CHROMEOS) 661 #if defined(OS_CHROMEOS)
624 static bool force_constrain_pointer_to_root = 662 static bool force_constrain_pointer_to_root =
625 CommandLine::ForCurrentProcess()->HasSwitch( 663 CommandLine::ForCurrentProcess()->HasSwitch(
626 switches::kAshConstrainPointerToRoot); 664 switches::kAshConstrainPointerToRoot);
627 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) 665 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root)
628 root->ConfineCursorToWindow(); 666 root->ConfineCursorToWindow();
629 #endif 667 #endif
630 return root; 668 return root;
631 } 669 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 secondary_display->set_bounds( 714 secondary_display->set_bounds(
677 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 715 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
678 secondary_display->UpdateWorkAreaFromInsets(insets); 716 secondary_display->UpdateWorkAreaFromInsets(insets);
679 } 717 }
680 718
681 void DisplayController::NotifyDisplayConfigurationChanging() { 719 void DisplayController::NotifyDisplayConfigurationChanging() {
682 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); 720 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
683 } 721 }
684 722
685 } // namespace ash 723 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698