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

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

Issue 2471073002: X11: Use CopyFromParent colormap when possible (Reland) (Closed)
Patch Set: 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 system_visual_id_(0), 1423 system_visual_id_(0),
Daniel Erat 2016/11/02 15:14:46 nit: also initialize default_visual_id_ to 0 here
Tom (Use chromium acct) 2016/11/02 17:38:58 Done.
1424 transparent_visual_id_(0), 1424 transparent_visual_id_(0),
1425 using_software_rendering_(false), 1425 using_software_rendering_(false),
1426 have_gpu_argb_visual_(false) { 1426 have_gpu_argb_visual_(false) {
1427 int visuals_len; 1427 int visuals_len;
1428 XVisualInfo visual_template; 1428 XVisualInfo visual_template;
1429 visual_template.screen = DefaultScreen(display_); 1429 visual_template.screen = DefaultScreen(display_);
1430 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( 1430 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo(
1431 display_, VisualScreenMask, &visual_template, &visuals_len)); 1431 display_, VisualScreenMask, &visual_template, &visuals_len));
1432 for (int i = 0; i < visuals_len; ++i) 1432 for (int i = 0; i < visuals_len; ++i)
1433 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); 1433 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i]));
1434 1434
1435 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);
1436 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None; 1436 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None;
1437 1437
1438 // Choose the opaque visual. 1438 // Choose the opaque visual.
1439 XWindowAttributes attribs; 1439 default_visual_id_ =
1440 Window root = XDefaultRootWindow(display_); 1440 XVisualIDFromVisual(DefaultVisual(display_, DefaultScreen(display_)));
1441 Status status = XGetWindowAttributes(display_, root, &attribs); 1441 system_visual_id_ = default_visual_id_;
Daniel Erat 2016/11/02 15:14:46 i was initially confused about why there are two m
Tom (Use chromium acct) 2016/11/02 17:38:58 Added a small comment in x11_util_internal.h to cl
1442 DCHECK_NE(0, status);
1443 system_visual_id_ = attribs.visual->visualid;
1444 DCHECK(system_visual_id_); 1442 DCHECK(system_visual_id_);
1445 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); 1443 DCHECK(visuals_.find(system_visual_id_) != visuals_.end());
1446 1444
1447 // Choose the transparent visual. 1445 // Choose the transparent visual.
1448 for (const auto& pair : visuals_) { 1446 for (const auto& pair : visuals_) {
1449 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In 1447 // 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 1448 // gdkvisual-x11.cc, they look for this specific visual and use it for
1451 // all their alpha channel using needs. 1449 // all their alpha channel using needs.
1452 const XVisualInfo& info = pair.second->visual_info; 1450 const XVisualInfo& info = pair.second->visual_info;
1453 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && 1451 if (info.depth == 32 && info.visual->red_mask == 0xff0000 &&
1454 info.visual->green_mask == 0x00ff00 && 1452 info.visual->green_mask == 0x00ff00 &&
1455 info.visual->blue_mask == 0x0000ff) { 1453 info.visual->blue_mask == 0x0000ff) {
1456 transparent_visual_id_ = info.visualid; 1454 transparent_visual_id_ = info.visualid;
1457 break; 1455 break;
1458 } 1456 }
1459 } 1457 }
1460 if (transparent_visual_id_) 1458 if (transparent_visual_id_)
1461 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end()); 1459 DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end());
1462 } 1460 }
1463 1461
1464 XVisualManager::~XVisualManager() {} 1462 XVisualManager::~XVisualManager() {}
1465 1463
1466 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual, 1464 void XVisualManager::ChooseVisualForWindow(bool want_argb_visual,
1467 Visual** visual, 1465 Visual** visual,
1468 int* depth, 1466 int* depth,
1469 Colormap* colormap, 1467 Colormap* colormap,
1470 bool* using_argb_visual) { 1468 bool* using_argb_visual) {
1471 bool use_argb = want_argb_visual && using_compositing_wm_ && 1469 bool use_argb = want_argb_visual && using_compositing_wm_ &&
1472 (using_software_rendering_ || have_gpu_argb_visual_); 1470 (using_software_rendering_ || have_gpu_argb_visual_);
1473 XVisualData& visual_data = 1471 VisualID visual_id = use_argb && transparent_visual_id_
1474 *visuals_[use_argb && transparent_visual_id_ ? transparent_visual_id_ 1472 ? transparent_visual_id_
1475 : system_visual_id_]; 1473 : system_visual_id_;
1474 XVisualData& visual_data = *visuals_[visual_id];
1475 const XVisualInfo& visual_info = visual_data.visual_info;
1476
1477 bool is_default_visual = visual_id == default_visual_id_;
1478
1476 if (visual) 1479 if (visual)
1477 *visual = visual_data.visual_info.visual; 1480 *visual = is_default_visual ? CopyFromParent : visual_info.visual;
1478 if (depth) 1481 if (depth)
1479 *depth = visual_data.visual_info.depth; 1482 *depth = is_default_visual ? CopyFromParent : visual_info.depth;
1480 if (colormap) 1483 if (colormap)
1481 *colormap = visual_data.GetColormap(); 1484 *colormap = is_default_visual ? CopyFromParent : visual_data.GetColormap();
1482 if (using_argb_visual) 1485 if (using_argb_visual)
1483 *using_argb_visual = use_argb; 1486 *using_argb_visual = use_argb;
1484 } 1487 }
1485 1488
1486 bool XVisualManager::OnGPUInfoChanged(bool software_rendering, 1489 bool XVisualManager::OnGPUInfoChanged(bool software_rendering,
1487 VisualID system_visual_id, 1490 VisualID system_visual_id,
1488 VisualID transparent_visual_id) { 1491 VisualID transparent_visual_id) {
1489 // TODO(thomasanderson): Cache these visual IDs as a property of the root 1492 // TODO(thomasanderson): Cache these visual IDs as a property of the root
1490 // window so that newly created browser processes can get them immediately. 1493 // window so that newly created browser processes can get them immediately.
1491 if ((system_visual_id && !visuals_.count(system_visual_id)) || 1494 if ((system_visual_id && !visuals_.count(system_visual_id)) ||
(...skipping 25 matching lines...) Expand all
1517 return colormap_; 1520 return colormap_;
1518 } 1521 }
1519 1522
1520 #endif 1523 #endif
1521 1524
1522 // ---------------------------------------------------------------------------- 1525 // ----------------------------------------------------------------------------
1523 // End of x11_util_internal.h 1526 // End of x11_util_internal.h
1524 1527
1525 1528
1526 } // namespace ui 1529 } // 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