Frediano Ziglio | 6250dff | 2016-12-08 10:45:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015-2016 Gerd Hoffmann <kraxel@redhat.com> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 17 | #include "qemu/osdep.h" |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 18 | #include <glob.h> |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 19 | #include <dirent.h> |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 20 | |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 21 | #include "qemu/error-report.h" |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 22 | #include "ui/egl-helpers.h" |
| 23 | |
| 24 | EGLDisplay *qemu_egl_display; |
| 25 | EGLConfig qemu_egl_config; |
| 26 | |
Gerd Hoffmann | 6fafc26 | 2017-06-14 10:41:46 +0200 | [diff] [blame] | 27 | /* ------------------------------------------------------------------ */ |
| 28 | |
| 29 | void egl_fb_destroy(egl_fb *fb) |
| 30 | { |
| 31 | if (!fb->framebuffer) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (fb->delete_texture) { |
| 36 | glDeleteTextures(1, &fb->texture); |
| 37 | fb->delete_texture = false; |
| 38 | } |
| 39 | glDeleteFramebuffers(1, &fb->framebuffer); |
| 40 | |
| 41 | fb->width = 0; |
| 42 | fb->height = 0; |
| 43 | fb->texture = 0; |
| 44 | fb->framebuffer = 0; |
| 45 | } |
| 46 | |
| 47 | void egl_fb_setup_default(egl_fb *fb, int width, int height) |
| 48 | { |
| 49 | fb->width = width; |
| 50 | fb->height = height; |
| 51 | fb->framebuffer = 0; /* default framebuffer */ |
| 52 | } |
| 53 | |
| 54 | void egl_fb_create_for_tex(egl_fb *fb, int width, int height, GLuint texture) |
| 55 | { |
| 56 | fb->width = width; |
| 57 | fb->height = height; |
| 58 | fb->texture = texture; |
| 59 | if (!fb->framebuffer) { |
| 60 | glGenFramebuffers(1, &fb->framebuffer); |
| 61 | } |
| 62 | |
| 63 | glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb->framebuffer); |
| 64 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, |
| 65 | GL_TEXTURE_2D, fb->texture, 0); |
| 66 | } |
| 67 | |
| 68 | void egl_fb_create_new_tex(egl_fb *fb, int width, int height) |
| 69 | { |
| 70 | GLuint texture; |
| 71 | |
| 72 | glGenTextures(1, &texture); |
| 73 | glBindTexture(GL_TEXTURE_2D, texture); |
| 74 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, |
| 75 | 0, GL_BGRA, GL_UNSIGNED_BYTE, 0); |
| 76 | |
| 77 | egl_fb_create_for_tex(fb, width, height, texture); |
| 78 | fb->delete_texture = true; |
| 79 | } |
| 80 | |
| 81 | void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip) |
| 82 | { |
| 83 | GLuint y1, y2; |
| 84 | |
| 85 | glBindFramebuffer(GL_READ_FRAMEBUFFER, src->framebuffer); |
| 86 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->framebuffer); |
| 87 | glViewport(0, 0, dst->width, dst->height); |
| 88 | y1 = flip ? src->height : 0; |
| 89 | y2 = flip ? 0 : src->height; |
| 90 | glBlitFramebuffer(0, y1, src->width, y2, |
| 91 | 0, 0, dst->width, dst->height, |
| 92 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 93 | } |
| 94 | |
| 95 | void egl_fb_read(void *dst, egl_fb *src) |
| 96 | { |
| 97 | glBindFramebuffer(GL_READ_FRAMEBUFFER, src->framebuffer); |
| 98 | glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); |
| 99 | glReadPixels(0, 0, src->width, src->height, |
| 100 | GL_BGRA, GL_UNSIGNED_BYTE, dst); |
| 101 | } |
| 102 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 103 | /* ---------------------------------------------------------------------- */ |
| 104 | |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 105 | #ifdef CONFIG_OPENGL_DMABUF |
| 106 | |
| 107 | int qemu_egl_rn_fd; |
| 108 | struct gbm_device *qemu_egl_rn_gbm_dev; |
| 109 | EGLContext qemu_egl_rn_ctx; |
| 110 | |
Marc-André Lureau | 7b52550 | 2017-02-12 15:21:18 +0400 | [diff] [blame] | 111 | static int qemu_egl_rendernode_open(const char *rendernode) |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 112 | { |
| 113 | DIR *dir; |
| 114 | struct dirent *e; |
| 115 | int r, fd; |
| 116 | char *p; |
| 117 | |
Marc-André Lureau | 7b52550 | 2017-02-12 15:21:18 +0400 | [diff] [blame] | 118 | if (rendernode) { |
| 119 | return open(rendernode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); |
| 120 | } |
| 121 | |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 122 | dir = opendir("/dev/dri"); |
| 123 | if (!dir) { |
| 124 | return -1; |
| 125 | } |
| 126 | |
| 127 | fd = -1; |
| 128 | while ((e = readdir(dir))) { |
| 129 | if (e->d_type != DT_CHR) { |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | if (strncmp(e->d_name, "renderD", 7)) { |
| 134 | continue; |
| 135 | } |
| 136 | |
Gonglei | f454f49 | 2016-05-12 17:57:07 +0800 | [diff] [blame] | 137 | p = g_strdup_printf("/dev/dri/%s", e->d_name); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 138 | |
| 139 | r = open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); |
| 140 | if (r < 0) { |
Gonglei | f454f49 | 2016-05-12 17:57:07 +0800 | [diff] [blame] | 141 | g_free(p); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 142 | continue; |
| 143 | } |
| 144 | fd = r; |
Gonglei | f454f49 | 2016-05-12 17:57:07 +0800 | [diff] [blame] | 145 | g_free(p); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | |
| 149 | closedir(dir); |
| 150 | if (fd < 0) { |
| 151 | return -1; |
| 152 | } |
| 153 | return fd; |
| 154 | } |
| 155 | |
Marc-André Lureau | 7b52550 | 2017-02-12 15:21:18 +0400 | [diff] [blame] | 156 | int egl_rendernode_init(const char *rendernode) |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 157 | { |
| 158 | qemu_egl_rn_fd = -1; |
Gerd Hoffmann | 151c8e6 | 2017-05-05 12:40:59 +0200 | [diff] [blame] | 159 | int rc; |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 160 | |
Marc-André Lureau | 7b52550 | 2017-02-12 15:21:18 +0400 | [diff] [blame] | 161 | qemu_egl_rn_fd = qemu_egl_rendernode_open(rendernode); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 162 | if (qemu_egl_rn_fd == -1) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 163 | error_report("egl: no drm render node available"); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 164 | goto err; |
| 165 | } |
| 166 | |
| 167 | qemu_egl_rn_gbm_dev = gbm_create_device(qemu_egl_rn_fd); |
| 168 | if (!qemu_egl_rn_gbm_dev) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 169 | error_report("egl: gbm_create_device failed"); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 170 | goto err; |
| 171 | } |
| 172 | |
Gerd Hoffmann | 151c8e6 | 2017-05-05 12:40:59 +0200 | [diff] [blame] | 173 | rc = qemu_egl_init_dpy_mesa((EGLNativeDisplayType)qemu_egl_rn_gbm_dev); |
| 174 | if (rc != 0) { |
| 175 | /* qemu_egl_init_dpy_mesa reports error */ |
| 176 | goto err; |
| 177 | } |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 178 | |
| 179 | if (!epoxy_has_egl_extension(qemu_egl_display, |
| 180 | "EGL_KHR_surfaceless_context")) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 181 | error_report("egl: EGL_KHR_surfaceless_context not supported"); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 182 | goto err; |
| 183 | } |
| 184 | if (!epoxy_has_egl_extension(qemu_egl_display, |
| 185 | "EGL_MESA_image_dma_buf_export")) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 186 | error_report("egl: EGL_MESA_image_dma_buf_export not supported"); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 187 | goto err; |
| 188 | } |
| 189 | |
| 190 | qemu_egl_rn_ctx = qemu_egl_init_ctx(); |
| 191 | if (!qemu_egl_rn_ctx) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 192 | error_report("egl: egl_init_ctx failed"); |
Gerd Hoffmann | 1e31659 | 2015-10-12 12:03:49 +0200 | [diff] [blame] | 193 | goto err; |
| 194 | } |
| 195 | |
| 196 | return 0; |
| 197 | |
| 198 | err: |
| 199 | if (qemu_egl_rn_gbm_dev) { |
| 200 | gbm_device_destroy(qemu_egl_rn_gbm_dev); |
| 201 | } |
| 202 | if (qemu_egl_rn_fd != -1) { |
| 203 | close(qemu_egl_rn_fd); |
| 204 | } |
| 205 | |
| 206 | return -1; |
| 207 | } |
| 208 | |
| 209 | int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc) |
| 210 | { |
| 211 | EGLImageKHR image; |
| 212 | EGLint num_planes, fd; |
| 213 | |
| 214 | image = eglCreateImageKHR(qemu_egl_display, eglGetCurrentContext(), |
| 215 | EGL_GL_TEXTURE_2D_KHR, |
| 216 | (EGLClientBuffer)(unsigned long)tex_id, |
| 217 | NULL); |
| 218 | if (!image) { |
| 219 | return -1; |
| 220 | } |
| 221 | |
| 222 | eglExportDMABUFImageQueryMESA(qemu_egl_display, image, fourcc, |
| 223 | &num_planes, NULL); |
| 224 | if (num_planes != 1) { |
| 225 | eglDestroyImageKHR(qemu_egl_display, image); |
| 226 | return -1; |
| 227 | } |
| 228 | eglExportDMABUFImageMESA(qemu_egl_display, image, &fd, stride, NULL); |
| 229 | eglDestroyImageKHR(qemu_egl_display, image); |
| 230 | |
| 231 | return fd; |
| 232 | } |
| 233 | |
| 234 | #endif /* CONFIG_OPENGL_DMABUF */ |
| 235 | |
| 236 | /* ---------------------------------------------------------------------- */ |
| 237 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 238 | EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win) |
| 239 | { |
| 240 | EGLSurface esurface; |
| 241 | EGLBoolean b; |
| 242 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 243 | esurface = eglCreateWindowSurface(qemu_egl_display, |
| 244 | qemu_egl_config, |
| 245 | (EGLNativeWindowType)win, NULL); |
| 246 | if (esurface == EGL_NO_SURFACE) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 247 | error_report("egl: eglCreateWindowSurface failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | b = eglMakeCurrent(qemu_egl_display, esurface, esurface, ectx); |
| 252 | if (b == EGL_FALSE) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 253 | error_report("egl: eglMakeCurrent failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 254 | return NULL; |
| 255 | } |
| 256 | |
| 257 | return esurface; |
| 258 | } |
| 259 | |
| 260 | /* ---------------------------------------------------------------------- */ |
| 261 | |
Gerd Hoffmann | 8bce03e | 2017-03-20 09:04:02 +0100 | [diff] [blame] | 262 | /* |
| 263 | * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed |
| 264 | * |
| 265 | * Create an EGLDisplay from a native display type. This is a little quirky |
| 266 | * for a few reasons. |
| 267 | * |
| 268 | * 1: GetPlatformDisplayEXT and GetPlatformDisplay are the API you want to |
| 269 | * use, but have different function signatures in the third argument; this |
| 270 | * happens not to matter for us, at the moment, but it means epoxy won't alias |
| 271 | * them together. |
| 272 | * |
| 273 | * 2: epoxy 1.3 and earlier don't understand EGL client extensions, which |
| 274 | * means you can't call "eglGetPlatformDisplayEXT" directly, as the resolver |
| 275 | * will crash. |
| 276 | * |
| 277 | * 3: You can't tell whether you have EGL 1.5 at this point, because |
| 278 | * eglQueryString(EGL_VERSION) is a property of the display, which we don't |
| 279 | * have yet. So you have to query for extensions no matter what. Fortunately |
| 280 | * epoxy_has_egl_extension _does_ let you query for client extensions, so |
| 281 | * we don't have to write our own extension string parsing. |
| 282 | * |
| 283 | * 4. There is no EGL_KHR_platform_base to complement the EXT one, thus one |
| 284 | * needs to know EGL 1.5 is supported in order to use the eglGetPlatformDisplay |
| 285 | * function pointer. |
| 286 | * We can workaround this (circular dependency) by probing for the EGL 1.5 |
| 287 | * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem |
| 288 | * like mesa will be able to advertise these (even though it can do EGL 1.5). |
| 289 | */ |
Gerd Hoffmann | e1913db | 2017-05-05 12:40:58 +0200 | [diff] [blame] | 290 | static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native, |
| 291 | EGLenum platform) |
Gerd Hoffmann | 8bce03e | 2017-03-20 09:04:02 +0100 | [diff] [blame] | 292 | { |
| 293 | EGLDisplay dpy = EGL_NO_DISPLAY; |
| 294 | |
Gerd Hoffmann | 8bce03e | 2017-03-20 09:04:02 +0100 | [diff] [blame] | 295 | /* In practise any EGL 1.5 implementation would support the EXT extension */ |
| 296 | if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) { |
| 297 | PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = |
| 298 | (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); |
Gerd Hoffmann | e1913db | 2017-05-05 12:40:58 +0200 | [diff] [blame] | 299 | if (getPlatformDisplayEXT && platform != 0) { |
| 300 | dpy = getPlatformDisplayEXT(platform, native, NULL); |
Gerd Hoffmann | 8bce03e | 2017-03-20 09:04:02 +0100 | [diff] [blame] | 301 | } |
| 302 | } |
Gerd Hoffmann | 8bce03e | 2017-03-20 09:04:02 +0100 | [diff] [blame] | 303 | |
| 304 | if (dpy == EGL_NO_DISPLAY) { |
| 305 | /* fallback */ |
| 306 | dpy = eglGetDisplay(native); |
| 307 | } |
| 308 | return dpy; |
| 309 | } |
| 310 | |
Gerd Hoffmann | e1913db | 2017-05-05 12:40:58 +0200 | [diff] [blame] | 311 | static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, |
| 312 | EGLenum platform) |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 313 | { |
| 314 | static const EGLint conf_att_gl[] = { |
| 315 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 316 | EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
| 317 | EGL_RED_SIZE, 5, |
| 318 | EGL_GREEN_SIZE, 5, |
| 319 | EGL_BLUE_SIZE, 5, |
| 320 | EGL_ALPHA_SIZE, 0, |
| 321 | EGL_NONE, |
| 322 | }; |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 323 | EGLint major, minor; |
| 324 | EGLBoolean b; |
| 325 | EGLint n; |
| 326 | |
Gerd Hoffmann | e1913db | 2017-05-05 12:40:58 +0200 | [diff] [blame] | 327 | qemu_egl_display = qemu_egl_get_display(dpy, platform); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 328 | if (qemu_egl_display == EGL_NO_DISPLAY) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 329 | error_report("egl: eglGetDisplay failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 330 | return -1; |
| 331 | } |
| 332 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 333 | b = eglInitialize(qemu_egl_display, &major, &minor); |
| 334 | if (b == EGL_FALSE) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 335 | error_report("egl: eglInitialize failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 336 | return -1; |
| 337 | } |
| 338 | |
Gerd Hoffmann | 9f728c7 | 2017-05-05 12:40:57 +0200 | [diff] [blame] | 339 | b = eglBindAPI(EGL_OPENGL_API); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 340 | if (b == EGL_FALSE) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 341 | error_report("egl: eglBindAPI failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 342 | return -1; |
| 343 | } |
| 344 | |
Gerd Hoffmann | 9f728c7 | 2017-05-05 12:40:57 +0200 | [diff] [blame] | 345 | b = eglChooseConfig(qemu_egl_display, conf_att_gl, |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 346 | &qemu_egl_config, 1, &n); |
| 347 | if (b == EGL_FALSE || n != 1) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 348 | error_report("egl: eglChooseConfig failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 349 | return -1; |
| 350 | } |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Gerd Hoffmann | e1913db | 2017-05-05 12:40:58 +0200 | [diff] [blame] | 354 | int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy) |
| 355 | { |
| 356 | #ifdef EGL_KHR_platform_x11 |
| 357 | return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR); |
| 358 | #else |
| 359 | return qemu_egl_init_dpy(dpy, 0); |
| 360 | #endif |
| 361 | } |
| 362 | |
| 363 | int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy) |
| 364 | { |
| 365 | #ifdef EGL_MESA_platform_gbm |
| 366 | return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA); |
| 367 | #else |
| 368 | return qemu_egl_init_dpy(dpy, 0); |
| 369 | #endif |
| 370 | } |
| 371 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 372 | EGLContext qemu_egl_init_ctx(void) |
| 373 | { |
| 374 | static const EGLint ctx_att_gl[] = { |
Gerd Hoffmann | bc8c946 | 2017-05-05 12:41:00 +0200 | [diff] [blame] | 375 | EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 376 | EGL_NONE |
| 377 | }; |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 378 | EGLContext ectx; |
| 379 | EGLBoolean b; |
| 380 | |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 381 | ectx = eglCreateContext(qemu_egl_display, qemu_egl_config, EGL_NO_CONTEXT, |
Gerd Hoffmann | 9f728c7 | 2017-05-05 12:40:57 +0200 | [diff] [blame] | 382 | ctx_att_gl); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 383 | if (ectx == EGL_NO_CONTEXT) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 384 | error_report("egl: eglCreateContext failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 385 | return NULL; |
| 386 | } |
| 387 | |
| 388 | b = eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ectx); |
| 389 | if (b == EGL_FALSE) { |
Cole Robinson | 38a55bd | 2016-05-18 12:40:49 -0400 | [diff] [blame] | 390 | error_report("egl: eglMakeCurrent failed"); |
Gerd Hoffmann | 7ced9e9 | 2015-01-06 15:40:00 +0100 | [diff] [blame] | 391 | return NULL; |
| 392 | } |
| 393 | |
| 394 | return ectx; |
| 395 | } |