Refactor libXCB and libX11 wrappers Previously these wrappers had slightly different interfaces, and the X11 one had its own header/source file while libXCB was part of XcbSurfaceKHR. This change separates the libXCB wrapper into its own files as well. While it is only used by XcbSurfaceKHR and likely won't ever be used elsewhere, the other WSI surface implementations don't use/need wrapper classes so it helps to keep that these two responsibilities separate. Bug: b/203541908 Change-Id: I052d5079cd15183eb658fbd96fabbc4885cada12 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/58508 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Sean Risser <srisser@google.com> Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/WSI/libXCB.cpp b/src/WSI/libXCB.cpp new file mode 100644 index 0000000..c540cb8 --- /dev/null +++ b/src/WSI/libXCB.cpp
@@ -0,0 +1,56 @@ +// Copyright 2021 The SwiftShader Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "libXCB.hpp" + +#include "System/SharedLibrary.hpp" + +#include <memory> + +LibXcbExports::LibXcbExports(void *lib) +{ + getFuncAddress(lib, "xcb_create_gc", &xcb_create_gc); + getFuncAddress(lib, "xcb_flush", &xcb_flush); + getFuncAddress(lib, "xcb_free_gc", &xcb_free_gc); + getFuncAddress(lib, "xcb_generate_id", &xcb_generate_id); + getFuncAddress(lib, "xcb_get_geometry", &xcb_get_geometry); + getFuncAddress(lib, "xcb_get_geometry_reply", &xcb_get_geometry_reply); + getFuncAddress(lib, "xcb_put_image", &xcb_put_image); +} + +LibXcbExports *LibXCB::operator->() +{ + return loadExports(); +} + +LibXcbExports *LibXCB::loadExports() +{ + static auto exports = [] { + if(getProcAddress(RTLD_DEFAULT, "xcb_create_gc")) + { + return std::make_unique<LibXcbExports>(RTLD_DEFAULT); + } + + if(void *lib = loadLibrary("libxcb.so.1")) + { + return std::make_unique<LibXcbExports>(lib); + } + + return std::unique_ptr<LibXcbExports>(); + }(); + + return exports.get(); +} + +LibXCB libXCB;