Commit b43825d5 authored by Tom Anderson's avatar Tom Anderson Committed by Chromium LUCI CQ

[XProto] Use alternate XCB connection for Vulkan

This is needed for [1] which adds the assumption that Chrome makes
all requests on the main Xcb connection.  This CL simply moves the
requests to occur on a separate connection to satisfy this assumption.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2565440

R=penghuang

Bug: None
Change-Id: Ia85799c460d0fef372121dae3244874130158fa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566342
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832195}
parent f843c01e
...@@ -104,7 +104,8 @@ bool VulkanImplementationX11::GetPhysicalDevicePresentationSupport( ...@@ -104,7 +104,8 @@ bool VulkanImplementationX11::GetPhysicalDevicePresentationSupport(
return true; return true;
auto* connection = x11::Connection::Get(); auto* connection = x11::Connection::Get();
return vkGetPhysicalDeviceXcbPresentationSupportKHR( return vkGetPhysicalDeviceXcbPresentationSupportKHR(
device, queue_family_index, connection->XcbConnection(), device, queue_family_index,
connection->GetXlibDisplay().GetXcbConnection(),
static_cast<xcb_visualid_t>(connection->default_root_visual().visual_id)); static_cast<xcb_visualid_t>(connection->default_root_visual().visual_id));
} }
......
...@@ -76,7 +76,7 @@ std::unique_ptr<VulkanSurfaceX11> VulkanSurfaceX11::Create( ...@@ -76,7 +76,7 @@ std::unique_ptr<VulkanSurfaceX11> VulkanSurfaceX11::Create(
VkSurfaceKHR vk_surface; VkSurfaceKHR vk_surface;
const VkXcbSurfaceCreateInfoKHR surface_create_info = { const VkXcbSurfaceCreateInfoKHR surface_create_info = {
.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
.connection = connection->XcbConnection(), .connection = connection->GetXlibDisplay().GetXcbConnection(),
.window = static_cast<xcb_window_t>(window), .window = static_cast<xcb_window_t>(window),
}; };
VkResult result = vkCreateXcbSurfaceKHR(vk_instance, &surface_create_info, VkResult result = vkCreateXcbSurfaceKHR(vk_instance, &surface_create_info,
......
...@@ -38,6 +38,15 @@ generate_library_loader("xlib_loader") { ...@@ -38,6 +38,15 @@ generate_library_loader("xlib_loader") {
] ]
} }
generate_library_loader("xlib_xcb_loader") {
name = "XlibXcbLoader"
output_h = "xlib_xcb_loader.h"
output_cc = "xlib_xcb_loader.cc"
header = "\"ui/gfx/x/xlib_xcb.h\""
functions = [ "XGetXCBConnection" ]
}
action("gen_xprotos") { action("gen_xprotos") {
visibility = [ ":xprotos" ] visibility = [ ":xprotos" ]
script = "gen_xproto.py" script = "gen_xproto.py"
...@@ -100,6 +109,7 @@ component("xprotos") { ...@@ -100,6 +109,7 @@ component("xprotos") {
deps = [ deps = [
":gen_xprotos", ":gen_xprotos",
":xlib_loader", ":xlib_loader",
":xlib_xcb_loader",
"//base", "//base",
"//base:i18n", "//base:i18n",
"//ui/events/platform", "//ui/events/platform",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "library_loaders/xlib_loader.h" #include "library_loaders/xlib_loader.h"
#include "library_loaders/xlib_xcb_loader.h"
namespace x11 { namespace x11 {
...@@ -24,6 +25,11 @@ XlibLoader* GetXlibLoader() { ...@@ -24,6 +25,11 @@ XlibLoader* GetXlibLoader() {
return xlib_loader.get(); return xlib_loader.get();
} }
XlibXcbLoader* GetXlibXcbLoader() {
static base::NoDestructor<XlibXcbLoader> xlib_xcb_loader;
return xlib_xcb_loader.get();
}
} // namespace } // namespace
DISABLE_CFI_ICALL DISABLE_CFI_ICALL
...@@ -34,6 +40,9 @@ void InitXlib() { ...@@ -34,6 +40,9 @@ void InitXlib() {
CHECK(xlib_loader->Load("libX11.so.6")); CHECK(xlib_loader->Load("libX11.so.6"));
auto* xlib_xcb_loader = GetXlibXcbLoader();
CHECK(xlib_xcb_loader->Load("libX11-xcb.so.1"));
CHECK(xlib_loader->XInitThreads()); CHECK(xlib_loader->XInitThreads());
// The default Xlib error handler calls exit(1), which we don't want. This // The default Xlib error handler calls exit(1), which we don't want. This
...@@ -103,4 +112,9 @@ XlibDisplayWrapper& XlibDisplayWrapper::operator=(XlibDisplayWrapper&& other) { ...@@ -103,4 +112,9 @@ XlibDisplayWrapper& XlibDisplayWrapper::operator=(XlibDisplayWrapper&& other) {
return *this; return *this;
} }
DISABLE_CFI_ICALL
struct xcb_connection_t* XlibDisplayWrapper::GetXcbConnection() {
return GetXlibXcbLoader()->XGetXCBConnection(display_);
}
} // namespace x11 } // namespace x11
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/component_export.h" #include "base/component_export.h"
struct _XDisplay; struct _XDisplay;
struct xcb_connection_t;
namespace x11 { namespace x11 {
...@@ -60,6 +61,8 @@ class COMPONENT_EXPORT(X11) XlibDisplayWrapper { ...@@ -60,6 +61,8 @@ class COMPONENT_EXPORT(X11) XlibDisplayWrapper {
} }
operator struct _XDisplay *() { return display_; } operator struct _XDisplay *() { return display_; }
struct xcb_connection_t* GetXcbConnection();
XlibDisplayWrapper(XlibDisplayWrapper&& other); XlibDisplayWrapper(XlibDisplayWrapper&& other);
XlibDisplayWrapper& operator=(XlibDisplayWrapper&& other); XlibDisplayWrapper& operator=(XlibDisplayWrapper&& other);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_X_XLIB_XCB_H_
#define UI_GFX_X_XLIB_XCB_H_
extern "C" {
struct xcb_connection_t* XGetXCBConnection(struct _XDisplay*);
}
#endif // UI_GFX_X_XLIB_XCB_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment