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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
11 #include <ctype.h> | 11 #include <ctype.h> |
12 #include <sys/ipc.h> | 12 #include <sys/ipc.h> |
13 #include <sys/shm.h> | 13 #include <sys/shm.h> |
14 | 14 |
15 #include <list> | 15 #include <list> |
16 #include <map> | 16 #include <map> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include <X11/extensions/shape.h> | 20 #include <X11/extensions/shape.h> |
21 #include <X11/extensions/XInput2.h> | 21 #include <X11/extensions/XInput2.h> |
22 #include <X11/Xcursor/Xcursor.h> | 22 #include <X11/Xcursor/Xcursor.h> |
23 | 23 |
24 #include "base/bind.h" | 24 #include "base/bind.h" |
25 #include "base/command_line.h" | |
25 #include "base/logging.h" | 26 #include "base/logging.h" |
26 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
27 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
28 #include "base/message_loop/message_loop.h" | 29 #include "base/message_loop/message_loop.h" |
29 #include "base/metrics/histogram.h" | 30 #include "base/metrics/histogram.h" |
30 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
31 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
32 #include "base/strings/stringprintf.h" | 33 #include "base/strings/stringprintf.h" |
33 #include "base/sys_byteorder.h" | 34 #include "base/sys_byteorder.h" |
34 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
45 #include "ui/gfx/canvas.h" | 46 #include "ui/gfx/canvas.h" |
46 #include "ui/gfx/geometry/insets.h" | 47 #include "ui/gfx/geometry/insets.h" |
47 #include "ui/gfx/geometry/point.h" | 48 #include "ui/gfx/geometry/point.h" |
48 #include "ui/gfx/geometry/point_conversions.h" | 49 #include "ui/gfx/geometry/point_conversions.h" |
49 #include "ui/gfx/geometry/rect.h" | 50 #include "ui/gfx/geometry/rect.h" |
50 #include "ui/gfx/geometry/size.h" | 51 #include "ui/gfx/geometry/size.h" |
51 #include "ui/gfx/image/image_skia.h" | 52 #include "ui/gfx/image/image_skia.h" |
52 #include "ui/gfx/image/image_skia_rep.h" | 53 #include "ui/gfx/image/image_skia_rep.h" |
53 #include "ui/gfx/skia_util.h" | 54 #include "ui/gfx/skia_util.h" |
54 #include "ui/gfx/x/x11_error_tracker.h" | 55 #include "ui/gfx/x/x11_error_tracker.h" |
56 #include "ui/gfx/x/x11_switches.h" | |
55 | 57 |
56 #if defined(OS_FREEBSD) | 58 #if defined(OS_FREEBSD) |
57 #include <sys/sysctl.h> | 59 #include <sys/sysctl.h> |
58 #include <sys/types.h> | 60 #include <sys/types.h> |
59 #endif | 61 #endif |
60 | 62 |
61 namespace ui { | 63 namespace ui { |
62 | 64 |
63 namespace { | 65 namespace { |
64 | 66 |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 LOG(WARNING) | 1404 LOG(WARNING) |
1403 << "X error received: " | 1405 << "X error received: " |
1404 << "serial " << error_event.serial << ", " | 1406 << "serial " << error_event.serial << ", " |
1405 << "error_code " << static_cast<int>(error_event.error_code) | 1407 << "error_code " << static_cast<int>(error_event.error_code) |
1406 << " (" << error_str << "), " | 1408 << " (" << error_str << "), " |
1407 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1409 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1408 << "minor_code " << static_cast<int>(error_event.minor_code) | 1410 << "minor_code " << static_cast<int>(error_event.minor_code) |
1409 << " (" << request_str << ")"; | 1411 << " (" << request_str << ")"; |
1410 } | 1412 } |
1411 | 1413 |
1414 void ChooseVisualForWindow(Visual** visual, int* depth) { | |
1415 static Visual* s_visual = NULL; | |
1416 static int s_depth = 0; | |
1417 | |
1418 if (!s_visual) { | |
1419 XDisplay* display = gfx::GetXDisplay(); | |
1420 XAtom NET_WM_CM_S0 = XInternAtom(display, "_NET_WM_CM_S0", False); | |
1421 | |
1422 // TODO(cwallez) make the switch be a constant again | |
1423 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1424 "enable-transparent-visuals") && | |
1425 XGetSelectionOwner(display, NET_WM_CM_S0) != None) { | |
1426 // Choose the first ARGB8888 visual | |
1427 XVisualInfo visual_template; | |
1428 visual_template.screen = 0; | |
1429 | |
1430 int visuals_len; | |
1431 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | |
1432 display, VisualScreenMask, &visual_template, &visuals_len)); | |
1433 for (int i = 0; i < visuals_len; ++i) { | |
1434 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | |
1435 // gdkvisual-x11.cc, they look for this specific visual and use it for | |
1436 // all their alpha channel using needs. | |
1437 // | |
1438 // TODO(erg): While the following does find a valid visual, some GL | |
1439 // drivers | |
1440 // don't believe that this has an alpha channel. According to marcheu@, | |
1441 // this should work on open source driver though. (It doesn't work with | |
1442 // NVidia's binaries currently.) http://crbug.com/369209 | |
1443 const XVisualInfo& info = visual_list[i]; | |
1444 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | |
1445 info.visual->green_mask == 0x00ff00 && | |
1446 info.visual->blue_mask == 0x0000ff) { | |
1447 s_visual = info.visual; | |
1448 s_depth = info.depth; | |
piman
2015/11/20 21:56:58
nit: break;
Julien Isorce Samsung
2015/11/20 23:26:39
Ah right, I completely missed that one, thx.
| |
1449 } | |
1450 } | |
1451 } else { | |
1452 XWindowAttributes windowAttribs; | |
1453 Window root = XDefaultRootWindow(display); | |
1454 Status status = XGetWindowAttributes(display, root, &windowAttribs); | |
1455 DCHECK(status != 0); | |
1456 s_visual = windowAttribs.visual; | |
1457 s_depth = windowAttribs.depth; | |
1458 } | |
1459 } // !s_visual | |
1460 | |
1461 DCHECK(s_visual); | |
1462 DCHECK(s_depth > 0); | |
1463 | |
1464 if (visual) | |
1465 *visual = s_visual; | |
1466 if (depth) | |
1467 *depth = s_depth; | |
1468 } | |
1469 | |
1412 // ---------------------------------------------------------------------------- | 1470 // ---------------------------------------------------------------------------- |
1413 // End of x11_util_internal.h | 1471 // End of x11_util_internal.h |
1414 | 1472 |
1415 | 1473 |
1416 } // namespace ui | 1474 } // namespace ui |
OLD | NEW |