1 // SPDX-License-Identifier: MPL-2.0
2 // Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
3 
4 #pragma once
5 
6 #include <stdio.h>
7 #include <xcb/xcb.h>
8 
9 struct session;
10 struct backend_base;
11 
12 // A list of known driver quirks:
13 // *  NVIDIA driver doesn't like seeing the same pixmap under different
14 //    ids, so avoid naming the pixmap again when it didn't actually change.
15 
16 /// A list of possible drivers.
17 /// The driver situation is a bit complicated. There are two drivers we care about: the
18 /// DDX, and the OpenGL driver. They are usually paired, but not always, since there is
19 /// also the generic modesetting driver.
20 /// This enum represents _both_ drivers.
21 enum driver {
22 	DRIVER_AMDGPU = 1, // AMDGPU for DDX, radeonsi for OpenGL
23 	DRIVER_RADEON = 2, // ATI for DDX, mesa r600 for OpenGL
24 	DRIVER_FGLRX = 4,
25 	DRIVER_NVIDIA = 8,
26 	DRIVER_NOUVEAU = 16,
27 	DRIVER_INTEL = 32,
28 	DRIVER_MODESETTING = 64,
29 };
30 
31 /// Return a list of all drivers currently in use by the X server.
32 /// Note, this is a best-effort test, so no guarantee all drivers will be detected.
33 enum driver detect_driver(xcb_connection_t *, struct backend_base *, xcb_window_t);
34 
35 // Print driver names to stdout, for diagnostics
print_drivers(enum driver drivers)36 static inline void print_drivers(enum driver drivers) {
37 	if (drivers & DRIVER_AMDGPU) {
38 		printf("AMDGPU, ");
39 	}
40 	if (drivers & DRIVER_RADEON) {
41 		printf("Radeon, ");
42 	}
43 	if (drivers & DRIVER_FGLRX) {
44 		printf("fglrx, ");
45 	}
46 	if (drivers & DRIVER_NVIDIA) {
47 		printf("NVIDIA, ");
48 	}
49 	if (drivers & DRIVER_NOUVEAU) {
50 		printf("nouveau, ");
51 	}
52 	if (drivers & DRIVER_INTEL) {
53 		printf("Intel, ");
54 	}
55 	if (drivers & DRIVER_MODESETTING) {
56 		printf("modesetting, ");
57 	}
58 	printf("\b\b \n");
59 }
60