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

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: Remove dependencies of chrome in ash. 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 void OutputConfigurator::SendProjectingStateToPowerManager() {
Daniel Erat 2014/01/15 22:42:59 the order of methods in the .cc file should match
hshi1 2014/01/16 02:01:44 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;
Daniel Erat 2014/01/15 22:42:59 nit: just do: if (cached_outputs_[i].type == OU
hshi1 2014/01/16 02:01:44 Done.
262
263 // "Projecting" is defined as having more than 1 output connected while at
264 // least one of them is an internal output.
265 bool is_projecting = has_internal_output && (connected_output_count > 1);
266 delegate_->SendProjectingStateToPowerManager(is_projecting);
267 }
268
270 void OutputConfigurator::Init(bool is_panel_fitting_enabled) { 269 void OutputConfigurator::Init(bool is_panel_fitting_enabled) {
271 is_panel_fitting_enabled_ = is_panel_fitting_enabled; 270 is_panel_fitting_enabled_ = is_panel_fitting_enabled;
272 if (!configure_display_) 271 if (!configure_display_)
273 return; 272 return;
274 273
275 if (!delegate_) 274 if (!delegate_)
276 delegate_.reset(new RealOutputConfiguratorDelegate()); 275 delegate_.reset(new RealOutputConfiguratorDelegate());
277 } 276 }
278 277
279 void OutputConfigurator::Start(uint32 background_color_argb) { 278 void OutputConfigurator::Start(uint32 background_color_argb) {
280 if (!configure_display_) 279 if (!configure_display_)
281 return; 280 return;
282 281
283 delegate_->GrabServer(); 282 delegate_->GrabServer();
284 delegate_->InitXRandRExtension(&xrandr_event_base_); 283 delegate_->InitXRandRExtension(&xrandr_event_base_);
285 284
286 UpdateCachedOutputs(); 285 UpdateCachedOutputs();
287 if (cached_outputs_.size() > 1 && background_color_argb) 286 if (cached_outputs_.size() > 1 && background_color_argb)
288 delegate_->SetBackgroundColor(background_color_argb); 287 delegate_->SetBackgroundColor(background_color_argb);
289 const OutputState new_state = ChooseOutputState(power_state_); 288 const OutputState new_state = ChooseOutputState(power_state_);
290 const bool success = EnterStateOrFallBackToSoftwareMirroring( 289 const bool success = EnterStateOrFallBackToSoftwareMirroring(
291 new_state, power_state_); 290 new_state, power_state_);
292 291
293 // Force the DPMS on chrome startup as the driver doesn't always detect 292 // Force the DPMS on chrome startup as the driver doesn't always detect
294 // that all displays are on when signing out. 293 // that all displays are on when signing out.
295 delegate_->ForceDPMSOn(); 294 delegate_->ForceDPMSOn();
296 delegate_->UngrabServer(); 295 delegate_->UngrabServer();
297 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); 296 SendProjectingStateToPowerManager();
298 NotifyObservers(success, new_state); 297 NotifyObservers(success, new_state);
299 } 298 }
300 299
301 bool OutputConfigurator::ApplyProtections(const DisplayProtections& requests) { 300 bool OutputConfigurator::ApplyProtections(const DisplayProtections& requests) {
302 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); 301 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin();
303 it != cached_outputs_.end(); ++it) { 302 it != cached_outputs_.end(); ++it) {
304 RROutput this_id = it->output; 303 RROutput this_id = it->output;
305 uint32_t all_desired = 0; 304 uint32_t all_desired = 0;
306 DisplayProtections::const_iterator request_it = requests.find( 305 DisplayProtections::const_iterator request_it = requests.find(
307 it->display_id); 306 it->display_id);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 configure_timer_.reset(); 769 configure_timer_.reset();
771 770
772 delegate_->GrabServer(); 771 delegate_->GrabServer();
773 UpdateCachedOutputs(); 772 UpdateCachedOutputs();
774 const OutputState new_state = ChooseOutputState(power_state_); 773 const OutputState new_state = ChooseOutputState(power_state_);
775 const bool success = EnterStateOrFallBackToSoftwareMirroring( 774 const bool success = EnterStateOrFallBackToSoftwareMirroring(
776 new_state, power_state_); 775 new_state, power_state_);
777 delegate_->UngrabServer(); 776 delegate_->UngrabServer();
778 777
779 NotifyObservers(success, new_state); 778 NotifyObservers(success, new_state);
780 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); 779 SendProjectingStateToPowerManager();
781 } 780 }
782 781
783 void OutputConfigurator::NotifyObservers(bool success, 782 void OutputConfigurator::NotifyObservers(bool success,
784 OutputState attempted_state) { 783 OutputState attempted_state) {
785 if (success) { 784 if (success) {
786 FOR_EACH_OBSERVER(Observer, observers_, 785 FOR_EACH_OBSERVER(Observer, observers_,
787 OnDisplayModeChanged(cached_outputs_)); 786 OnDisplayModeChanged(cached_outputs_));
788 } else { 787 } else {
789 FOR_EACH_OBSERVER(Observer, observers_, 788 FOR_EACH_OBSERVER(Observer, observers_,
790 OnDisplayModeChangeFailed(attempted_state)); 789 OnDisplayModeChangeFailed(attempted_state));
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1128
1130 float width_ratio = static_cast<float>(mirror_mode_info->width) / 1129 float width_ratio = static_cast<float>(mirror_mode_info->width) /
1131 static_cast<float>(native_mode_info->width); 1130 static_cast<float>(native_mode_info->width);
1132 float height_ratio = static_cast<float>(mirror_mode_info->height) / 1131 float height_ratio = static_cast<float>(mirror_mode_info->height) /
1133 static_cast<float>(native_mode_info->height); 1132 static_cast<float>(native_mode_info->height);
1134 1133
1135 area_ratio = width_ratio * height_ratio; 1134 area_ratio = width_ratio * height_ratio;
1136 return area_ratio; 1135 return area_ratio;
1137 } 1136 }
1138 1137
1138 void OutputConfigurator::OnScreenSharingStateChanged(bool started) {
Daniel Erat 2014/01/15 22:42:59 same here
hshi1 2014/01/16 02:01:44 Done.
1139 if (started) {
1140 ++screen_sharing_count_;
Daniel Erat 2014/01/15 22:42:59 indent two spaces beyond the previous line, not fo
hshi1 2014/01/16 02:01:44 Done.
1141 } else {
1142 DCHECK_GT(screen_sharing_count_, 0);
1143 --screen_sharing_count_;
1144 }
1145 SendProjectingStateToPowerManager();
1146 }
1147
1139 } // namespace chromeos 1148 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698