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

Side by Side Diff: chromeos/display/output_configurator.cc

Issue 10989084: Handles the failures of output state change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | « chromeos/display/output_configurator.h ('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 "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
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 XRRFreeScreenResources(screen); 731 XRRFreeScreenResources(screen);
729 XUngrabServer(display); 732 XUngrabServer(display);
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;
oshima 2012/10/01 21:44:02 is it possible to return output_state_ == new_stat
Jun Mukai 2012/10/01 21:49:35 The header said it "returns false if it was called
oshima 2012/10/01 22:16:19 I was thinking to add if (output_state_ == new_st
Jun Mukai 2012/10/01 22:36:56 That would be safe. Added.
739 742
740 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay(); 743 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
741 CHECK(display != NULL); 744 CHECK(display != NULL);
742 XGrabServer(display); 745 XGrabServer(display);
743 Window window = DefaultRootWindow(display); 746 Window window = DefaultRootWindow(display);
744 XRRScreenResources* screen = GetScreenResourcesAndRecordUMA(display, window); 747 XRRScreenResources* screen = GetScreenResourcesAndRecordUMA(display, window);
745 CHECK(screen != NULL); 748 CHECK(screen != NULL);
746 749
750 bool did_change = false;
747 OutputSnapshot outputs[2] = { {0}, {0} }; 751 OutputSnapshot outputs[2] = { {0}, {0} };
748 connected_output_count_ = 752 connected_output_count_ =
749 GetDualOutputs(display, screen, &outputs[0], &outputs[1]); 753 GetDualOutputs(display, screen, &outputs[0], &outputs[1]);
750 if (EnterState(display, 754 if (EnterState(display,
751 screen, 755 screen,
752 window, 756 window,
753 new_state, 757 new_state,
754 outputs, 758 outputs,
755 connected_output_count_)) { 759 connected_output_count_)) {
756 output_state_ = new_state; 760 output_state_ = new_state;
761 did_change = true;
757 } 762 }
758 763
759 XRRFreeScreenResources(screen); 764 XRRFreeScreenResources(screen);
760 XUngrabServer(display); 765 XUngrabServer(display);
766
767 if (!did_change)
768 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChangeFailed());
761 return true; 769 return true;
762 } 770 }
763 771
764 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) { 772 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) {
765 // Ignore this event if the Xrandr extension isn't supported. 773 // Ignore this event if the Xrandr extension isn't supported.
766 if (!is_running_on_chrome_os_ || 774 if (!is_running_on_chrome_os_ ||
767 (event->type - xrandr_event_base_ != RRNotify)) { 775 (event->type - xrandr_event_base_ != RRNotify)) {
768 return true; 776 return true;
769 } 777 }
770 XEvent* xevent = static_cast<XEvent*>(event); 778 XEvent* xevent = static_cast<XEvent*>(event);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 // distinguish internal display. 853 // distinguish internal display.
846 return false; 854 return false;
847 } 855 }
848 856
849 void OutputConfigurator::NotifyOnDisplayChanged() { 857 void OutputConfigurator::NotifyOnDisplayChanged() {
850 notification_timer_.reset(); 858 notification_timer_.reset();
851 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChanged()); 859 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayModeChanged());
852 } 860 }
853 861
854 } // namespace chromeos 862 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/display/output_configurator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698