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

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

Issue 139053003: Chrome OS: avoid suspending on lid close when casting is active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Oshima's suggestion. Created 6 years, 11 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
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/Xrandr.h> 8 #include <X11/extensions/Xrandr.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 (state == DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && !internal) || 99 (state == DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && !internal) ||
100 (state == DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF && internal); 100 (state == DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF && internal);
101 if (output_power) 101 if (output_power)
102 (*output_power)[i] = on; 102 (*output_power)[i] = on;
103 if (on) 103 if (on)
104 num_on_outputs++; 104 num_on_outputs++;
105 } 105 }
106 return num_on_outputs; 106 return num_on_outputs;
107 } 107 }
108 108
109 // Determine if there is an "internal" output and how many outputs are
110 // connected.
111 bool IsProjecting(
112 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
113 bool has_internal_output = false;
114 int connected_output_count = outputs.size();
115 for (size_t i = 0; i < outputs.size(); ++i)
116 has_internal_output |= outputs[i].type == OUTPUT_TYPE_INTERNAL;
117
118 // "Projecting" is defined as having more than 1 output connected while at
119 // least one of them is an internal output.
120 return has_internal_output && (connected_output_count > 1);
121 }
122
123 } // namespace 109 } // namespace
124 110
125 OutputConfigurator::ModeInfo::ModeInfo() 111 OutputConfigurator::ModeInfo::ModeInfo()
126 : width(0), 112 : width(0),
127 height(0), 113 height(0),
128 interlaced(false), 114 interlaced(false),
129 refresh_rate(0.0) {} 115 refresh_rate(0.0) {}
130 116
131 OutputConfigurator::ModeInfo::ModeInfo(int width, 117 OutputConfigurator::ModeInfo::ModeInfo(int width,
132 int height, 118 int height,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 231 }
246 232
247 OutputConfigurator::OutputConfigurator() 233 OutputConfigurator::OutputConfigurator()
248 : state_controller_(NULL), 234 : state_controller_(NULL),
249 mirroring_controller_(NULL), 235 mirroring_controller_(NULL),
250 is_panel_fitting_enabled_(false), 236 is_panel_fitting_enabled_(false),
251 configure_display_(base::SysInfo::IsRunningOnChromeOS()), 237 configure_display_(base::SysInfo::IsRunningOnChromeOS()),
252 xrandr_event_base_(0), 238 xrandr_event_base_(0),
253 output_state_(STATE_INVALID), 239 output_state_(STATE_INVALID),
254 power_state_(DISPLAY_POWER_ALL_ON), 240 power_state_(DISPLAY_POWER_ALL_ON),
255 next_output_protection_client_id_(1) { 241 next_output_protection_client_id_(1),
242 screen_sharing_count_(0) {
256 } 243 }
257 244
258 OutputConfigurator::~OutputConfigurator() {} 245 OutputConfigurator::~OutputConfigurator() {}
259 246
260 void OutputConfigurator::SetDelegateForTesting(scoped_ptr<Delegate> delegate) { 247 void OutputConfigurator::SetDelegateForTesting(scoped_ptr<Delegate> delegate) {
261 delegate_ = delegate.Pass(); 248 delegate_ = delegate.Pass();
262 configure_display_ = true; 249 configure_display_ = true;
263 } 250 }
264 251
265 void OutputConfigurator::SetInitialDisplayPower(DisplayPowerState power_state) { 252 void OutputConfigurator::SetInitialDisplayPower(DisplayPowerState power_state) {
266 DCHECK_EQ(output_state_, STATE_INVALID); 253 DCHECK_EQ(output_state_, STATE_INVALID);
267 power_state_ = power_state; 254 power_state_ = power_state;
268 } 255 }
269 256
257 bool OutputConfigurator::IsProjecting() const {
oshima 2014/01/15 02:26:37 Since IsProjecting is always used with delegate ho
hshi1 2014/01/15 19:43:24 Done.
258 bool has_internal_output = false;
259 int connected_output_count = cached_outputs_.size() + screen_sharing_count_;
260 for (size_t i = 0; i < cached_outputs_.size(); ++i)
261 has_internal_output |= cached_outputs_[i].type == OUTPUT_TYPE_INTERNAL;
262
263 // "Projecting" is defined as having more than 1 output connected while at
264 // least one of them is an internal output.
265 return has_internal_output && (connected_output_count > 1);
266 }
267
270 void OutputConfigurator::Init(bool is_panel_fitting_enabled) { 268 void OutputConfigurator::Init(bool is_panel_fitting_enabled) {
271 is_panel_fitting_enabled_ = is_panel_fitting_enabled; 269 is_panel_fitting_enabled_ = is_panel_fitting_enabled;
272 if (!configure_display_) 270 if (!configure_display_)
273 return; 271 return;
274 272
275 if (!delegate_) 273 if (!delegate_)
276 delegate_.reset(new RealOutputConfiguratorDelegate()); 274 delegate_.reset(new RealOutputConfiguratorDelegate());
277 } 275 }
278 276
279 void OutputConfigurator::Start(uint32 background_color_argb) { 277 void OutputConfigurator::Start(uint32 background_color_argb) {
280 if (!configure_display_) 278 if (!configure_display_)
281 return; 279 return;
282 280
283 delegate_->GrabServer(); 281 delegate_->GrabServer();
284 delegate_->InitXRandRExtension(&xrandr_event_base_); 282 delegate_->InitXRandRExtension(&xrandr_event_base_);
285 283
286 UpdateCachedOutputs(); 284 UpdateCachedOutputs();
287 if (cached_outputs_.size() > 1 && background_color_argb) 285 if (cached_outputs_.size() > 1 && background_color_argb)
288 delegate_->SetBackgroundColor(background_color_argb); 286 delegate_->SetBackgroundColor(background_color_argb);
289 const OutputState new_state = ChooseOutputState(power_state_); 287 const OutputState new_state = ChooseOutputState(power_state_);
290 const bool success = EnterStateOrFallBackToSoftwareMirroring( 288 const bool success = EnterStateOrFallBackToSoftwareMirroring(
291 new_state, power_state_); 289 new_state, power_state_);
292 290
293 // Force the DPMS on chrome startup as the driver doesn't always detect 291 // Force the DPMS on chrome startup as the driver doesn't always detect
294 // that all displays are on when signing out. 292 // that all displays are on when signing out.
295 delegate_->ForceDPMSOn(); 293 delegate_->ForceDPMSOn();
296 delegate_->UngrabServer(); 294 delegate_->UngrabServer();
297 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); 295 delegate_->SendProjectingStateToPowerManager(IsProjecting());
298 NotifyObservers(success, new_state); 296 NotifyObservers(success, new_state);
299 } 297 }
300 298
301 bool OutputConfigurator::ApplyProtections(const DisplayProtections& requests) { 299 bool OutputConfigurator::ApplyProtections(const DisplayProtections& requests) {
302 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); 300 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin();
303 it != cached_outputs_.end(); ++it) { 301 it != cached_outputs_.end(); ++it) {
304 RROutput this_id = it->output; 302 RROutput this_id = it->output;
305 uint32_t all_desired = 0; 303 uint32_t all_desired = 0;
306 DisplayProtections::const_iterator request_it = requests.find( 304 DisplayProtections::const_iterator request_it = requests.find(
307 it->display_id); 305 it->display_id);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 configure_timer_.reset(); 768 configure_timer_.reset();
771 769
772 delegate_->GrabServer(); 770 delegate_->GrabServer();
773 UpdateCachedOutputs(); 771 UpdateCachedOutputs();
774 const OutputState new_state = ChooseOutputState(power_state_); 772 const OutputState new_state = ChooseOutputState(power_state_);
775 const bool success = EnterStateOrFallBackToSoftwareMirroring( 773 const bool success = EnterStateOrFallBackToSoftwareMirroring(
776 new_state, power_state_); 774 new_state, power_state_);
777 delegate_->UngrabServer(); 775 delegate_->UngrabServer();
778 776
779 NotifyObservers(success, new_state); 777 NotifyObservers(success, new_state);
780 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); 778 delegate_->SendProjectingStateToPowerManager(IsProjecting());
781 } 779 }
782 780
783 void OutputConfigurator::NotifyObservers(bool success, 781 void OutputConfigurator::NotifyObservers(bool success,
784 OutputState attempted_state) { 782 OutputState attempted_state) {
785 if (success) { 783 if (success) {
786 FOR_EACH_OBSERVER(Observer, observers_, 784 FOR_EACH_OBSERVER(Observer, observers_,
787 OnDisplayModeChanged(cached_outputs_)); 785 OnDisplayModeChanged(cached_outputs_));
788 } else { 786 } else {
789 FOR_EACH_OBSERVER(Observer, observers_, 787 FOR_EACH_OBSERVER(Observer, observers_,
790 OnDisplayModeChangeFailed(attempted_state)); 788 OnDisplayModeChangeFailed(attempted_state));
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1127
1130 float width_ratio = static_cast<float>(mirror_mode_info->width) / 1128 float width_ratio = static_cast<float>(mirror_mode_info->width) /
1131 static_cast<float>(native_mode_info->width); 1129 static_cast<float>(native_mode_info->width);
1132 float height_ratio = static_cast<float>(mirror_mode_info->height) / 1130 float height_ratio = static_cast<float>(mirror_mode_info->height) /
1133 static_cast<float>(native_mode_info->height); 1131 static_cast<float>(native_mode_info->height);
1134 1132
1135 area_ratio = width_ratio * height_ratio; 1133 area_ratio = width_ratio * height_ratio;
1136 return area_ratio; 1134 return area_ratio;
1137 } 1135 }
1138 1136
1137 void OutputConfigurator::SetScreenSharingCount(int screen_sharing_count) {
1138 if (screen_sharing_count_ == screen_sharing_count)
1139 return;
1140
1141 screen_sharing_count_ = screen_sharing_count;
1142 delegate_->SendProjectingStateToPowerManager(IsProjecting());
1143 }
1144
1139 } // namespace chromeos 1145 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698