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 |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 << "X error received: " | 1405 << "X error received: " |
1406 << "serial " << error_event.serial << ", " | 1406 << "serial " << error_event.serial << ", " |
1407 << "error_code " << static_cast<int>(error_event.error_code) | 1407 << "error_code " << static_cast<int>(error_event.error_code) |
1408 << " (" << error_str << "), " | 1408 << " (" << error_str << "), " |
1409 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1409 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1410 << "minor_code " << static_cast<int>(error_event.minor_code) | 1410 << "minor_code " << static_cast<int>(error_event.minor_code) |
1411 << " (" << request_str << ")"; | 1411 << " (" << request_str << ")"; |
1412 } | 1412 } |
1413 | 1413 |
1414 #if !defined(OS_CHROMEOS) | 1414 #if !defined(OS_CHROMEOS) |
1415 void ChooseVisualForWindow(bool enable_transparent_visuals, | |
1416 Visual** visual, | |
1417 int* depth) { | |
1418 static Visual* s_default_visual = nullptr; | |
1419 static Visual* s_transparent_visual = nullptr; | |
1420 static int s_default_depth = 0; | |
1421 static int s_transparent_depth = 0; | |
1422 | 1415 |
1423 if (!s_default_visual || !s_transparent_visual) { | 1416 // static |
1424 XDisplay* display = gfx::GetXDisplay(); | 1417 XVisualManager* XVisualManager::GetInstance() { |
1425 XAtom NET_WM_CM_S0 = XInternAtom(display, "_NET_WM_CM_S0", False); | 1418 return base::Singleton<XVisualManager>::get(); |
1419 } | |
1426 | 1420 |
1427 if (enable_transparent_visuals && | 1421 XVisualManager::XVisualManager() |
1428 XGetSelectionOwner(display, NET_WM_CM_S0) != None) { | 1422 : display_(gfx::GetXDisplay()), |
1429 // Choose the first ARGB8888 visual | 1423 default_visual_id_(0), |
1430 XVisualInfo visual_template; | 1424 transparent_visual_id_(0), |
1431 visual_template.screen = 0; | 1425 using_software_rendering_(false), |
1426 have_gpu_argb_visual_(false) { | |
1427 XDisplay* display = gfx::GetXDisplay(); | |
piman
2016/09/22 21:24:55
nit: isn't that display_ ?
Tom (Use chromium acct)
2016/09/23 20:00:37
Done.
| |
1428 int visuals_len; | |
1429 XVisualInfo visual_template; | |
1430 visual_template.screen = DefaultScreen(display); | |
1431 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | |
1432 display, VisualScreenMask, &visual_template, &visuals_len)); | |
1433 for (int i = 0; i < visuals_len; ++i) | |
1434 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); | |
1432 | 1435 |
1433 int visuals_len; | 1436 XAtom NET_WM_CM_S0 = XInternAtom(display, "_NET_WM_CM_S0", False); |
1434 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | 1437 using_compositing_wm_ = XGetSelectionOwner(display, NET_WM_CM_S0) != None; |
1435 display, VisualScreenMask, &visual_template, &visuals_len)); | 1438 |
1436 for (int i = 0; i < visuals_len; ++i) { | 1439 // Choose the opaque visual. |
1437 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | 1440 XWindowAttributes attribs; |
1438 // gdkvisual-x11.cc, they look for this specific visual and use it for | 1441 Window root = XDefaultRootWindow(display_); |
1439 // all their alpha channel using needs. | 1442 Status status = XGetWindowAttributes(display_, root, &attribs); |
1440 const XVisualInfo& info = visual_list[i]; | 1443 DCHECK_NE(0, status); |
1441 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | 1444 default_visual_id_ = attribs.visual->visualid; |
1442 info.visual->green_mask == 0x00ff00 && | 1445 DCHECK(default_visual_id_); |
1443 info.visual->blue_mask == 0x0000ff) { | 1446 DCHECK(visuals_.find(default_visual_id_) != visuals_.end()); |
1444 s_transparent_visual = info.visual; | 1447 |
1445 s_transparent_depth = info.depth; | 1448 // Choose the transparent visual. |
1446 DCHECK(s_transparent_visual); | 1449 for (const auto& pair : visuals_) { |
1447 break; | 1450 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In |
1448 } | 1451 // gdkvisual-x11.cc, they look for this specific visual and use it for |
1449 } | 1452 // all their alpha channel using needs. |
1453 const XVisualInfo& info = pair.second->visual_info; | |
1454 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | |
1455 info.visual->green_mask == 0x00ff00 && | |
1456 info.visual->blue_mask == 0x0000ff) { | |
1457 transparent_visual_id_ = info.visualid; | |
1458 break; | |
1450 } | 1459 } |
1460 } | |
1461 DCHECK(transparent_visual_id_); | |
1462 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end()); | |
1463 } | |
1451 | 1464 |
1452 XWindowAttributes attribs; | 1465 XVisualManager::~XVisualManager() {} |
1453 Window root = XDefaultRootWindow(display); | |
1454 Status status = XGetWindowAttributes(display, root, &attribs); | |
1455 DCHECK_NE(0, status); | |
1456 s_default_visual = attribs.visual; | |
1457 s_default_depth = attribs.depth; | |
1458 | 1466 |
1459 if (!s_transparent_visual) { | 1467 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual, |
1460 s_transparent_visual = s_default_visual; | 1468 Visual** visual, |
1461 s_transparent_depth = s_default_depth; | 1469 int* depth, |
1462 } | 1470 Colormap* colormap, |
1463 } // !s_default_visual || !s_transparent_visual | 1471 bool* using_argb_visual) { |
1472 DCHECK(visual && depth && colormap && using_argb_visual); | |
1473 *using_argb_visual = want_argb_visual && using_compositing_wm_ && | |
1474 (using_software_rendering_ || have_gpu_argb_visual_); | |
1475 VisualID ret_visual_id = | |
1476 *using_argb_visual ? transparent_visual_id_ : default_visual_id_; | |
1477 XVisualData& visual_data = *visuals_[ret_visual_id]; | |
1478 *visual = visual_data.visual_info.visual; | |
1479 *depth = visual_data.visual_info.depth; | |
1480 *colormap = visual_data.GetColormap(); | |
1481 } | |
1464 | 1482 |
1465 DCHECK(s_default_visual); | 1483 void XVisualManager::OnGPUInfoChanged(bool software_rendering, |
1466 DCHECK(s_default_depth > 0); | 1484 VisualID default_visual_id, |
1467 DCHECK(s_transparent_visual); | 1485 VisualID transparent_visual_id) { |
1468 DCHECK(s_transparent_depth > 0); | 1486 // TODO(thomasanderson): Cache these visual IDs as a property of the root |
1487 // window so that newly created browser processes can get them immediately. | |
1488 using_software_rendering_ = software_rendering; | |
1489 have_gpu_argb_visual_ = have_gpu_argb_visual_ || transparent_visual_id; | |
1490 if (default_visual_id) | |
1491 default_visual_id_ = default_visual_id; | |
1492 if (transparent_visual_id) | |
1493 transparent_visual_id_ = transparent_visual_id; | |
1494 } | |
1469 | 1495 |
1470 if (visual) | 1496 XVisualManager::XVisualData::XVisualData(XVisualInfo visual_info) |
1471 *visual = | 1497 : visual_info(visual_info), colormap_(CopyFromParent) {} |
1472 enable_transparent_visuals ? s_transparent_visual : s_default_visual; | 1498 |
1473 if (depth) | 1499 XVisualManager::XVisualData::~XVisualData() { |
1474 *depth = enable_transparent_visuals ? s_transparent_depth : s_default_depth; | 1500 // Do not XFreeColormap as this would uninstall the colormap even for |
1501 // non-Chromium clients. | |
1475 } | 1502 } |
1503 | |
1504 Colormap XVisualManager::XVisualData::GetColormap() { | |
1505 XDisplay* display = gfx::GetXDisplay(); | |
1506 if (colormap_ == CopyFromParent) { | |
1507 colormap_ = XCreateColormap(display, DefaultRootWindow(display), | |
1508 visual_info.visual, AllocNone); | |
1509 } | |
1510 return colormap_; | |
1511 } | |
1512 | |
1476 #endif | 1513 #endif |
1477 | 1514 |
1478 // ---------------------------------------------------------------------------- | 1515 // ---------------------------------------------------------------------------- |
1479 // End of x11_util_internal.h | 1516 // End of x11_util_internal.h |
1480 | 1517 |
1481 | 1518 |
1482 } // namespace ui | 1519 } // namespace ui |
OLD | NEW |