Wayland 의 Client Application 프로그래밍 시 기본 루틴을 설명
1. wl_display를 가져 와서 wl_registry를 얻는다.
struct wl_display *display = NULL; display = wl_display_connect(NULL); struct wl_registry *registry = wl_display_get_registry(display);
2. 레지스트리를 스캔하고 wl_compositor 및 wl_shm_pool을 가져온다.
struct wl_compositor *compositor = NULL; struct wl_shm_listener shm_listener = { shm_format }; static void global_registry_handler(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { if (strcmp(interface, "wl_compositor") == 0) { compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1); } else if (strcmp(interface, "wl_shell") == 0) { shell = wl_registry_bind(registry, id, &wl_shell_interface, 1); } else if (strcmp(interface, "wl_shm") == 0) { shm = wl_registry_bind(registry, id, &wl_shm_interface, 1); wl_shm_add_listener(shm, &shm_listener, NULL); } } static void global_registry_remover(void *data, struct wl_registry *registry, uint32_t id) { printf("Got a registry losing event for %d\n", id); } static const struct wl_registry_listener registry_listener = { global_registry_handler, global_registry_remover }; wl_registry_add_listener(registry, ®istryListener, this);
3. wl_compositor 인터페이스를 사용하여 wl_surface를 생성한다.
struct wl_surface *surface = NULL; surface = wl_compositor_create_surface(compositor);
4. 표면의 역할을 부여하기 위해 wl_shell 인터페이스를 사용
struct wl_shell_surface *shell_surface = NULL; shell_surface = wl_shell_get_shell_surface(shell, surface); // 역할 부여 wl_shell_surface_set_toplevel(shell_surface); wl_shell_surface_add_listener(shell_surface, &shell_surface_listener, NULL);
5. wl_shm 인터페이스를 사용하여 픽셀을 저장할 공유 메모리를 할당하고 공유 메모리 버퍼를 wl_surface에 연결한다.
void *shm_data; int WIDTH = 480; int HEIGHT = 360; int os_create_anonymous_file(off_t size) { static const char template[] = "/weston-shared-XXXXXX"; const char *path; char *name; int fd; path = getenv("XDG_RUNTIME_DIR"); if (!path) { errno = ENOENT; return -1; } name = malloc(strlen(path) + sizeof(template)); if (!name) return -1; strcpy(name, path); strcat(name, template); fd = create_tmpfile_cloexec(name); free(name); if (fd < 0) return -1; if (ftruncate(fd, size) < 0) { close(fd); return -1; } return fd; } static struct wl_buffer *create_buffer() { struct wl_shm_pool *pool; int stride = WIDTH * 4; // 4 bytes per pixel int size = stride * HEIGHT; int fd; struct wl_buffer *buff; fd = os_create_anonymous_file(size); if (fd < 0) { fprintf(stderr, "creating a buffer file for %d B failed: %m\n", size); exit(1); } shm_data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shm_data == MAP_FAILED) { fprintf(stderr, "mmap failed: %m\n"); close(fd); exit(1); } pool = wl_shm_create_pool(shm, fd, size); buff = wl_shm_pool_create_buffer(pool, 0, WIDTH, HEIGHT, stride, WL_SHM_FORMAT_XRGB8888); //wl_buffer_add_listener(buffer, &buffer_listener, buffer); wl_shm_pool_destroy(pool); return buff; } static void create_shm() { buffer = create_buffer(); wl_surface_attach(surface, buffer, 0, 0); wl_surface_commit(surface); }
6. 공유 메모리 버퍼에 뭔가를 그린다.
static void paint_pixels() { int n; uint32_t *pixel = shm_data; fprintf(stderr, "Painting pixels\n"); for (n =0; n < WIDTH * HEIGHT; n++) { *pixel++ = 0xffff; } }
7. 이벤트 처리를 요청한다.
// 이벤트를 처리. while (wl_display_dispatch(display) != -1) { ; }
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
45 | mmap() 함수, munmap() 함수 | pjk | 2014.02.05 | 15641 |
44 | 6. Makefile 작성의 가이드라인 | pjk | 2014.02.05 | 2362 |
43 | 5. make 중요 옵션 정리 | pjk | 2014.02.05 | 2444 |
42 | 4. Makefile를 작성할 때 알면 좋은 것들 | pjk | 2014.02.05 | 3071 |
41 | 3. 매크로(Macro) 와 확장자(Suffix) 규칙 | pjk | 2014.02.05 | 2620 |
40 | 2. 간단한 Makefile | pjk | 2014.02.05 | 2606 |
39 | 1. make | pjk | 2014.02.05 | 2109 |
38 | 키패드 드라이버 | pjk | 2014.02.12 | 6537 |
37 | ioctl() 함수 | makersweb | 2014.02.27 | 14194 |
36 | file_operations | makersweb | 2014.02.27 | 3297 |
35 | 리눅스 디렉터리 구조 | makersweb | 2014.02.28 | 3242 |
34 | read() 함수, write() 함수 | makersweb | 2014.03.04 | 11358 |
33 | 리눅스 커널 소스코드 구성도 | makersweb | 2014.03.04 | 5504 |
32 | 디바이스 드라이버에 대해서 | makersweb | 2014.04.19 | 4142 |
31 | 리눅스 데스크탑 환경 종류 | pjk | 2015.02.11 | 4628 |
30 | 리눅스 프레임버퍼(Linux Frame Buffer) | makersweb | 2015.02.15 | 7520 |
29 | [IPC]D-Bus 소개 | makersweb | 2015.02.28 | 29818 |
28 | Build Qt 4.7.0 for Embedded Linux | makersweb | 2015.05.25 | 5433 |
27 | UVC 장치를 사용할때 v4l2: select timeout 에러 발생 | makersweb | 2017.12.27 | 2412 |
26 | Ubuntu16.04에서 weston구동 | makersweb | 2017.12.28 | 989 |