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

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

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

Powered by Google App Engine
This is Rietveld 408576698