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

Side by Side Diff: ui/base/x/x11_util.cc

Issue 1429083002: gl_surface_egl: ensure off and on screen surfaces use the same EGLConfig (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 // 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 <mutex>
17 #include <utility> 18 #include <utility>
18 #include <vector> 19 #include <vector>
19 20
20 #include <X11/extensions/shape.h> 21 #include <X11/extensions/shape.h>
21 #include <X11/extensions/XInput2.h> 22 #include <X11/extensions/XInput2.h>
22 #include <X11/Xcursor/Xcursor.h> 23 #include <X11/Xcursor/Xcursor.h>
23 24
24 #include "base/bind.h" 25 #include "base/bind.h"
26 #include "base/command_line.h"
25 #include "base/logging.h" 27 #include "base/logging.h"
26 #include "base/memory/scoped_ptr.h" 28 #include "base/memory/scoped_ptr.h"
27 #include "base/memory/singleton.h" 29 #include "base/memory/singleton.h"
28 #include "base/message_loop/message_loop.h" 30 #include "base/message_loop/message_loop.h"
29 #include "base/metrics/histogram.h" 31 #include "base/metrics/histogram.h"
30 #include "base/strings/string_number_conversions.h" 32 #include "base/strings/string_number_conversions.h"
31 #include "base/strings/string_util.h" 33 #include "base/strings/string_util.h"
32 #include "base/strings/stringprintf.h" 34 #include "base/strings/stringprintf.h"
33 #include "base/sys_byteorder.h" 35 #include "base/sys_byteorder.h"
34 #include "base/threading/thread.h" 36 #include "base/threading/thread.h"
(...skipping 10 matching lines...) Expand all
45 #include "ui/gfx/canvas.h" 47 #include "ui/gfx/canvas.h"
46 #include "ui/gfx/geometry/insets.h" 48 #include "ui/gfx/geometry/insets.h"
47 #include "ui/gfx/geometry/point.h" 49 #include "ui/gfx/geometry/point.h"
48 #include "ui/gfx/geometry/point_conversions.h" 50 #include "ui/gfx/geometry/point_conversions.h"
49 #include "ui/gfx/geometry/rect.h" 51 #include "ui/gfx/geometry/rect.h"
50 #include "ui/gfx/geometry/size.h" 52 #include "ui/gfx/geometry/size.h"
51 #include "ui/gfx/image/image_skia.h" 53 #include "ui/gfx/image/image_skia.h"
52 #include "ui/gfx/image/image_skia_rep.h" 54 #include "ui/gfx/image/image_skia_rep.h"
53 #include "ui/gfx/skia_util.h" 55 #include "ui/gfx/skia_util.h"
54 #include "ui/gfx/x/x11_error_tracker.h" 56 #include "ui/gfx/x/x11_error_tracker.h"
57 #include "ui/gfx/x/x11_switches.h"
55 58
56 #if defined(OS_FREEBSD) 59 #if defined(OS_FREEBSD)
57 #include <sys/sysctl.h> 60 #include <sys/sysctl.h>
58 #include <sys/types.h> 61 #include <sys/types.h>
59 #endif 62 #endif
60 63
61 namespace ui { 64 namespace ui {
62 65
63 namespace { 66 namespace {
64 67
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 LOG(WARNING) 1405 LOG(WARNING)
1403 << "X error received: " 1406 << "X error received: "
1404 << "serial " << error_event.serial << ", " 1407 << "serial " << error_event.serial << ", "
1405 << "error_code " << static_cast<int>(error_event.error_code) 1408 << "error_code " << static_cast<int>(error_event.error_code)
1406 << " (" << error_str << "), " 1409 << " (" << error_str << "), "
1407 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1410 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1408 << "minor_code " << static_cast<int>(error_event.minor_code) 1411 << "minor_code " << static_cast<int>(error_event.minor_code)
1409 << " (" << request_str << ")"; 1412 << " (" << request_str << ")";
1410 } 1413 }
1411 1414
1415 static void ChooseARGBVisualForWindowOnce(Visual** visual, int* depth) {
1416 XDisplay* display = gfx::GetXDisplay();
1417 XAtom NET_WM_CM_S0 = XInternAtom(display, "_NET_WM_CM_S0", False);
1418
1419 // TODO(cwallez) make the switch be a constant again
1420 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1421 "enable-transparent-visuals") &&
1422 XGetSelectionOwner(display, NET_WM_CM_S0) != None) {
1423 // Choose the first ARGB8888 visual
1424 XVisualInfo visual_template;
1425 visual_template.screen = 0;
1426
1427 int visuals_len;
1428 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo(
1429 display, VisualScreenMask, &visual_template, &visuals_len));
1430 for (int i = 0; i < visuals_len; ++i) {
1431 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In
1432 // gdkvisual-x11.cc, they look for this specific visual and use it for all
1433 // their alpha channel using needs.
1434 //
1435 // TODO(erg): While the following does find a valid visual, some GL
1436 // drivers
1437 // don't believe that this has an alpha channel. According to marcheu@,
1438 // this should work on open source driver though. (It doesn't work with
1439 // NVidia's binaries currently.) http://crbug.com/369209
1440 const XVisualInfo& info = visual_list[i];
1441 if (info.depth == 32 && info.visual->red_mask == 0xff0000 &&
1442 info.visual->green_mask == 0x00ff00 &&
1443 info.visual->blue_mask == 0x0000ff) {
1444 *visual = info.visual;
1445 *depth = info.depth;
1446 }
1447 }
1448 } else {
1449 XWindowAttributes windowAttribs;
1450 Window root = XDefaultRootWindow(display);
1451 Status status = XGetWindowAttributes(display, root, &windowAttribs);
1452 DCHECK(status != 0);
1453 *visual = windowAttribs.visual;
1454 *depth = windowAttribs.depth;
1455 }
1456 }
1457
1458 void ChooseARGBVisualForWindow(Visual** visual, int* depth) {
1459 static std::once_flag init_flag;
1460 static Visual* s_visual = NULL;
1461 static int s_depth = 0;
1462
1463 std::call_once(init_flag, ChooseARGBVisualForWindowOnce, &s_visual, &s_depth);
piman 2015/11/20 01:44:41 std::call_once is a c++11 library feature that is
Julien Isorce Samsung 2015/11/20 09:13:55 Acknowledged.
1464
1465 DCHECK(s_visual);
1466 DCHECK(s_depth > 0);
1467
1468 if (visual)
1469 *visual = s_visual;
1470 if (depth)
1471 *depth = s_depth;
1472 }
1473
1412 // ---------------------------------------------------------------------------- 1474 // ----------------------------------------------------------------------------
1413 // End of x11_util_internal.h 1475 // End of x11_util_internal.h
1414 1476
1415 1477
1416 } // namespace ui 1478 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698