Skip to content

Commit c08c75e

Browse files
committed
Added gpu device option
1 parent 01ca06d commit c08c75e

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

include/backend/screen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct fb;
1212
* the Wayland compositor is presented.
1313
*/
1414

15-
struct screen *screen_setup(void (*vblank_notify)(int,unsigned int,unsigned int,
15+
struct screen *screen_setup(char *gdevpath, void (*vblank_notify)(int,unsigned int,unsigned int,
1616
unsigned int, void*, bool), void *user_data, bool dmabuf_mod);
1717

1818
void drm_handle_event(int fd);

include/swvkc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdint.h>
22

3-
int swvkc_initialize(char *kdevpath, char *pdevpath);
3+
int swvkc_initialize(char *gdevpath, char *kdevpath, char *pdevpath);
44
void swvkc_run();
55
void swvkc_terminate();
66

src/backend/screen.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ struct screen {
9292
bool pending_page_flip;
9393
};
9494

95-
int drm_setup(struct screen *);
95+
int drm_setup(char *gdevpath, struct screen *);
9696
struct fb *screen_fb_create_main(struct screen *screen, int width, int height,
9797
bool linear, bool no_alpha);
9898
void screen_fb_destroy(struct screen *screen, struct fb *fb);
9999
const char *conn_get_name(uint32_t type_id);
100100

101-
struct screen *screen_setup(void (*vblank_notify)(int,unsigned int,unsigned int,
101+
struct screen *screen_setup(char *gdevpath, void (*vblank_notify)(int,unsigned int,unsigned int,
102102
unsigned int, void*, bool), void *user_data, bool dmabuf_mod) {
103103
printf("├─ VIDEO (Direct Rendering Manager)\n");
104104
struct screen *screen = calloc(1, sizeof(struct screen));
105105
wl_list_init(&screen->fb_destroy_list);
106106
screen->vblank_notify = vblank_notify;
107107
screen->user_data = user_data;
108108

109-
if (drm_setup(screen) < 0) {
109+
if (drm_setup(gdevpath, screen) < 0) {
110110
return NULL;
111111
}
112112

@@ -224,8 +224,13 @@ static int read_cache(uint32_t *connector_id, uint32_t *crtc_id) {
224224
return 0;
225225
}
226226

227-
int drm_setup(struct screen *S) {
228-
char *devpath = boot_gpu_devpath();
227+
int drm_setup(char *gdevpath, struct screen *S) {
228+
char *devpath;
229+
if (gdevpath) {
230+
devpath = gdevpath;
231+
} else {
232+
devpath = boot_gpu_devpath();
233+
}
229234
if (!devpath) {
230235
fprintf(stderr, "No suitable DRM device found");
231236
return -1;
@@ -235,7 +240,9 @@ int drm_setup(struct screen *S) {
235240
fprintf(stderr, "open %s: %s\n", devpath, strerror(errno));
236241
return -1;
237242
}
238-
free(devpath);
243+
if (!gdevpath) {
244+
free(devpath);
245+
}
239246

240247
if (!drmIsMaster(S->gpu_fd)) {
241248
fprintf(stderr, "The display is already taken by another program\n");

src/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void spawn_client(char **argv) {
2020
}
2121
}
2222

23-
const char *usage = "usage: swvkc [-k <devpath>] [-p <devpath>] [client]\n\
23+
const char *usage = "usage: swvkc [-g <devpath>] [-k <devpath>] [-p <devpath>] [client]\n\
2424
\n\
2525
Experimental Wayland compositor\n\
2626
\n\
@@ -29,15 +29,17 @@ positional arguments:\n\
2929
\n\
3030
optional arguments:\n\
3131
-h show this help message and exit\n\
32+
-g <devpath> gpu device node\n\
3233
-k <devpath> keyboard device node\n\
3334
-p <devpath> pointer device node\n";
3435

3536
int main(int argc, char *argv[]) {
36-
char *kdevpath = NULL, *pdevpath = NULL;
37+
char *gdevpath = NULL, *kdevpath = NULL, *pdevpath = NULL;
3738

3839
int opt;
39-
while ((opt = getopt(argc, argv, "hk:p:")) != -1) {
40+
while ((opt = getopt(argc, argv, "hg:k:p:")) != -1) {
4041
switch (opt) {
42+
case 'g': gdevpath = optarg; break;
4143
case 'k': kdevpath = optarg; break;
4244
case 'p': pdevpath = optarg; break;
4345
default:
@@ -46,12 +48,14 @@ int main(int argc, char *argv[]) {
4648
}
4749
}
4850

51+
if (gdevpath)
52+
printf("%s\n", gdevpath);
4953
if (kdevpath)
5054
printf("%s\n", kdevpath);
5155
if (pdevpath)
5256
printf("%s\n", pdevpath);
5357

54-
if (swvkc_initialize(kdevpath, pdevpath))
58+
if (swvkc_initialize(gdevpath, kdevpath, pdevpath))
5559
return EXIT_FAILURE;
5660

5761
if (argc > optind)

src/swvkc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int timed_commit(void *data) {
112112
}
113113

114114
static struct server *swvkc; //TODO
115-
int swvkc_initialize(char *kdevpath, char *pdevpath) {
115+
int swvkc_initialize(char *gdevpath, char *kdevpath, char *pdevpath) {
116116
struct server *server = calloc(1, sizeof(struct server));
117117
swvkc = server;
118118
wl_list_init(&server->mapped_surfaces_list);
@@ -125,7 +125,7 @@ int swvkc_initialize(char *kdevpath, char *pdevpath) {
125125
return EXIT_FAILURE;
126126
}
127127

128-
server->screen = screen_setup(vblank_notify, server, dmabuf_mod);
128+
server->screen = screen_setup(gdevpath, vblank_notify, server, dmabuf_mod);
129129
if (!server->screen) {
130130
errlog("Could not setup screen");
131131
return EXIT_FAILURE;

0 commit comments

Comments
 (0)