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 "chromeos/display/output_configurator.h" | 5 #include "chromeos/display/output_configurator.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/dpms.h> | 8 #include <X11/extensions/dpms.h> |
9 #include <X11/extensions/Xrandr.h> | 9 #include <X11/extensions/Xrandr.h> |
10 | 10 |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 connected_output_count_)) { | 654 connected_output_count_)) { |
655 did_change = true; | 655 did_change = true; |
656 } | 656 } |
657 // We have seen cases where the XRandR data can get out of sync with our own | 657 // We have seen cases where the XRandR data can get out of sync with our own |
658 // cache so over-write it with whatever we detected, even if we didn't think | 658 // cache so over-write it with whatever we detected, even if we didn't think |
659 // anything changed. | 659 // anything changed. |
660 output_state_ = next_state; | 660 output_state_ = next_state; |
661 | 661 |
662 XRRFreeScreenResources(screen); | 662 XRRFreeScreenResources(screen); |
663 XUngrabServer(display); | 663 XUngrabServer(display); |
| 664 |
| 665 if (!did_change) |
| 666 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChangeFailed()); |
664 return did_change; | 667 return did_change; |
665 } | 668 } |
666 | 669 |
667 bool OutputConfigurator::ScreenPowerSet(bool power_on, bool all_displays) { | 670 bool OutputConfigurator::ScreenPowerSet(bool power_on, bool all_displays) { |
668 VLOG(1) << "OutputConfigurator::SetScreensOn " << power_on | 671 VLOG(1) << "OutputConfigurator::SetScreensOn " << power_on |
669 << " all displays " << all_displays; | 672 << " all displays " << all_displays; |
670 if (!is_running_on_chrome_os_) | 673 if (!is_running_on_chrome_os_) |
671 return false; | 674 return false; |
672 | 675 |
673 bool success = false; | 676 bool success = false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 | 733 |
731 return success; | 734 return success; |
732 } | 735 } |
733 | 736 |
734 bool OutputConfigurator::SetDisplayMode(OutputState new_state) { | 737 bool OutputConfigurator::SetDisplayMode(OutputState new_state) { |
735 if (output_state_ == STATE_INVALID || | 738 if (output_state_ == STATE_INVALID || |
736 output_state_ == STATE_HEADLESS || | 739 output_state_ == STATE_HEADLESS || |
737 output_state_ == STATE_SINGLE) | 740 output_state_ == STATE_SINGLE) |
738 return false; | 741 return false; |
739 | 742 |
| 743 if (output_state_ == new_state) |
| 744 return true; |
| 745 |
740 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay(); | 746 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
741 CHECK(display != NULL); | 747 CHECK(display != NULL); |
742 XGrabServer(display); | 748 XGrabServer(display); |
743 Window window = DefaultRootWindow(display); | 749 Window window = DefaultRootWindow(display); |
744 XRRScreenResources* screen = GetScreenResourcesAndRecordUMA(display, window); | 750 XRRScreenResources* screen = GetScreenResourcesAndRecordUMA(display, window); |
745 CHECK(screen != NULL); | 751 CHECK(screen != NULL); |
746 | 752 |
747 OutputSnapshot outputs[2] = { {0}, {0} }; | 753 OutputSnapshot outputs[2] = { {0}, {0} }; |
748 connected_output_count_ = | 754 connected_output_count_ = |
749 GetDualOutputs(display, screen, &outputs[0], &outputs[1]); | 755 GetDualOutputs(display, screen, &outputs[0], &outputs[1]); |
750 if (EnterState(display, | 756 if (EnterState(display, |
751 screen, | 757 screen, |
752 window, | 758 window, |
753 new_state, | 759 new_state, |
754 outputs, | 760 outputs, |
755 connected_output_count_)) { | 761 connected_output_count_)) { |
756 output_state_ = new_state; | 762 output_state_ = new_state; |
757 } | 763 } |
758 | 764 |
759 XRRFreeScreenResources(screen); | 765 XRRFreeScreenResources(screen); |
760 XUngrabServer(display); | 766 XUngrabServer(display); |
| 767 |
| 768 if (output_state_ != new_state) |
| 769 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChangeFailed()); |
761 return true; | 770 return true; |
762 } | 771 } |
763 | 772 |
764 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) { | 773 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) { |
765 // Ignore this event if the Xrandr extension isn't supported. | 774 // Ignore this event if the Xrandr extension isn't supported. |
766 if (!is_running_on_chrome_os_ || | 775 if (!is_running_on_chrome_os_ || |
767 (event->type - xrandr_event_base_ != RRNotify)) { | 776 (event->type - xrandr_event_base_ != RRNotify)) { |
768 return true; | 777 return true; |
769 } | 778 } |
770 XEvent* xevent = static_cast<XEvent*>(event); | 779 XEvent* xevent = static_cast<XEvent*>(event); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 // distinguish internal display. | 854 // distinguish internal display. |
846 return false; | 855 return false; |
847 } | 856 } |
848 | 857 |
849 void OutputConfigurator::NotifyOnDisplayChanged() { | 858 void OutputConfigurator::NotifyOnDisplayChanged() { |
850 notification_timer_.reset(); | 859 notification_timer_.reset(); |
851 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChanged()); | 860 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChanged()); |
852 } | 861 } |
853 | 862 |
854 } // namespace chromeos | 863 } // namespace chromeos |
OLD | NEW |