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 system_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 int visuals_len; |
| 1428 XVisualInfo visual_template; |
| 1429 visual_template.screen = DefaultScreen(display_); |
| 1430 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( |
| 1431 display_, VisualScreenMask, &visual_template, &visuals_len)); |
| 1432 for (int i = 0; i < visuals_len; ++i) |
| 1433 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); |
1432 | 1434 |
1433 int visuals_len; | 1435 XAtom NET_WM_CM_S0 = XInternAtom(display_, "_NET_WM_CM_S0", False); |
1434 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | 1436 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None; |
1435 display, VisualScreenMask, &visual_template, &visuals_len)); | 1437 |
1436 for (int i = 0; i < visuals_len; ++i) { | 1438 // Choose the opaque visual. |
1437 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | 1439 XWindowAttributes attribs; |
1438 // gdkvisual-x11.cc, they look for this specific visual and use it for | 1440 Window root = XDefaultRootWindow(display_); |
1439 // all their alpha channel using needs. | 1441 Status status = XGetWindowAttributes(display_, root, &attribs); |
1440 const XVisualInfo& info = visual_list[i]; | 1442 DCHECK_NE(0, status); |
1441 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | 1443 system_visual_id_ = attribs.visual->visualid; |
1442 info.visual->green_mask == 0x00ff00 && | 1444 DCHECK(system_visual_id_); |
1443 info.visual->blue_mask == 0x0000ff) { | 1445 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); |
1444 s_transparent_visual = info.visual; | 1446 |
1445 s_transparent_depth = info.depth; | 1447 // Choose the transparent visual. |
1446 DCHECK(s_transparent_visual); | 1448 for (const auto& pair : visuals_) { |
1447 break; | 1449 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In |
1448 } | 1450 // gdkvisual-x11.cc, they look for this specific visual and use it for |
1449 } | 1451 // all their alpha channel using needs. |
| 1452 const XVisualInfo& info = pair.second->visual_info; |
| 1453 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && |
| 1454 info.visual->green_mask == 0x00ff00 && |
| 1455 info.visual->blue_mask == 0x0000ff) { |
| 1456 transparent_visual_id_ = info.visualid; |
| 1457 break; |
1450 } | 1458 } |
| 1459 } |
| 1460 DCHECK(transparent_visual_id_); |
| 1461 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end()); |
| 1462 } |
1451 | 1463 |
1452 XWindowAttributes attribs; | 1464 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 | 1465 |
1459 if (!s_transparent_visual) { | 1466 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual, |
1460 s_transparent_visual = s_default_visual; | 1467 Visual** visual, |
1461 s_transparent_depth = s_default_depth; | 1468 int* depth, |
1462 } | 1469 Colormap* colormap, |
1463 } // !s_default_visual || !s_transparent_visual | 1470 bool* using_argb_visual) { |
| 1471 bool use_argb = want_argb_visual && using_compositing_wm_ && |
| 1472 (using_software_rendering_ || have_gpu_argb_visual_); |
| 1473 XVisualData& visual_data = |
| 1474 *visuals_[use_argb ? transparent_visual_id_ : system_visual_id_]; |
| 1475 if (visual) |
| 1476 *visual = visual_data.visual_info.visual; |
| 1477 if (depth) |
| 1478 *depth = visual_data.visual_info.depth; |
| 1479 if (colormap) |
| 1480 *colormap = visual_data.GetColormap(); |
| 1481 if (using_argb_visual) |
| 1482 *using_argb_visual = use_argb; |
| 1483 } |
1464 | 1484 |
1465 DCHECK(s_default_visual); | 1485 bool XVisualManager::OnGPUInfoChanged(bool software_rendering, |
1466 DCHECK(s_default_depth > 0); | 1486 VisualID system_visual_id, |
1467 DCHECK(s_transparent_visual); | 1487 VisualID transparent_visual_id) { |
1468 DCHECK(s_transparent_depth > 0); | 1488 // TODO(thomasanderson): Cache these visual IDs as a property of the root |
| 1489 // window so that newly created browser processes can get them immediately. |
| 1490 if ((system_visual_id && !visuals_.count(system_visual_id)) || |
| 1491 (transparent_visual_id && !visuals_.count(transparent_visual_id))) |
| 1492 return false; |
| 1493 using_software_rendering_ = software_rendering; |
| 1494 have_gpu_argb_visual_ = have_gpu_argb_visual_ || transparent_visual_id; |
| 1495 if (system_visual_id) |
| 1496 system_visual_id_ = system_visual_id; |
| 1497 if (transparent_visual_id) |
| 1498 transparent_visual_id_ = transparent_visual_id; |
| 1499 return true; |
| 1500 } |
1469 | 1501 |
1470 if (visual) | 1502 XVisualManager::XVisualData::XVisualData(XVisualInfo visual_info) |
1471 *visual = | 1503 : visual_info(visual_info), colormap_(CopyFromParent) {} |
1472 enable_transparent_visuals ? s_transparent_visual : s_default_visual; | 1504 |
1473 if (depth) | 1505 XVisualManager::XVisualData::~XVisualData() { |
1474 *depth = enable_transparent_visuals ? s_transparent_depth : s_default_depth; | 1506 // Do not XFreeColormap as this would uninstall the colormap even for |
| 1507 // non-Chromium clients. |
1475 } | 1508 } |
| 1509 |
| 1510 Colormap XVisualManager::XVisualData::GetColormap() { |
| 1511 XDisplay* display = gfx::GetXDisplay(); |
| 1512 if (colormap_ == CopyFromParent) { |
| 1513 colormap_ = XCreateColormap(display, DefaultRootWindow(display), |
| 1514 visual_info.visual, AllocNone); |
| 1515 } |
| 1516 return colormap_; |
| 1517 } |
| 1518 |
1476 #endif | 1519 #endif |
1477 | 1520 |
1478 // ---------------------------------------------------------------------------- | 1521 // ---------------------------------------------------------------------------- |
1479 // End of x11_util_internal.h | 1522 // End of x11_util_internal.h |
1480 | 1523 |
1481 | 1524 |
1482 } // namespace ui | 1525 } // namespace ui |
OLD | NEW |