Skip to content

Commit

Permalink
Added gpu device option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ella-0 committed Jun 27, 2021
1 parent 01ca06d commit f201288
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/backend/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct fb;
* the Wayland compositor is presented.
*/

struct screen *screen_setup(void (*vblank_notify)(int,unsigned int,unsigned int,
struct screen *screen_setup(char *gdevpath, void (*vblank_notify)(int,unsigned int,unsigned int,
unsigned int, void*, bool), void *user_data, bool dmabuf_mod);

void drm_handle_event(int fd);
Expand Down
2 changes: 1 addition & 1 deletion include/swvkc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdint.h>

int swvkc_initialize(char *kdevpath, char *pdevpath);
int swvkc_initialize(char *gdevpath, char *kdevpath, char *pdevpath);
void swvkc_run();
void swvkc_terminate();

Expand Down
15 changes: 10 additions & 5 deletions src/backend/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ struct screen {
bool pending_page_flip;
};

int drm_setup(struct screen *);
int drm_setup(char *gdevpath, struct screen *);
struct fb *screen_fb_create_main(struct screen *screen, int width, int height,
bool linear, bool no_alpha);
void screen_fb_destroy(struct screen *screen, struct fb *fb);
const char *conn_get_name(uint32_t type_id);

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

if (drm_setup(screen) < 0) {
if (drm_setup(gdevpath, screen) < 0) {
return NULL;
}

Expand Down Expand Up @@ -224,8 +224,13 @@ static int read_cache(uint32_t *connector_id, uint32_t *crtc_id) {
return 0;
}

int drm_setup(struct screen *S) {
char *devpath = boot_gpu_devpath();
int drm_setup(char *gdevpath, struct screen *S) {
char *devpath;
if (gdevpath) {
devpath = gdevpath;
} else {
devpath = boot_gpu_devpath();
}
if (!devpath) {
fprintf(stderr, "No suitable DRM device found");
return -1;
Expand Down
12 changes: 8 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void spawn_client(char **argv) {
}
}

const char *usage = "usage: swvkc [-k <devpath>] [-p <devpath>] [client]\n\
const char *usage = "usage: swvkc [-g <devpath>] [-k <devpath>] [-p <devpath>] [client]\n\
\n\
Experimental Wayland compositor\n\
\n\
Expand All @@ -29,15 +29,17 @@ positional arguments:\n\
\n\
optional arguments:\n\
-h show this help message and exit\n\
-g <devpath> gpu device node\n\
-k <devpath> keyboard device node\n\
-p <devpath> pointer device node\n";

int main(int argc, char *argv[]) {
char *kdevpath = NULL, *pdevpath = NULL;
char *gdevpath = NULL, *kdevpath = NULL, *pdevpath = NULL;

int opt;
while ((opt = getopt(argc, argv, "hk:p:")) != -1) {
while ((opt = getopt(argc, argv, "hg:k:p:")) != -1) {
switch (opt) {
case 'g': gdevpath = optarg; break;
case 'k': kdevpath = optarg; break;
case 'p': pdevpath = optarg; break;
default:
Expand All @@ -46,12 +48,14 @@ int main(int argc, char *argv[]) {
}
}

if (gdevpath)
printf("%s\n", gdevpath);
if (kdevpath)
printf("%s\n", kdevpath);
if (pdevpath)
printf("%s\n", pdevpath);

if (swvkc_initialize(kdevpath, pdevpath))
if (swvkc_initialize(strdup(gdevpath), kdevpath, pdevpath))
return EXIT_FAILURE;

if (argc > optind)
Expand Down
4 changes: 2 additions & 2 deletions src/swvkc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int timed_commit(void *data) {
}

static struct server *swvkc; //TODO
int swvkc_initialize(char *kdevpath, char *pdevpath) {
int swvkc_initialize(char *gdevpath, char *kdevpath, char *pdevpath) {
struct server *server = calloc(1, sizeof(struct server));
swvkc = server;
wl_list_init(&server->mapped_surfaces_list);
Expand All @@ -125,7 +125,7 @@ int swvkc_initialize(char *kdevpath, char *pdevpath) {
return EXIT_FAILURE;
}

server->screen = screen_setup(vblank_notify, server, dmabuf_mod);
server->screen = screen_setup(gdevpath, vblank_notify, server, dmabuf_mod);
if (!server->screen) {
errlog("Could not setup screen");
return EXIT_FAILURE;
Expand Down

0 comments on commit f201288

Please sign in to comment.