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/Xrandr.h> | 8 #include <X11/extensions/Xrandr.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 | 10 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 current_mode(None), | 125 current_mode(None), |
126 native_mode(None), | 126 native_mode(None), |
127 mirror_mode(None), | 127 mirror_mode(None), |
128 selected_mode(None), | 128 selected_mode(None), |
129 x(0), | 129 x(0), |
130 y(0), | 130 y(0), |
131 width_mm(0), | 131 width_mm(0), |
132 height_mm(0), | 132 height_mm(0), |
133 is_internal(false), | 133 is_internal(false), |
134 is_aspect_preserving_scaling(false), | 134 is_aspect_preserving_scaling(false), |
| 135 type(OUTPUT_TYPE_UNKNOWN), |
135 touch_device_id(0), | 136 touch_device_id(0), |
136 display_id(0), | 137 display_id(0), |
137 has_display_id(false), | 138 has_display_id(false), |
138 index(0) {} | 139 index(0) {} |
139 | 140 |
140 OutputConfigurator::OutputSnapshot::~OutputSnapshot() {} | 141 OutputConfigurator::OutputSnapshot::~OutputSnapshot() {} |
141 | 142 |
142 void OutputConfigurator::TestApi::SendScreenChangeEvent() { | 143 void OutputConfigurator::TestApi::SendScreenChangeEvent() { |
143 XRRScreenChangeNotifyEvent event = {0}; | 144 XRRScreenChangeNotifyEvent event = {0}; |
144 event.type = xrandr_event_base_ + RRScreenChangeNotify; | 145 event.type = xrandr_event_base_ + RRScreenChangeNotify; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return found; | 221 return found; |
221 } | 222 } |
222 | 223 |
223 OutputConfigurator::OutputConfigurator() | 224 OutputConfigurator::OutputConfigurator() |
224 : state_controller_(NULL), | 225 : state_controller_(NULL), |
225 mirroring_controller_(NULL), | 226 mirroring_controller_(NULL), |
226 is_panel_fitting_enabled_(false), | 227 is_panel_fitting_enabled_(false), |
227 configure_display_(base::chromeos::IsRunningOnChromeOS()), | 228 configure_display_(base::chromeos::IsRunningOnChromeOS()), |
228 xrandr_event_base_(0), | 229 xrandr_event_base_(0), |
229 output_state_(STATE_INVALID), | 230 output_state_(STATE_INVALID), |
230 power_state_(DISPLAY_POWER_ALL_ON) { | 231 power_state_(DISPLAY_POWER_ALL_ON), |
| 232 next_output_protection_client_id_(1) { |
231 } | 233 } |
232 | 234 |
233 OutputConfigurator::~OutputConfigurator() {} | 235 OutputConfigurator::~OutputConfigurator() {} |
234 | 236 |
235 void OutputConfigurator::SetDelegateForTesting(scoped_ptr<Delegate> delegate) { | 237 void OutputConfigurator::SetDelegateForTesting(scoped_ptr<Delegate> delegate) { |
236 delegate_ = delegate.Pass(); | 238 delegate_ = delegate.Pass(); |
237 configure_display_ = true; | 239 configure_display_ = true; |
238 } | 240 } |
239 | 241 |
240 void OutputConfigurator::SetInitialDisplayPower(DisplayPowerState power_state) { | 242 void OutputConfigurator::SetInitialDisplayPower(DisplayPowerState power_state) { |
(...skipping 25 matching lines...) Expand all Loading... |
266 new_state, power_state_); | 268 new_state, power_state_); |
267 | 269 |
268 // Force the DPMS on chrome startup as the driver doesn't always detect | 270 // Force the DPMS on chrome startup as the driver doesn't always detect |
269 // that all displays are on when signing out. | 271 // that all displays are on when signing out. |
270 delegate_->ForceDPMSOn(); | 272 delegate_->ForceDPMSOn(); |
271 delegate_->UngrabServer(); | 273 delegate_->UngrabServer(); |
272 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); | 274 delegate_->SendProjectingStateToPowerManager(IsProjecting(cached_outputs_)); |
273 NotifyObservers(success, new_state); | 275 NotifyObservers(success, new_state); |
274 } | 276 } |
275 | 277 |
| 278 OutputConfigurator::OutputProtectionClientId |
| 279 OutputConfigurator::RegisterOutputProtectionClient() { |
| 280 if (!configure_display_) |
| 281 return 0; |
| 282 |
| 283 return next_output_protection_client_id_++; |
| 284 } |
| 285 |
| 286 void OutputConfigurator::UnregisterOutputProtectionClient( |
| 287 OutputProtectionClientId client_id) { |
| 288 EnableOutputProtection(client_id, OUTPUT_PROTECTION_METHOD_NONE); |
| 289 } |
| 290 |
| 291 bool OutputConfigurator::QueryOutputProtectionStatus( |
| 292 OutputProtectionClientId client_id, |
| 293 uint32_t* link_mask, |
| 294 uint32_t* protection_mask) { |
| 295 if (!configure_display_) |
| 296 return false; |
| 297 |
| 298 uint32_t enabled = 0; |
| 299 uint32_t unfulfilled = 0; |
| 300 *link_mask = 0; |
| 301 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); |
| 302 it != cached_outputs_.end(); ++it) { |
| 303 RROutput this_id = it->output; |
| 304 *link_mask |= it->type; |
| 305 switch (it->type) { |
| 306 case OUTPUT_TYPE_UNKNOWN: |
| 307 return false; |
| 308 // HDMI and DisplayPort both support HDCP. |
| 309 case OUTPUT_TYPE_HDMI: |
| 310 case OUTPUT_TYPE_DISPLAYPORT: { |
| 311 HDCPState state; |
| 312 if (!delegate_->GetHDCPState(this_id, &state)) |
| 313 return false; |
| 314 if (state == HDCP_STATE_ENABLED) |
| 315 enabled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| 316 else |
| 317 unfulfilled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| 318 break; |
| 319 } |
| 320 case OUTPUT_TYPE_INTERNAL: |
| 321 case OUTPUT_TYPE_VGA: |
| 322 case OUTPUT_TYPE_DVI: |
| 323 // No protections for these types. Do nothing. |
| 324 break; |
| 325 case OUTPUT_TYPE_NONE: |
| 326 NOTREACHED(); |
| 327 break; |
| 328 } |
| 329 } |
| 330 |
| 331 // Don't reveal protections requested by other clients. |
| 332 ProtectionRequests::iterator it = client_protection_requests_.find(client_id); |
| 333 if (it != client_protection_requests_.end()) { |
| 334 uint32_t requested_mask = it->second; |
| 335 *protection_mask = enabled & ~unfulfilled & requested_mask; |
| 336 } else { |
| 337 *protection_mask = 0; |
| 338 } |
| 339 return true; |
| 340 } |
| 341 |
| 342 bool OutputConfigurator::EnableOutputProtection( |
| 343 OutputProtectionClientId client_id, |
| 344 uint32_t desired_method_mask) { |
| 345 if (!configure_display_) |
| 346 return false; |
| 347 |
| 348 uint32_t all_desired = desired_method_mask; |
| 349 for (ProtectionRequests::const_iterator it = |
| 350 client_protection_requests_.begin(); |
| 351 it != client_protection_requests_.end(); |
| 352 ++it) { |
| 353 if (it->first != client_id) |
| 354 all_desired |= it->second; |
| 355 } |
| 356 |
| 357 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); |
| 358 it != cached_outputs_.end(); ++it) { |
| 359 RROutput this_id = it->output; |
| 360 switch (it->type) { |
| 361 case OUTPUT_TYPE_UNKNOWN: |
| 362 return false; |
| 363 // HDMI and DisplayPort both support HDCP. |
| 364 case OUTPUT_TYPE_HDMI: |
| 365 case OUTPUT_TYPE_DISPLAYPORT: { |
| 366 HDCPState new_desired_state = |
| 367 (all_desired & OUTPUT_PROTECTION_METHOD_HDCP) ? |
| 368 HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED; |
| 369 if (!delegate_->SetHDCPState(this_id, new_desired_state)) |
| 370 return false; |
| 371 break; |
| 372 } |
| 373 case OUTPUT_TYPE_INTERNAL: |
| 374 case OUTPUT_TYPE_VGA: |
| 375 case OUTPUT_TYPE_DVI: |
| 376 // No protections for these types. Do nothing. |
| 377 break; |
| 378 case OUTPUT_TYPE_NONE: |
| 379 NOTREACHED(); |
| 380 break; |
| 381 } |
| 382 } |
| 383 |
| 384 if (desired_method_mask == OUTPUT_PROTECTION_METHOD_NONE) |
| 385 client_protection_requests_.erase(client_id); |
| 386 else |
| 387 client_protection_requests_[client_id] = desired_method_mask; |
| 388 |
| 389 return true; |
| 390 } |
| 391 |
276 void OutputConfigurator::Stop() { | 392 void OutputConfigurator::Stop() { |
277 configure_display_ = false; | 393 configure_display_ = false; |
278 } | 394 } |
279 | 395 |
280 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state, | 396 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state, |
281 int flags) { | 397 int flags) { |
282 if (!configure_display_) | 398 if (!configure_display_) |
283 return false; | 399 return false; |
284 | 400 |
285 VLOG(1) << "SetDisplayPower: power_state=" | 401 VLOG(1) << "SetDisplayPower: power_state=" |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 float width_ratio = static_cast<float>(mirror_mode_info->width) / | 973 float width_ratio = static_cast<float>(mirror_mode_info->width) / |
858 static_cast<float>(native_mode_info->width); | 974 static_cast<float>(native_mode_info->width); |
859 float height_ratio = static_cast<float>(mirror_mode_info->height) / | 975 float height_ratio = static_cast<float>(mirror_mode_info->height) / |
860 static_cast<float>(native_mode_info->height); | 976 static_cast<float>(native_mode_info->height); |
861 | 977 |
862 area_ratio = width_ratio * height_ratio; | 978 area_ratio = width_ratio * height_ratio; |
863 return area_ratio; | 979 return area_ratio; |
864 } | 980 } |
865 | 981 |
866 } // namespace chromeos | 982 } // namespace chromeos |
OLD | NEW |