Commit d47a9ad1 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Dynamically load gbm functions that are not available on all systems

This CL adds the initial wrapping functions that make use of dlsym(). In
a followup, the get_gbm_* family of functions can be used to test
feature support.

BUG=1031269
R=msisov
CC=spang

Change-Id: Iab2d66eb702921b0c4d4d294fc3a98330c1f41c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1970570
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#725604}
parent 93a20d0f
......@@ -16,14 +16,56 @@
#include "ui/gfx/linux/gbm_device.h"
#if !defined(MINIGBM)
#include <dlfcn.h>
#include <fcntl.h>
#include <xf86drm.h>
#include "base/strings/stringize_macros.h"
#endif
namespace gbm_wrapper {
namespace {
#if defined(MINIGBM)
// Minigbm has all needed functions, so dynamic loading is not necessary.
#define WRAP_GBM_FN(x) \
ALLOW_UNUSED_TYPE decltype(x)* get_##x() { return x; }
#else
#define WRAP_GBM_FN(x) \
decltype(auto) get_##x() { \
static auto* x##_ = \
reinterpret_cast<decltype(::x)*>(dlsym(RTLD_DEFAULT, STRINGIZE(x))); \
return x##_; \
} \
/* Functions that call dlsym-loaded functions must not be instrumented with \
* CFI_ICALL. */ \
template <typename... Args> \
NO_SANITIZE("cfi-icall") \
decltype(auto) x(Args&&... args) { \
if (!get_##x()) { \
LOG(FATAL) << STRINGIZE(x) << "() is not available on this platform. " \
<< STRINGIZE(get_##x) \
<< "() should be used to determine availability."; \
} \
return get_##x()(std::forward<Args>(args)...); \
}
#endif
// TODO(https://crbug.com/784010): Remove these once support for Ubuntu Trusty
// is dropped.
WRAP_GBM_FN(gbm_bo_map)
WRAP_GBM_FN(gbm_bo_unmap)
// TODO(https://crbug.com/784010): Remove these once support for Ubuntu Trusty
// and Debian Stretch are dropped.
WRAP_GBM_FN(gbm_bo_create_with_modifiers)
WRAP_GBM_FN(gbm_bo_get_handle_for_plane)
WRAP_GBM_FN(gbm_bo_get_modifier)
WRAP_GBM_FN(gbm_bo_get_offset)
WRAP_GBM_FN(gbm_bo_get_plane_count)
WRAP_GBM_FN(gbm_bo_get_stride_for_plane)
int GetPlaneFdForBo(gbm_bo* bo, size_t plane) {
#if defined(MINIGBM)
return gbm_bo_get_plane_fd(bo, plane);
......
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