2019-04-19 19:21:38 -04:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-08-25 01:32:40 -04:00
|
|
|
#include <stddef.h>
|
2019-04-19 19:21:38 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
2020-08-25 01:32:40 -04:00
|
|
|
#include "utils.h"
|
|
|
|
|
2019-04-19 19:21:38 -04:00
|
|
|
struct session;
|
|
|
|
struct backend_base;
|
|
|
|
|
2019-09-16 17:09:05 -04:00
|
|
|
// A list of known driver quirks:
|
|
|
|
// * NVIDIA driver doesn't like seeing the same pixmap under different
|
|
|
|
// ids, so avoid naming the pixmap again when it didn't actually change.
|
|
|
|
|
2019-04-19 19:21:38 -04:00
|
|
|
/// A list of possible drivers.
|
|
|
|
/// The driver situation is a bit complicated. There are two drivers we care about: the
|
|
|
|
/// DDX, and the OpenGL driver. They are usually paired, but not always, since there is
|
|
|
|
/// also the generic modesetting driver.
|
|
|
|
/// This enum represents _both_ drivers.
|
|
|
|
enum driver {
|
2020-08-25 01:32:40 -04:00
|
|
|
DRIVER_AMDGPU = 1, // AMDGPU for DDX, radeonsi for OpenGL
|
|
|
|
DRIVER_RADEON = 2, // ATI for DDX, mesa r600 for OpenGL
|
2019-04-19 19:21:38 -04:00
|
|
|
DRIVER_FGLRX = 4,
|
|
|
|
DRIVER_NVIDIA = 8,
|
|
|
|
DRIVER_NOUVEAU = 16,
|
|
|
|
DRIVER_INTEL = 32,
|
|
|
|
DRIVER_MODESETTING = 64,
|
|
|
|
};
|
|
|
|
|
2020-08-25 01:32:40 -04:00
|
|
|
static const char *driver_names[] = {
|
|
|
|
"AMDGPU", "Radeon", "fglrx", "NVIDIA", "nouveau", "Intel", "modesetting",
|
|
|
|
};
|
|
|
|
|
2019-04-19 20:09:10 -04:00
|
|
|
/// Return a list of all drivers currently in use by the X server.
|
2019-04-19 19:21:38 -04:00
|
|
|
/// Note, this is a best-effort test, so no guarantee all drivers will be detected.
|
|
|
|
enum driver detect_driver(xcb_connection_t *, struct backend_base *, xcb_window_t);
|
|
|
|
|
2020-04-22 13:05:04 -04:00
|
|
|
/// Apply driver specified global workarounds. It's safe to call this multiple times.
|
2020-04-22 15:13:18 -04:00
|
|
|
void apply_driver_workarounds(struct session *ps, enum driver);
|
2020-04-22 13:05:04 -04:00
|
|
|
|
2019-04-19 19:21:38 -04:00
|
|
|
// Print driver names to stdout, for diagnostics
|
|
|
|
static inline void print_drivers(enum driver drivers) {
|
2020-08-25 01:32:40 -04:00
|
|
|
const char *seen_drivers[ARR_SIZE(driver_names)];
|
|
|
|
int driver_count = 0;
|
|
|
|
for (size_t i = 0; i < ARR_SIZE(driver_names); i++) {
|
|
|
|
if (drivers & (1ul << i)) {
|
|
|
|
seen_drivers[driver_count++] = driver_names[i];
|
|
|
|
}
|
2019-04-19 19:21:38 -04:00
|
|
|
}
|
2020-08-25 01:32:40 -04:00
|
|
|
|
|
|
|
if (driver_count > 0) {
|
|
|
|
printf("%s", seen_drivers[0]);
|
|
|
|
for (int i = 1; i < driver_count; i++) {
|
|
|
|
printf(", %s", seen_drivers[i]);
|
|
|
|
}
|
2019-04-19 19:21:38 -04:00
|
|
|
}
|
2020-08-25 01:32:40 -04:00
|
|
|
printf("\n");
|
2019-04-19 19:21:38 -04:00
|
|
|
}
|