aboutsummaryrefslogtreecommitdiff
path: root/src/backend/driver.h
blob: a37cda3b67e29a857fcfc69f46904cd0e0892c60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) Yuxuan Shui <[email protected]>

#pragma once

#include <stddef.h>
#include <stdio.h>
#include <xcb/xcb.h>

#include "utils.h"

struct session;
struct backend_base;

// 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.

/// 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 {
	DRIVER_AMDGPU = 1,        // AMDGPU for DDX, radeonsi for OpenGL
	DRIVER_RADEON = 2,        // ATI for DDX, mesa r600 for OpenGL
	DRIVER_FGLRX = 4,
	DRIVER_NVIDIA = 8,
	DRIVER_NOUVEAU = 16,
	DRIVER_INTEL = 32,
	DRIVER_MODESETTING = 64,
};

static const char *driver_names[] = {
    "AMDGPU", "Radeon", "fglrx", "NVIDIA", "nouveau", "Intel", "modesetting",
};

/// Return a list of all drivers currently in use by the X server.
/// 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);

/// Apply driver specified global workarounds. It's safe to call this multiple times.
void apply_driver_workarounds(struct session *ps, enum driver);

// Print driver names to stdout, for diagnostics
static inline void print_drivers(enum driver drivers) {
	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];
		}
	}

	if (driver_count > 0) {
		printf("%s", seen_drivers[0]);
		for (int i = 1; i < driver_count; i++) {
			printf(", %s", seen_drivers[i]);
		}
	}
	printf("\n");
}