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

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

Issue 24039002: Pepper API implementation for output protection. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: use cached_outputs_ in output_configurator Created 7 years, 3 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
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
266 new_state, power_state_, outputs); 268 new_state, power_state_, outputs);
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(outputs)); 274 delegate_->SendProjectingStateToPowerManager(IsProjecting(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_desires = desired_method_mask;
Daniel Erat 2013/09/23 19:31:43 nit: s/all_desires/all_desired/
kcwu 2013/09/24 13:55:06 Done.
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) {
Daniel Erat 2013/09/23 19:31:43 nit: remove curly brackets here
kcwu 2013/09/24 13:55:06 Done.
354 all_desires |= it->second;
355 }
356 }
357
358 for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin();
359 it != cached_outputs_.end(); ++it) {
360 RROutput this_id = it->output;
361 switch (it->type) {
362 case OUTPUT_TYPE_UNKNOWN:
363 return false;
364 // HDMI and DisplayPort both support HDCP.
365 case OUTPUT_TYPE_HDMI:
366 case OUTPUT_TYPE_DISPLAYPORT: {
367 HDCPState new_desired_state =
368 (all_desires & OUTPUT_PROTECTION_METHOD_HDCP) ?
369 HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED;
370 if (!delegate_->SetHDCPState(this_id, new_desired_state))
371 return false;
372 break;
373 }
374 case OUTPUT_TYPE_INTERNAL:
375 case OUTPUT_TYPE_VGA:
376 case OUTPUT_TYPE_DVI:
377 // No protections for these types. Do nothing.
378 break;
379 case OUTPUT_TYPE_NONE:
380 NOTREACHED();
381 break;
382 }
383 }
384
385 if (desired_method_mask == OUTPUT_PROTECTION_METHOD_NONE)
386 client_protection_requests_.erase(client_id);
387 else
388 client_protection_requests_[client_id] = desired_method_mask;
389
390 return true;
391 }
392
276 void OutputConfigurator::Stop() { 393 void OutputConfigurator::Stop() {
277 configure_display_ = false; 394 configure_display_ = false;
278 } 395 }
279 396
280 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state, 397 bool OutputConfigurator::SetDisplayPower(DisplayPowerState power_state,
281 int flags) { 398 int flags) {
282 if (!configure_display_) 399 if (!configure_display_)
283 return false; 400 return false;
284 401
285 VLOG(1) << "SetDisplayPower: power_state=" 402 VLOG(1) << "SetDisplayPower: power_state="
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 float width_ratio = static_cast<float>(mirror_mode_info->width) / 978 float width_ratio = static_cast<float>(mirror_mode_info->width) /
862 static_cast<float>(native_mode_info->width); 979 static_cast<float>(native_mode_info->width);
863 float height_ratio = static_cast<float>(mirror_mode_info->height) / 980 float height_ratio = static_cast<float>(mirror_mode_info->height) /
864 static_cast<float>(native_mode_info->height); 981 static_cast<float>(native_mode_info->height);
865 982
866 area_ratio = width_ratio * height_ratio; 983 area_ratio = width_ratio * height_ratio;
867 return area_ratio; 984 return area_ratio;
868 } 985 }
869 986
870 } // namespace chromeos 987 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698