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

Side by Side Diff: ui/display/manager/chromeos/x11/native_display_delegate_x11.cc

Issue 2914103002: Remove usages of XInternAtom (Closed)
Patch Set: Address sadrul and sergeyu comments Created 3 years, 6 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
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/display/util/x11/edid_parser_x11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/display/manager/chromeos/x11/native_display_delegate_x11.h" 5 #include "ui/display/manager/chromeos/x11/native_display_delegate_x11.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 #include <X11/extensions/dpms.h> 9 #include <X11/extensions/dpms.h>
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
11 #include <X11/extensions/Xrandr.h> 11 #include <X11/extensions/Xrandr.h>
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "ui/base/x/x11_util.h"
19 #include "ui/display/manager/chromeos/x11/display_mode_x11.h" 20 #include "ui/display/manager/chromeos/x11/display_mode_x11.h"
20 #include "ui/display/manager/chromeos/x11/display_snapshot_x11.h" 21 #include "ui/display/manager/chromeos/x11/display_snapshot_x11.h"
21 #include "ui/display/manager/chromeos/x11/display_util_x11.h" 22 #include "ui/display/manager/chromeos/x11/display_util_x11.h"
22 #include "ui/display/manager/chromeos/x11/native_display_event_dispatcher_x11.h" 23 #include "ui/display/manager/chromeos/x11/native_display_event_dispatcher_x11.h"
23 #include "ui/display/types/native_display_observer.h" 24 #include "ui/display/types/native_display_observer.h"
24 #include "ui/display/util/x11/edid_parser_x11.h" 25 #include "ui/display/util/x11/edid_parser_x11.h"
25 #include "ui/events/platform/platform_event_source.h" 26 #include "ui/events/platform/platform_event_source.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
27 #include "ui/gfx/x/x11_error_tracker.h" 28 #include "ui/gfx/x/x11_error_tracker.h"
28 #include "ui/gfx/x/x11_types.h" 29 #include "ui/gfx/x/x11_types.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 396
396 bool NativeDisplayDelegateX11::GetHDCPState(const DisplaySnapshot& output, 397 bool NativeDisplayDelegateX11::GetHDCPState(const DisplaySnapshot& output,
397 HDCPState* state) { 398 HDCPState* state) {
398 unsigned char* values = NULL; 399 unsigned char* values = NULL;
399 int actual_format = 0; 400 int actual_format = 0;
400 unsigned long nitems = 0; 401 unsigned long nitems = 0;
401 unsigned long bytes_after = 0; 402 unsigned long bytes_after = 0;
402 Atom actual_type = None; 403 Atom actual_type = None;
403 int success = 0; 404 int success = 0;
404 RROutput output_id = static_cast<const DisplaySnapshotX11&>(output).output(); 405 RROutput output_id = static_cast<const DisplaySnapshotX11&>(output).output();
405 // TODO(kcwu): Use X11AtomCache to save round trip time of XInternAtom. 406 Atom prop = ui::GetAtom(kContentProtectionAtomName);
406 Atom prop = XInternAtom(display_, kContentProtectionAtomName, False);
407 407
408 // TODO(kcwu): Move this to x11_util (similar method calls in this file and 408 // TODO(kcwu): Move this to x11_util (similar method calls in this file and
409 // output_util.cc) 409 // output_util.cc)
410 success = XRRGetOutputProperty(display_, 410 success = XRRGetOutputProperty(display_,
411 output_id, 411 output_id,
412 prop, 412 prop,
413 0, 413 0,
414 100, 414 100,
415 False, 415 False,
416 False, 416 False,
417 AnyPropertyType, 417 AnyPropertyType,
418 &actual_type, 418 &actual_type,
419 &actual_format, 419 &actual_format,
420 &nitems, 420 &nitems,
421 &bytes_after, 421 &bytes_after,
422 &values); 422 &values);
423 gfx::XScopedPtr<unsigned char> scoped_values(values); 423 gfx::XScopedPtr<unsigned char> scoped_values(values);
424 if (actual_type == None) { 424 if (actual_type == None) {
425 LOG(ERROR) << "Property '" << kContentProtectionAtomName 425 LOG(ERROR) << "Property '" << kContentProtectionAtomName
426 << "' does not exist"; 426 << "' does not exist";
427 return false; 427 return false;
428 } 428 }
429 429
430 if (success == Success && actual_type == XA_ATOM && actual_format == 32 && 430 if (success == Success && actual_type == XA_ATOM && actual_format == 32 &&
431 nitems == 1) { 431 nitems == 1) {
432 Atom value = reinterpret_cast<Atom*>(values)[0]; 432 Atom value = reinterpret_cast<Atom*>(values)[0];
433 if (value == XInternAtom(display_, kProtectionUndesiredAtomName, False)) { 433 if (value == ui::GetAtom(kProtectionUndesiredAtomName)) {
434 *state = HDCP_STATE_UNDESIRED; 434 *state = HDCP_STATE_UNDESIRED;
435 } else if (value == 435 } else if (value == ui::GetAtom(kProtectionDesiredAtomName)) {
436 XInternAtom(display_, kProtectionDesiredAtomName, False)) {
437 *state = HDCP_STATE_DESIRED; 436 *state = HDCP_STATE_DESIRED;
438 } else if (value == 437 } else if (value == ui::GetAtom(kProtectionEnabledAtomName)) {
439 XInternAtom(display_, kProtectionEnabledAtomName, False)) {
440 *state = HDCP_STATE_ENABLED; 438 *state = HDCP_STATE_ENABLED;
441 } else { 439 } else {
442 LOG(ERROR) << "Unknown " << kContentProtectionAtomName 440 LOG(ERROR) << "Unknown " << kContentProtectionAtomName
443 << " value: " << value; 441 << " value: " << value;
444 return false; 442 return false;
445 } 443 }
446 } else { 444 } else {
447 LOG(ERROR) << "XRRGetOutputProperty failed"; 445 LOG(ERROR) << "XRRGetOutputProperty failed";
448 return false; 446 return false;
449 } 447 }
450 448
451 VLOG(3) << "HDCP state: success," << *state; 449 VLOG(3) << "HDCP state: success," << *state;
452 return true; 450 return true;
453 } 451 }
454 452
455 void NativeDisplayDelegateX11::SetHDCPState( 453 void NativeDisplayDelegateX11::SetHDCPState(
456 const DisplaySnapshot& output, 454 const DisplaySnapshot& output,
457 HDCPState state, 455 HDCPState state,
458 const SetHDCPStateCallback& callback) { 456 const SetHDCPStateCallback& callback) {
459 callback.Run(SetHDCPState(output, state)); 457 callback.Run(SetHDCPState(output, state));
460 } 458 }
461 459
462 bool NativeDisplayDelegateX11::SetHDCPState(const DisplaySnapshot& output, 460 bool NativeDisplayDelegateX11::SetHDCPState(const DisplaySnapshot& output,
463 HDCPState state) { 461 HDCPState state) {
464 Atom name = XInternAtom(display_, kContentProtectionAtomName, False); 462 Atom name = ui::GetAtom(kContentProtectionAtomName);
465 Atom value = None; 463 Atom value = None;
466 switch (state) { 464 switch (state) {
467 case HDCP_STATE_UNDESIRED: 465 case HDCP_STATE_UNDESIRED:
468 value = XInternAtom(display_, kProtectionUndesiredAtomName, False); 466 value = ui::GetAtom(kProtectionUndesiredAtomName);
469 break; 467 break;
470 case HDCP_STATE_DESIRED: 468 case HDCP_STATE_DESIRED:
471 value = XInternAtom(display_, kProtectionDesiredAtomName, False); 469 value = ui::GetAtom(kProtectionDesiredAtomName);
472 break; 470 break;
473 default: 471 default:
474 NOTREACHED() << "Invalid HDCP state: " << state; 472 NOTREACHED() << "Invalid HDCP state: " << state;
475 return false; 473 return false;
476 } 474 }
477 gfx::X11ErrorTracker err_tracker; 475 gfx::X11ErrorTracker err_tracker;
478 unsigned char* data = reinterpret_cast<unsigned char*>(&value); 476 unsigned char* data = reinterpret_cast<unsigned char*>(&value);
479 RROutput output_id = static_cast<const DisplaySnapshotX11&>(output).output(); 477 RROutput output_id = static_cast<const DisplaySnapshotX11&>(output).output();
480 XRRChangeOutputProperty( 478 XRRChangeOutputProperty(
481 display_, output_id, name, XA_ATOM, 32, PropModeReplace, data, 1); 479 display_, output_id, name, XA_ATOM, 32, PropModeReplace, data, 1);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 output = None; 536 output = None;
539 mode_info = NULL; 537 mode_info = NULL;
540 } 538 }
541 } 539 }
542 540
543 ConfigureCrtc(x11_output->crtc(), mode, output, 0, 0); 541 ConfigureCrtc(x11_output->crtc(), mode, output, 0, 0);
544 } 542 }
545 } 543 }
546 544
547 bool NativeDisplayDelegateX11::IsOutputAspectPreservingScaling(RROutput id) { 545 bool NativeDisplayDelegateX11::IsOutputAspectPreservingScaling(RROutput id) {
548 Atom scaling_prop = XInternAtom(display_, "scaling mode", False); 546 Atom scaling_prop = ui::GetAtom("scaling mode");
549 Atom full_aspect_atom = XInternAtom(display_, "Full aspect", False); 547 Atom full_aspect_atom = ui::GetAtom("Full aspect");
550 if (scaling_prop == None || full_aspect_atom == None) 548 if (scaling_prop == None || full_aspect_atom == None)
551 return false; 549 return false;
552 550
553 int nprop = 0; 551 int nprop = 0;
554 gfx::XScopedPtr<Atom[]> props(XRRListOutputProperties(display_, id, &nprop)); 552 gfx::XScopedPtr<Atom[]> props(XRRListOutputProperties(display_, id, &nprop));
555 for (int j = 0; j < nprop; j++) { 553 for (int j = 0; j < nprop; j++) {
556 Atom prop = props[j]; 554 Atom prop = props[j];
557 if (scaling_prop == prop) { 555 if (scaling_prop == prop) {
558 unsigned char* values = NULL; 556 unsigned char* values = NULL;
559 int actual_format; 557 int actual_format;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 XSetForeground(display_, gc, color.pixel); 647 XSetForeground(display_, gc, color.pixel);
650 XSetFillStyle(display_, gc, FillSolid); 648 XSetFillStyle(display_, gc, FillSolid);
651 int width = DisplayWidth(display_, DefaultScreen(display_)); 649 int width = DisplayWidth(display_, DefaultScreen(display_));
652 int height = DisplayHeight(display_, DefaultScreen(display_)); 650 int height = DisplayHeight(display_, DefaultScreen(display_));
653 XFillRectangle(display_, window_, gc, 0, 0, width, height); 651 XFillRectangle(display_, window_, gc, 0, 0, width, height);
654 XFreeGC(display_, gc); 652 XFreeGC(display_, gc);
655 XFreeColors(display_, colormap, &color.pixel, 1, 0); 653 XFreeColors(display_, colormap, &color.pixel, 1, 0);
656 } 654 }
657 655
658 } // namespace display 656 } // namespace display
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/display/util/x11/edid_parser_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698