Skip to content

Commit

Permalink
Support for retreiving the monitor color space on X11.
Browse files Browse the repository at this point in the history
BUG=622133

Review-Url: https://codereview.chromium.org/2115103002
Cr-Commit-Position: refs/heads/master@{#403958}
  • Loading branch information
hubbe authored and Commit bot committed Jul 6, 2016
1 parent f0fad4a commit b0df9e3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ui/gfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ component("gfx") {
"color_space.h",
"color_space_mac.mm",
"color_space_win.cc",
"color_space_x11.cc",
"color_utils.cc",
"color_utils.h",
"favicon_size.cc",
Expand Down Expand Up @@ -400,7 +401,10 @@ component("gfx") {
deps += [ "//ui/gfx/x" ]
configs += [ "//build/config/linux:x11" ]
} else {
sources -= [ "path_x11.cc" ]
sources -= [
"color_space_x11.cc",
"path_x11.cc",
]
}

if (use_cairo) {
Expand Down
2 changes: 1 addition & 1 deletion ui/gfx/color_space.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ColorSpace ColorSpace::FromICCProfile(const std::vector<char>& icc_profile) {
return color_space;
}

#if !defined(OS_WIN) && !defined(OS_MACOSX)
#if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11)
// static
ColorSpace ColorSpace::FromBestMonitor() {
return ColorSpace();
Expand Down
40 changes: 40 additions & 0 deletions ui/gfx/color_space_x11.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

extern "C" {
#include <X11/Xatom.h>
#include <X11/Xlib.h>
}

#include "ui/gfx/color_space.h"

#include "ui/gfx/x/x11_types.h"

namespace gfx {

// static
ColorSpace ColorSpace::FromBestMonitor() {
ColorSpace color_space;
Atom property = XInternAtom(GetXDisplay(), "_ICC_PROFILE", true);
if (property != None) {
Atom prop_type = None;
int prop_format = 0;
unsigned long nitems = 0;
unsigned long nbytes = 0;
char* property_data = NULL;
if (XGetWindowProperty(
GetXDisplay(), DefaultRootWindow(GetXDisplay()), property, 0,
0x1FFFFFFF /* MAXINT32 / 4 */, False, AnyPropertyType, &prop_type,
&prop_format, &nitems, &nbytes,
reinterpret_cast<unsigned char**>(&property_data)) == Success) {
color_space.icc_profile_.assign(property_data, property_data + nitems);
XFree(property_data);
}
}
return color_space;
}

} // namespace gfx
1 change: 1 addition & 0 deletions ui/gfx/gfx.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
'color_space.h',
'color_space_mac.mm',
'color_space_win.cc',
'color_space_x11.cc',
'color_utils.cc',
'color_utils.h',
'favicon_size.cc',
Expand Down

0 comments on commit b0df9e3

Please sign in to comment.