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 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 | 1413 |
1414 #if !defined(OS_CHROMEOS) | 1414 #if !defined(OS_CHROMEOS) |
1415 | 1415 |
1416 // static | 1416 // static |
1417 XVisualManager* XVisualManager::GetInstance() { | 1417 XVisualManager* XVisualManager::GetInstance() { |
1418 return base::Singleton<XVisualManager>::get(); | 1418 return base::Singleton<XVisualManager>::get(); |
1419 } | 1419 } |
1420 | 1420 |
1421 XVisualManager::XVisualManager() | 1421 XVisualManager::XVisualManager() |
1422 : display_(gfx::GetXDisplay()), | 1422 : display_(gfx::GetXDisplay()), |
1423 default_visual_id_(0), | |
1424 system_visual_id_(0), | 1423 system_visual_id_(0), |
1425 transparent_visual_id_(0), | 1424 transparent_visual_id_(0), |
1426 using_software_rendering_(false), | 1425 using_software_rendering_(false), |
1427 have_gpu_argb_visual_(false) { | 1426 have_gpu_argb_visual_(false) { |
1428 int visuals_len; | 1427 int visuals_len; |
1429 XVisualInfo visual_template; | 1428 XVisualInfo visual_template; |
1430 visual_template.screen = DefaultScreen(display_); | 1429 visual_template.screen = DefaultScreen(display_); |
1431 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | 1430 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( |
1432 display_, VisualScreenMask, &visual_template, &visuals_len)); | 1431 display_, VisualScreenMask, &visual_template, &visuals_len)); |
1433 for (int i = 0; i < visuals_len; ++i) | 1432 for (int i = 0; i < visuals_len; ++i) |
1434 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); | 1433 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); |
1435 | 1434 |
1436 XAtom NET_WM_CM_S0 = XInternAtom(display_, "_NET_WM_CM_S0", False); | 1435 XAtom NET_WM_CM_S0 = XInternAtom(display_, "_NET_WM_CM_S0", False); |
1437 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None; | 1436 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None; |
1438 | 1437 |
1439 // Choose the opaque visual. | 1438 // Choose the opaque visual. |
1440 default_visual_id_ = | 1439 XWindowAttributes attribs; |
1441 XVisualIDFromVisual(DefaultVisual(display_, DefaultScreen(display_))); | 1440 Window root = XDefaultRootWindow(display_); |
1442 system_visual_id_ = default_visual_id_; | 1441 Status status = XGetWindowAttributes(display_, root, &attribs); |
| 1442 DCHECK_NE(0, status); |
| 1443 system_visual_id_ = attribs.visual->visualid; |
1443 DCHECK(system_visual_id_); | 1444 DCHECK(system_visual_id_); |
1444 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); | 1445 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); |
1445 | 1446 |
1446 // Choose the transparent visual. | 1447 // Choose the transparent visual. |
1447 for (const auto& pair : visuals_) { | 1448 for (const auto& pair : visuals_) { |
1448 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | 1449 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In |
1449 // gdkvisual-x11.cc, they look for this specific visual and use it for | 1450 // gdkvisual-x11.cc, they look for this specific visual and use it for |
1450 // all their alpha channel using needs. | 1451 // all their alpha channel using needs. |
1451 const XVisualInfo& info = pair.second->visual_info; | 1452 const XVisualInfo& info = pair.second->visual_info; |
1452 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | 1453 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && |
1453 info.visual->green_mask == 0x00ff00 && | 1454 info.visual->green_mask == 0x00ff00 && |
1454 info.visual->blue_mask == 0x0000ff) { | 1455 info.visual->blue_mask == 0x0000ff) { |
1455 transparent_visual_id_ = info.visualid; | 1456 transparent_visual_id_ = info.visualid; |
1456 break; | 1457 break; |
1457 } | 1458 } |
1458 } | 1459 } |
1459 if (transparent_visual_id_) | 1460 if (transparent_visual_id_) |
1460 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end()); | 1461 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end()); |
1461 } | 1462 } |
1462 | 1463 |
1463 XVisualManager::~XVisualManager() {} | 1464 XVisualManager::~XVisualManager() {} |
1464 | 1465 |
1465 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual, | 1466 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual, |
1466 Visual** visual, | 1467 Visual** visual, |
1467 int* depth, | 1468 int* depth, |
1468 Colormap* colormap, | 1469 Colormap* colormap, |
1469 bool* using_argb_visual) { | 1470 bool* using_argb_visual) { |
1470 bool use_argb = want_argb_visual && using_compositing_wm_ && | 1471 bool use_argb = want_argb_visual && using_compositing_wm_ && |
1471 (using_software_rendering_ || have_gpu_argb_visual_); | 1472 (using_software_rendering_ || have_gpu_argb_visual_); |
1472 VisualID visual_id = use_argb && transparent_visual_id_ | 1473 XVisualData& visual_data = |
1473 ? transparent_visual_id_ | 1474 *visuals_[use_argb && transparent_visual_id_ ? transparent_visual_id_ |
1474 : system_visual_id_; | 1475 : system_visual_id_]; |
1475 XVisualData& visual_data = *visuals_[visual_id]; | |
1476 const XVisualInfo& visual_info = visual_data.visual_info; | |
1477 | |
1478 bool is_default_visual = visual_id == default_visual_id_; | |
1479 | |
1480 if (visual) | 1476 if (visual) |
1481 *visual = is_default_visual ? CopyFromParent : visual_info.visual; | 1477 *visual = visual_data.visual_info.visual; |
1482 if (depth) | 1478 if (depth) |
1483 *depth = is_default_visual ? CopyFromParent : visual_info.depth; | 1479 *depth = visual_data.visual_info.depth; |
1484 if (colormap) | 1480 if (colormap) |
1485 *colormap = is_default_visual ? CopyFromParent : visual_data.GetColormap(); | 1481 *colormap = visual_data.GetColormap(); |
1486 if (using_argb_visual) | 1482 if (using_argb_visual) |
1487 *using_argb_visual = use_argb; | 1483 *using_argb_visual = use_argb; |
1488 } | 1484 } |
1489 | 1485 |
1490 bool XVisualManager::OnGPUInfoChanged(bool software_rendering, | 1486 bool XVisualManager::OnGPUInfoChanged(bool software_rendering, |
1491 VisualID system_visual_id, | 1487 VisualID system_visual_id, |
1492 VisualID transparent_visual_id) { | 1488 VisualID transparent_visual_id) { |
1493 // TODO(thomasanderson): Cache these visual IDs as a property of the root | 1489 // TODO(thomasanderson): Cache these visual IDs as a property of the root |
1494 // window so that newly created browser processes can get them immediately. | 1490 // window so that newly created browser processes can get them immediately. |
1495 if ((system_visual_id && !visuals_.count(system_visual_id)) || | 1491 if ((system_visual_id && !visuals_.count(system_visual_id)) || |
(...skipping 25 matching lines...) Expand all Loading... |
1521 return colormap_; | 1517 return colormap_; |
1522 } | 1518 } |
1523 | 1519 |
1524 #endif | 1520 #endif |
1525 | 1521 |
1526 // ---------------------------------------------------------------------------- | 1522 // ---------------------------------------------------------------------------- |
1527 // End of x11_util_internal.h | 1523 // End of x11_util_internal.h |
1528 | 1524 |
1529 | 1525 |
1530 } // namespace ui | 1526 } // namespace ui |
OLD | NEW |