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

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

Issue 22875019: chromeos: Notify observers after display power changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make NotifyObservers take a success argument Created 7 years, 4 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (!configure_display_) 206 if (!configure_display_)
207 return; 207 return;
208 208
209 delegate_->GrabServer(); 209 delegate_->GrabServer();
210 delegate_->InitXRandRExtension(&xrandr_event_base_); 210 delegate_->InitXRandRExtension(&xrandr_event_base_);
211 211
212 std::vector<OutputSnapshot> outputs = 212 std::vector<OutputSnapshot> outputs =
213 delegate_->GetOutputs(state_controller_); 213 delegate_->GetOutputs(state_controller_);
214 if (outputs.size() > 1 && background_color_argb) 214 if (outputs.size() > 1 && background_color_argb)
215 delegate_->SetBackgroundColor(background_color_argb); 215 delegate_->SetBackgroundColor(background_color_argb);
216 EnterStateOrFallBackToSoftwareMirroring( 216 const OutputState new_state = GetOutputState(outputs, power_state_);
217 GetOutputState(outputs, power_state_), power_state_, outputs); 217 const bool success = EnterStateOrFallBackToSoftwareMirroring(
218 new_state, power_state_, outputs);
218 219
219 // Force the DPMS on chrome startup as the driver doesn't always detect 220 // Force the DPMS on chrome startup as the driver doesn't always detect
220 // that all displays are on when signing out. 221 // that all displays are on when signing out.
221 delegate_->ForceDPMSOn(); 222 delegate_->ForceDPMSOn();
222 delegate_->UngrabServer(); 223 delegate_->UngrabServer();
223 delegate_->SendProjectingStateToPowerManager(IsProjecting(outputs)); 224 delegate_->SendProjectingStateToPowerManager(IsProjecting(outputs));
224 NotifyOnDisplayChanged(); 225 NotifyObservers(success, new_state);
225 } 226 }
226 227
227 void OutputConfigurator::Stop() { 228 void OutputConfigurator::Stop() {
228 configure_display_ = false; 229 configure_display_ = false;
229 } 230 }
230 231
231 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state, 232 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state,
232 int flags) { 233 int flags) {
233 if (!configure_display_) 234 if (!configure_display_)
234 return false; 235 return false;
235 236
236 VLOG(1) << "SetDisplayPower: power_state=" 237 VLOG(1) << "SetDisplayPower: power_state="
237 << DisplayPowerStateToString(power_state) << " flags=" << flags; 238 << DisplayPowerStateToString(power_state) << " flags=" << flags;
238 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe)) 239 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe))
239 return true; 240 return true;
240 241
241 delegate_->GrabServer(); 242 delegate_->GrabServer();
242 std::vector<OutputSnapshot> outputs = 243 std::vector<OutputSnapshot> outputs =
243 delegate_->GetOutputs(state_controller_); 244 delegate_->GetOutputs(state_controller_);
244 245
246 const OutputState new_state = GetOutputState(outputs, power_state);
247 bool attempted_change = false;
248 bool success = false;
249
245 bool only_if_single_internal_display = 250 bool only_if_single_internal_display =
246 flags & kSetDisplayPowerOnlyIfSingleInternalDisplay; 251 flags & kSetDisplayPowerOnlyIfSingleInternalDisplay;
247 bool single_internal_display = outputs.size() == 1 && outputs[0].is_internal; 252 bool single_internal_display = outputs.size() == 1 && outputs[0].is_internal;
248 if ((single_internal_display || !only_if_single_internal_display) && 253 if (single_internal_display || !only_if_single_internal_display) {
249 EnterStateOrFallBackToSoftwareMirroring( 254 if (EnterStateOrFallBackToSoftwareMirroring(
250 GetOutputState(outputs, power_state), power_state, outputs)) { 255 new_state, power_state, outputs)) {
oshima 2013/08/16 16:19:14 success = EnterState...; if (success && power_stat
Daniel Erat 2013/08/16 16:42:16 Done.
251 if (power_state != DISPLAY_POWER_ALL_OFF) {
252 // Force the DPMS on since the driver doesn't always detect that it 256 // Force the DPMS on since the driver doesn't always detect that it
253 // should turn on. This is needed when coming back from idle suspend. 257 // should turn on. This is needed when coming back from idle suspend.
254 delegate_->ForceDPMSOn(); 258 if (power_state != DISPLAY_POWER_ALL_OFF)
259 delegate_->ForceDPMSOn();
260 success = true;
255 } 261 }
262 attempted_change = true;
256 } 263 }
257 264
258 delegate_->UngrabServer(); 265 delegate_->UngrabServer();
266 if (attempted_change)
267 NotifyObservers(success, new_state);
259 return true; 268 return true;
260 } 269 }
261 270
262 bool OutputConfigurator::SetDisplayMode(OutputState new_state) { 271 bool OutputConfigurator::SetDisplayMode(OutputState new_state) {
263 if (!configure_display_) 272 if (!configure_display_)
264 return false; 273 return false;
265 274
266 VLOG(1) << "SetDisplayMode: state=" << OutputStateToString(new_state); 275 VLOG(1) << "SetDisplayMode: state=" << OutputStateToString(new_state);
267 if (output_state_ == new_state) { 276 if (output_state_ == new_state) {
268 // Cancel software mirroring if the state is moving from 277 // Cancel software mirroring if the state is moving from
269 // STATE_DUAL_EXTENDED to STATE_DUAL_EXTENDED. 278 // STATE_DUAL_EXTENDED to STATE_DUAL_EXTENDED.
270 if (mirroring_controller_ && new_state == STATE_DUAL_EXTENDED) 279 if (mirroring_controller_ && new_state == STATE_DUAL_EXTENDED)
271 mirroring_controller_->SetSoftwareMirroring(false); 280 mirroring_controller_->SetSoftwareMirroring(false);
272 NotifyOnDisplayChanged(); 281 NotifyObservers(true, new_state);
273 return true; 282 return true;
274 } 283 }
275 284
276 delegate_->GrabServer(); 285 delegate_->GrabServer();
277 std::vector<OutputSnapshot> outputs = 286 std::vector<OutputSnapshot> outputs =
278 delegate_->GetOutputs(state_controller_); 287 delegate_->GetOutputs(state_controller_);
279 bool success = EnterStateOrFallBackToSoftwareMirroring( 288 const bool success = EnterStateOrFallBackToSoftwareMirroring(
280 new_state, power_state_, outputs); 289 new_state, power_state_, outputs);
281 delegate_->UngrabServer(); 290 delegate_->UngrabServer();
282 291
283 if (success) { 292 NotifyObservers(success, new_state);
284 NotifyOnDisplayChanged();
285 } else {
286 FOR_EACH_OBSERVER(
287 Observer, observers_, OnDisplayModeChangeFailed(new_state));
288 }
289 return success; 293 return success;
290 } 294 }
291 295
292 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) { 296 bool OutputConfigurator::Dispatch(const base::NativeEvent& event) {
293 if (!configure_display_) 297 if (!configure_display_)
294 return true; 298 return true;
295 299
296 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { 300 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) {
297 VLOG(1) << "Received RRScreenChangeNotify event"; 301 VLOG(1) << "Received RRScreenChangeNotify event";
298 delegate_->UpdateXRandRConfiguration(event); 302 delegate_->UpdateXRandRConfiguration(event);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 &OutputConfigurator::ConfigureOutputs); 409 &OutputConfigurator::ConfigureOutputs);
406 } 410 }
407 } 411 }
408 412
409 void OutputConfigurator::ConfigureOutputs() { 413 void OutputConfigurator::ConfigureOutputs() {
410 configure_timer_.reset(); 414 configure_timer_.reset();
411 415
412 delegate_->GrabServer(); 416 delegate_->GrabServer();
413 std::vector<OutputSnapshot> outputs = 417 std::vector<OutputSnapshot> outputs =
414 delegate_->GetOutputs(state_controller_); 418 delegate_->GetOutputs(state_controller_);
415 OutputState new_state = GetOutputState(outputs, power_state_); 419 const OutputState new_state = GetOutputState(outputs, power_state_);
416 bool success = EnterStateOrFallBackToSoftwareMirroring( 420 const bool success = EnterStateOrFallBackToSoftwareMirroring(
417 new_state, power_state_, outputs); 421 new_state, power_state_, outputs);
418 delegate_->UngrabServer(); 422 delegate_->UngrabServer();
419 423
420 if (success) { 424 NotifyObservers(success, new_state);
421 NotifyOnDisplayChanged();
422 } else {
423 FOR_EACH_OBSERVER(
424 Observer, observers_, OnDisplayModeChangeFailed(new_state));
425 }
426 delegate_->SendProjectingStateToPowerManager(IsProjecting(outputs)); 425 delegate_->SendProjectingStateToPowerManager(IsProjecting(outputs));
427 } 426 }
428 427
429 void OutputConfigurator::NotifyOnDisplayChanged() { 428 void OutputConfigurator::NotifyObservers(bool success,
430 FOR_EACH_OBSERVER(Observer, observers_, 429 OutputState attempted_state) {
431 OnDisplayModeChanged(cached_outputs_)); 430 if (success) {
431 FOR_EACH_OBSERVER(Observer, observers_,
432 OnDisplayModeChanged(cached_outputs_));
433 } else {
434 FOR_EACH_OBSERVER(Observer, observers_,
435 OnDisplayModeChangeFailed(attempted_state));
436 }
432 } 437 }
433 438
434 bool OutputConfigurator::EnterStateOrFallBackToSoftwareMirroring( 439 bool OutputConfigurator::EnterStateOrFallBackToSoftwareMirroring(
435 OutputState output_state, 440 OutputState output_state,
436 DisplayPowerState power_state, 441 DisplayPowerState power_state,
437 const std::vector<OutputSnapshot>& outputs) { 442 const std::vector<OutputSnapshot>& outputs) {
438 bool success = EnterState(output_state, power_state, outputs); 443 bool success = EnterState(output_state, power_state, outputs);
439 if (mirroring_controller_) { 444 if (mirroring_controller_) {
440 bool enable_software_mirroring = false; 445 bool enable_software_mirroring = false;
441 if (!success && output_state == STATE_DUAL_MIRROR) { 446 if (!success && output_state == STATE_DUAL_MIRROR) {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 float width_ratio = static_cast<float>(mirror_mode_info->width) / 691 float width_ratio = static_cast<float>(mirror_mode_info->width) /
687 static_cast<float>(native_mode_info->width); 692 static_cast<float>(native_mode_info->width);
688 float height_ratio = static_cast<float>(mirror_mode_info->height) / 693 float height_ratio = static_cast<float>(mirror_mode_info->height) /
689 static_cast<float>(native_mode_info->height); 694 static_cast<float>(native_mode_info->height);
690 695
691 area_ratio = width_ratio * height_ratio; 696 area_ratio = width_ratio * height_ratio;
692 return area_ratio; 697 return area_ratio;
693 } 698 }
694 699
695 } // namespace chromeos 700 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698