Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 7 | #include "bs_drm.h" |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 8 | |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 9 | #include <getopt.h> |
| 10 | |
Gurchetan Singh | 10008e6 | 2017-03-09 11:14:38 -0800 | [diff] [blame] | 11 | #define NUM_BUFFERS 2 |
| 12 | |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 13 | static uint32_t allowed_formats[] = { |
Gurchetan Singh | 3f82d6d | 2017-11-08 14:43:20 -0800 | [diff] [blame] | 14 | GBM_FORMAT_XRGB8888, GBM_FORMAT_XBGR8888, GBM_FORMAT_XRGB2101010, GBM_FORMAT_XBGR2101010, |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 15 | }; |
| 16 | |
| 17 | const size_t allowed_formats_length = BS_ARRAY_LEN(allowed_formats); |
| 18 | |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 19 | static GLuint solid_shader_create() |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 20 | { |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 21 | const GLchar *vert = |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 22 | "attribute vec4 vPosition;\n" |
| 23 | "attribute vec4 vColor;\n" |
| 24 | "varying vec4 vFillColor;\n" |
| 25 | "void main() {\n" |
| 26 | " gl_Position = vPosition;\n" |
| 27 | " vFillColor = vColor;\n" |
| 28 | "}\n"; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 29 | |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 30 | const GLchar *frag = |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 31 | "precision mediump float;\n" |
| 32 | "varying vec4 vFillColor;\n" |
| 33 | "void main() {\n" |
| 34 | " gl_FragColor = vFillColor;\n" |
| 35 | "}\n"; |
Lauri Peltonen | 763ca46 | 2014-12-17 12:22:21 -0800 | [diff] [blame] | 36 | |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 37 | struct bs_gl_program_create_binding bindings[] = { |
Gurchetan Singh | 3f82d6d | 2017-11-08 14:43:20 -0800 | [diff] [blame] | 38 | { 0, "vPosition" }, { 1, "vColor" }, { 0, NULL }, |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 39 | }; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 40 | |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 41 | return bs_gl_program_create_vert_frag_bind(vert, frag, bindings); |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Lauri Peltonen | 95226da | 2014-12-18 16:39:54 -0800 | [diff] [blame] | 44 | static float f(int i) |
| 45 | { |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 46 | int a = i % 40; |
| 47 | int b = (i / 40) % 6; |
| 48 | switch (b) { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 49 | case 0: |
| 50 | case 1: |
| 51 | return 0.0f; |
| 52 | case 3: |
| 53 | case 4: |
| 54 | return 1.0f; |
| 55 | case 2: |
| 56 | return (a / 40.0f); |
| 57 | case 5: |
| 58 | return 1.0f - (a / 40.0f); |
| 59 | default: |
| 60 | return 0.0f; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 64 | static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, |
| 65 | void *data) |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 66 | { |
| 67 | int *waiting_for_flip = data; |
| 68 | *waiting_for_flip = 0; |
| 69 | } |
| 70 | |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 71 | static uint32_t find_format(char *fourcc) |
| 72 | { |
| 73 | if (!fourcc || strlen(fourcc) < 4) |
| 74 | return 0; |
| 75 | |
| 76 | uint32_t format = fourcc_code(fourcc[0], fourcc[1], fourcc[2], fourcc[3]); |
| 77 | for (int i = 0; i < allowed_formats_length; i++) { |
| 78 | if (allowed_formats[i] == format) |
| 79 | return format; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 85 | static const struct option longopts[] = { |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 86 | { "format", required_argument, NULL, 'f' }, |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 87 | { "modifier", required_argument, NULL, 'm' }, |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 88 | { "test-page-flip-format-change", required_argument, NULL, 'p' }, |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 89 | { "help", no_argument, NULL, 'h' }, |
| 90 | { 0, 0, 0, 0 }, |
| 91 | }; |
| 92 | |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 93 | static void print_help(const char *argv0, int fd) |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 94 | { |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 95 | char allowed_formats_string[allowed_formats_length * 6]; |
| 96 | int i; |
| 97 | for (i = 0; i < allowed_formats_length; i++) { |
| 98 | uint32_t format = allowed_formats[i]; |
| 99 | sprintf(allowed_formats_string + i * 6, "%.4s, ", (char *)&format); |
| 100 | } |
| 101 | |
| 102 | allowed_formats_string[i * 6 - 2] = 0; |
| 103 | |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 104 | // clang-format off |
| 105 | printf("usage: %s [OPTIONS] [drm_device_path]\n", argv0); |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 106 | printf(" -f, --format <format> defines the fb format.\n"); |
| 107 | printf(" -m, --modifier <modifier> pass modifiers.\n"); |
| 108 | printf(" -p, --test-page-flip-format-change <format> test page flips alternating formats.\n"); |
| 109 | printf(" -h, --help show help\n"); |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 110 | printf("\n"); |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 111 | printf(" <format> must be one of [ %s ].\n", allowed_formats_string); |
| 112 | printf(" <modifier> must be one of "); |
| 113 | bs_print_supported_modifiers(fd); |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 114 | printf("\n"); |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 115 | printf("\n"); |
| 116 | // clang-format on |
| 117 | } |
| 118 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 119 | int main(int argc, char **argv) |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 120 | { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 121 | int fd = -1; |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 122 | bool help_flag = false; |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 123 | uint32_t format = GBM_FORMAT_XRGB8888; |
Daniele Castagna | 95d027f | 2017-11-01 21:56:58 -0400 | [diff] [blame] | 124 | uint32_t test_page_flip_format_change = 0; |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 125 | uint64_t modifier = DRM_FORMAT_MOD_INVALID; |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 126 | |
| 127 | int c = -1; |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 128 | while ((c = getopt_long(argc, argv, "m:hp:f:", longopts, NULL)) != -1) { |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 129 | switch (c) { |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 130 | case 'p': |
| 131 | test_page_flip_format_change = find_format(optarg); |
| 132 | if (!test_page_flip_format_change) |
| 133 | help_flag = true; |
| 134 | break; |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 135 | case 'f': |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 136 | format = find_format(optarg); |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 137 | if (!format) { |
| 138 | bs_debug_error("unsupported format: %s", optarg); |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 139 | help_flag = true; |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 140 | } |
| 141 | break; |
| 142 | case 'm': |
| 143 | modifier = bs_string_to_modifier(optarg); |
| 144 | if (modifier == -1) { |
| 145 | bs_debug_error("unsupported modifier: %s", optarg); |
| 146 | help_flag = true; |
| 147 | } |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 148 | break; |
| 149 | case 'h': |
| 150 | help_flag = true; |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 155 | if (optind < argc) { |
| 156 | fd = open(argv[optind], O_RDWR); |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 157 | if (fd < 0) { |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 158 | bs_debug_error("failed to open card %s", argv[optind]); |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 159 | return 1; |
| 160 | } |
Zach Reizner | bf26be8 | 2016-09-15 16:06:21 -0700 | [diff] [blame] | 161 | } else { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 162 | fd = bs_drm_open_main_display(); |
| 163 | if (fd < 0) { |
| 164 | bs_debug_error("failed to open card for display"); |
| 165 | return 1; |
| 166 | } |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 169 | if (help_flag) { |
| 170 | print_help(*argv, fd); |
| 171 | close(fd); |
| 172 | return 1; |
| 173 | } |
| 174 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 175 | struct gbm_device *gbm = gbm_create_device(fd); |
| 176 | if (!gbm) { |
| 177 | bs_debug_error("failed to create gbm"); |
| 178 | return 1; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 181 | struct bs_drm_pipe pipe = { 0 }; |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 182 | if (!bs_drm_pipe_make(fd, &pipe)) { |
| 183 | bs_debug_error("failed to make pipe"); |
| 184 | return 1; |
| 185 | } |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 186 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 187 | drmModeConnector *connector = drmModeGetConnector(fd, pipe.connector_id); |
| 188 | assert(connector); |
| 189 | drmModeModeInfo *mode = &connector->modes[0]; |
| 190 | |
| 191 | struct bs_egl *egl = bs_egl_new(); |
| 192 | if (!bs_egl_setup(egl)) { |
| 193 | bs_debug_error("failed to setup egl context"); |
| 194 | return 1; |
| 195 | } |
| 196 | |
Gurchetan Singh | 10008e6 | 2017-03-09 11:14:38 -0800 | [diff] [blame] | 197 | struct gbm_bo *bos[NUM_BUFFERS]; |
| 198 | uint32_t ids[NUM_BUFFERS]; |
| 199 | struct bs_egl_fb *egl_fbs[NUM_BUFFERS]; |
| 200 | EGLImageKHR egl_images[NUM_BUFFERS]; |
| 201 | for (size_t fb_index = 0; fb_index < NUM_BUFFERS; fb_index++) { |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 202 | if (test_page_flip_format_change && fb_index) { |
Daniele Castagna | 7272912 | 2017-10-18 17:09:36 -0400 | [diff] [blame] | 203 | format = test_page_flip_format_change; |
Daniele Castagna | 8a63a60 | 2016-10-10 18:43:29 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Fritz Koenig | 01ee3d4 | 2018-11-07 10:42:17 -0800 | [diff] [blame^] | 206 | if (modifier != DRM_FORMAT_MOD_INVALID) { |
| 207 | bos[fb_index] = gbm_bo_create_with_modifiers( |
| 208 | gbm, mode->hdisplay, mode->vdisplay, format, &modifier, 1); |
| 209 | } else { |
| 210 | bos[fb_index] = gbm_bo_create(gbm, mode->hdisplay, mode->vdisplay, format, |
| 211 | GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); |
| 212 | } |
| 213 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 214 | if (bos[fb_index] == NULL) { |
| 215 | bs_debug_error("failed to allocate framebuffer"); |
| 216 | return 1; |
| 217 | } |
| 218 | |
| 219 | ids[fb_index] = bs_drm_fb_create_gbm(bos[fb_index]); |
| 220 | if (ids[fb_index] == 0) { |
| 221 | bs_debug_error("failed to create framebuffer id"); |
| 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | EGLImageKHR egl_image = bs_egl_image_create_gbm(egl, bos[fb_index]); |
| 226 | if (egl_image == EGL_NO_IMAGE_KHR) { |
| 227 | bs_debug_error("failed to create EGLImageKHR from framebuffer"); |
| 228 | return 1; |
| 229 | } |
| 230 | |
| 231 | egl_fbs[fb_index] = bs_egl_fb_new(egl, egl_image); |
| 232 | if (!egl_fbs[fb_index]) { |
| 233 | bs_debug_error("failed to create framebuffer from EGLImageKHR"); |
| 234 | return 1; |
| 235 | } |
Haixia Shi | fe4e2ff | 2016-10-17 14:28:55 -0700 | [diff] [blame] | 236 | egl_images[fb_index] = egl_image; |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | int ret = drmModeSetCrtc(fd, pipe.crtc_id, ids[0], 0 /* x */, 0 /* y */, &pipe.connector_id, |
| 240 | 1 /* connector count */, mode); |
| 241 | if (ret) { |
| 242 | bs_debug_error("failed to set CRTC"); |
| 243 | return 1; |
| 244 | } |
| 245 | |
| 246 | GLuint program = solid_shader_create(); |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 247 | if (!program) { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 248 | bs_debug_error("failed to create solid shader"); |
| 249 | return 1; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 252 | int fb_idx = 1; |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 253 | for (int i = 0; i <= 500; i++) { |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 254 | int waiting_for_flip = 1; |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 255 | // clang-format off |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 256 | GLfloat verts[] = { |
| 257 | 0.0f, -0.5f, 0.0f, |
| 258 | -0.5f, 0.5f, 0.0f, |
| 259 | 0.5f, 0.5f, 0.0f |
| 260 | }; |
| 261 | GLfloat colors[] = { |
| 262 | 1.0f, 0.0f, 0.0f, 1.0f, |
| 263 | 0.0f, 1.0f, 0.0f, 1.0f, |
| 264 | 0.0f, 0.0f, 1.0f, 1.0f |
| 265 | }; |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 266 | // clang-format on |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 267 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 268 | glBindFramebuffer(GL_FRAMEBUFFER, bs_egl_fb_name(egl_fbs[fb_idx])); |
| 269 | glViewport(0, 0, (GLint)mode->hdisplay, (GLint)mode->vdisplay); |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 270 | |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 271 | glClearColor(f(i), f(i + 80), f(i + 160), 0.0f); |
| 272 | glClear(GL_COLOR_BUFFER_BIT); |
| 273 | |
| 274 | glUseProgram(program); |
| 275 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, verts); |
| 276 | glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, colors); |
| 277 | glEnableVertexAttribArray(0); |
| 278 | glEnableVertexAttribArray(1); |
| 279 | glDrawArrays(GL_TRIANGLES, 0, 3); |
| 280 | |
| 281 | usleep(1e6 / 120); /* 120 Hz */ |
| 282 | glFinish(); |
Haixia Shi | fe4e2ff | 2016-10-17 14:28:55 -0700 | [diff] [blame] | 283 | |
| 284 | if (!bs_egl_image_flush_external(egl, egl_images[fb_idx])) { |
| 285 | bs_debug_error("failed to call image_flush_external"); |
| 286 | return 1; |
| 287 | } |
| 288 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 289 | ret = drmModePageFlip(fd, pipe.crtc_id, ids[fb_idx], DRM_MODE_PAGE_FLIP_EVENT, |
| 290 | &waiting_for_flip); |
| 291 | if (ret) { |
| 292 | bs_debug_error("failed page flip: %d", ret); |
| 293 | return 1; |
| 294 | } |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 295 | |
| 296 | while (waiting_for_flip) { |
| 297 | drmEventContext evctx = { |
Zach Reizner | 4dfdf60 | 2016-03-01 13:06:30 -0800 | [diff] [blame] | 298 | .version = DRM_EVENT_CONTEXT_VERSION, |
| 299 | .page_flip_handler = page_flip_handler, |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | fd_set fds; |
| 303 | FD_ZERO(&fds); |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 304 | FD_SET(fd, &fds); |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 305 | |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 306 | ret = select(fd + 1, &fds, NULL, NULL, NULL); |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 307 | if (ret < 0) { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 308 | bs_debug_error("select err: %s", strerror(errno)); |
| 309 | return 1; |
Zach Reizner | bf26be8 | 2016-09-15 16:06:21 -0700 | [diff] [blame] | 310 | } else if (ret == 0) { |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 311 | bs_debug_error("select timeout"); |
| 312 | return 1; |
| 313 | } |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 314 | ret = drmHandleEvent(fd, &evctx); |
| 315 | if (ret) { |
| 316 | bs_debug_error("failed to wait for page flip: %d", ret); |
| 317 | return 1; |
| 318 | } |
Haixia Shi | 4652b8c | 2014-11-19 17:55:38 -0800 | [diff] [blame] | 319 | } |
| 320 | fb_idx = fb_idx ^ 1; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Gurchetan Singh | 10008e6 | 2017-03-09 11:14:38 -0800 | [diff] [blame] | 323 | for (size_t fb_index = 0; fb_index < NUM_BUFFERS; fb_index++) { |
| 324 | bs_egl_fb_destroy(&egl_fbs[fb_index]); |
| 325 | bs_egl_image_destroy(egl, &egl_images[fb_index]); |
| 326 | drmModeRmFB(fd, ids[fb_idx]); |
| 327 | gbm_bo_destroy(bos[fb_index]); |
| 328 | } |
| 329 | |
| 330 | bs_egl_destroy(&egl); |
| 331 | gbm_device_destroy(gbm); |
| 332 | close(fd); |
Zach Reizner | 38f0fd9 | 2016-02-18 14:28:02 -0800 | [diff] [blame] | 333 | return 0; |
Haixia Shi | e04ddfd | 2014-11-11 19:14:32 -0800 | [diff] [blame] | 334 | } |