Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 19 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Kristian Høgsberg <krh@bitplanet.net> |
| 26 | */ |
| 27 | |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 28 | #include <stdbool.h> |
Emil Velikov | bf0e4d2 | 2015-02-28 17:12:40 +0000 | [diff] [blame] | 29 | #include <stdint.h> |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 30 | #include <stdbool.h> |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include <stdio.h> |
| 34 | #include <limits.h> |
| 35 | #include <dlfcn.h> |
| 36 | #include <fcntl.h> |
| 37 | #include <errno.h> |
| 38 | #include <unistd.h> |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 39 | #include <c11/threads.h> |
| 40 | #include <time.h> |
Emil Velikov | 6638c55 | 2014-05-28 14:36:46 +0100 | [diff] [blame] | 41 | #ifdef HAVE_LIBDRM |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 42 | #include <xf86drm.h> |
Eric Engestrom | f137480 | 2019-02-12 18:18:03 +0000 | [diff] [blame] | 43 | #include "drm-uapi/drm_fourcc.h" |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 44 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 45 | #include <GL/gl.h> |
| 46 | #include <GL/internal/dri_interface.h> |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 47 | #include <sys/types.h> |
| 48 | #include <sys/stat.h> |
| 49 | |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 50 | #ifdef HAVE_WAYLAND_PLATFORM |
Emil Velikov | 9fa1d82 | 2018-03-14 17:31:27 +0000 | [diff] [blame] | 51 | #include <wayland-client.h> |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 52 | #include "wayland-drm.h" |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 53 | #include "wayland-drm-client-protocol.h" |
Daniel Stone | 02cc359 | 2017-06-16 18:01:23 +0100 | [diff] [blame] | 54 | #include "linux-dmabuf-unstable-v1-client-protocol.h" |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 55 | #endif |
| 56 | |
Gregory Hainaut | 3fde8db | 2017-05-29 13:18:27 +0200 | [diff] [blame] | 57 | #ifdef HAVE_X11_PLATFORM |
| 58 | #include "X11/Xlibint.h" |
| 59 | #endif |
| 60 | |
Eric Engestrom | d75fbff | 2018-05-16 14:17:30 +0100 | [diff] [blame] | 61 | #include "egldefines.h" |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 62 | #include "egl_dri2.h" |
Matt Turner | 4e97084 | 2017-07-06 18:40:53 -0700 | [diff] [blame] | 63 | #include "GL/mesa_glinterop.h" |
Christian Gmeiner | 0c73a3b | 2016-11-09 15:50:06 +0100 | [diff] [blame] | 64 | #include "loader/loader.h" |
Eric Engestrom | 419b446 | 2020-06-05 10:22:22 +0200 | [diff] [blame] | 65 | #include "util/os_file.h" |
Alexander von Gluck IV | ba65196 | 2015-08-07 12:55:40 -0500 | [diff] [blame] | 66 | #include "util/u_atomic.h" |
Daniel Stone | 02cc359 | 2017-06-16 18:01:23 +0100 | [diff] [blame] | 67 | #include "util/u_vector.h" |
Emil Velikov | d884d8d | 2017-09-27 17:36:29 +0100 | [diff] [blame] | 68 | #include "mapi/glapi/glapi.h" |
Kevin Strasser | 641320c | 2019-09-12 09:38:24 -0700 | [diff] [blame] | 69 | #include "util/bitscan.h" |
Mathias Fröhlich | c7617d8 | 2019-12-13 17:09:56 +0100 | [diff] [blame] | 70 | #include "util/u_math.h" |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 71 | |
Tapani Pälli | 722f96b | 2019-02-11 10:01:35 +0200 | [diff] [blame] | 72 | /* Additional definitions not yet in the drm_fourcc.h. |
| 73 | */ |
| 74 | #ifndef DRM_FORMAT_P010 |
| 75 | #define DRM_FORMAT_P010 fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cb:Cr plane 10 bits per channel */ |
| 76 | #endif |
| 77 | |
| 78 | #ifndef DRM_FORMAT_P012 |
| 79 | #define DRM_FORMAT_P012 fourcc_code('P', '0', '1', '2') /* 2x2 subsampled Cb:Cr plane 12 bits per channel */ |
| 80 | #endif |
| 81 | |
| 82 | #ifndef DRM_FORMAT_P016 |
| 83 | #define DRM_FORMAT_P016 fourcc_code('P', '0', '1', '6') /* 2x2 subsampled Cb:Cr plane 16 bits per channel */ |
| 84 | #endif |
| 85 | |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 86 | #define NUM_ATTRIBS 12 |
Chris Wilson | 5c56183 | 2016-10-27 19:54:49 +0100 | [diff] [blame] | 87 | |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 88 | static const struct dri2_pbuffer_visual { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 89 | const char *format_name; |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 90 | unsigned int dri_image_format; |
| 91 | int rgba_shifts[4]; |
| 92 | unsigned int rgba_sizes[4]; |
| 93 | } dri2_pbuffer_visuals[] = { |
| 94 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 95 | "ABGR16F", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 96 | __DRI_IMAGE_FORMAT_ABGR16161616F, |
| 97 | { 0, 16, 32, 48 }, |
| 98 | { 16, 16, 16, 16 } |
| 99 | }, |
| 100 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 101 | "XBGR16F", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 102 | __DRI_IMAGE_FORMAT_XBGR16161616F, |
| 103 | { 0, 16, 32, -1 }, |
| 104 | { 16, 16, 16, 0 } |
| 105 | }, |
| 106 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 107 | "A2RGB10", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 108 | __DRI_IMAGE_FORMAT_ARGB2101010, |
| 109 | { 20, 10, 0, 30 }, |
| 110 | { 10, 10, 10, 2 } |
| 111 | }, |
| 112 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 113 | "X2RGB10", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 114 | __DRI_IMAGE_FORMAT_XRGB2101010, |
| 115 | { 20, 10, 0, -1 }, |
| 116 | { 10, 10, 10, 0 } |
| 117 | }, |
| 118 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 119 | "ARGB8888", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 120 | __DRI_IMAGE_FORMAT_ARGB8888, |
| 121 | { 16, 8, 0, 24 }, |
| 122 | { 8, 8, 8, 8 } |
| 123 | }, |
| 124 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 125 | "RGB888", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 126 | __DRI_IMAGE_FORMAT_XRGB8888, |
| 127 | { 16, 8, 0, -1 }, |
| 128 | { 8, 8, 8, 0 } |
| 129 | }, |
| 130 | { |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 131 | "RGB565", |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 132 | __DRI_IMAGE_FORMAT_RGB565, |
| 133 | { 11, 5, 0, -1 }, |
| 134 | { 5, 6, 5, 0 } |
| 135 | }, |
| 136 | }; |
| 137 | |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 138 | static void |
| 139 | dri_set_background_context(void *loaderPrivate) |
| 140 | { |
| 141 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 142 | _EGLThreadInfo *t = _eglGetCurrentThread(); |
| 143 | |
| 144 | _eglBindContextToThread(ctx, t); |
| 145 | } |
| 146 | |
Eric Engestrom | 7823cfe | 2017-09-26 12:16:33 +0100 | [diff] [blame] | 147 | static void |
| 148 | dri2_gl_flush() |
| 149 | { |
| 150 | static void (*glFlush)(void); |
| 151 | static mtx_t glFlushMutex = _MTX_INITIALIZER_NP; |
| 152 | |
| 153 | mtx_lock(&glFlushMutex); |
| 154 | if (!glFlush) |
| 155 | glFlush = _glapi_get_proc_address("glFlush"); |
| 156 | mtx_unlock(&glFlushMutex); |
| 157 | |
| 158 | /* if glFlush is not available things are horribly broken */ |
| 159 | if (!glFlush) { |
| 160 | _eglLog(_EGL_WARNING, "DRI2: failed to find glFlush entry point"); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | glFlush(); |
| 165 | } |
| 166 | |
Gregory Hainaut | 3fde8db | 2017-05-29 13:18:27 +0200 | [diff] [blame] | 167 | static GLboolean |
| 168 | dri_is_thread_safe(void *loaderPrivate) |
| 169 | { |
| 170 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
Eric Engestrom | 14be04f | 2019-06-22 14:27:29 +0100 | [diff] [blame] | 171 | UNUSED _EGLDisplay *display = dri2_surf->base.Resource.Display; |
Gregory Hainaut | 3fde8db | 2017-05-29 13:18:27 +0200 | [diff] [blame] | 172 | |
| 173 | #ifdef HAVE_X11_PLATFORM |
| 174 | Display *xdpy = (Display*)display->PlatformDisplay; |
| 175 | |
| 176 | /* Check Xlib is running in thread safe mode when running on EGL/X11-xlib |
| 177 | * platform |
| 178 | * |
| 179 | * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'. |
| 180 | * It wll be NULL if XInitThreads wasn't called. |
| 181 | */ |
| 182 | if (display->Platform == _EGL_PLATFORM_X11 && xdpy && !xdpy->lock_fns) |
| 183 | return false; |
| 184 | #endif |
| 185 | |
| 186 | #ifdef HAVE_WAYLAND_PLATFORM |
| 187 | if (display->Platform == _EGL_PLATFORM_WAYLAND) |
| 188 | return true; |
| 189 | #endif |
| 190 | |
| 191 | return true; |
| 192 | } |
| 193 | |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 194 | const __DRIbackgroundCallableExtension background_callable_extension = { |
Gregory Hainaut | 3fde8db | 2017-05-29 13:18:27 +0200 | [diff] [blame] | 195 | .base = { __DRI_BACKGROUND_CALLABLE, 2 }, |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 196 | |
| 197 | .setBackgroundContext = dri_set_background_context, |
Gregory Hainaut | 3fde8db | 2017-05-29 13:18:27 +0200 | [diff] [blame] | 198 | .isThreadSafe = dri_is_thread_safe, |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 201 | const __DRIuseInvalidateExtension use_invalidate = { |
Emil Velikov | 5f280d0 | 2014-02-12 20:13:15 +0000 | [diff] [blame] | 202 | .base = { __DRI_USE_INVALIDATE, 1 } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 203 | }; |
| 204 | |
Eric Anholt | 6a8d39dc | 2019-07-23 13:18:21 -0700 | [diff] [blame] | 205 | static void |
| 206 | dri2_get_pbuffer_drawable_info(__DRIdrawable * draw, |
| 207 | int *x, int *y, int *w, int *h, |
| 208 | void *loaderPrivate) |
| 209 | { |
| 210 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 211 | |
| 212 | *x = *y = 0; |
| 213 | *w = dri2_surf->base.Width; |
| 214 | *h = dri2_surf->base.Height; |
| 215 | } |
| 216 | |
Mathias Fröhlich | c7617d8 | 2019-12-13 17:09:56 +0100 | [diff] [blame] | 217 | static int |
| 218 | dri2_get_bytes_per_pixel(struct dri2_egl_surface *dri2_surf) |
| 219 | { |
| 220 | const int depth = dri2_surf->base.Config->BufferSize; |
| 221 | return depth ? util_next_power_of_two(depth / 8) : 0; |
| 222 | } |
| 223 | |
| 224 | static void |
| 225 | dri2_put_image(__DRIdrawable * draw, int op, |
| 226 | int x, int y, int w, int h, |
| 227 | char *data, void *loaderPrivate) |
| 228 | { |
| 229 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 230 | const int bpp = dri2_get_bytes_per_pixel(dri2_surf); |
| 231 | const int width = dri2_surf->base.Width; |
| 232 | const int height = dri2_surf->base.Height; |
| 233 | const int dst_stride = width*bpp; |
| 234 | const int src_stride = w*bpp; |
| 235 | const int x_offset = x*bpp; |
| 236 | int copy_width = src_stride; |
| 237 | |
| 238 | if (!dri2_surf->swrast_device_buffer) |
| 239 | dri2_surf->swrast_device_buffer = malloc(height*dst_stride); |
| 240 | |
| 241 | if (dri2_surf->swrast_device_buffer) { |
| 242 | const char *src = data; |
| 243 | char *dst = dri2_surf->swrast_device_buffer; |
| 244 | |
| 245 | dst += x_offset; |
| 246 | dst += y*dst_stride; |
| 247 | |
| 248 | /* Drivers are allowed to submit OOB PutImage requests, so clip here. */ |
| 249 | if (copy_width > dst_stride - x_offset) |
| 250 | copy_width = dst_stride - x_offset; |
| 251 | if (h > height - y) |
| 252 | h = height - y; |
| 253 | |
| 254 | for (; 0 < h; --h) { |
| 255 | memcpy(dst, src, copy_width); |
| 256 | dst += dst_stride; |
| 257 | src += src_stride; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static void |
| 263 | dri2_get_image(__DRIdrawable * read, |
| 264 | int x, int y, int w, int h, |
| 265 | char *data, void *loaderPrivate) |
| 266 | { |
| 267 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 268 | const int bpp = dri2_get_bytes_per_pixel(dri2_surf); |
| 269 | const int width = dri2_surf->base.Width; |
| 270 | const int height = dri2_surf->base.Height; |
| 271 | const int src_stride = width*bpp; |
| 272 | const int dst_stride = w*bpp; |
| 273 | const int x_offset = x*bpp; |
| 274 | int copy_width = dst_stride; |
| 275 | const char *src = dri2_surf->swrast_device_buffer; |
| 276 | char *dst = data; |
| 277 | |
| 278 | if (!src) { |
| 279 | memset(data, 0, copy_width * h); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | src += x_offset; |
| 284 | src += y*src_stride; |
| 285 | |
| 286 | /* Drivers are allowed to submit OOB GetImage requests, so clip here. */ |
| 287 | if (copy_width > src_stride - x_offset) |
| 288 | copy_width = src_stride - x_offset; |
| 289 | if (h > height - y) |
| 290 | h = height - y; |
| 291 | |
| 292 | for (; 0 < h; --h) { |
| 293 | memcpy(dst, src, copy_width); |
| 294 | src += src_stride; |
| 295 | dst += dst_stride; |
| 296 | } |
| 297 | |
| 298 | } |
| 299 | |
| 300 | /* HACK: technically we should have swrast_null, instead of these. |
Eric Anholt | 6a8d39dc | 2019-07-23 13:18:21 -0700 | [diff] [blame] | 301 | */ |
| 302 | const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension = { |
| 303 | .base = { __DRI_SWRAST_LOADER, 1 }, |
| 304 | .getDrawableInfo = dri2_get_pbuffer_drawable_info, |
Mathias Fröhlich | c7617d8 | 2019-12-13 17:09:56 +0100 | [diff] [blame] | 305 | .putImage = dri2_put_image, |
| 306 | .getImage = dri2_get_image, |
Eric Anholt | 6a8d39dc | 2019-07-23 13:18:21 -0700 | [diff] [blame] | 307 | }; |
| 308 | |
Emil Velikov | b664309 | 2017-05-01 19:40:31 +0100 | [diff] [blame] | 309 | static const EGLint dri2_to_egl_attribute_map[__DRI_ATTRIB_MAX] = { |
Emil Velikov | e5efaeb | 2017-04-28 17:01:03 +0100 | [diff] [blame] | 310 | [__DRI_ATTRIB_BUFFER_SIZE ] = EGL_BUFFER_SIZE, |
| 311 | [__DRI_ATTRIB_LEVEL] = EGL_LEVEL, |
Emil Velikov | e5efaeb | 2017-04-28 17:01:03 +0100 | [diff] [blame] | 312 | [__DRI_ATTRIB_LUMINANCE_SIZE] = EGL_LUMINANCE_SIZE, |
Emil Velikov | e5efaeb | 2017-04-28 17:01:03 +0100 | [diff] [blame] | 313 | [__DRI_ATTRIB_DEPTH_SIZE] = EGL_DEPTH_SIZE, |
| 314 | [__DRI_ATTRIB_STENCIL_SIZE] = EGL_STENCIL_SIZE, |
| 315 | [__DRI_ATTRIB_SAMPLE_BUFFERS] = EGL_SAMPLE_BUFFERS, |
| 316 | [__DRI_ATTRIB_SAMPLES] = EGL_SAMPLES, |
| 317 | [__DRI_ATTRIB_MAX_PBUFFER_WIDTH] = EGL_MAX_PBUFFER_WIDTH, |
| 318 | [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT] = EGL_MAX_PBUFFER_HEIGHT, |
| 319 | [__DRI_ATTRIB_MAX_PBUFFER_PIXELS] = EGL_MAX_PBUFFER_PIXELS, |
| 320 | [__DRI_ATTRIB_MAX_SWAP_INTERVAL] = EGL_MAX_SWAP_INTERVAL, |
| 321 | [__DRI_ATTRIB_MIN_SWAP_INTERVAL] = EGL_MIN_SWAP_INTERVAL, |
| 322 | [__DRI_ATTRIB_YINVERTED] = EGL_Y_INVERTED_NOK, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 323 | }; |
| 324 | |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 325 | const __DRIconfig * |
| 326 | dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type, |
| 327 | EGLenum colorspace) |
| 328 | { |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 329 | const bool double_buffer = surface_type == EGL_WINDOW_BIT; |
Emil Velikov | 858f2f2 | 2015-09-13 12:25:27 +0100 | [diff] [blame] | 330 | const bool srgb = colorspace == EGL_GL_COLORSPACE_SRGB_KHR; |
| 331 | |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 332 | return conf->dri_config[double_buffer][srgb]; |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 335 | static EGLBoolean |
| 336 | dri2_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) |
| 337 | { |
| 338 | if (_eglCompareConfigs(conf, criteria, NULL, EGL_FALSE) != 0) |
| 339 | return EGL_FALSE; |
| 340 | |
| 341 | if (!_eglMatchConfig(conf, criteria)) |
| 342 | return EGL_FALSE; |
| 343 | |
| 344 | return EGL_TRUE; |
| 345 | } |
| 346 | |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 347 | void |
| 348 | dri2_get_shifts_and_sizes(const __DRIcoreExtension *core, |
| 349 | const __DRIconfig *config, int *shifts, |
| 350 | unsigned int *sizes) |
| 351 | { |
| 352 | unsigned int mask; |
| 353 | |
| 354 | if (core->getConfigAttrib(config, __DRI_ATTRIB_RED_SHIFT, (unsigned int *)&shifts[0])) { |
| 355 | core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SHIFT, (unsigned int *)&shifts[1]); |
| 356 | core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SHIFT, (unsigned int *)&shifts[2]); |
| 357 | core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SHIFT, (unsigned int *)&shifts[3]); |
| 358 | } else { |
| 359 | /* Driver isn't exposing shifts, so convert masks to shifts */ |
| 360 | core->getConfigAttrib(config, __DRI_ATTRIB_RED_MASK, &mask); |
| 361 | shifts[0] = ffs(mask) - 1; |
| 362 | core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_MASK, &mask); |
| 363 | shifts[1] = ffs(mask) - 1; |
| 364 | core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_MASK, &mask); |
| 365 | shifts[2] = ffs(mask) - 1; |
| 366 | core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_MASK, &mask); |
| 367 | shifts[3] = ffs(mask) - 1; |
| 368 | } |
| 369 | |
| 370 | core->getConfigAttrib(config, __DRI_ATTRIB_RED_SIZE, &sizes[0]); |
| 371 | core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SIZE, &sizes[1]); |
| 372 | core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SIZE, &sizes[2]); |
| 373 | core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SIZE, &sizes[3]); |
| 374 | } |
| 375 | |
Kevin Strasser | 482ed43 | 2019-01-24 16:55:33 -0800 | [diff] [blame] | 376 | void |
| 377 | dri2_get_render_type_float(const __DRIcoreExtension *core, |
| 378 | const __DRIconfig *config, |
| 379 | bool *is_float) |
| 380 | { |
| 381 | unsigned int render_type; |
| 382 | |
| 383 | core->getConfigAttrib(config, __DRI_ATTRIB_RENDER_TYPE, &render_type); |
| 384 | *is_float = (render_type & __DRI_ATTRIB_FLOAT_BIT) ? true : false; |
| 385 | } |
| 386 | |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 387 | unsigned int |
| 388 | dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy, |
| 389 | const __DRIconfig *config) |
| 390 | { |
| 391 | int shifts[4]; |
| 392 | unsigned int sizes[4]; |
| 393 | |
| 394 | dri2_get_shifts_and_sizes(dri2_dpy->core, config, shifts, sizes); |
| 395 | |
| 396 | for (unsigned i = 0; i < ARRAY_SIZE(dri2_pbuffer_visuals); ++i) { |
| 397 | const struct dri2_pbuffer_visual *visual = &dri2_pbuffer_visuals[i]; |
| 398 | |
| 399 | if (shifts[0] == visual->rgba_shifts[0] && |
| 400 | shifts[1] == visual->rgba_shifts[1] && |
| 401 | shifts[2] == visual->rgba_shifts[2] && |
| 402 | shifts[3] == visual->rgba_shifts[3] && |
| 403 | sizes[0] == visual->rgba_sizes[0] && |
| 404 | sizes[1] == visual->rgba_sizes[1] && |
| 405 | sizes[2] == visual->rgba_sizes[2] && |
| 406 | sizes[3] == visual->rgba_sizes[3]) { |
| 407 | return visual->dri_image_format; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return __DRI_IMAGE_FORMAT_NONE; |
| 412 | } |
| 413 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 414 | struct dri2_egl_config * |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 415 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 416 | EGLint surface_type, const EGLint *attr_list, |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 417 | const int *rgba_shifts, const unsigned int *rgba_sizes) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 418 | { |
| 419 | struct dri2_egl_config *conf; |
Emil Velikov | 532ec2e | 2016-07-15 12:47:37 +0100 | [diff] [blame] | 420 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 421 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 422 | unsigned int attrib, value, double_buffer; |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 423 | bool srgb = false; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 424 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 425 | int dri_shifts[4] = { -1, -1, -1, -1 }; |
| 426 | unsigned int dri_sizes[4] = { 0, 0, 0, 0 }; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 427 | _EGLConfig *matching_config; |
| 428 | EGLint num_configs = 0; |
Emil Velikov | aeaf21a | 2016-11-09 21:45:07 +0000 | [diff] [blame] | 429 | EGLint config_id; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 430 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 431 | _eglInitConfig(&base, disp, id); |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 432 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 433 | double_buffer = 0; |
| 434 | bind_to_texture_rgb = 0; |
| 435 | bind_to_texture_rgba = 0; |
| 436 | |
Kevin Strasser | 70b36c0 | 2019-01-28 10:42:44 -0800 | [diff] [blame] | 437 | for (int i = 0; i < __DRI_ATTRIB_MAX; ++i) { |
| 438 | if (!dri2_dpy->core->indexConfigAttrib(dri_config, i, &attrib, &value)) |
| 439 | break; |
| 440 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 441 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 442 | case __DRI_ATTRIB_RENDER_TYPE: |
Kevin Strasser | 482ed43 | 2019-01-24 16:55:33 -0800 | [diff] [blame] | 443 | if (value & __DRI_ATTRIB_FLOAT_BIT) |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 444 | base.ComponentType = EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT; |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 445 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 446 | value = EGL_RGB_BUFFER; |
| 447 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 448 | value = EGL_LUMINANCE_BUFFER; |
| 449 | else |
| 450 | return NULL; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 451 | base.ColorBufferType = value; |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 452 | break; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 453 | |
| 454 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 455 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 456 | value = EGL_NON_CONFORMANT_CONFIG; |
| 457 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 458 | value = EGL_SLOW_CONFIG; |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 459 | else |
| 460 | value = EGL_NONE; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 461 | base.ConfigCaveat = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 462 | break; |
| 463 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 464 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 465 | bind_to_texture_rgb = value; |
| 466 | break; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 467 | |
| 468 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 469 | bind_to_texture_rgba = value; |
| 470 | break; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 471 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 472 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 473 | double_buffer = value; |
| 474 | break; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 475 | |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 476 | case __DRI_ATTRIB_RED_SIZE: |
| 477 | dri_sizes[0] = value; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 478 | base.RedSize = value; |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 479 | break; |
| 480 | |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 481 | case __DRI_ATTRIB_RED_MASK: |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 482 | dri_shifts[0] = ffs(value) - 1; |
| 483 | break; |
| 484 | |
| 485 | case __DRI_ATTRIB_RED_SHIFT: |
| 486 | dri_shifts[0] = value; |
| 487 | break; |
| 488 | |
| 489 | case __DRI_ATTRIB_GREEN_SIZE: |
| 490 | dri_sizes[1] = value; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 491 | base.GreenSize = value; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 492 | break; |
| 493 | |
| 494 | case __DRI_ATTRIB_GREEN_MASK: |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 495 | dri_shifts[1] = ffs(value) - 1; |
| 496 | break; |
| 497 | |
| 498 | case __DRI_ATTRIB_GREEN_SHIFT: |
| 499 | dri_shifts[1] = value; |
| 500 | break; |
| 501 | |
| 502 | case __DRI_ATTRIB_BLUE_SIZE: |
| 503 | dri_sizes[2] = value; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 504 | base.BlueSize = value; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 505 | break; |
| 506 | |
| 507 | case __DRI_ATTRIB_BLUE_MASK: |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 508 | dri_shifts[2] = ffs(value) - 1; |
| 509 | break; |
| 510 | |
| 511 | case __DRI_ATTRIB_BLUE_SHIFT: |
| 512 | dri_shifts[2] = value; |
| 513 | break; |
| 514 | |
| 515 | case __DRI_ATTRIB_ALPHA_SIZE: |
| 516 | dri_sizes[3] = value; |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 517 | base.AlphaSize = value; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 518 | break; |
| 519 | |
| 520 | case __DRI_ATTRIB_ALPHA_MASK: |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 521 | dri_shifts[3] = ffs(value) - 1; |
| 522 | break; |
| 523 | |
| 524 | case __DRI_ATTRIB_ALPHA_SHIFT: |
| 525 | dri_shifts[3] = value; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 526 | break; |
| 527 | |
Marek Olšák | 396cbab | 2015-04-09 23:25:07 +0200 | [diff] [blame] | 528 | case __DRI_ATTRIB_ACCUM_RED_SIZE: |
| 529 | case __DRI_ATTRIB_ACCUM_GREEN_SIZE: |
| 530 | case __DRI_ATTRIB_ACCUM_BLUE_SIZE: |
| 531 | case __DRI_ATTRIB_ACCUM_ALPHA_SIZE: |
| 532 | /* Don't expose visuals with the accumulation buffer. */ |
| 533 | if (value > 0) |
| 534 | return NULL; |
| 535 | break; |
| 536 | |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 537 | case __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE: |
| 538 | srgb = value != 0; |
Emil Velikov | 54702c2 | 2015-11-29 16:48:51 +0000 | [diff] [blame] | 539 | if (!disp->Extensions.KHR_gl_colorspace && srgb) |
| 540 | return NULL; |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 541 | break; |
| 542 | |
Tapani Pälli | b91e1e3 | 2016-10-20 10:33:33 +0300 | [diff] [blame] | 543 | case __DRI_ATTRIB_MAX_PBUFFER_WIDTH: |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 544 | base.MaxPbufferWidth = _EGL_MAX_PBUFFER_WIDTH; |
Tapani Pälli | b91e1e3 | 2016-10-20 10:33:33 +0300 | [diff] [blame] | 545 | break; |
| 546 | case __DRI_ATTRIB_MAX_PBUFFER_HEIGHT: |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 547 | base.MaxPbufferHeight = _EGL_MAX_PBUFFER_HEIGHT; |
Tapani Pälli | b91e1e3 | 2016-10-20 10:33:33 +0300 | [diff] [blame] | 548 | break; |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 549 | case __DRI_ATTRIB_MUTABLE_RENDER_BUFFER: |
| 550 | if (disp->Extensions.KHR_mutable_render_buffer) |
| 551 | surface_type |= EGL_MUTABLE_RENDER_BUFFER_BIT_KHR; |
| 552 | break; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 553 | default: |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 554 | key = dri2_to_egl_attribute_map[attrib]; |
| 555 | if (key != 0) |
| 556 | _eglSetConfigKey(&base, key, value); |
| 557 | break; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 561 | if (attr_list) |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 562 | for (int i = 0; attr_list[i] != EGL_NONE; i += 2) |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 563 | _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 564 | |
Kevin Strasser | 7b4ed2b | 2019-01-24 16:32:48 -0800 | [diff] [blame] | 565 | if (rgba_shifts && memcmp(rgba_shifts, dri_shifts, sizeof(dri_shifts))) |
| 566 | return NULL; |
| 567 | |
| 568 | if (rgba_sizes && memcmp(rgba_sizes, dri_sizes, sizeof(dri_sizes))) |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 569 | return NULL; |
| 570 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 571 | base.NativeRenderable = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 572 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 573 | base.SurfaceType = surface_type; |
Benjamin Franzke | a8128d7 | 2011-02-04 12:32:30 +0100 | [diff] [blame] | 574 | if (surface_type & (EGL_PBUFFER_BIT | |
| 575 | (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 576 | base.BindToTextureRGB = bind_to_texture_rgb; |
| 577 | if (base.AlphaSize > 0) |
| 578 | base.BindToTextureRGBA = bind_to_texture_rgba; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 579 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 580 | |
Hal Gentz | 4ef2c53 | 2019-10-18 01:03:30 -0600 | [diff] [blame] | 581 | if (double_buffer) { |
| 582 | surface_type &= ~EGL_PIXMAP_BIT; |
| 583 | } |
| 584 | |
Adam Jackson | 7e0e53a | 2019-09-10 12:07:07 -0400 | [diff] [blame] | 585 | /* No support for pbuffer + MSAA for now. |
| 586 | * |
| 587 | * XXX TODO: pbuffer + MSAA does not work and causes crashes. |
| 588 | * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509 |
| 589 | */ |
| 590 | if (base.Samples) { |
| 591 | surface_type &= ~EGL_PBUFFER_BIT; |
| 592 | } |
| 593 | |
Hal Gentz | 4ef2c53 | 2019-10-18 01:03:30 -0600 | [diff] [blame] | 594 | if (!surface_type) |
| 595 | return NULL; |
| 596 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 597 | base.RenderableType = disp->ClientAPIs; |
| 598 | base.Conformant = disp->ClientAPIs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 599 | |
Chad Versace | d3dfce3 | 2013-04-23 04:17:48 +0200 | [diff] [blame] | 600 | base.MinSwapInterval = dri2_dpy->min_swap_interval; |
| 601 | base.MaxSwapInterval = dri2_dpy->max_swap_interval; |
| 602 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 603 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 604 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 605 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 606 | } |
| 607 | |
Emil Velikov | aeaf21a | 2016-11-09 21:45:07 +0000 | [diff] [blame] | 608 | config_id = base.ConfigID; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 609 | base.ConfigID = EGL_DONT_CARE; |
| 610 | base.SurfaceType = EGL_DONT_CARE; |
| 611 | num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 612 | (_EGLArrayForEach) dri2_match_config, &base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 613 | |
| 614 | if (num_configs == 1) { |
| 615 | conf = (struct dri2_egl_config *) matching_config; |
| 616 | |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 617 | if (!conf->dri_config[double_buffer][srgb]) |
| 618 | conf->dri_config[double_buffer][srgb] = dri_config; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 619 | else |
Benjamin Franzke | 83c6875 | 2011-05-12 19:30:05 +0200 | [diff] [blame] | 620 | /* a similar config type is already added (unlikely) => discard */ |
| 621 | return NULL; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 622 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 623 | else if (num_configs == 0) { |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 624 | conf = calloc(1, sizeof *conf); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 625 | if (conf == NULL) |
| 626 | return NULL; |
| 627 | |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 628 | conf->dri_config[double_buffer][srgb] = dri_config; |
Varad Gautam | f988eff | 2015-10-07 09:48:14 +0530 | [diff] [blame] | 629 | |
Varad Gautam | deb1765 | 2015-10-07 09:48:15 +0530 | [diff] [blame] | 630 | memcpy(&conf->base, &base, sizeof base); |
Varad Gautam | f988eff | 2015-10-07 09:48:14 +0530 | [diff] [blame] | 631 | conf->base.SurfaceType = 0; |
Emil Velikov | aeaf21a | 2016-11-09 21:45:07 +0000 | [diff] [blame] | 632 | conf->base.ConfigID = config_id; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 633 | |
Chia-I Wu | 8a6bdf3 | 2010-10-23 00:47:22 +0800 | [diff] [blame] | 634 | _eglLinkConfig(&conf->base); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 635 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 636 | else { |
Eric Engestrom | ea738a9 | 2018-10-28 18:20:20 +0000 | [diff] [blame] | 637 | unreachable("duplicates should not be possible"); |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 638 | return NULL; |
| 639 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 640 | |
Kristian Høgsberg | 447bb45 | 2011-08-31 18:20:06 -0400 | [diff] [blame] | 641 | conf->base.SurfaceType |= surface_type; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 642 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 643 | return conf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 646 | EGLBoolean |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 647 | dri2_add_pbuffer_configs_for_visuals(_EGLDisplay *disp) |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 648 | { |
| 649 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 650 | unsigned int format_count[ARRAY_SIZE(dri2_pbuffer_visuals)] = { 0 }; |
| 651 | unsigned int config_count = 0; |
| 652 | |
| 653 | for (unsigned i = 0; dri2_dpy->driver_configs[i] != NULL; i++) { |
| 654 | for (unsigned j = 0; j < ARRAY_SIZE(dri2_pbuffer_visuals); j++) { |
| 655 | struct dri2_egl_config *dri2_conf; |
| 656 | |
| 657 | dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], |
| 658 | config_count + 1, EGL_PBUFFER_BIT, NULL, |
| 659 | dri2_pbuffer_visuals[j].rgba_shifts, dri2_pbuffer_visuals[j].rgba_sizes); |
| 660 | |
| 661 | if (dri2_conf) { |
| 662 | if (dri2_conf->base.ConfigID == config_count + 1) |
| 663 | config_count++; |
| 664 | format_count[j]++; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) { |
| 670 | if (!format_count[i]) { |
| 671 | _eglLog(_EGL_DEBUG, "No DRI config supports native format %s", |
| 672 | dri2_pbuffer_visuals[i].format_name); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | return (config_count != 0); |
| 677 | } |
| 678 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 679 | __DRIimage * |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 680 | dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 681 | { |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 682 | _EGLDisplay *disp = data; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 683 | struct dri2_egl_image *dri2_img; |
| 684 | _EGLImage *img; |
| 685 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 686 | (void) screen; |
| 687 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 688 | img = _eglLookupImage(image, disp); |
| 689 | if (img == NULL) { |
| 690 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 691 | return NULL; |
| 692 | } |
| 693 | |
| 694 | dri2_img = dri2_egl_image(image); |
| 695 | |
| 696 | return dri2_img->dri_image; |
| 697 | } |
| 698 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 699 | const __DRIimageLookupExtension image_lookup_extension = { |
Emil Velikov | 5f280d0 | 2014-02-12 20:13:15 +0000 | [diff] [blame] | 700 | .base = { __DRI_IMAGE_LOOKUP, 1 }, |
| 701 | |
| 702 | .lookupEGLImage = dri2_lookup_egl_image |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 703 | }; |
| 704 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 705 | struct dri2_extension_match { |
| 706 | const char *name; |
| 707 | int version; |
| 708 | int offset; |
| 709 | }; |
| 710 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 711 | static const struct dri2_extension_match dri3_driver_extensions[] = { |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 712 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 713 | { __DRI_IMAGE_DRIVER, 1, offsetof(struct dri2_egl_display, image_driver) }, |
| 714 | { NULL, 0, 0 } |
| 715 | }; |
| 716 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 717 | static const struct dri2_extension_match dri2_driver_extensions[] = { |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 718 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 719 | { __DRI_DRI2, 2, offsetof(struct dri2_egl_display, dri2) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 720 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 721 | }; |
| 722 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 723 | static const struct dri2_extension_match dri2_core_extensions[] = { |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 724 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 725 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | 1670737 | 2013-03-19 13:20:36 -0400 | [diff] [blame] | 726 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 727 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 728 | }; |
| 729 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 730 | static const struct dri2_extension_match swrast_driver_extensions[] = { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 731 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 732 | { __DRI_SWRAST, 2, offsetof(struct dri2_egl_display, swrast) }, |
Ian Romanick | 9d76ad2 | 2012-07-19 11:08:02 -0700 | [diff] [blame] | 733 | { NULL, 0, 0 } |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 734 | }; |
| 735 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 736 | static const struct dri2_extension_match swrast_core_extensions[] = { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 737 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Ian Romanick | 9d76ad2 | 2012-07-19 11:08:02 -0700 | [diff] [blame] | 738 | { NULL, 0, 0 } |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 739 | }; |
| 740 | |
Veluri Mithun | 85edfc0 | 2019-01-23 22:45:42 +0530 | [diff] [blame] | 741 | static const struct dri2_extension_match optional_driver_extensions[] = { |
| 742 | { __DRI_CONFIG_OPTIONS, 1, offsetof(struct dri2_egl_display, configOptions) }, |
| 743 | { NULL, 0, 0 } |
| 744 | }; |
| 745 | |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 746 | static const struct dri2_extension_match optional_core_extensions[] = { |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 747 | { __DRI2_ROBUSTNESS, 1, offsetof(struct dri2_egl_display, robustness) }, |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 748 | { __DRI2_NO_ERROR, 1, offsetof(struct dri2_egl_display, no_error) }, |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 749 | { __DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_egl_display, config) }, |
| 750 | { __DRI2_FENCE, 1, offsetof(struct dri2_egl_display, fence) }, |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 751 | { __DRI2_BUFFER_DAMAGE, 1, offsetof(struct dri2_egl_display, buffer_damage) }, |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 752 | { __DRI2_RENDERER_QUERY, 1, offsetof(struct dri2_egl_display, rendererQuery) }, |
| 753 | { __DRI2_INTEROP, 1, offsetof(struct dri2_egl_display, interop) }, |
Gurchetan Singh | 12181b5 | 2017-08-01 14:51:40 -0700 | [diff] [blame] | 754 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 755 | { __DRI2_FLUSH_CONTROL, 1, offsetof(struct dri2_egl_display, flush_control) }, |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 756 | { __DRI2_BLOB, 1, offsetof(struct dri2_egl_display, blob) }, |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 757 | { __DRI_MUTABLE_RENDER_BUFFER_DRIVER, 1, offsetof(struct dri2_egl_display, mutable_render_buffer) }, |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 758 | { NULL, 0, 0 } |
| 759 | }; |
| 760 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 761 | static EGLBoolean |
| 762 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
Emil Velikov | 665cad1 | 2016-08-25 00:52:36 +0100 | [diff] [blame] | 763 | const struct dri2_extension_match *matches, |
Emil Velikov | 38526bd | 2016-08-25 00:16:01 +0100 | [diff] [blame] | 764 | const __DRIextension **extensions, |
| 765 | bool optional) |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 766 | { |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 767 | int ret = EGL_TRUE; |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 768 | void *field; |
| 769 | |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 770 | for (int i = 0; extensions[i]; i++) { |
Martin Peres | 4518eea | 2015-10-30 17:16:35 +0200 | [diff] [blame] | 771 | _eglLog(_EGL_DEBUG, "found extension `%s'", extensions[i]->name); |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 772 | for (int j = 0; matches[j].name; j++) { |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 773 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 774 | extensions[i]->version >= matches[j].version) { |
| 775 | field = ((char *) dri2_dpy + matches[j].offset); |
| 776 | *(const __DRIextension **) field = extensions[i]; |
| 777 | _eglLog(_EGL_INFO, "found extension %s version %d", |
| 778 | extensions[i]->name, extensions[i]->version); |
Emil Velikov | fdd373a | 2016-08-25 09:51:54 +0100 | [diff] [blame] | 779 | break; |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 780 | } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 781 | } |
| 782 | } |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 783 | |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 784 | for (int j = 0; matches[j].name; j++) { |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 785 | field = ((char *) dri2_dpy + matches[j].offset); |
| 786 | if (*(const __DRIextension **) field == NULL) { |
Emil Velikov | 38526bd | 2016-08-25 00:16:01 +0100 | [diff] [blame] | 787 | if (optional) { |
| 788 | _eglLog(_EGL_DEBUG, "did not find optional extension %s version %d", |
| 789 | matches[j].name, matches[j].version); |
| 790 | } else { |
| 791 | _eglLog(_EGL_WARNING, "did not find extension %s version %d", |
| 792 | matches[j].name, matches[j].version); |
| 793 | ret = EGL_FALSE; |
| 794 | } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | return ret; |
| 799 | } |
| 800 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 801 | static const __DRIextension ** |
| 802 | dri2_open_driver(_EGLDisplay *disp) |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 803 | { |
Emil Velikov | 532ec2e | 2016-07-15 12:47:37 +0100 | [diff] [blame] | 804 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Anholt | d971a42 | 2018-11-15 13:54:49 -0800 | [diff] [blame] | 805 | static const char *search_path_vars[] = { |
| 806 | "LIBGL_DRIVERS_PATH", |
| 807 | NULL, |
| 808 | }; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 809 | |
Eric Anholt | d971a42 | 2018-11-15 13:54:49 -0800 | [diff] [blame] | 810 | return loader_open_driver(dri2_dpy->driver_name, |
| 811 | &dri2_dpy->driver, |
| 812 | search_path_vars); |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 813 | } |
| 814 | |
Emil Velikov | 9d84a92 | 2019-02-05 15:19:46 +0000 | [diff] [blame] | 815 | static EGLBoolean |
| 816 | dri2_load_driver_common(_EGLDisplay *disp, |
| 817 | const struct dri2_extension_match *driver_extensions) |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 818 | { |
Emil Velikov | 532ec2e | 2016-07-15 12:47:37 +0100 | [diff] [blame] | 819 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 820 | const __DRIextension **extensions; |
| 821 | |
| 822 | extensions = dri2_open_driver(disp); |
| 823 | if (!extensions) |
| 824 | return EGL_FALSE; |
| 825 | |
Emil Velikov | d3c9143 | 2020-03-05 13:05:36 +0000 | [diff] [blame] | 826 | if (!dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false)) { |
| 827 | dlclose(dri2_dpy->driver); |
| 828 | dri2_dpy->driver = NULL; |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 829 | return EGL_FALSE; |
Emil Velikov | d3c9143 | 2020-03-05 13:05:36 +0000 | [diff] [blame] | 830 | } |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 831 | dri2_dpy->driver_extensions = extensions; |
| 832 | |
Veluri Mithun | 85edfc0 | 2019-01-23 22:45:42 +0530 | [diff] [blame] | 833 | dri2_bind_extensions(dri2_dpy, optional_driver_extensions, extensions, true); |
| 834 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 835 | return EGL_TRUE; |
| 836 | } |
| 837 | |
| 838 | EGLBoolean |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 839 | dri2_load_driver(_EGLDisplay *disp) |
| 840 | { |
Emil Velikov | 9d84a92 | 2019-02-05 15:19:46 +0000 | [diff] [blame] | 841 | return dri2_load_driver_common(disp, dri2_driver_extensions); |
| 842 | } |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 843 | |
Emil Velikov | 9d84a92 | 2019-02-05 15:19:46 +0000 | [diff] [blame] | 844 | EGLBoolean |
| 845 | dri2_load_driver_dri3(_EGLDisplay *disp) |
| 846 | { |
| 847 | return dri2_load_driver_common(disp, dri3_driver_extensions); |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | EGLBoolean |
| 851 | dri2_load_driver_swrast(_EGLDisplay *disp) |
| 852 | { |
Emil Velikov | 9d84a92 | 2019-02-05 15:19:46 +0000 | [diff] [blame] | 853 | return dri2_load_driver_common(disp, swrast_driver_extensions); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 854 | } |
| 855 | |
Marek Olšák | 4f57ccd | 2015-06-10 14:45:58 +0200 | [diff] [blame] | 856 | static unsigned |
| 857 | dri2_renderer_query_integer(struct dri2_egl_display *dri2_dpy, int param) |
| 858 | { |
| 859 | const __DRI2rendererQueryExtension *rendererQuery = dri2_dpy->rendererQuery; |
| 860 | unsigned int value = 0; |
| 861 | |
| 862 | if (!rendererQuery || |
| 863 | rendererQuery->queryInteger(dri2_dpy->dri_screen, param, &value) == -1) |
| 864 | return 0; |
| 865 | |
| 866 | return value; |
| 867 | } |
| 868 | |
Veluri Mithun | 85edfc0 | 2019-01-23 22:45:42 +0530 | [diff] [blame] | 869 | static const char * |
| 870 | dri2_query_driver_name(_EGLDisplay *disp) |
| 871 | { |
| 872 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 873 | return dri2_dpy->driver_name; |
| 874 | } |
| 875 | |
| 876 | static char * |
| 877 | dri2_query_driver_config(_EGLDisplay *disp) |
| 878 | { |
| 879 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 880 | const __DRIconfigOptionsExtension *ext = dri2_dpy->configOptions; |
| 881 | |
| 882 | if (ext->base.version >= 2) |
| 883 | return ext->getXml(dri2_dpy->driver_name); |
| 884 | |
| 885 | return strdup(ext->xml); |
| 886 | } |
| 887 | |
| 888 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 889 | void |
| 890 | dri2_setup_screen(_EGLDisplay *disp) |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 891 | { |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 892 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 893 | unsigned int api_mask; |
| 894 | |
Tomasz Figa | 23a09b4 | 2017-08-10 22:59:45 +0900 | [diff] [blame] | 895 | /* |
| 896 | * EGL 1.5 specification defines the default value to 1. Moreover, |
| 897 | * eglSwapInterval() is required to clamp requested value to the supported |
| 898 | * range. Since the default value is implicitly assumed to be supported, |
| 899 | * use it as both minimum and maximum for the platforms that do not allow |
| 900 | * changing the interval. Platforms, which allow it (e.g. x11, wayland) |
| 901 | * override these values already. |
| 902 | */ |
| 903 | dri2_dpy->min_swap_interval = 1; |
| 904 | dri2_dpy->max_swap_interval = 1; |
| 905 | dri2_dpy->default_swap_interval = 1; |
| 906 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 907 | if (dri2_dpy->image_driver) { |
| 908 | api_mask = dri2_dpy->image_driver->getAPIMask(dri2_dpy->dri_screen); |
| 909 | } else if (dri2_dpy->dri2) { |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 910 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 911 | } else { |
| 912 | assert(dri2_dpy->swrast); |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 913 | api_mask = 1 << __DRI_API_OPENGL | |
| 914 | 1 << __DRI_API_GLES | |
| 915 | 1 << __DRI_API_GLES2 | |
| 916 | 1 << __DRI_API_GLES3; |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 917 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 918 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 919 | disp->ClientAPIs = 0; |
Emil Velikov | 03eaa6c | 2016-08-25 12:15:13 +0100 | [diff] [blame] | 920 | if ((api_mask & (1 <<__DRI_API_OPENGL)) && _eglIsApiValid(EGL_OPENGL_API)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 921 | disp->ClientAPIs |= EGL_OPENGL_BIT; |
Emil Velikov | 03eaa6c | 2016-08-25 12:15:13 +0100 | [diff] [blame] | 922 | if ((api_mask & (1 << __DRI_API_GLES)) && _eglIsApiValid(EGL_OPENGL_ES_API)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 923 | disp->ClientAPIs |= EGL_OPENGL_ES_BIT; |
Emil Velikov | 03eaa6c | 2016-08-25 12:15:13 +0100 | [diff] [blame] | 924 | if ((api_mask & (1 << __DRI_API_GLES2)) && _eglIsApiValid(EGL_OPENGL_ES_API)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 925 | disp->ClientAPIs |= EGL_OPENGL_ES2_BIT; |
Emil Velikov | 03eaa6c | 2016-08-25 12:15:13 +0100 | [diff] [blame] | 926 | if ((api_mask & (1 << __DRI_API_GLES3)) && _eglIsApiValid(EGL_OPENGL_ES_API)) |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 927 | disp->ClientAPIs |= EGL_OPENGL_ES3_BIT_KHR; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 928 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 929 | assert(dri2_dpy->image_driver || dri2_dpy->dri2 || dri2_dpy->swrast); |
Adam Jackson | d9f5b19 | 2016-09-09 12:25:34 -0400 | [diff] [blame] | 930 | disp->Extensions.KHR_no_config_context = EGL_TRUE; |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 931 | disp->Extensions.KHR_surfaceless_context = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 932 | |
Veluri Mithun | 85edfc0 | 2019-01-23 22:45:42 +0530 | [diff] [blame] | 933 | if (dri2_dpy->configOptions) { |
| 934 | disp->Extensions.MESA_query_driver = EGL_TRUE; |
| 935 | } |
| 936 | |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 937 | /* Report back to EGL the bitmask of priorities supported */ |
| 938 | disp->Extensions.IMG_context_priority = |
| 939 | dri2_renderer_query_integer(dri2_dpy, |
| 940 | __DRI2_RENDERER_HAS_CONTEXT_PRIORITY); |
| 941 | |
Tapani Pälli | 41f7de4 | 2017-10-31 10:57:42 +0200 | [diff] [blame] | 942 | disp->Extensions.EXT_pixel_format_float = EGL_TRUE; |
| 943 | |
Marek Olšák | 4f57ccd | 2015-06-10 14:45:58 +0200 | [diff] [blame] | 944 | if (dri2_renderer_query_integer(dri2_dpy, |
| 945 | __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB)) |
| 946 | disp->Extensions.KHR_gl_colorspace = EGL_TRUE; |
| 947 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 948 | if (dri2_dpy->image_driver || |
| 949 | (dri2_dpy->dri2 && dri2_dpy->dri2->base.version >= 3) || |
Boyan Ding | 63c4b7e | 2015-07-21 23:43:58 +0800 | [diff] [blame] | 950 | (dri2_dpy->swrast && dri2_dpy->swrast->base.version >= 3)) { |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 951 | disp->Extensions.KHR_create_context = EGL_TRUE; |
| 952 | |
| 953 | if (dri2_dpy->robustness) |
| 954 | disp->Extensions.EXT_create_context_robustness = EGL_TRUE; |
| 955 | } |
| 956 | |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 957 | if (dri2_dpy->no_error) |
| 958 | disp->Extensions.KHR_create_context_no_error = EGL_TRUE; |
| 959 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 960 | if (dri2_dpy->fence) { |
| 961 | disp->Extensions.KHR_fence_sync = EGL_TRUE; |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 962 | disp->Extensions.KHR_wait_sync = EGL_TRUE; |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 963 | if (dri2_dpy->fence->get_fence_from_cl_event) |
| 964 | disp->Extensions.KHR_cl_event2 = EGL_TRUE; |
Emil Velikov | f0d053c | 2017-08-07 17:23:19 +0100 | [diff] [blame] | 965 | if (dri2_dpy->fence->base.version >= 2 && |
| 966 | dri2_dpy->fence->get_capabilities) { |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 967 | unsigned capabilities = |
| 968 | dri2_dpy->fence->get_capabilities(dri2_dpy->dri_screen); |
| 969 | disp->Extensions.ANDROID_native_fence_sync = |
| 970 | (capabilities & __DRI_FENCE_CAP_NATIVE_FD) != 0; |
| 971 | } |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 972 | } |
| 973 | |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 974 | if (dri2_dpy->blob) |
| 975 | disp->Extensions.ANDROID_blob_cache = EGL_TRUE; |
| 976 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 977 | disp->Extensions.KHR_reusable_sync = EGL_TRUE; |
| 978 | |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 979 | if (dri2_dpy->image) { |
Giovanni Campagna | e57ad3d | 2014-07-23 19:28:52 +0100 | [diff] [blame] | 980 | if (dri2_dpy->image->base.version >= 10 && |
| 981 | dri2_dpy->image->getCapabilities != NULL) { |
| 982 | int capabilities; |
| 983 | |
| 984 | capabilities = dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen); |
| 985 | disp->Extensions.MESA_drm_image = (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 986 | |
| 987 | if (dri2_dpy->image->base.version >= 11) |
| 988 | disp->Extensions.MESA_image_dma_buf_export = EGL_TRUE; |
| 989 | } else { |
Giovanni Campagna | e57ad3d | 2014-07-23 19:28:52 +0100 | [diff] [blame] | 990 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 991 | if (dri2_dpy->image->base.version >= 11) |
| 992 | disp->Extensions.MESA_image_dma_buf_export = EGL_TRUE; |
| 993 | } |
Giovanni Campagna | e57ad3d | 2014-07-23 19:28:52 +0100 | [diff] [blame] | 994 | |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 995 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 996 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 997 | if (dri2_dpy->image->base.version >= 5 && |
| 998 | dri2_dpy->image->createImageFromTexture) { |
| 999 | disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; |
| 1000 | disp->Extensions.KHR_gl_texture_cubemap_image = EGL_TRUE; |
Emil Velikov | 4506a74 | 2017-06-28 16:41:30 +0100 | [diff] [blame] | 1001 | |
| 1002 | if (dri2_renderer_query_integer(dri2_dpy, |
| 1003 | __DRI2_RENDERER_HAS_TEXTURE_3D)) |
| 1004 | disp->Extensions.KHR_gl_texture_3D_image = EGL_TRUE; |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 1005 | } |
Axel Davy | 63986f9 | 2015-01-14 20:36:04 +0100 | [diff] [blame] | 1006 | #ifdef HAVE_LIBDRM |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 1007 | if (dri2_dpy->image->base.version >= 8 && |
| 1008 | dri2_dpy->image->createImageFromDmaBufs) { |
| 1009 | disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE; |
Varad Gautam | 4c41229 | 2017-05-30 17:23:40 +0530 | [diff] [blame] | 1010 | disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE; |
| 1011 | } |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 1012 | #endif |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 1013 | } |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 1014 | |
| 1015 | if (dri2_dpy->flush_control) |
| 1016 | disp->Extensions.KHR_context_flush_control = EGL_TRUE; |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 1017 | |
| 1018 | if (dri2_dpy->buffer_damage && dri2_dpy->buffer_damage->set_damage_region) |
| 1019 | disp->Extensions.KHR_partial_update = EGL_TRUE; |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
Emil Velikov | 47b06f5 | 2017-08-05 00:25:46 +0100 | [diff] [blame] | 1022 | void |
| 1023 | dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval) |
| 1024 | { |
| 1025 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1026 | GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; |
| 1027 | |
| 1028 | /* Allow driconf to override applications.*/ |
| 1029 | if (dri2_dpy->config) |
| 1030 | dri2_dpy->config->configQueryi(dri2_dpy->dri_screen, |
| 1031 | "vblank_mode", &vblank_mode); |
| 1032 | switch (vblank_mode) { |
| 1033 | case DRI_CONF_VBLANK_NEVER: |
| 1034 | dri2_dpy->min_swap_interval = 0; |
| 1035 | dri2_dpy->max_swap_interval = 0; |
| 1036 | dri2_dpy->default_swap_interval = 0; |
| 1037 | break; |
| 1038 | case DRI_CONF_VBLANK_ALWAYS_SYNC: |
| 1039 | dri2_dpy->min_swap_interval = 1; |
| 1040 | dri2_dpy->max_swap_interval = max_swap_interval; |
| 1041 | dri2_dpy->default_swap_interval = 1; |
| 1042 | break; |
| 1043 | case DRI_CONF_VBLANK_DEF_INTERVAL_0: |
| 1044 | dri2_dpy->min_swap_interval = 0; |
| 1045 | dri2_dpy->max_swap_interval = max_swap_interval; |
| 1046 | dri2_dpy->default_swap_interval = 0; |
| 1047 | break; |
| 1048 | default: |
| 1049 | case DRI_CONF_VBLANK_DEF_INTERVAL_1: |
| 1050 | dri2_dpy->min_swap_interval = 0; |
| 1051 | dri2_dpy->max_swap_interval = max_swap_interval; |
| 1052 | dri2_dpy->default_swap_interval = 1; |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1057 | /* All platforms but DRM call this function to create the screen and populate |
| 1058 | * the driver_configs. DRM inherits that information from its display - GBM. |
Emil Velikov | 8ed08e6 | 2014-11-07 03:42:15 +0000 | [diff] [blame] | 1059 | */ |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1060 | EGLBoolean |
| 1061 | dri2_create_screen(_EGLDisplay *disp) |
| 1062 | { |
Emil Velikov | 532ec2e | 2016-07-15 12:47:37 +0100 | [diff] [blame] | 1063 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1064 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 1065 | if (dri2_dpy->image_driver) { |
| 1066 | dri2_dpy->dri_screen = |
| 1067 | dri2_dpy->image_driver->createNewScreen2(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1068 | dri2_dpy->loader_extensions, |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 1069 | dri2_dpy->driver_extensions, |
| 1070 | &dri2_dpy->driver_configs, |
| 1071 | disp); |
| 1072 | } else if (dri2_dpy->dri2) { |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1073 | if (dri2_dpy->dri2->base.version >= 4) { |
| 1074 | dri2_dpy->dri_screen = |
| 1075 | dri2_dpy->dri2->createNewScreen2(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1076 | dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1077 | dri2_dpy->driver_extensions, |
| 1078 | &dri2_dpy->driver_configs, disp); |
| 1079 | } else { |
| 1080 | dri2_dpy->dri_screen = |
| 1081 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1082 | dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1083 | &dri2_dpy->driver_configs, disp); |
| 1084 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1085 | } else { |
| 1086 | assert(dri2_dpy->swrast); |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1087 | if (dri2_dpy->swrast->base.version >= 4) { |
| 1088 | dri2_dpy->dri_screen = |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1089 | dri2_dpy->swrast->createNewScreen2(0, dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1090 | dri2_dpy->driver_extensions, |
| 1091 | &dri2_dpy->driver_configs, disp); |
| 1092 | } else { |
| 1093 | dri2_dpy->dri_screen = |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1094 | dri2_dpy->swrast->createNewScreen(0, dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 1095 | &dri2_dpy->driver_configs, disp); |
| 1096 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | if (dri2_dpy->dri_screen == NULL) { |
| 1100 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
| 1101 | return EGL_FALSE; |
| 1102 | } |
| 1103 | |
Eric Engestrom | 60f9842 | 2017-06-19 00:16:21 +0100 | [diff] [blame] | 1104 | dri2_dpy->own_dri_screen = true; |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1105 | return EGL_TRUE; |
| 1106 | } |
| 1107 | |
| 1108 | EGLBoolean |
| 1109 | dri2_setup_extensions(_EGLDisplay *disp) |
| 1110 | { |
| 1111 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1112 | const struct dri2_extension_match *mandatory_core_extensions; |
| 1113 | const __DRIextension **extensions; |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 1114 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1115 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 1116 | |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1117 | if (dri2_dpy->image_driver || dri2_dpy->dri2) |
| 1118 | mandatory_core_extensions = dri2_core_extensions; |
| 1119 | else |
| 1120 | mandatory_core_extensions = swrast_core_extensions; |
| 1121 | |
| 1122 | if (!dri2_bind_extensions(dri2_dpy, mandatory_core_extensions, extensions, false)) |
| 1123 | return EGL_FALSE; |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 1124 | |
Daniel Stone | 478fc2d | 2018-03-19 15:03:22 +0000 | [diff] [blame] | 1125 | #ifdef HAVE_DRI3_MODIFIERS |
Louis-Francis Ratté-Boulianne | 069fdd5 | 2017-07-07 02:54:26 -0400 | [diff] [blame] | 1126 | dri2_dpy->multibuffers_available = |
| 1127 | (dri2_dpy->dri3_major_version > 1 || (dri2_dpy->dri3_major_version == 1 && |
| 1128 | dri2_dpy->dri3_minor_version >= 2)) && |
Louis-Francis Ratté-Boulianne | 3160cb8 | 2017-10-06 01:26:51 -0400 | [diff] [blame] | 1129 | (dri2_dpy->present_major_version > 1 || (dri2_dpy->present_major_version == 1 && |
| 1130 | dri2_dpy->present_minor_version >= 2)) && |
Louis-Francis Ratté-Boulianne | 069fdd5 | 2017-07-07 02:54:26 -0400 | [diff] [blame] | 1131 | (dri2_dpy->image && dri2_dpy->image->base.version >= 15); |
| 1132 | #endif |
| 1133 | |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 1134 | dri2_bind_extensions(dri2_dpy, optional_core_extensions, extensions, true); |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1135 | return EGL_TRUE; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1138 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1139 | * Called via eglInitialize(), drv->Initialize(). |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1140 | * |
| 1141 | * This must be guaranteed to be called exactly once, even if eglInitialize is |
| 1142 | * called many times (without a eglTerminate in between). |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1143 | */ |
| 1144 | static EGLBoolean |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1145 | dri2_initialize(_EGLDisplay *disp) |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1146 | { |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1147 | EGLBoolean ret = EGL_FALSE; |
| 1148 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1149 | |
| 1150 | /* In the case where the application calls eglMakeCurrent(context1), |
| 1151 | * eglTerminate, then eglInitialize again (without a call to eglReleaseThread |
| 1152 | * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still |
| 1153 | * initialized, as we need it to be able to free context1 correctly. |
| 1154 | * |
| 1155 | * It would probably be safest to forcibly release the display with |
| 1156 | * dri2_display_release, to make sure the display is reinitialized correctly. |
| 1157 | * However, the EGL spec states that we need to keep a reference to the |
| 1158 | * current context (so we cannot call dri2_make_current(NULL)), and therefore |
| 1159 | * we would leak context1 as we would be missing the old display connection |
| 1160 | * to free it up correctly. |
| 1161 | */ |
| 1162 | if (dri2_dpy) { |
| 1163 | dri2_dpy->ref_count++; |
| 1164 | return EGL_TRUE; |
| 1165 | } |
| 1166 | |
Eric Anholt | 2bc1f5c | 2018-11-15 14:47:30 -0800 | [diff] [blame] | 1167 | loader_set_logger(_eglLog); |
| 1168 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1169 | switch (disp->Platform) { |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 1170 | case _EGL_PLATFORM_SURFACELESS: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1171 | ret = dri2_initialize_surfaceless(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1172 | break; |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 1173 | case _EGL_PLATFORM_DEVICE: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1174 | ret = dri2_initialize_device(disp); |
Emil Velikov | d6edcce | 2019-05-16 18:01:40 +0100 | [diff] [blame] | 1175 | break; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1176 | case _EGL_PLATFORM_X11: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1177 | ret = dri2_initialize_x11(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1178 | break; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1179 | case _EGL_PLATFORM_DRM: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1180 | ret = dri2_initialize_drm(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1181 | break; |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 1182 | case _EGL_PLATFORM_WAYLAND: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1183 | ret = dri2_initialize_wayland(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1184 | break; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1185 | case _EGL_PLATFORM_ANDROID: |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1186 | ret = dri2_initialize_android(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1187 | break; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1188 | default: |
Emil Velikov | 55245fe | 2017-11-09 17:55:19 +0000 | [diff] [blame] | 1189 | unreachable("Callers ensure we cannot get here."); |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1190 | return EGL_FALSE; |
| 1191 | } |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1192 | |
Emil Velikov | 2f76dff | 2017-08-27 11:20:26 +0100 | [diff] [blame] | 1193 | if (!ret) |
| 1194 | return EGL_FALSE; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1195 | |
Emil Velikov | 2f76dff | 2017-08-27 11:20:26 +0100 | [diff] [blame] | 1196 | dri2_dpy = dri2_egl_display(disp); |
| 1197 | dri2_dpy->ref_count++; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1198 | |
Emil Velikov | 2f76dff | 2017-08-27 11:20:26 +0100 | [diff] [blame] | 1199 | return EGL_TRUE; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1202 | /** |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1203 | * Decrement display reference count, and free up display if necessary. |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1204 | */ |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1205 | static void |
Emil Velikov | 02f1158 | 2016-08-16 11:03:33 +0100 | [diff] [blame] | 1206 | dri2_display_release(_EGLDisplay *disp) |
| 1207 | { |
Emil Velikov | d6dcf3b | 2016-08-18 16:43:36 +0100 | [diff] [blame] | 1208 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1209 | |
Emil Velikov | d6dcf3b | 2016-08-18 16:43:36 +0100 | [diff] [blame] | 1210 | if (!disp) |
| 1211 | return; |
| 1212 | |
| 1213 | dri2_dpy = dri2_egl_display(disp); |
| 1214 | |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1215 | assert(dri2_dpy->ref_count > 0); |
| 1216 | dri2_dpy->ref_count--; |
| 1217 | |
| 1218 | if (dri2_dpy->ref_count > 0) |
| 1219 | return; |
| 1220 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1221 | _eglCleanupDisplay(disp); |
Emil Velikov | 3e73c02 | 2017-05-11 17:13:33 +0100 | [diff] [blame] | 1222 | dri2_display_destroy(disp); |
| 1223 | } |
| 1224 | |
| 1225 | void |
| 1226 | dri2_display_destroy(_EGLDisplay *disp) |
| 1227 | { |
| 1228 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1229 | |
Thomas Hellstrom | 2db9548 | 2017-08-10 15:35:39 +0200 | [diff] [blame] | 1230 | if (dri2_dpy->own_dri_screen) { |
Frank Binns | 6160bf9 | 2018-02-22 13:37:54 +0000 | [diff] [blame] | 1231 | if (dri2_dpy->vtbl && dri2_dpy->vtbl->close_screen_notify) |
Thomas Hellstrom | 2db9548 | 2017-08-10 15:35:39 +0200 | [diff] [blame] | 1232 | dri2_dpy->vtbl->close_screen_notify(disp); |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 1233 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Thomas Hellstrom | 2db9548 | 2017-08-10 15:35:39 +0200 | [diff] [blame] | 1234 | } |
Emil Velikov | a1ac742 | 2015-09-10 14:41:38 +0100 | [diff] [blame] | 1235 | if (dri2_dpy->fd >= 0) |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 1236 | close(dri2_dpy->fd); |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 1237 | if (dri2_dpy->driver) |
| 1238 | dlclose(dri2_dpy->driver); |
Emil Velikov | 5cb1cad | 2014-06-02 12:26:17 +0100 | [diff] [blame] | 1239 | free(dri2_dpy->driver_name); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 1240 | |
Frank Binns | d6f669b | 2016-06-17 18:41:22 +0100 | [diff] [blame] | 1241 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1242 | free(dri2_dpy->device_name); |
| 1243 | #endif |
| 1244 | |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1245 | switch (disp->Platform) { |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1246 | case _EGL_PLATFORM_X11: |
Emil Velikov | 938fcab | 2017-11-09 18:58:52 +0000 | [diff] [blame] | 1247 | dri2_teardown_x11(dri2_dpy); |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1248 | break; |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1249 | case _EGL_PLATFORM_DRM: |
Emil Velikov | 9b02230 | 2017-11-16 18:33:22 +0000 | [diff] [blame] | 1250 | dri2_teardown_drm(dri2_dpy); |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1251 | break; |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1252 | case _EGL_PLATFORM_WAYLAND: |
Emil Velikov | 9b02230 | 2017-11-16 18:33:22 +0000 | [diff] [blame] | 1253 | dri2_teardown_wayland(dri2_dpy); |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1254 | break; |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1255 | default: |
Emil Velikov | 6614804 | 2017-11-13 14:02:56 +0000 | [diff] [blame] | 1256 | /* TODO: add teardown for other platforms */ |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 1257 | break; |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 1258 | } |
| 1259 | |
Emil Velikov | 38cec03 | 2014-11-07 03:33:56 +0000 | [diff] [blame] | 1260 | /* The drm platform does not create the screen/driver_configs but reuses |
| 1261 | * the ones from the gbm device. As such the gbm itself is responsible |
| 1262 | * for the cleanup. |
| 1263 | */ |
Tapani Pälli | 12196d1 | 2017-05-12 12:18:32 +0300 | [diff] [blame] | 1264 | if (disp->Platform != _EGL_PLATFORM_DRM && dri2_dpy->driver_configs) { |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1265 | for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) |
Emil Velikov | 38cec03 | 2014-11-07 03:33:56 +0000 | [diff] [blame] | 1266 | free((__DRIconfig *) dri2_dpy->driver_configs[i]); |
| 1267 | free(dri2_dpy->driver_configs); |
| 1268 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1269 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1270 | disp->DriverData = NULL; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1271 | } |
| 1272 | |
Gwan-gyeong Mun | 640b6e6 | 2017-08-05 00:16:11 +0900 | [diff] [blame] | 1273 | __DRIbuffer * |
| 1274 | dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf, |
| 1275 | unsigned int att, unsigned int format) |
| 1276 | { |
| 1277 | struct dri2_egl_display *dri2_dpy = |
| 1278 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 1279 | |
| 1280 | if (att >= ARRAY_SIZE(dri2_surf->local_buffers)) |
| 1281 | return NULL; |
| 1282 | |
| 1283 | if (!dri2_surf->local_buffers[att]) { |
| 1284 | dri2_surf->local_buffers[att] = |
| 1285 | dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format, |
| 1286 | dri2_surf->base.Width, dri2_surf->base.Height); |
| 1287 | } |
| 1288 | |
| 1289 | return dri2_surf->local_buffers[att]; |
| 1290 | } |
| 1291 | |
| 1292 | void |
| 1293 | dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf) |
| 1294 | { |
| 1295 | struct dri2_egl_display *dri2_dpy = |
| 1296 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 1297 | |
| 1298 | for (int i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) { |
| 1299 | if (dri2_surf->local_buffers[i]) { |
| 1300 | dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen, |
| 1301 | dri2_surf->local_buffers[i]); |
| 1302 | dri2_surf->local_buffers[i] = NULL; |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1307 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1308 | * Called via eglTerminate(), drv->Terminate(). |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1309 | * |
| 1310 | * This must be guaranteed to be called exactly once, even if eglTerminate is |
| 1311 | * called many times (without a eglInitialize in between). |
| 1312 | */ |
| 1313 | static EGLBoolean |
Eric Engestrom | 435ad51 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1314 | dri2_terminate(_EGLDisplay *disp) |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1315 | { |
| 1316 | /* Release all non-current Context/Surfaces. */ |
Eric Engestrom | 485f8f8 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1317 | _eglReleaseDisplayResources(disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1318 | |
| 1319 | dri2_display_release(disp); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1320 | |
| 1321 | return EGL_TRUE; |
| 1322 | } |
| 1323 | |
Chad Versace | 5cf8536 | 2012-11-09 14:06:41 -0800 | [diff] [blame] | 1324 | /** |
| 1325 | * Set the error code after a call to |
| 1326 | * dri2_egl_display::dri2::createContextAttribs. |
| 1327 | */ |
| 1328 | static void |
| 1329 | dri2_create_context_attribs_error(int dri_error) |
| 1330 | { |
| 1331 | EGLint egl_error; |
| 1332 | |
| 1333 | switch (dri_error) { |
| 1334 | case __DRI_CTX_ERROR_SUCCESS: |
| 1335 | return; |
| 1336 | |
| 1337 | case __DRI_CTX_ERROR_NO_MEMORY: |
| 1338 | egl_error = EGL_BAD_ALLOC; |
| 1339 | break; |
| 1340 | |
| 1341 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 1342 | * |
| 1343 | * * If <config> does not support a client API context compatible |
| 1344 | * with the requested API major and minor version, [...] context flags, |
| 1345 | * and context reset notification behavior (for client API types where |
| 1346 | * these attributes are supported), then an EGL_BAD_MATCH error is |
| 1347 | * generated. |
| 1348 | * |
| 1349 | * * If an OpenGL ES context is requested and the values for |
| 1350 | * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 1351 | * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that |
| 1352 | * is not defined, than an EGL_BAD_MATCH error is generated. |
| 1353 | * |
| 1354 | * * If an OpenGL context is requested, the requested version is |
| 1355 | * greater than 3.2, and the value for attribute |
| 1356 | * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any |
| 1357 | * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and |
| 1358 | * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than |
| 1359 | * one of these bits set; or if the implementation does not support |
| 1360 | * the requested profile, then an EGL_BAD_MATCH error is generated. |
| 1361 | */ |
| 1362 | case __DRI_CTX_ERROR_BAD_API: |
| 1363 | case __DRI_CTX_ERROR_BAD_VERSION: |
| 1364 | case __DRI_CTX_ERROR_BAD_FLAG: |
| 1365 | egl_error = EGL_BAD_MATCH; |
| 1366 | break; |
| 1367 | |
| 1368 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 1369 | * |
| 1370 | * * If an attribute name or attribute value in <attrib_list> is not |
| 1371 | * recognized (including unrecognized bits in bitmask attributes), |
| 1372 | * then an EGL_BAD_ATTRIBUTE error is generated." |
| 1373 | */ |
| 1374 | case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE: |
| 1375 | case __DRI_CTX_ERROR_UNKNOWN_FLAG: |
| 1376 | egl_error = EGL_BAD_ATTRIBUTE; |
| 1377 | break; |
| 1378 | |
| 1379 | default: |
Eric Engestrom | ea738a9 | 2018-10-28 18:20:20 +0000 | [diff] [blame] | 1380 | assert(!"unknown dri_error code"); |
Chad Versace | 5cf8536 | 2012-11-09 14:06:41 -0800 | [diff] [blame] | 1381 | egl_error = EGL_BAD_MATCH; |
| 1382 | break; |
| 1383 | } |
| 1384 | |
| 1385 | _eglError(egl_error, "dri2_create_context"); |
| 1386 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1387 | |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1388 | static bool |
| 1389 | dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx, |
| 1390 | struct dri2_egl_display *dri2_dpy, |
| 1391 | uint32_t *ctx_attribs, |
| 1392 | unsigned *num_attribs) |
| 1393 | { |
| 1394 | int pos = 0; |
| 1395 | |
Chris Wilson | 5c56183 | 2016-10-27 19:54:49 +0100 | [diff] [blame] | 1396 | assert(*num_attribs >= NUM_ATTRIBS); |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1397 | |
| 1398 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MAJOR_VERSION; |
| 1399 | ctx_attribs[pos++] = dri2_ctx->base.ClientMajorVersion; |
| 1400 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MINOR_VERSION; |
| 1401 | ctx_attribs[pos++] = dri2_ctx->base.ClientMinorVersion; |
| 1402 | |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 1403 | if (dri2_ctx->base.Flags != 0 || dri2_ctx->base.NoError) { |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1404 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 1405 | * extension, don't even try to send it the robust-access flag. |
| 1406 | * It may explode. Instead, generate the required EGL error here. |
| 1407 | */ |
| 1408 | if ((dri2_ctx->base.Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0 |
| 1409 | && !dri2_dpy->robustness) { |
| 1410 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 1411 | return false; |
| 1412 | } |
| 1413 | |
| 1414 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_FLAGS; |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 1415 | ctx_attribs[pos++] = dri2_ctx->base.Flags | |
Kenneth Graunke | c7af6d2 | 2017-07-14 14:26:42 -0700 | [diff] [blame] | 1416 | (dri2_ctx->base.NoError ? __DRI_CTX_FLAG_NO_ERROR : 0); |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) { |
| 1420 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 1421 | * extension, don't even try to send it a reset strategy. It may |
| 1422 | * explode. Instead, generate the required EGL error here. |
| 1423 | */ |
| 1424 | if (!dri2_dpy->robustness) { |
| 1425 | _eglError(EGL_BAD_CONFIG, "eglCreateContext"); |
| 1426 | return false; |
| 1427 | } |
| 1428 | |
| 1429 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RESET_STRATEGY; |
| 1430 | ctx_attribs[pos++] = __DRI_CTX_RESET_LOSE_CONTEXT; |
| 1431 | } |
| 1432 | |
Chris Wilson | 5c56183 | 2016-10-27 19:54:49 +0100 | [diff] [blame] | 1433 | if (dri2_ctx->base.ContextPriority != EGL_CONTEXT_PRIORITY_MEDIUM_IMG) { |
| 1434 | unsigned val; |
| 1435 | |
| 1436 | switch (dri2_ctx->base.ContextPriority) { |
| 1437 | case EGL_CONTEXT_PRIORITY_HIGH_IMG: |
| 1438 | val = __DRI_CTX_PRIORITY_HIGH; |
| 1439 | break; |
| 1440 | case EGL_CONTEXT_PRIORITY_MEDIUM_IMG: |
| 1441 | val = __DRI_CTX_PRIORITY_MEDIUM; |
| 1442 | break; |
| 1443 | case EGL_CONTEXT_PRIORITY_LOW_IMG: |
| 1444 | val = __DRI_CTX_PRIORITY_LOW; |
| 1445 | break; |
| 1446 | default: |
| 1447 | _eglError(EGL_BAD_CONFIG, "eglCreateContext"); |
| 1448 | return false; |
| 1449 | } |
| 1450 | |
| 1451 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PRIORITY; |
| 1452 | ctx_attribs[pos++] = val; |
| 1453 | } |
| 1454 | |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 1455 | if (dri2_ctx->base.ReleaseBehavior == EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR) { |
| 1456 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR; |
| 1457 | ctx_attribs[pos++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE; |
| 1458 | } |
| 1459 | |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1460 | *num_attribs = pos; |
| 1461 | |
| 1462 | return true; |
| 1463 | } |
| 1464 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1465 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1466 | * Called via eglCreateContext(), drv->CreateContext(). |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1467 | */ |
| 1468 | static _EGLContext * |
Eric Engestrom | f27a32a | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1469 | dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1470 | _EGLContext *share_list, const EGLint *attrib_list) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1471 | { |
| 1472 | struct dri2_egl_context *dri2_ctx; |
| 1473 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1474 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 1475 | __DRIcontext *shared = |
| 1476 | dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1477 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1478 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1479 | int api; |
Adam Jackson | 9ef7158 | 2016-09-22 03:38:01 -0400 | [diff] [blame] | 1480 | unsigned error; |
| 1481 | unsigned num_attribs = NUM_ATTRIBS; |
| 1482 | uint32_t ctx_attribs[NUM_ATTRIBS]; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1483 | |
| 1484 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 1485 | if (!dri2_ctx) { |
| 1486 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 1487 | return NULL; |
| 1488 | } |
| 1489 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1490 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 1491 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1492 | |
Kenneth Graunke | 4061bbc | 2017-02-28 17:20:52 -0800 | [diff] [blame] | 1493 | /* The EGL_EXT_create_context_robustness spec says: |
| 1494 | * |
| 1495 | * "Add to the eglCreateContext context creation errors: [...] |
| 1496 | * |
| 1497 | * * If the reset notification behavior of <share_context> and the |
| 1498 | * newly created context are different then an EGL_BAD_MATCH error is |
| 1499 | * generated." |
| 1500 | */ |
| 1501 | if (share_list && share_list->ResetNotificationStrategy != |
| 1502 | dri2_ctx->base.ResetNotificationStrategy) { |
| 1503 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 1504 | goto cleanup; |
| 1505 | } |
| 1506 | |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 1507 | /* The EGL_KHR_create_context_no_error spec says: |
| 1508 | * |
| 1509 | * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR |
| 1510 | * used to create <share_context> does not match the value of |
| 1511 | * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created." |
| 1512 | */ |
| 1513 | if (share_list && share_list->NoError != dri2_ctx->base.NoError) { |
| 1514 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 1515 | goto cleanup; |
| 1516 | } |
| 1517 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1518 | switch (dri2_ctx->base.ClientAPI) { |
| 1519 | case EGL_OPENGL_ES_API: |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 1520 | switch (dri2_ctx->base.ClientMajorVersion) { |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1521 | case 1: |
| 1522 | api = __DRI_API_GLES; |
| 1523 | break; |
| 1524 | case 2: |
Ian Romanick | d786bf2 | 2013-01-15 14:17:46 -0800 | [diff] [blame] | 1525 | api = __DRI_API_GLES2; |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 1526 | break; |
Ian Romanick | dbecb41 | 2012-07-19 16:12:13 -0700 | [diff] [blame] | 1527 | case 3: |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 1528 | api = __DRI_API_GLES3; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1529 | break; |
| 1530 | default: |
Emil Velikov | a3e78ba | 2014-05-08 16:49:45 +0100 | [diff] [blame] | 1531 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 1532 | free(dri2_ctx); |
| 1533 | return NULL; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1534 | } |
| 1535 | break; |
| 1536 | case EGL_OPENGL_API: |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1537 | if ((dri2_ctx->base.ClientMajorVersion >= 4 |
| 1538 | || (dri2_ctx->base.ClientMajorVersion == 3 |
| 1539 | && dri2_ctx->base.ClientMinorVersion >= 2)) |
| 1540 | && dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) |
| 1541 | api = __DRI_API_OPENGL_CORE; |
Timothy Arceri | 74f96b0 | 2019-08-02 11:38:45 +1000 | [diff] [blame] | 1542 | else if (dri2_ctx->base.ClientMajorVersion == 3 && |
| 1543 | dri2_ctx->base.ClientMinorVersion == 1) |
| 1544 | api = __DRI_API_OPENGL_CORE; |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1545 | else |
| 1546 | api = __DRI_API_OPENGL; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1547 | break; |
| 1548 | default: |
| 1549 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
Vinson Lee | 080e91a | 2013-01-31 23:41:14 -0800 | [diff] [blame] | 1550 | free(dri2_ctx); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1551 | return NULL; |
| 1552 | } |
| 1553 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1554 | if (conf != NULL) { |
| 1555 | /* The config chosen here isn't necessarily |
| 1556 | * used for surfaces later. |
| 1557 | * A pixmap surface will use the single config. |
| 1558 | * This opportunity depends on disabling the |
| 1559 | * doubleBufferMode check in |
| 1560 | * src/mesa/main/context.c:check_compatible() |
| 1561 | */ |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 1562 | if (dri2_config->dri_config[1][0]) |
| 1563 | dri_config = dri2_config->dri_config[1][0]; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1564 | else |
Eric Engestrom | b81cfc7 | 2017-06-21 10:40:31 +0100 | [diff] [blame] | 1565 | dri_config = dri2_config->dri_config[0][0]; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1566 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1567 | else |
| 1568 | dri_config = NULL; |
| 1569 | |
Adam Jackson | 9ef7158 | 2016-09-22 03:38:01 -0400 | [diff] [blame] | 1570 | if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs, |
| 1571 | &num_attribs)) |
| 1572 | goto cleanup; |
| 1573 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 1574 | if (dri2_dpy->image_driver) { |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 1575 | dri2_ctx->dri_context = |
| 1576 | dri2_dpy->image_driver->createContextAttribs(dri2_dpy->dri_screen, |
| 1577 | api, |
| 1578 | dri_config, |
| 1579 | shared, |
| 1580 | num_attribs / 2, |
| 1581 | ctx_attribs, |
| 1582 | & error, |
| 1583 | dri2_ctx); |
| 1584 | dri2_create_context_attribs_error(error); |
| 1585 | } else if (dri2_dpy->dri2) { |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1586 | if (dri2_dpy->dri2->base.version >= 3) { |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1587 | dri2_ctx->dri_context = |
| 1588 | dri2_dpy->dri2->createContextAttribs(dri2_dpy->dri_screen, |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1589 | api, |
| 1590 | dri_config, |
| 1591 | shared, |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1592 | num_attribs / 2, |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1593 | ctx_attribs, |
| 1594 | & error, |
| 1595 | dri2_ctx); |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1596 | dri2_create_context_attribs_error(error); |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1597 | } else { |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1598 | dri2_ctx->dri_context = |
| 1599 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 1600 | api, |
| 1601 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 1602 | shared, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1603 | dri2_ctx); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 1604 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1605 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 1606 | assert(dri2_dpy->swrast); |
Boyan Ding | 6345d2d | 2015-07-21 23:43:57 +0800 | [diff] [blame] | 1607 | if (dri2_dpy->swrast->base.version >= 3) { |
Boyan Ding | 6345d2d | 2015-07-21 23:43:57 +0800 | [diff] [blame] | 1608 | dri2_ctx->dri_context = |
| 1609 | dri2_dpy->swrast->createContextAttribs(dri2_dpy->dri_screen, |
| 1610 | api, |
| 1611 | dri_config, |
| 1612 | shared, |
| 1613 | num_attribs / 2, |
| 1614 | ctx_attribs, |
| 1615 | & error, |
| 1616 | dri2_ctx); |
| 1617 | dri2_create_context_attribs_error(error); |
| 1618 | } else { |
| 1619 | dri2_ctx->dri_context = |
| 1620 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 1621 | api, |
| 1622 | dri_config, |
| 1623 | shared, |
| 1624 | dri2_ctx); |
| 1625 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1626 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1627 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1628 | if (!dri2_ctx->dri_context) |
| 1629 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1630 | |
| 1631 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1632 | |
| 1633 | cleanup: |
| 1634 | free(dri2_ctx); |
| 1635 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1636 | } |
| 1637 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1638 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1639 | * Called via eglDestroyContext(), drv->DestroyContext(). |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1640 | */ |
| 1641 | static EGLBoolean |
Eric Engestrom | f27a32a | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1642 | dri2_destroy_context(_EGLDisplay *disp, _EGLContext *ctx) |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1643 | { |
| 1644 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1645 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1646 | |
| 1647 | if (_eglPutContext(ctx)) { |
| 1648 | dri2_dpy->core->destroyContext(dri2_ctx->dri_context); |
| 1649 | free(dri2_ctx); |
| 1650 | } |
| 1651 | |
| 1652 | return EGL_TRUE; |
| 1653 | } |
| 1654 | |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1655 | EGLBoolean |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1656 | dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, |
Paulo Zanoni | 04ecda3 | 2019-05-01 15:42:26 -0700 | [diff] [blame] | 1657 | _EGLConfig *conf, const EGLint *attrib_list, |
| 1658 | EGLBoolean enable_out_fence, void *native_surface) |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1659 | { |
| 1660 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1661 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1662 | |
| 1663 | dri2_surf->out_fence_fd = -1; |
| 1664 | dri2_surf->enable_out_fence = false; |
| 1665 | if (dri2_dpy->fence && dri2_dpy->fence->base.version >= 2 && |
| 1666 | dri2_dpy->fence->get_capabilities && |
| 1667 | (dri2_dpy->fence->get_capabilities(dri2_dpy->dri_screen) & |
| 1668 | __DRI_FENCE_CAP_NATIVE_FD)) { |
| 1669 | dri2_surf->enable_out_fence = enable_out_fence; |
| 1670 | } |
| 1671 | |
Paulo Zanoni | 04ecda3 | 2019-05-01 15:42:26 -0700 | [diff] [blame] | 1672 | return _eglInitSurface(surf, disp, type, conf, attrib_list, native_surface); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | static void |
| 1676 | dri2_surface_set_out_fence_fd( _EGLSurface *surf, int fence_fd) |
| 1677 | { |
| 1678 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1679 | |
| 1680 | if (dri2_surf->out_fence_fd >= 0) |
| 1681 | close(dri2_surf->out_fence_fd); |
| 1682 | |
| 1683 | dri2_surf->out_fence_fd = fence_fd; |
| 1684 | } |
| 1685 | |
| 1686 | void |
| 1687 | dri2_fini_surface(_EGLSurface *surf) |
| 1688 | { |
| 1689 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1690 | |
| 1691 | dri2_surface_set_out_fence_fd(surf, -1); |
| 1692 | dri2_surf->enable_out_fence = false; |
| 1693 | } |
| 1694 | |
Emil Velikov | 8cf83f9 | 2016-08-18 16:33:39 +0100 | [diff] [blame] | 1695 | static EGLBoolean |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1696 | dri2_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) |
Emil Velikov | 8cf83f9 | 2016-08-18 16:33:39 +0100 | [diff] [blame] | 1697 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1698 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Emil Velikov | 8cf83f9 | 2016-08-18 16:33:39 +0100 | [diff] [blame] | 1699 | |
| 1700 | if (!_eglPutSurface(surf)) |
| 1701 | return EGL_TRUE; |
| 1702 | |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1703 | return dri2_dpy->vtbl->destroy_surface(disp, surf); |
Emil Velikov | 8cf83f9 | 2016-08-18 16:33:39 +0100 | [diff] [blame] | 1704 | } |
| 1705 | |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1706 | static void |
| 1707 | dri2_surf_update_fence_fd(_EGLContext *ctx, |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1708 | _EGLDisplay *disp, _EGLSurface *surf) |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1709 | { |
| 1710 | __DRIcontext *dri_ctx = dri2_egl_context(ctx)->dri_context; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1711 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1712 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1713 | int fence_fd = -1; |
| 1714 | void *fence; |
| 1715 | |
| 1716 | if (!dri2_surf->enable_out_fence) |
| 1717 | return; |
| 1718 | |
| 1719 | fence = dri2_dpy->fence->create_fence_fd(dri_ctx, -1); |
| 1720 | if (fence) { |
| 1721 | fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen, |
| 1722 | fence); |
| 1723 | dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence); |
| 1724 | } |
| 1725 | dri2_surface_set_out_fence_fd(surf, fence_fd); |
| 1726 | } |
| 1727 | |
Emil Velikov | 2282ec0 | 2019-05-16 18:01:38 +0100 | [diff] [blame] | 1728 | EGLBoolean |
| 1729 | dri2_create_drawable(struct dri2_egl_display *dri2_dpy, |
| 1730 | const __DRIconfig *config, |
Mathias Fröhlich | a7ecf78 | 2019-06-07 07:12:42 +0200 | [diff] [blame] | 1731 | struct dri2_egl_surface *dri2_surf, |
| 1732 | void *loaderPrivate) |
Emil Velikov | 2282ec0 | 2019-05-16 18:01:38 +0100 | [diff] [blame] | 1733 | { |
| 1734 | __DRIcreateNewDrawableFunc createNewDrawable; |
Emil Velikov | 2282ec0 | 2019-05-16 18:01:38 +0100 | [diff] [blame] | 1735 | |
| 1736 | if (dri2_dpy->image_driver) |
| 1737 | createNewDrawable = dri2_dpy->image_driver->createNewDrawable; |
| 1738 | else if (dri2_dpy->dri2) |
| 1739 | createNewDrawable = dri2_dpy->dri2->createNewDrawable; |
| 1740 | else if (dri2_dpy->swrast) |
| 1741 | createNewDrawable = dri2_dpy->swrast->createNewDrawable; |
| 1742 | else |
| 1743 | return _eglError(EGL_BAD_ALLOC, "no createNewDrawable"); |
| 1744 | |
Eric Engestrom | 1361ab3 | 2018-11-27 12:48:42 +0000 | [diff] [blame] | 1745 | dri2_surf->dri_drawable = createNewDrawable(dri2_dpy->dri_screen, |
| 1746 | config, loaderPrivate); |
Emil Velikov | 2282ec0 | 2019-05-16 18:01:38 +0100 | [diff] [blame] | 1747 | if (dri2_surf->dri_drawable == NULL) |
| 1748 | return _eglError(EGL_BAD_ALLOC, "createNewDrawable"); |
| 1749 | |
| 1750 | return EGL_TRUE; |
| 1751 | } |
| 1752 | |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1753 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1754 | * Called via eglMakeCurrent(), drv->MakeCurrent(). |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1755 | */ |
| 1756 | static EGLBoolean |
Eric Engestrom | 1a17f1d | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1757 | dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1758 | _EGLSurface *rsurf, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1759 | { |
| 1760 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1761 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 1762 | _EGLDisplay *old_disp = NULL; |
| 1763 | struct dri2_egl_display *old_dri2_dpy = NULL; |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1764 | _EGLContext *old_ctx; |
| 1765 | _EGLSurface *old_dsurf, *old_rsurf; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1766 | _EGLSurface *tmp_dsurf, *tmp_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1767 | __DRIdrawable *ddraw, *rdraw; |
| 1768 | __DRIcontext *cctx; |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1769 | EGLint egl_error = EGL_SUCCESS; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1770 | |
| 1771 | if (!dri2_dpy) |
| 1772 | return _eglError(EGL_NOT_INITIALIZED, "eglMakeCurrent"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1773 | |
Luigi Santivetti | 6b12999 | 2020-06-30 10:14:08 +0100 | [diff] [blame] | 1774 | /* make new bindings, set the EGL error otherwise */ |
| 1775 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1776 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1777 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 1778 | if (old_ctx) { |
| 1779 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
Luigi Santivetti | 6b12999 | 2020-06-30 10:14:08 +0100 | [diff] [blame] | 1780 | old_disp = old_ctx->Resource.Display; |
| 1781 | old_dri2_dpy = dri2_egl_display(old_disp); |
| 1782 | |
| 1783 | /* flush before context switch */ |
| 1784 | dri2_gl_flush(); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1785 | |
| 1786 | if (old_dsurf) |
| 1787 | dri2_surf_update_fence_fd(old_ctx, disp, old_dsurf); |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 1788 | |
| 1789 | /* Disable shared buffer mode */ |
| 1790 | if (old_dsurf && _eglSurfaceInSharedBufferMode(old_dsurf) && |
| 1791 | old_dri2_dpy->vtbl->set_shared_buffer_mode) { |
| 1792 | old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, false); |
| 1793 | } |
| 1794 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 1795 | dri2_dpy->core->unbindContext(old_cctx); |
| 1796 | } |
| 1797 | |
Luigi Santivetti | 6b12999 | 2020-06-30 10:14:08 +0100 | [diff] [blame] | 1798 | ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL; |
| 1799 | rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL; |
| 1800 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1801 | |
Luigi Santivetti | 8b0b6f9 | 2020-06-30 11:32:49 +0100 | [diff] [blame] | 1802 | if (cctx || ddraw || rdraw) { |
| 1803 | if (!dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1804 | _EGLContext *tmp_ctx; |
| 1805 | |
| 1806 | /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but |
| 1807 | * setting the error to EGL_BAD_MATCH is surely better than leaving it |
| 1808 | * as EGL_SUCCESS. |
| 1809 | */ |
| 1810 | egl_error = EGL_BAD_MATCH; |
| 1811 | |
Luigi Santivetti | 8b0b6f9 | 2020-06-30 11:32:49 +0100 | [diff] [blame] | 1812 | /* undo the previous _eglBindContext */ |
| 1813 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); |
| 1814 | assert(&dri2_ctx->base == ctx && |
| 1815 | tmp_dsurf == dsurf && |
| 1816 | tmp_rsurf == rsurf); |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1817 | |
Luigi Santivetti | 8b0b6f9 | 2020-06-30 11:32:49 +0100 | [diff] [blame] | 1818 | _eglPutSurface(dsurf); |
| 1819 | _eglPutSurface(rsurf); |
| 1820 | _eglPutContext(ctx); |
| 1821 | |
| 1822 | _eglPutSurface(old_dsurf); |
| 1823 | _eglPutSurface(old_rsurf); |
| 1824 | _eglPutContext(old_ctx); |
| 1825 | |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1826 | ddraw = (old_dsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_dsurf) : NULL; |
| 1827 | rdraw = (old_rsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_rsurf) : NULL; |
| 1828 | cctx = (old_ctx) ? dri2_egl_context(old_ctx)->dri_context : NULL; |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 1829 | |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1830 | /* undo the previous dri2_dpy->core->unbindContext */ |
| 1831 | if (dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
| 1832 | if (old_dsurf && _eglSurfaceInSharedBufferMode(old_dsurf) && |
| 1833 | old_dri2_dpy->vtbl->set_shared_buffer_mode) { |
| 1834 | old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, true); |
| 1835 | } |
| 1836 | |
| 1837 | return _eglError(egl_error, "eglMakeCurrent"); |
| 1838 | } |
| 1839 | |
| 1840 | /* We cannot restore the same state as it was before calling |
| 1841 | * eglMakeCurrent() and the spec isn't clear about what to do. We |
| 1842 | * can prevent EGL from calling into the DRI driver with no DRI |
| 1843 | * context bound. |
| 1844 | */ |
| 1845 | dsurf = rsurf = NULL; |
| 1846 | ctx = NULL; |
| 1847 | |
| 1848 | _eglBindContext(ctx, dsurf, rsurf, &tmp_ctx, &tmp_dsurf, &tmp_rsurf); |
| 1849 | assert(tmp_ctx == old_ctx && tmp_dsurf == old_dsurf && |
| 1850 | tmp_rsurf == old_rsurf); |
| 1851 | |
| 1852 | _eglLog(_EGL_WARNING, "DRI2: failed to rebind the previous context"); |
Frank Binns | d0e32e5 | 2020-07-28 15:50:30 +0100 | [diff] [blame] | 1853 | } else { |
| 1854 | /* dri2_dpy->core->bindContext succeeded, so take a reference on the |
| 1855 | * dri2_dpy. This prevents dri2_dpy from being reinitialized when a |
| 1856 | * EGLDisplay is terminated and then initialized again while a |
| 1857 | * context is still bound. See dri2_intitialize() for a more in depth |
| 1858 | * explanation. */ |
| 1859 | dri2_dpy->ref_count++; |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1860 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1861 | } |
Chad Versace | eabf597 | 2018-04-07 13:01:15 -0700 | [diff] [blame] | 1862 | |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1863 | dri2_destroy_surface(disp, old_dsurf); |
| 1864 | dri2_destroy_surface(disp, old_rsurf); |
Chad Versace | eabf597 | 2018-04-07 13:01:15 -0700 | [diff] [blame] | 1865 | |
Chad Versace | eabf597 | 2018-04-07 13:01:15 -0700 | [diff] [blame] | 1866 | if (old_ctx) { |
Eric Engestrom | f27a32a | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1867 | dri2_destroy_context(disp, old_ctx); |
Chad Versace | eabf597 | 2018-04-07 13:01:15 -0700 | [diff] [blame] | 1868 | dri2_display_release(old_disp); |
| 1869 | } |
| 1870 | |
Luigi Santivetti | 2907fae | 2020-06-30 14:59:45 +0100 | [diff] [blame] | 1871 | if (egl_error != EGL_SUCCESS) |
| 1872 | return _eglError(egl_error, "eglMakeCurrent"); |
| 1873 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame] | 1874 | if (dsurf && _eglSurfaceHasMutableRenderBuffer(dsurf) && |
| 1875 | dri2_dpy->vtbl->set_shared_buffer_mode) { |
| 1876 | /* Always update the shared buffer mode. This is obviously needed when |
| 1877 | * the active EGL_RENDER_BUFFER is EGL_SINGLE_BUFFER. When |
| 1878 | * EGL_RENDER_BUFFER is EGL_BACK_BUFFER, the update protects us in the |
| 1879 | * case where external non-EGL API may have changed window's shared |
| 1880 | * buffer mode since we last saw it. |
| 1881 | */ |
| 1882 | bool mode = (dsurf->ActiveRenderBuffer == EGL_SINGLE_BUFFER); |
| 1883 | dri2_dpy->vtbl->set_shared_buffer_mode(disp, dsurf, mode); |
| 1884 | } |
| 1885 | |
Chad Versace | eabf597 | 2018-04-07 13:01:15 -0700 | [diff] [blame] | 1886 | return EGL_TRUE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1889 | __DRIdrawable * |
| 1890 | dri2_surface_get_dri_drawable(_EGLSurface *surf) |
| 1891 | { |
| 1892 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1893 | |
| 1894 | return dri2_surf->dri_drawable; |
| 1895 | } |
| 1896 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1897 | /* |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 1898 | * Called from eglGetProcAddress() via drv->GetProcAddress(). |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1899 | */ |
| 1900 | static _EGLProc |
Eric Engestrom | a7d15d2 | 2018-04-22 16:48:15 +0200 | [diff] [blame^] | 1901 | dri2_get_proc_address(const char *procname) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1902 | { |
Emil Velikov | d884d8d | 2017-09-27 17:36:29 +0100 | [diff] [blame] | 1903 | return _glapi_get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1904 | } |
| 1905 | |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1906 | static _EGLSurface* |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1907 | dri2_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, |
| 1908 | void *native_window, const EGLint *attrib_list) |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1909 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1910 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1911 | return dri2_dpy->vtbl->create_window_surface(disp, conf, native_window, |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1912 | attrib_list); |
| 1913 | } |
| 1914 | |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1915 | static _EGLSurface* |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1916 | dri2_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, |
| 1917 | void *native_pixmap, const EGLint *attrib_list) |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1918 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1919 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 179e442 | 2020-07-11 00:29:17 +0200 | [diff] [blame] | 1920 | if (!dri2_dpy->vtbl->create_pixmap_surface) |
| 1921 | return NULL; |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1922 | return dri2_dpy->vtbl->create_pixmap_surface(disp, conf, native_pixmap, |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1923 | attrib_list); |
| 1924 | } |
| 1925 | |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1926 | static _EGLSurface* |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1927 | dri2_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, |
| 1928 | const EGLint *attrib_list) |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1929 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1930 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 43e2d80 | 2020-07-11 00:31:32 +0200 | [diff] [blame] | 1931 | if (!dri2_dpy->vtbl->create_pbuffer_surface) |
| 1932 | return NULL; |
Eric Engestrom | 6b4c474 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1933 | return dri2_dpy->vtbl->create_pbuffer_surface(disp, conf, attrib_list); |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1936 | static EGLBoolean |
Eric Engestrom | 347840c | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1937 | dri2_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval) |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 1938 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1939 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | dd9eb8d | 2017-08-02 17:25:44 +0100 | [diff] [blame] | 1940 | if (!dri2_dpy->vtbl->swap_interval) |
| 1941 | return EGL_TRUE; |
Eric Engestrom | 347840c | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1942 | return dri2_dpy->vtbl->swap_interval(disp, surf, interval); |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1945 | /** |
| 1946 | * Asks the client API to flush any rendering to the drawable so that we can |
| 1947 | * do our swapbuffers. |
| 1948 | */ |
| 1949 | void |
| 1950 | dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw) |
| 1951 | { |
| 1952 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1953 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(draw); |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1954 | |
| 1955 | if (dri2_dpy->flush) { |
| 1956 | if (dri2_dpy->flush->base.version >= 4) { |
| 1957 | /* We know there's a current context because: |
| 1958 | * |
| 1959 | * "If surface is not bound to the calling thread’s current |
| 1960 | * context, an EGL_BAD_SURFACE error is generated." |
| 1961 | */ |
| 1962 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1963 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1964 | |
| 1965 | /* From the EGL 1.4 spec (page 52): |
| 1966 | * |
| 1967 | * "The contents of ancillary buffers are always undefined |
| 1968 | * after calling eglSwapBuffers." |
| 1969 | */ |
| 1970 | dri2_dpy->flush->flush_with_flags(dri2_ctx->dri_context, |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1971 | dri_drawable, |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1972 | __DRI2_FLUSH_DRAWABLE | |
| 1973 | __DRI2_FLUSH_INVALIDATE_ANCILLARY, |
| 1974 | __DRI2_THROTTLE_SWAPBUFFER); |
| 1975 | } else { |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1976 | dri2_dpy->flush->flush(dri_drawable); |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 1981 | static EGLBoolean |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1982 | dri2_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf) |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 1983 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1984 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 1985 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1986 | _EGLContext *ctx = _eglGetCurrentContext(); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 1987 | EGLBoolean ret; |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 1988 | |
| 1989 | if (ctx && surf) |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 1990 | dri2_surf_update_fence_fd(ctx, disp, surf); |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 1991 | ret = dri2_dpy->vtbl->swap_buffers(disp, surf); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 1992 | |
| 1993 | /* SwapBuffers marks the end of the frame; reset the damage region for |
| 1994 | * use again next time. |
| 1995 | */ |
| 1996 | if (ret && dri2_dpy->buffer_damage && |
| 1997 | dri2_dpy->buffer_damage->set_damage_region) |
| 1998 | dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL); |
| 1999 | |
| 2000 | return ret; |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | static EGLBoolean |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2004 | dri2_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *surf, |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 2005 | const EGLint *rects, EGLint n_rects) |
| 2006 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2007 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2008 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 2009 | _EGLContext *ctx = _eglGetCurrentContext(); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2010 | EGLBoolean ret; |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 2011 | |
| 2012 | if (ctx && surf) |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2013 | dri2_surf_update_fence_fd(ctx, disp, surf); |
Eric Engestrom | 7d5a13e | 2020-07-11 00:36:08 +0200 | [diff] [blame] | 2014 | if (dri2_dpy->vtbl->swap_buffers_with_damage) |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2015 | ret = dri2_dpy->vtbl->swap_buffers_with_damage(disp, surf, |
Eric Engestrom | 7d5a13e | 2020-07-11 00:36:08 +0200 | [diff] [blame] | 2016 | rects, n_rects); |
| 2017 | else |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2018 | ret = dri2_dpy->vtbl->swap_buffers(disp, surf); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2019 | |
| 2020 | /* SwapBuffers marks the end of the frame; reset the damage region for |
| 2021 | * use again next time. |
| 2022 | */ |
| 2023 | if (ret && dri2_dpy->buffer_damage && |
| 2024 | dri2_dpy->buffer_damage->set_damage_region) |
| 2025 | dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL); |
| 2026 | |
| 2027 | return ret; |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 2028 | } |
| 2029 | |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2030 | static EGLBoolean |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2031 | dri2_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *surf, |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2032 | EGLint numRects, const EGLint *rects) |
| 2033 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2034 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2035 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
| 2036 | EGLBoolean ret; |
| 2037 | |
Eric Engestrom | 1ba5075a | 2020-07-11 00:38:38 +0200 | [diff] [blame] | 2038 | if (!dri2_dpy->vtbl->swap_buffers_region) |
| 2039 | return EGL_FALSE; |
Eric Engestrom | 82035b2 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2040 | ret = dri2_dpy->vtbl->swap_buffers_region(disp, surf, numRects, rects); |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2041 | |
| 2042 | /* SwapBuffers marks the end of the frame; reset the damage region for |
| 2043 | * use again next time. |
| 2044 | */ |
| 2045 | if (ret && dri2_dpy->buffer_damage && |
| 2046 | dri2_dpy->buffer_damage->set_damage_region) |
| 2047 | dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL); |
| 2048 | |
| 2049 | return ret; |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | static EGLBoolean |
Eric Engestrom | 648f603 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2053 | dri2_set_damage_region(_EGLDisplay *disp, _EGLSurface *surf, |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 2054 | EGLint *rects, EGLint n_rects) |
| 2055 | { |
Harish Krupo | a4a8ebe | 2019-08-12 12:07:06 +0200 | [diff] [blame] | 2056 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2057 | __DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
| 2058 | |
| 2059 | if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region) |
| 2060 | return EGL_FALSE; |
| 2061 | |
| 2062 | dri2_dpy->buffer_damage->set_damage_region(drawable, n_rects, rects); |
| 2063 | return EGL_TRUE; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2067 | dri2_post_sub_buffer(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2068 | EGLint x, EGLint y, EGLint width, EGLint height) |
| 2069 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2070 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 2d5f12ae3 | 2020-07-11 00:39:41 +0200 | [diff] [blame] | 2071 | if (!dri2_dpy->vtbl->post_sub_buffer) |
| 2072 | return EGL_FALSE; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2073 | return dri2_dpy->vtbl->post_sub_buffer(drv, disp, surf, x, y, width, height); |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | static EGLBoolean |
Eric Engestrom | d202fd6 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2077 | dri2_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target) |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2078 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2079 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 90000b0 | 2020-07-11 00:40:20 +0200 | [diff] [blame] | 2080 | if (!dri2_dpy->vtbl->copy_buffers) |
| 2081 | return _eglError(EGL_BAD_NATIVE_PIXMAP, "no support for native pixmaps"); |
Eric Engestrom | d202fd6 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2082 | return dri2_dpy->vtbl->copy_buffers(disp, surf, native_pixmap_target); |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2085 | static EGLint |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2086 | dri2_query_buffer_age(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2087 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2088 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | c5fb1fb | 2020-07-11 00:40:57 +0200 | [diff] [blame] | 2089 | if (!dri2_dpy->vtbl->query_buffer_age) |
| 2090 | return 0; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2091 | return dri2_dpy->vtbl->query_buffer_age(drv, disp, surf); |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2092 | } |
| 2093 | |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 2094 | static EGLBoolean |
Eric Engestrom | 4e65469 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2095 | dri2_wait_client(_EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2096 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 2097 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2098 | _EGLSurface *surf = ctx->DrawSurface; |
| 2099 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 2100 | |
| 2101 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 2102 | * we need to copy fake to real here.*/ |
| 2103 | |
José Fonseca | 5048e69 | 2013-02-05 13:43:01 +0000 | [diff] [blame] | 2104 | if (dri2_dpy->flush != NULL) |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2105 | dri2_dpy->flush->flush(dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2106 | |
| 2107 | return EGL_TRUE; |
| 2108 | } |
| 2109 | |
| 2110 | static EGLBoolean |
Eric Engestrom | b8d1c46 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2111 | dri2_wait_native(EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2112 | { |
| 2113 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 2114 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 2115 | /* glXWaitX(); */ |
| 2116 | |
| 2117 | return EGL_TRUE; |
| 2118 | } |
| 2119 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 2120 | static EGLBoolean |
Eric Engestrom | 2f4a6ad | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2121 | dri2_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2122 | { |
| 2123 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2124 | struct dri2_egl_context *dri2_ctx; |
| 2125 | _EGLContext *ctx; |
| 2126 | GLint format, target; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2127 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2128 | |
| 2129 | ctx = _eglGetCurrentContext(); |
| 2130 | dri2_ctx = dri2_egl_context(ctx); |
| 2131 | |
Eric Engestrom | 2f4a6ad | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2132 | if (!_eglBindTexImage(disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2133 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2134 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2135 | switch (surf->TextureFormat) { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2136 | case EGL_TEXTURE_RGB: |
| 2137 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 2138 | break; |
| 2139 | case EGL_TEXTURE_RGBA: |
| 2140 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 2141 | break; |
| 2142 | default: |
Brian Paul | 54070a9 | 2015-05-29 16:01:37 -0600 | [diff] [blame] | 2143 | assert(!"Unexpected texture format in dri2_bind_tex_image()"); |
| 2144 | format = __DRI_TEXTURE_FORMAT_RGBA; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2145 | } |
| 2146 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2147 | switch (surf->TextureTarget) { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2148 | case EGL_TEXTURE_2D: |
| 2149 | target = GL_TEXTURE_2D; |
| 2150 | break; |
| 2151 | default: |
Brian Paul | 54070a9 | 2015-05-29 16:01:37 -0600 | [diff] [blame] | 2152 | target = GL_TEXTURE_2D; |
| 2153 | assert(!"Unexpected texture target in dri2_bind_tex_image()"); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2154 | } |
| 2155 | |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 2156 | dri2_dpy->tex_buffer->setTexBuffer2(dri2_ctx->dri_context, |
| 2157 | target, format, |
| 2158 | dri_drawable); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2159 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 2160 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | static EGLBoolean |
Eric Engestrom | 2f4a6ad | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2164 | dri2_release_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2165 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2166 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2167 | struct dri2_egl_context *dri2_ctx; |
| 2168 | _EGLContext *ctx; |
| 2169 | GLint target; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2170 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2171 | |
| 2172 | ctx = _eglGetCurrentContext(); |
| 2173 | dri2_ctx = dri2_egl_context(ctx); |
| 2174 | |
Eric Engestrom | 2f4a6ad | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2175 | if (!_eglReleaseTexImage(disp, surf, buffer)) |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2176 | return EGL_FALSE; |
| 2177 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 2178 | switch (surf->TextureTarget) { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2179 | case EGL_TEXTURE_2D: |
| 2180 | target = GL_TEXTURE_2D; |
| 2181 | break; |
| 2182 | default: |
Eric Engestrom | ea738a9 | 2018-10-28 18:20:20 +0000 | [diff] [blame] | 2183 | assert(!"missing texture target"); |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 2184 | } |
Emil Velikov | 9b42fd1 | 2014-02-18 03:04:03 +0000 | [diff] [blame] | 2185 | |
| 2186 | if (dri2_dpy->tex_buffer->base.version >= 3 && |
| 2187 | dri2_dpy->tex_buffer->releaseTexBuffer != NULL) { |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 2188 | dri2_dpy->tex_buffer->releaseTexBuffer(dri2_ctx->dri_context, |
| 2189 | target, dri_drawable); |
Emil Velikov | 9b42fd1 | 2014-02-18 03:04:03 +0000 | [diff] [blame] | 2190 | } |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2191 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2192 | return EGL_TRUE; |
| 2193 | } |
| 2194 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2195 | static _EGLImage* |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2196 | dri2_create_image(const _EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx, |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2197 | EGLenum target, EGLClientBuffer buffer, |
| 2198 | const EGLint *attr_list) |
| 2199 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2200 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2201 | return dri2_dpy->vtbl->create_image(drv, disp, ctx, target, buffer, |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2202 | attr_list); |
| 2203 | } |
| 2204 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2205 | static _EGLImage * |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2206 | dri2_create_image_from_dri(_EGLDisplay *disp, __DRIimage *dri_image) |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 2207 | { |
| 2208 | struct dri2_egl_image *dri2_img; |
| 2209 | |
| 2210 | if (dri_image == NULL) { |
| 2211 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 2212 | return NULL; |
| 2213 | } |
| 2214 | |
| 2215 | dri2_img = malloc(sizeof *dri2_img); |
| 2216 | if (!dri2_img) { |
| 2217 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 2218 | return NULL; |
| 2219 | } |
| 2220 | |
Emil Velikov | d42b095 | 2017-06-20 15:22:39 +0100 | [diff] [blame] | 2221 | _eglInitImage(&dri2_img->base, disp); |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 2222 | |
| 2223 | dri2_img->dri_image = dri_image; |
| 2224 | |
| 2225 | return &dri2_img->base; |
| 2226 | } |
| 2227 | |
Nicolai Hähnle | d0d6efc | 2017-10-10 13:58:47 +0200 | [diff] [blame] | 2228 | /** |
| 2229 | * Translate a DRI Image extension error code into an EGL error code. |
| 2230 | */ |
| 2231 | static EGLint |
| 2232 | egl_error_from_dri_image_error(int dri_error) |
| 2233 | { |
| 2234 | switch (dri_error) { |
| 2235 | case __DRI_IMAGE_ERROR_SUCCESS: |
| 2236 | return EGL_SUCCESS; |
| 2237 | case __DRI_IMAGE_ERROR_BAD_ALLOC: |
| 2238 | return EGL_BAD_ALLOC; |
| 2239 | case __DRI_IMAGE_ERROR_BAD_MATCH: |
| 2240 | return EGL_BAD_MATCH; |
| 2241 | case __DRI_IMAGE_ERROR_BAD_PARAMETER: |
| 2242 | return EGL_BAD_PARAMETER; |
| 2243 | case __DRI_IMAGE_ERROR_BAD_ACCESS: |
| 2244 | return EGL_BAD_ACCESS; |
| 2245 | default: |
Eric Engestrom | ea738a9 | 2018-10-28 18:20:20 +0000 | [diff] [blame] | 2246 | assert(!"unknown dri_error code"); |
Nicolai Hähnle | d0d6efc | 2017-10-10 13:58:47 +0200 | [diff] [blame] | 2247 | return EGL_BAD_ALLOC; |
| 2248 | } |
| 2249 | } |
| 2250 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 2251 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2252 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2253 | EGLClientBuffer buffer, |
| 2254 | const EGLint *attr_list) |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2255 | { |
| 2256 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2257 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 2258 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 2259 | __DRIimage *dri_image; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2260 | |
| 2261 | if (renderbuffer == 0) { |
| 2262 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2263 | return EGL_NO_IMAGE_KHR; |
| 2264 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2265 | |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2266 | if (!disp->Extensions.KHR_gl_renderbuffer_image) { |
| 2267 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2268 | return EGL_NO_IMAGE_KHR; |
| 2269 | } |
| 2270 | |
Emil Velikov | 872a373 | 2017-10-10 18:50:13 +0100 | [diff] [blame] | 2271 | if (dri2_dpy->image->base.version >= 17 && |
| 2272 | dri2_dpy->image->createImageFromRenderbuffer2) { |
Nicolai Hähnle | bad2439 | 2017-10-10 13:58:47 +0200 | [diff] [blame] | 2273 | unsigned error = ~0; |
| 2274 | |
| 2275 | dri_image = dri2_dpy->image->createImageFromRenderbuffer2( |
| 2276 | dri2_ctx->dri_context, renderbuffer, NULL, &error); |
| 2277 | |
| 2278 | assert(!!dri_image == (error == __DRI_IMAGE_ERROR_SUCCESS)); |
| 2279 | |
| 2280 | if (!dri_image) { |
| 2281 | _eglError(egl_error_from_dri_image_error(error), "dri2_create_image_khr"); |
| 2282 | return EGL_NO_IMAGE_KHR; |
| 2283 | } |
| 2284 | } else { |
| 2285 | dri_image = dri2_dpy->image->createImageFromRenderbuffer( |
| 2286 | dri2_ctx->dri_context, renderbuffer, NULL); |
| 2287 | if (!dri_image) { |
| 2288 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2289 | return EGL_NO_IMAGE_KHR; |
| 2290 | } |
| 2291 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2292 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2293 | return dri2_create_image_from_dri(disp, dri_image); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 2296 | #ifdef HAVE_WAYLAND_PLATFORM |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2297 | |
| 2298 | /* This structure describes how a wl_buffer maps to one or more |
| 2299 | * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the |
| 2300 | * offsets and strides of the planes in the buffer. This table maps a |
| 2301 | * wl_drm format code to a description of the planes in the buffer |
| 2302 | * that lets us create a __DRIimage for each of the planes. */ |
| 2303 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2304 | static const struct wl_drm_components_descriptor { |
| 2305 | uint32_t dri_components; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2306 | EGLint components; |
| 2307 | int nplanes; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2308 | } wl_drm_components[] = { |
| 2309 | { __DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1 }, |
| 2310 | { __DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1 }, |
| 2311 | { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 }, |
| 2312 | { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 }, |
| 2313 | { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 }, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2314 | }; |
| 2315 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2316 | static _EGLImage * |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2317 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2318 | EGLClientBuffer _buffer, |
| 2319 | const EGLint *attr_list) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2320 | { |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2321 | struct wl_drm_buffer *buffer; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 2322 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2323 | const struct wl_drm_components_descriptor *f; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2324 | __DRIimage *dri_image; |
| 2325 | _EGLImageAttribs attrs; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2326 | int32_t plane; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2327 | |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 2328 | buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_drm, |
| 2329 | (struct wl_resource *) _buffer); |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2330 | if (!buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2331 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2332 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2333 | if (!_eglParseImageAttribList(&attrs, disp, attr_list)) |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2334 | return NULL; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2335 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2336 | plane = attrs.PlaneWL; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2337 | f = buffer->driver_format; |
| 2338 | if (plane < 0 || plane >= f->nplanes) { |
| 2339 | _eglError(EGL_BAD_PARAMETER, |
| 2340 | "dri2_create_image_wayland_wl_buffer (plane out of bounds)"); |
| 2341 | return NULL; |
| 2342 | } |
| 2343 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2344 | dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL); |
Louis-Francis Ratté-Boulianne | a34715a | 2017-09-28 03:18:33 -0400 | [diff] [blame] | 2345 | if (dri_image == NULL && plane == 0) |
| 2346 | dri_image = dri2_dpy->image->dupImage(buffer->driver_buffer, NULL); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2347 | if (dri_image == NULL) { |
| 2348 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 2349 | return NULL; |
| 2350 | } |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 2351 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2352 | return dri2_create_image_from_dri(disp, dri_image); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2353 | } |
| 2354 | #endif |
| 2355 | |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2356 | static EGLBoolean |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2357 | dri2_get_sync_values_chromium(_EGLDisplay *disp, _EGLSurface *surf, |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2358 | EGLuint64KHR *ust, EGLuint64KHR *msc, |
| 2359 | EGLuint64KHR *sbc) |
| 2360 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2361 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | bc38fe8 | 2020-07-11 00:42:08 +0200 | [diff] [blame] | 2362 | if (!dri2_dpy->vtbl->get_sync_values) |
| 2363 | return EGL_FALSE; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2364 | return dri2_dpy->vtbl->get_sync_values(disp, surf, ust, msc, sbc); |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2367 | /** |
| 2368 | * Set the error code after a call to |
| 2369 | * dri2_egl_image::dri_image::createImageFromTexture. |
| 2370 | */ |
| 2371 | static void |
| 2372 | dri2_create_image_khr_texture_error(int dri_error) |
| 2373 | { |
Nicolai Hähnle | d0d6efc | 2017-10-10 13:58:47 +0200 | [diff] [blame] | 2374 | EGLint egl_error = egl_error_from_dri_image_error(dri_error); |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2375 | |
Nicolai Hähnle | d0d6efc | 2017-10-10 13:58:47 +0200 | [diff] [blame] | 2376 | if (egl_error != EGL_SUCCESS) |
| 2377 | _eglError(egl_error, "dri2_create_image_khr_texture"); |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | static _EGLImage * |
| 2381 | dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2382 | EGLenum target, |
| 2383 | EGLClientBuffer buffer, |
| 2384 | const EGLint *attr_list) |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2385 | { |
| 2386 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2387 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2388 | struct dri2_egl_image *dri2_img; |
| 2389 | GLuint texture = (GLuint) (uintptr_t) buffer; |
| 2390 | _EGLImageAttribs attrs; |
| 2391 | GLuint depth; |
| 2392 | GLenum gl_target; |
| 2393 | unsigned error; |
| 2394 | |
| 2395 | if (texture == 0) { |
| 2396 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2397 | return EGL_NO_IMAGE_KHR; |
| 2398 | } |
| 2399 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2400 | if (!_eglParseImageAttribList(&attrs, disp, attr_list)) |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2401 | return EGL_NO_IMAGE_KHR; |
| 2402 | |
| 2403 | switch (target) { |
| 2404 | case EGL_GL_TEXTURE_2D_KHR: |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2405 | if (!disp->Extensions.KHR_gl_texture_2D_image) { |
| 2406 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2407 | return EGL_NO_IMAGE_KHR; |
| 2408 | } |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2409 | depth = 0; |
| 2410 | gl_target = GL_TEXTURE_2D; |
| 2411 | break; |
| 2412 | case EGL_GL_TEXTURE_3D_KHR: |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2413 | if (!disp->Extensions.KHR_gl_texture_3D_image) { |
Anatoli Antonovitch | b193f2b | 2015-06-10 14:42:31 +0200 | [diff] [blame] | 2414 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2415 | return EGL_NO_IMAGE_KHR; |
| 2416 | } |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2417 | |
| 2418 | depth = attrs.GLTextureZOffset; |
| 2419 | gl_target = GL_TEXTURE_3D; |
| 2420 | break; |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2421 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 2422 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 2423 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 2424 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 2425 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 2426 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2427 | if (!disp->Extensions.KHR_gl_texture_cubemap_image) { |
| 2428 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2429 | return EGL_NO_IMAGE_KHR; |
| 2430 | } |
| 2431 | |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2432 | depth = target - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR; |
| 2433 | gl_target = GL_TEXTURE_CUBE_MAP; |
| 2434 | break; |
| 2435 | default: |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 2436 | unreachable("Unexpected target in dri2_create_image_khr_texture()"); |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2437 | return EGL_NO_IMAGE_KHR; |
| 2438 | } |
| 2439 | |
| 2440 | dri2_img = malloc(sizeof *dri2_img); |
| 2441 | if (!dri2_img) { |
| 2442 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2443 | return EGL_NO_IMAGE_KHR; |
| 2444 | } |
| 2445 | |
Emil Velikov | d42b095 | 2017-06-20 15:22:39 +0100 | [diff] [blame] | 2446 | _eglInitImage(&dri2_img->base, disp); |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 2447 | |
| 2448 | dri2_img->dri_image = |
| 2449 | dri2_dpy->image->createImageFromTexture(dri2_ctx->dri_context, |
| 2450 | gl_target, |
| 2451 | texture, |
| 2452 | depth, |
| 2453 | attrs.GLTextureLevel, |
| 2454 | &error, |
| 2455 | dri2_img); |
| 2456 | dri2_create_image_khr_texture_error(error); |
| 2457 | |
| 2458 | if (!dri2_img->dri_image) { |
| 2459 | free(dri2_img); |
| 2460 | return EGL_NO_IMAGE_KHR; |
| 2461 | } |
| 2462 | return &dri2_img->base; |
| 2463 | } |
| 2464 | |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 2465 | static EGLBoolean |
Eric Engestrom | 982ac69 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2466 | dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 2467 | EGLint attribute, EGLint *value) |
| 2468 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2469 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 2470 | if (!dri2_dpy->vtbl->query_surface) |
Eric Engestrom | 982ac69 | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 2471 | return _eglQuerySurface(disp, surf, attribute, value); |
| 2472 | return dri2_dpy->vtbl->query_surface(disp, surf, attribute, value); |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2475 | static struct wl_buffer* |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2476 | dri2_create_wayland_buffer_from_image(const _EGLDriver *drv, _EGLDisplay *disp, |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2477 | _EGLImage *img) |
| 2478 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2479 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Eric Engestrom | 2e3eb0c | 2020-07-11 00:41:35 +0200 | [diff] [blame] | 2480 | if (!dri2_dpy->vtbl->create_wayland_buffer_from_image) |
| 2481 | return NULL; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 2482 | return dri2_dpy->vtbl->create_wayland_buffer_from_image(drv, disp, img); |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2483 | } |
| 2484 | |
Axel Davy | 63986f9 | 2015-01-14 20:36:04 +0100 | [diff] [blame] | 2485 | #ifdef HAVE_LIBDRM |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2486 | static _EGLImage * |
| 2487 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2488 | EGLClientBuffer buffer, const EGLint *attr_list) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2489 | { |
| 2490 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Alejandro Piñeiro | 5767102 | 2017-07-13 11:38:48 +0200 | [diff] [blame] | 2491 | EGLint format, name, pitch; |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2492 | _EGLImageAttribs attrs; |
| 2493 | __DRIimage *dri_image; |
| 2494 | |
| 2495 | name = (EGLint) (uintptr_t) buffer; |
| 2496 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2497 | if (!_eglParseImageAttribList(&attrs, disp, attr_list)) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2498 | return NULL; |
| 2499 | |
| 2500 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 2501 | attrs.DRMBufferStrideMESA <= 0) { |
| 2502 | _eglError(EGL_BAD_PARAMETER, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2503 | "bad width, height or stride"); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2504 | return NULL; |
| 2505 | } |
| 2506 | |
| 2507 | switch (attrs.DRMBufferFormatMESA) { |
| 2508 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 2509 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 2510 | pitch = attrs.DRMBufferStrideMESA; |
| 2511 | break; |
| 2512 | default: |
| 2513 | _eglError(EGL_BAD_PARAMETER, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2514 | "dri2_create_image_khr: unsupported pixmap depth"); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2515 | return NULL; |
| 2516 | } |
| 2517 | |
Tapani Pälli | ff05f16 | 2019-11-12 17:32:41 +0200 | [diff] [blame] | 2518 | dri_image = |
| 2519 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 2520 | attrs.Width, |
| 2521 | attrs.Height, |
| 2522 | format, |
| 2523 | name, |
| 2524 | pitch, |
| 2525 | NULL); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2526 | |
| 2527 | return dri2_create_image_from_dri(disp, dri_image); |
| 2528 | } |
| 2529 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2530 | static EGLBoolean |
| 2531 | dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) |
| 2532 | { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2533 | /** |
| 2534 | * The spec says: |
| 2535 | * |
| 2536 | * "Required attributes and their values are as follows: |
| 2537 | * |
| 2538 | * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels |
| 2539 | * |
| 2540 | * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified |
| 2541 | * by drm_fourcc.h and used as the pixel_format parameter of the |
| 2542 | * drm_mode_fb_cmd2 ioctl." |
| 2543 | * |
| 2544 | * and |
| 2545 | * |
| 2546 | * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is |
| 2547 | * incomplete, EGL_BAD_PARAMETER is generated." |
| 2548 | */ |
| 2549 | if (attrs->Width <= 0 || attrs->Height <= 0 || |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2550 | !attrs->DMABufFourCC.IsPresent) |
| 2551 | return _eglError(EGL_BAD_PARAMETER, "attribute(s) missing"); |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2552 | |
| 2553 | /** |
| 2554 | * Also: |
| 2555 | * |
| 2556 | * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values |
| 2557 | * specified for a plane's pitch or offset isn't supported by EGL, |
| 2558 | * EGL_BAD_ACCESS is generated." |
| 2559 | */ |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2560 | for (unsigned i = 0; i < ARRAY_SIZE(attrs->DMABufPlanePitches); ++i) { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2561 | if (attrs->DMABufPlanePitches[i].IsPresent && |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2562 | attrs->DMABufPlanePitches[i].Value <= 0) |
| 2563 | return _eglError(EGL_BAD_ACCESS, "invalid pitch"); |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2566 | /** |
| 2567 | * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following |
| 2568 | * attribute values may be given. |
| 2569 | * |
| 2570 | * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and |
| 2571 | * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes. |
| 2572 | */ |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2573 | for (unsigned i = 0; i < DMA_BUF_MAX_PLANES; ++i) { |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2574 | if (attrs->DMABufPlaneModifiersLo[i].IsPresent != |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2575 | attrs->DMABufPlaneModifiersHi[i].IsPresent) |
| 2576 | return _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing"); |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't |
| 2580 | * mandate it, we only accept the same modifier across all planes. */ |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2581 | for (unsigned i = 1; i < DMA_BUF_MAX_PLANES; ++i) { |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2582 | if (attrs->DMABufPlaneFds[i].IsPresent) { |
| 2583 | if ((attrs->DMABufPlaneModifiersLo[0].IsPresent != |
| 2584 | attrs->DMABufPlaneModifiersLo[i].IsPresent) || |
| 2585 | (attrs->DMABufPlaneModifiersLo[0].Value != |
| 2586 | attrs->DMABufPlaneModifiersLo[i].Value) || |
| 2587 | (attrs->DMABufPlaneModifiersHi[0].Value != |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2588 | attrs->DMABufPlaneModifiersHi[i].Value)) |
| 2589 | return _eglError(EGL_BAD_PARAMETER, "modifier attributes not equal"); |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2593 | return EGL_TRUE; |
| 2594 | } |
| 2595 | |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2596 | /* Returns the total number of planes for the format or zero if it isn't a |
| 2597 | * valid fourcc format. |
| 2598 | */ |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2599 | static unsigned |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2600 | dri2_num_fourcc_format_planes(EGLint format) |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2601 | { |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2602 | switch (format) { |
Chad Versace | fd865d5 | 2015-06-23 15:48:17 -0700 | [diff] [blame] | 2603 | case DRM_FORMAT_R8: |
| 2604 | case DRM_FORMAT_RG88: |
| 2605 | case DRM_FORMAT_GR88: |
Rainer Hochecker | 09b140a | 2017-01-05 16:58:56 +0100 | [diff] [blame] | 2606 | case DRM_FORMAT_R16: |
| 2607 | case DRM_FORMAT_GR1616: |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2608 | case DRM_FORMAT_RGB332: |
| 2609 | case DRM_FORMAT_BGR233: |
| 2610 | case DRM_FORMAT_XRGB4444: |
| 2611 | case DRM_FORMAT_XBGR4444: |
| 2612 | case DRM_FORMAT_RGBX4444: |
| 2613 | case DRM_FORMAT_BGRX4444: |
| 2614 | case DRM_FORMAT_ARGB4444: |
| 2615 | case DRM_FORMAT_ABGR4444: |
| 2616 | case DRM_FORMAT_RGBA4444: |
| 2617 | case DRM_FORMAT_BGRA4444: |
| 2618 | case DRM_FORMAT_XRGB1555: |
| 2619 | case DRM_FORMAT_XBGR1555: |
| 2620 | case DRM_FORMAT_RGBX5551: |
| 2621 | case DRM_FORMAT_BGRX5551: |
| 2622 | case DRM_FORMAT_ARGB1555: |
| 2623 | case DRM_FORMAT_ABGR1555: |
| 2624 | case DRM_FORMAT_RGBA5551: |
| 2625 | case DRM_FORMAT_BGRA5551: |
| 2626 | case DRM_FORMAT_RGB565: |
| 2627 | case DRM_FORMAT_BGR565: |
| 2628 | case DRM_FORMAT_RGB888: |
| 2629 | case DRM_FORMAT_BGR888: |
| 2630 | case DRM_FORMAT_XRGB8888: |
| 2631 | case DRM_FORMAT_XBGR8888: |
| 2632 | case DRM_FORMAT_RGBX8888: |
| 2633 | case DRM_FORMAT_BGRX8888: |
| 2634 | case DRM_FORMAT_ARGB8888: |
| 2635 | case DRM_FORMAT_ABGR8888: |
| 2636 | case DRM_FORMAT_RGBA8888: |
| 2637 | case DRM_FORMAT_BGRA8888: |
| 2638 | case DRM_FORMAT_XRGB2101010: |
| 2639 | case DRM_FORMAT_XBGR2101010: |
| 2640 | case DRM_FORMAT_RGBX1010102: |
| 2641 | case DRM_FORMAT_BGRX1010102: |
| 2642 | case DRM_FORMAT_ARGB2101010: |
| 2643 | case DRM_FORMAT_ABGR2101010: |
| 2644 | case DRM_FORMAT_RGBA1010102: |
| 2645 | case DRM_FORMAT_BGRA1010102: |
Kevin Strasser | 4861d2a | 2019-01-24 17:32:36 -0800 | [diff] [blame] | 2646 | case DRM_FORMAT_XBGR16161616F: |
| 2647 | case DRM_FORMAT_ABGR16161616F: |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2648 | case DRM_FORMAT_YUYV: |
| 2649 | case DRM_FORMAT_YVYU: |
| 2650 | case DRM_FORMAT_UYVY: |
| 2651 | case DRM_FORMAT_VYUY: |
Lionel Landwerlin | 252ca7b | 2018-11-08 17:28:20 +0000 | [diff] [blame] | 2652 | case DRM_FORMAT_AYUV: |
Kasireddy, Vivek | 65600d0 | 2019-02-12 16:44:04 -0800 | [diff] [blame] | 2653 | case DRM_FORMAT_XYUV8888: |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2654 | return 1; |
| 2655 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2656 | case DRM_FORMAT_NV12: |
| 2657 | case DRM_FORMAT_NV21: |
| 2658 | case DRM_FORMAT_NV16: |
| 2659 | case DRM_FORMAT_NV61: |
Tapani Pälli | 722f96b | 2019-02-11 10:01:35 +0200 | [diff] [blame] | 2660 | case DRM_FORMAT_P010: |
| 2661 | case DRM_FORMAT_P012: |
| 2662 | case DRM_FORMAT_P016: |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2663 | return 2; |
| 2664 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2665 | case DRM_FORMAT_YUV410: |
| 2666 | case DRM_FORMAT_YVU410: |
| 2667 | case DRM_FORMAT_YUV411: |
| 2668 | case DRM_FORMAT_YVU411: |
| 2669 | case DRM_FORMAT_YUV420: |
| 2670 | case DRM_FORMAT_YVU420: |
| 2671 | case DRM_FORMAT_YUV422: |
| 2672 | case DRM_FORMAT_YVU422: |
| 2673 | case DRM_FORMAT_YUV444: |
| 2674 | case DRM_FORMAT_YVU444: |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2675 | return 3; |
| 2676 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2677 | default: |
Jason Ekstrand | b95896f | 2018-08-28 16:31:22 -0500 | [diff] [blame] | 2678 | return 0; |
| 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | /* Returns the total number of file descriptors. Zero indicates an error. */ |
| 2683 | static unsigned |
| 2684 | dri2_check_dma_buf_format(const _EGLImageAttribs *attrs) |
| 2685 | { |
| 2686 | unsigned plane_n = dri2_num_fourcc_format_planes(attrs->DMABufFourCC.Value); |
| 2687 | if (plane_n == 0) { |
Lionel Landwerlin | 1c56d21 | 2018-11-13 14:10:45 +0000 | [diff] [blame] | 2688 | _eglError(EGL_BAD_MATCH, "unknown drm fourcc format"); |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2689 | return 0; |
| 2690 | } |
| 2691 | |
Daniel Stone | 7d26a52 | 2017-07-31 18:34:57 +0100 | [diff] [blame] | 2692 | for (unsigned i = plane_n; i < DMA_BUF_MAX_PLANES; i++) { |
| 2693 | /** |
| 2694 | * The modifiers extension spec says: |
| 2695 | * |
| 2696 | * "Modifiers may modify any attribute of a buffer import, including |
| 2697 | * but not limited to adding extra planes to a format which |
| 2698 | * otherwise does not have those planes. As an example, a modifier |
| 2699 | * may add a plane for an external compression buffer to a |
| 2700 | * single-plane format. The exact meaning and effect of any |
| 2701 | * modifier is canonically defined by drm_fourcc.h, not as part of |
| 2702 | * this extension." |
| 2703 | */ |
| 2704 | if (attrs->DMABufPlaneModifiersLo[i].IsPresent && |
| 2705 | attrs->DMABufPlaneModifiersHi[i].IsPresent) { |
| 2706 | plane_n = i + 1; |
| 2707 | } |
| 2708 | } |
| 2709 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2710 | /** |
| 2711 | * The spec says: |
| 2712 | * |
| 2713 | * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is |
| 2714 | * incomplete, EGL_BAD_PARAMETER is generated." |
| 2715 | */ |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2716 | for (unsigned i = 0; i < plane_n; ++i) { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2717 | if (!attrs->DMABufPlaneFds[i].IsPresent || |
| 2718 | !attrs->DMABufPlaneOffsets[i].IsPresent || |
| 2719 | !attrs->DMABufPlanePitches[i].IsPresent) { |
| 2720 | _eglError(EGL_BAD_PARAMETER, "plane attribute(s) missing"); |
| 2721 | return 0; |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * The spec also says: |
| 2727 | * |
| 2728 | * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT |
| 2729 | * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is |
| 2730 | * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_* |
Pekka Paalanen | fb2a1c2 | 2017-05-30 17:23:35 +0530 | [diff] [blame] | 2731 | * or EGL_DMA_BUF_PLANE3_* attributes are specified." |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2732 | */ |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2733 | for (unsigned i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2734 | if (attrs->DMABufPlaneFds[i].IsPresent || |
| 2735 | attrs->DMABufPlaneOffsets[i].IsPresent || |
Daniel Stone | 7d26a52 | 2017-07-31 18:34:57 +0100 | [diff] [blame] | 2736 | attrs->DMABufPlanePitches[i].IsPresent) { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2737 | _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes"); |
| 2738 | return 0; |
| 2739 | } |
| 2740 | } |
| 2741 | |
| 2742 | return plane_n; |
| 2743 | } |
| 2744 | |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2745 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2746 | dri2_query_dma_buf_formats(const _EGLDriver *drv, _EGLDisplay *disp, |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2747 | EGLint max, EGLint *formats, EGLint *count) |
| 2748 | { |
| 2749 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2750 | if (max < 0 || (max > 0 && formats == NULL)) |
| 2751 | return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2752 | |
| 2753 | if (dri2_dpy->image->base.version < 15 || |
| 2754 | dri2_dpy->image->queryDmaBufFormats == NULL) |
| 2755 | return EGL_FALSE; |
| 2756 | |
| 2757 | if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max, |
| 2758 | formats, count)) |
| 2759 | return EGL_FALSE; |
| 2760 | |
Jason Ekstrand | 8c1b988 | 2018-08-28 16:43:57 -0500 | [diff] [blame] | 2761 | if (max > 0) { |
| 2762 | /* Assert that all of the formats returned are actually fourcc formats. |
| 2763 | * Some day, if we want the internal interface function to be able to |
| 2764 | * return the fake fourcc formats defined in dri_interface.h, we'll have |
| 2765 | * to do something more clever here to pair the list down to just real |
| 2766 | * fourcc formats so that we don't leak the fake internal ones. |
| 2767 | */ |
| 2768 | for (int i = 0; i < *count; i++) { |
| 2769 | assert(dri2_num_fourcc_format_planes(formats[i]) > 0); |
| 2770 | } |
| 2771 | } |
| 2772 | |
Varad Gautam | 6719e05 | 2017-05-30 17:23:38 +0530 | [diff] [blame] | 2773 | return EGL_TRUE; |
| 2774 | } |
| 2775 | |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2776 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2777 | dri2_query_dma_buf_modifiers(const _EGLDriver *drv, _EGLDisplay *disp, EGLint format, |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2778 | EGLint max, EGLuint64KHR *modifiers, |
| 2779 | EGLBoolean *external_only, EGLint *count) |
| 2780 | { |
| 2781 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2782 | |
Jason Ekstrand | 8c1b988 | 2018-08-28 16:43:57 -0500 | [diff] [blame] | 2783 | if (dri2_num_fourcc_format_planes(format) == 0) |
| 2784 | return _eglError(EGL_BAD_PARAMETER, "invalid fourcc format"); |
| 2785 | |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2786 | if (max < 0) |
| 2787 | return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2788 | |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2789 | if (max > 0 && modifiers == NULL) |
| 2790 | return _eglError(EGL_BAD_PARAMETER, "invalid modifiers array"); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2791 | |
| 2792 | if (dri2_dpy->image->base.version < 15 || |
| 2793 | dri2_dpy->image->queryDmaBufModifiers == NULL) |
| 2794 | return EGL_FALSE; |
| 2795 | |
| 2796 | if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, |
| 2797 | max, modifiers, |
| 2798 | (unsigned int *) external_only, |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2799 | count) == false) |
| 2800 | return _eglError(EGL_BAD_PARAMETER, "invalid format"); |
Varad Gautam | de3c459 | 2017-05-30 17:23:39 +0530 | [diff] [blame] | 2801 | |
| 2802 | return EGL_TRUE; |
| 2803 | } |
| 2804 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2805 | /** |
| 2806 | * The spec says: |
| 2807 | * |
Pekka Paalanen | 08264e5 | 2014-08-08 16:26:28 +0300 | [diff] [blame] | 2808 | * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the |
| 2809 | * EGL will take a reference to the dma_buf(s) which it will release at any |
| 2810 | * time while the EGLDisplay is initialized. It is the responsibility of the |
| 2811 | * application to close the dma_buf file descriptors." |
| 2812 | * |
| 2813 | * Therefore we must never close or otherwise modify the file descriptors. |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2814 | */ |
Emil Velikov | 38ef6f5 | 2016-05-01 12:42:53 +0100 | [diff] [blame] | 2815 | _EGLImage * |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2816 | dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2817 | EGLClientBuffer buffer, const EGLint *attr_list) |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2818 | { |
| 2819 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2820 | _EGLImage *res; |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2821 | _EGLImageAttribs attrs; |
| 2822 | __DRIimage *dri_image; |
| 2823 | unsigned num_fds; |
Pekka Paalanen | 9434f05 | 2017-05-30 17:23:34 +0530 | [diff] [blame] | 2824 | int fds[DMA_BUF_MAX_PLANES]; |
| 2825 | int pitches[DMA_BUF_MAX_PLANES]; |
| 2826 | int offsets[DMA_BUF_MAX_PLANES]; |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2827 | uint64_t modifier; |
| 2828 | bool has_modifier = false; |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2829 | unsigned error; |
| 2830 | |
| 2831 | /** |
| 2832 | * The spec says: |
| 2833 | * |
| 2834 | * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the |
| 2835 | * error EGL_BAD_PARAMETER is generated." |
| 2836 | */ |
| 2837 | if (buffer != NULL) { |
| 2838 | _eglError(EGL_BAD_PARAMETER, "buffer not NULL"); |
| 2839 | return NULL; |
| 2840 | } |
| 2841 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2842 | if (!_eglParseImageAttribList(&attrs, disp, attr_list)) |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2843 | return NULL; |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2844 | |
| 2845 | if (!dri2_check_dma_buf_attribs(&attrs)) |
| 2846 | return NULL; |
| 2847 | |
| 2848 | num_fds = dri2_check_dma_buf_format(&attrs); |
| 2849 | if (!num_fds) |
| 2850 | return NULL; |
| 2851 | |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 2852 | for (unsigned i = 0; i < num_fds; ++i) { |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2853 | fds[i] = attrs.DMABufPlaneFds[i].Value; |
| 2854 | pitches[i] = attrs.DMABufPlanePitches[i].Value; |
| 2855 | offsets[i] = attrs.DMABufPlaneOffsets[i].Value; |
| 2856 | } |
| 2857 | |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2858 | /* dri2_check_dma_buf_attribs ensures that the modifier, if available, |
| 2859 | * will be present in attrs.DMABufPlaneModifiersLo[0] and |
| 2860 | * attrs.DMABufPlaneModifiersHi[0] */ |
| 2861 | if (attrs.DMABufPlaneModifiersLo[0].IsPresent) { |
Eric Engestrom | 2de9e84 | 2018-08-16 15:22:46 +0100 | [diff] [blame] | 2862 | modifier = combine_u32_into_u64(attrs.DMABufPlaneModifiersHi[0].Value, |
| 2863 | attrs.DMABufPlaneModifiersLo[0].Value); |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2864 | has_modifier = true; |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2865 | } |
| 2866 | |
Tapani Pälli | ff05f16 | 2019-11-12 17:32:41 +0200 | [diff] [blame] | 2867 | if (has_modifier) { |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2868 | if (dri2_dpy->image->base.version < 15 || |
| 2869 | dri2_dpy->image->createImageFromDmaBufs2 == NULL) { |
| 2870 | _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier"); |
| 2871 | return EGL_NO_IMAGE_KHR; |
| 2872 | } |
| 2873 | dri_image = |
| 2874 | dri2_dpy->image->createImageFromDmaBufs2(dri2_dpy->dri_screen, |
| 2875 | attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, |
| 2876 | modifier, fds, num_fds, pitches, offsets, |
| 2877 | attrs.DMABufYuvColorSpaceHint.Value, |
| 2878 | attrs.DMABufSampleRangeHint.Value, |
| 2879 | attrs.DMABufChromaHorizontalSiting.Value, |
| 2880 | attrs.DMABufChromaVerticalSiting.Value, |
| 2881 | &error, |
| 2882 | NULL); |
Tapani Pälli | ff05f16 | 2019-11-12 17:32:41 +0200 | [diff] [blame] | 2883 | } |
| 2884 | else { |
Varad Gautam | 6f10e7c | 2017-05-30 17:23:37 +0530 | [diff] [blame] | 2885 | dri_image = |
| 2886 | dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen, |
| 2887 | attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, |
| 2888 | fds, num_fds, pitches, offsets, |
| 2889 | attrs.DMABufYuvColorSpaceHint.Value, |
| 2890 | attrs.DMABufSampleRangeHint.Value, |
| 2891 | attrs.DMABufChromaHorizontalSiting.Value, |
| 2892 | attrs.DMABufChromaVerticalSiting.Value, |
| 2893 | &error, |
| 2894 | NULL); |
| 2895 | } |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2896 | dri2_create_image_khr_texture_error(error); |
| 2897 | |
| 2898 | if (!dri_image) |
| 2899 | return EGL_NO_IMAGE_KHR; |
| 2900 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2901 | res = dri2_create_image_from_dri(disp, dri_image); |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2902 | |
| 2903 | return res; |
| 2904 | } |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2905 | static _EGLImage * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2906 | dri2_create_drm_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2907 | const EGLint *attr_list) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2908 | { |
| 2909 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2910 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2911 | _EGLImageAttribs attrs; |
| 2912 | unsigned int dri_use, valid_mask; |
| 2913 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2914 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2915 | (void) drv; |
| 2916 | |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2917 | if (!attr_list) { |
| 2918 | _eglError(EGL_BAD_PARAMETER, __func__); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2919 | return EGL_NO_IMAGE_KHR; |
| 2920 | } |
| 2921 | |
Emil Velikov | 81e9592 | 2017-06-28 20:31:18 +0100 | [diff] [blame] | 2922 | if (!_eglParseImageAttribList(&attrs, disp, attr_list)) |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2923 | return EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2924 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2925 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2926 | _eglError(EGL_BAD_PARAMETER, __func__); |
| 2927 | return EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2928 | } |
| 2929 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2930 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2931 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 2932 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 2933 | break; |
| 2934 | default: |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2935 | _eglError(EGL_BAD_PARAMETER, __func__); |
| 2936 | return EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | valid_mask = |
| 2940 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 2941 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 2942 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2943 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2944 | _eglError(EGL_BAD_PARAMETER, __func__); |
| 2945 | return EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2949 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2950 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2951 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2952 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 2953 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 2954 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2955 | |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2956 | dri2_img = malloc(sizeof *dri2_img); |
| 2957 | if (!dri2_img) { |
| 2958 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2959 | return EGL_NO_IMAGE_KHR; |
| 2960 | } |
| 2961 | |
| 2962 | _eglInitImage(&dri2_img->base, disp); |
| 2963 | |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 2964 | dri2_img->dri_image = |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2965 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2966 | attrs.Width, attrs.Height, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2967 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2968 | if (dri2_img->dri_image == NULL) { |
Emil Velikov | 9365ff4 | 2017-06-28 21:23:00 +0100 | [diff] [blame] | 2969 | free(dri2_img); |
| 2970 | _eglError(EGL_BAD_ALLOC, "dri2_create_drm_image_mesa"); |
| 2971 | return EGL_NO_IMAGE_KHR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | return &dri2_img->base; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 2978 | dri2_export_drm_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2979 | EGLint *name, EGLint *handle, EGLint *stride) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2980 | { |
| 2981 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2982 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 2983 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2984 | (void) drv; |
| 2985 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2986 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 2987 | __DRI_IMAGE_ATTRIB_NAME, name)) |
| 2988 | return _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2989 | |
| 2990 | if (handle) |
| 2991 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2992 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2993 | |
| 2994 | if (stride) |
| 2995 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2996 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2997 | |
| 2998 | return EGL_TRUE; |
| 2999 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3000 | |
Eric Anholt | f675045 | 2018-07-16 16:18:03 -0700 | [diff] [blame] | 3001 | /** |
| 3002 | * Checks if we can support EGL_MESA_image_dma_buf_export on this image. |
| 3003 | |
| 3004 | * The spec provides a boolean return for the driver to reject exporting for |
| 3005 | * basically any reason, but doesn't specify any particular error cases. For |
| 3006 | * now, we just fail if we don't have a DRM fourcc for the format. |
| 3007 | */ |
| 3008 | static bool |
| 3009 | dri2_can_export_dma_buf_image(_EGLDisplay *disp, _EGLImage *img) |
| 3010 | { |
| 3011 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3012 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 3013 | EGLint fourcc; |
| 3014 | |
| 3015 | if (!dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3016 | __DRI_IMAGE_ATTRIB_FOURCC, &fourcc)) { |
| 3017 | return false; |
| 3018 | } |
| 3019 | |
| 3020 | return true; |
| 3021 | } |
| 3022 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3023 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3024 | dri2_export_dma_buf_image_query_mesa(const _EGLDriver *drv, _EGLDisplay *disp, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3025 | _EGLImage *img, |
| 3026 | EGLint *fourcc, EGLint *nplanes, |
Dave Airlie | b5045e2 | 2015-05-05 09:10:34 +1000 | [diff] [blame] | 3027 | EGLuint64KHR *modifiers) |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3028 | { |
| 3029 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3030 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
Nicolas Dufresne | 08f1cef | 2019-07-14 14:48:11 -0400 | [diff] [blame] | 3031 | int num_planes; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3032 | |
| 3033 | (void) drv; |
| 3034 | |
Eric Anholt | f675045 | 2018-07-16 16:18:03 -0700 | [diff] [blame] | 3035 | if (!dri2_can_export_dma_buf_image(disp, img)) |
| 3036 | return EGL_FALSE; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3037 | |
Nicolas Dufresne | 08f1cef | 2019-07-14 14:48:11 -0400 | [diff] [blame] | 3038 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3039 | __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3040 | if (nplanes) |
Nicolas Dufresne | 08f1cef | 2019-07-14 14:48:11 -0400 | [diff] [blame] | 3041 | *nplanes = num_planes; |
| 3042 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3043 | if (fourcc) |
| 3044 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3045 | __DRI_IMAGE_ATTRIB_FOURCC, fourcc); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3046 | |
Nicolas Dufresne | 08f1cef | 2019-07-14 14:48:11 -0400 | [diff] [blame] | 3047 | if (modifiers) { |
| 3048 | int mod_hi, mod_lo; |
| 3049 | uint64_t modifier = DRM_FORMAT_MOD_INVALID; |
| 3050 | bool query; |
| 3051 | |
| 3052 | query = dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3053 | __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, |
| 3054 | &mod_hi); |
| 3055 | query &= dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3056 | __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, |
| 3057 | &mod_lo); |
| 3058 | if (query) |
| 3059 | modifier = combine_u32_into_u64 (mod_hi, mod_lo); |
| 3060 | |
| 3061 | for (int i = 0; i < num_planes; i++) |
| 3062 | modifiers[i] = modifier; |
| 3063 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3064 | |
| 3065 | return EGL_TRUE; |
| 3066 | } |
| 3067 | |
| 3068 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3069 | dri2_export_dma_buf_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3070 | int *fds, EGLint *strides, EGLint *offsets) |
| 3071 | { |
| 3072 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3073 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
Tapani Pälli | ef92308 | 2019-04-09 10:43:59 +0300 | [diff] [blame] | 3074 | EGLint nplanes; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3075 | |
| 3076 | (void) drv; |
| 3077 | |
Eric Anholt | f675045 | 2018-07-16 16:18:03 -0700 | [diff] [blame] | 3078 | if (!dri2_can_export_dma_buf_image(disp, img)) |
| 3079 | return EGL_FALSE; |
| 3080 | |
Tapani Pälli | ef92308 | 2019-04-09 10:43:59 +0300 | [diff] [blame] | 3081 | /* EGL_MESA_image_dma_buf_export spec says: |
| 3082 | * "If the number of fds is less than the number of planes, then |
| 3083 | * subsequent fd slots should contain -1." |
| 3084 | */ |
| 3085 | if (fds) { |
| 3086 | /* Query nplanes so that we know how big the given array is. */ |
| 3087 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3088 | __DRI_IMAGE_ATTRIB_NUM_PLANES, &nplanes); |
| 3089 | memset(fds, -1, nplanes * sizeof(int)); |
| 3090 | } |
| 3091 | |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3092 | /* rework later to provide multiple fds/strides/offsets */ |
| 3093 | if (fds) |
| 3094 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3095 | __DRI_IMAGE_ATTRIB_FD, fds); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3096 | |
| 3097 | if (strides) |
| 3098 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3099 | __DRI_IMAGE_ATTRIB_STRIDE, strides); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3100 | |
Chuanbo Weng | 9e8de86 | 2016-09-14 01:07:10 +0800 | [diff] [blame] | 3101 | if (offsets) { |
| 3102 | int img_offset; |
| 3103 | bool ret = dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 3104 | __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); |
| 3105 | if (ret) |
| 3106 | offsets[0] = img_offset; |
| 3107 | else |
| 3108 | offsets[0] = 0; |
| 3109 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 3110 | |
| 3111 | return EGL_TRUE; |
| 3112 | } |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3113 | |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 3114 | #endif |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 3115 | |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3116 | _EGLImage * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3117 | dri2_create_image_khr(const _EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3118 | _EGLContext *ctx, EGLenum target, |
| 3119 | EGLClientBuffer buffer, const EGLint *attr_list) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3120 | { |
| 3121 | (void) drv; |
| 3122 | |
| 3123 | switch (target) { |
| 3124 | case EGL_GL_TEXTURE_2D_KHR: |
| 3125 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 3126 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 3127 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 3128 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 3129 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 3130 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3131 | case EGL_GL_TEXTURE_3D_KHR: |
Emil Velikov | 962110f | 2017-06-29 00:35:56 +0100 | [diff] [blame] | 3132 | return dri2_create_image_khr_texture(disp, ctx, target, buffer, attr_list); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3133 | case EGL_GL_RENDERBUFFER_KHR: |
| 3134 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
| 3135 | #ifdef HAVE_LIBDRM |
| 3136 | case EGL_DRM_BUFFER_MESA: |
| 3137 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
| 3138 | case EGL_LINUX_DMA_BUF_EXT: |
| 3139 | return dri2_create_image_dma_buf(disp, ctx, buffer, attr_list); |
| 3140 | #endif |
| 3141 | #ifdef HAVE_WAYLAND_PLATFORM |
| 3142 | case EGL_WAYLAND_BUFFER_WL: |
| 3143 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 3144 | #endif |
| 3145 | default: |
| 3146 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 3147 | return EGL_NO_IMAGE_KHR; |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3152 | dri2_destroy_image_khr(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 3153 | { |
| 3154 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3155 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 3156 | |
| 3157 | (void) drv; |
| 3158 | |
| 3159 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 3160 | free(dri2_img); |
| 3161 | |
| 3162 | return EGL_TRUE; |
| 3163 | } |
| 3164 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3165 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3166 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 3167 | static void |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3168 | dri2_wl_reference_buffer(void *user_data, uint32_t name, int fd, |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 3169 | struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3170 | { |
| 3171 | _EGLDisplay *disp = user_data; |
| 3172 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 3173 | __DRIimage *img; |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 3174 | int dri_components = 0; |
Kristian Høgsberg | 7b1d94e | 2011-08-31 16:45:04 -0400 | [diff] [blame] | 3175 | |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3176 | if (fd == -1) |
| 3177 | img = dri2_dpy->image->createImageFromNames(dri2_dpy->dri_screen, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3178 | buffer->width, |
| 3179 | buffer->height, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3180 | buffer->format, |
| 3181 | (int*)&name, 1, |
| 3182 | buffer->stride, |
| 3183 | buffer->offset, |
| 3184 | NULL); |
| 3185 | else |
| 3186 | img = dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3187 | buffer->width, |
| 3188 | buffer->height, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3189 | buffer->format, |
| 3190 | &fd, 1, |
| 3191 | buffer->stride, |
| 3192 | buffer->offset, |
| 3193 | NULL); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3194 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 3195 | if (img == NULL) |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 3196 | return; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3197 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 3198 | dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, &dri_components); |
| 3199 | |
| 3200 | buffer->driver_format = NULL; |
Chad Versace | cd717cb | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 3201 | for (int i = 0; i < ARRAY_SIZE(wl_drm_components); i++) |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 3202 | if (wl_drm_components[i].dri_components == dri_components) |
| 3203 | buffer->driver_format = &wl_drm_components[i]; |
| 3204 | |
| 3205 | if (buffer->driver_format == NULL) |
| 3206 | dri2_dpy->image->destroyImage(img); |
| 3207 | else |
| 3208 | buffer->driver_buffer = img; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | static void |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 3212 | dri2_wl_release_buffer(void *user_data, struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3213 | { |
| 3214 | _EGLDisplay *disp = user_data; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3215 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3216 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 3217 | dri2_dpy->image->destroyImage(buffer->driver_buffer); |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3218 | } |
| 3219 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3220 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3221 | dri2_bind_wayland_display_wl(const _EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3222 | struct wl_display *wl_dpy) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3223 | { |
| 3224 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Emil Velikov | acb84ff | 2017-09-27 19:49:12 +0100 | [diff] [blame] | 3225 | const struct wayland_drm_callbacks wl_drm_callbacks = { |
| 3226 | .authenticate = (int(*)(void *, uint32_t)) dri2_dpy->vtbl->authenticate, |
| 3227 | .reference_buffer = dri2_wl_reference_buffer, |
Mario Kleiner | 820dfce | 2018-06-13 06:04:15 +0200 | [diff] [blame] | 3228 | .release_buffer = dri2_wl_release_buffer, |
| 3229 | .is_format_supported = dri2_wl_is_format_supported |
Emil Velikov | acb84ff | 2017-09-27 19:49:12 +0100 | [diff] [blame] | 3230 | }; |
Emil Velikov | 6638c55 | 2014-05-28 14:36:46 +0100 | [diff] [blame] | 3231 | int flags = 0; |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3232 | uint64_t cap; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3233 | |
| 3234 | (void) drv; |
| 3235 | |
| 3236 | if (dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3237 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3238 | |
Emil Velikov | 6638c55 | 2014-05-28 14:36:46 +0100 | [diff] [blame] | 3239 | if (drmGetCap(dri2_dpy->fd, DRM_CAP_PRIME, &cap) == 0 && |
| 3240 | cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) && |
Kristian Høgsberg | 1670737 | 2013-03-19 13:20:36 -0400 | [diff] [blame] | 3241 | dri2_dpy->image->base.version >= 7 && |
| 3242 | dri2_dpy->image->createImageFromFds != NULL) |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3243 | flags |= WAYLAND_DRM_PRIME; |
| 3244 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3245 | dri2_dpy->wl_server_drm = |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3246 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 3247 | &wl_drm_callbacks, disp, flags); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3248 | |
| 3249 | if (!dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3250 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3251 | |
Ander Conselvan de Oliveira | 1786030 | 2014-04-08 23:28:42 +0300 | [diff] [blame] | 3252 | #ifdef HAVE_DRM_PLATFORM |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 3253 | /* We have to share the wl_drm instance with gbm, so gbm can convert |
| 3254 | * wl_buffers to gbm bos. */ |
Kristian Høgsberg | 1d34927 | 2013-10-11 15:30:09 -0700 | [diff] [blame] | 3255 | if (dri2_dpy->gbm_dri) |
| 3256 | dri2_dpy->gbm_dri->wl_drm = dri2_dpy->wl_server_drm; |
Ander Conselvan de Oliveira | 1786030 | 2014-04-08 23:28:42 +0300 | [diff] [blame] | 3257 | #endif |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 3258 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3259 | return EGL_TRUE; |
| 3260 | } |
| 3261 | |
| 3262 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3263 | dri2_unbind_wayland_display_wl(const _EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3264 | struct wl_display *wl_dpy) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3265 | { |
| 3266 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 3267 | |
| 3268 | (void) drv; |
| 3269 | |
| 3270 | if (!dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 3271 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3272 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 3273 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3274 | dri2_dpy->wl_server_drm = NULL; |
| 3275 | |
| 3276 | return EGL_TRUE; |
| 3277 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3278 | |
| 3279 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3280 | dri2_query_wayland_buffer_wl(const _EGLDriver *drv, _EGLDisplay *disp, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3281 | struct wl_resource *buffer_resource, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3282 | EGLint attribute, EGLint *value) |
| 3283 | { |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 3284 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3285 | struct wl_drm_buffer *buffer; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 3286 | const struct wl_drm_components_descriptor *format; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3287 | |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 3288 | buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_drm, buffer_resource); |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3289 | if (!buffer) |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3290 | return EGL_FALSE; |
| 3291 | |
| 3292 | format = buffer->driver_format; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 3293 | switch (attribute) { |
| 3294 | case EGL_TEXTURE_FORMAT: |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3295 | *value = format->components; |
| 3296 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 3297 | case EGL_WIDTH: |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3298 | *value = buffer->width; |
Rob Bradford | 15e64de | 2013-04-10 11:36:24 +0100 | [diff] [blame] | 3299 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 3300 | case EGL_HEIGHT: |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 3301 | *value = buffer->height; |
Rob Bradford | 15e64de | 2013-04-10 11:36:24 +0100 | [diff] [blame] | 3302 | return EGL_TRUE; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | return EGL_FALSE; |
| 3306 | } |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3307 | #endif |
| 3308 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 3309 | static void |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3310 | dri2_egl_ref_sync(struct dri2_egl_sync *sync) |
| 3311 | { |
| 3312 | p_atomic_inc(&sync->refcount); |
| 3313 | } |
| 3314 | |
| 3315 | static void |
| 3316 | dri2_egl_unref_sync(struct dri2_egl_display *dri2_dpy, |
| 3317 | struct dri2_egl_sync *dri2_sync) |
| 3318 | { |
| 3319 | if (p_atomic_dec_zero(&dri2_sync->refcount)) { |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3320 | switch (dri2_sync->base.Type) { |
| 3321 | case EGL_SYNC_REUSABLE_KHR: |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3322 | cnd_destroy(&dri2_sync->cond); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3323 | break; |
| 3324 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
| 3325 | if (dri2_sync->base.SyncFd != EGL_NO_NATIVE_FENCE_FD_ANDROID) |
| 3326 | close(dri2_sync->base.SyncFd); |
| 3327 | break; |
| 3328 | default: |
| 3329 | break; |
| 3330 | } |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3331 | |
| 3332 | if (dri2_sync->fence) |
| 3333 | dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, dri2_sync->fence); |
| 3334 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3335 | free(dri2_sync); |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | static _EGLSync * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3340 | dri2_create_sync(const _EGLDriver *drv, _EGLDisplay *disp, |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 3341 | EGLenum type, const EGLAttrib *attrib_list) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3342 | { |
| 3343 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3344 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3345 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 3346 | struct dri2_egl_sync *dri2_sync; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3347 | EGLint ret; |
| 3348 | pthread_condattr_t attr; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3349 | |
| 3350 | dri2_sync = calloc(1, sizeof(struct dri2_egl_sync)); |
| 3351 | if (!dri2_sync) { |
| 3352 | _eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR"); |
| 3353 | return NULL; |
| 3354 | } |
| 3355 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3356 | if (!_eglInitSync(&dri2_sync->base, disp, type, attrib_list)) { |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3357 | free(dri2_sync); |
| 3358 | return NULL; |
| 3359 | } |
| 3360 | |
| 3361 | switch (type) { |
| 3362 | case EGL_SYNC_FENCE_KHR: |
| 3363 | dri2_sync->fence = dri2_dpy->fence->create_fence(dri2_ctx->dri_context); |
Chad Versace | b0f410a | 2015-05-05 19:05:20 -0700 | [diff] [blame] | 3364 | if (!dri2_sync->fence) { |
| 3365 | /* Why did it fail? DRI doesn't return an error code, so we emit |
Chad Versace | a6bfdd7 | 2015-05-07 08:09:07 -0700 | [diff] [blame] | 3366 | * a generic EGL error that doesn't communicate user error. |
| 3367 | */ |
Chad Versace | b0f410a | 2015-05-05 19:05:20 -0700 | [diff] [blame] | 3368 | _eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR"); |
| 3369 | free(dri2_sync); |
| 3370 | return NULL; |
| 3371 | } |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3372 | break; |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 3373 | |
| 3374 | case EGL_SYNC_CL_EVENT_KHR: |
| 3375 | dri2_sync->fence = dri2_dpy->fence->get_fence_from_cl_event( |
| 3376 | dri2_dpy->dri_screen, |
| 3377 | dri2_sync->base.CLEvent); |
| 3378 | /* this can only happen if the cl_event passed in is invalid. */ |
| 3379 | if (!dri2_sync->fence) { |
| 3380 | _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); |
| 3381 | free(dri2_sync); |
| 3382 | return NULL; |
| 3383 | } |
| 3384 | |
| 3385 | /* the initial status must be "signaled" if the cl_event is signaled */ |
| 3386 | if (dri2_dpy->fence->client_wait_sync(dri2_ctx->dri_context, |
| 3387 | dri2_sync->fence, 0, 0)) |
| 3388 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 3389 | break; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3390 | |
| 3391 | case EGL_SYNC_REUSABLE_KHR: |
| 3392 | /* intialize attr */ |
| 3393 | ret = pthread_condattr_init(&attr); |
| 3394 | |
| 3395 | if (ret) { |
| 3396 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 3397 | free(dri2_sync); |
| 3398 | return NULL; |
| 3399 | } |
| 3400 | |
| 3401 | /* change clock attribute to CLOCK_MONOTONIC */ |
| 3402 | ret = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); |
| 3403 | |
| 3404 | if (ret) { |
| 3405 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 3406 | free(dri2_sync); |
| 3407 | return NULL; |
| 3408 | } |
| 3409 | |
| 3410 | ret = pthread_cond_init(&dri2_sync->cond, &attr); |
| 3411 | |
| 3412 | if (ret) { |
| 3413 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 3414 | free(dri2_sync); |
| 3415 | return NULL; |
| 3416 | } |
| 3417 | |
| 3418 | /* initial status of reusable sync must be "unsignaled" */ |
| 3419 | dri2_sync->base.SyncStatus = EGL_UNSIGNALED_KHR; |
| 3420 | break; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3421 | |
| 3422 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
| 3423 | if (dri2_dpy->fence->create_fence_fd) { |
| 3424 | dri2_sync->fence = dri2_dpy->fence->create_fence_fd( |
| 3425 | dri2_ctx->dri_context, |
| 3426 | dri2_sync->base.SyncFd); |
| 3427 | } |
| 3428 | if (!dri2_sync->fence) { |
| 3429 | _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); |
| 3430 | free(dri2_sync); |
| 3431 | return NULL; |
| 3432 | } |
| 3433 | break; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | p_atomic_set(&dri2_sync->refcount, 1); |
| 3437 | return &dri2_sync->base; |
| 3438 | } |
| 3439 | |
| 3440 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3441 | dri2_destroy_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3442 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3443 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3444 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3445 | EGLint ret = EGL_TRUE; |
| 3446 | EGLint err; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3447 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3448 | /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet, |
| 3449 | * then unlock all threads possibly blocked by the reusable sync before |
| 3450 | * destroying it. |
| 3451 | */ |
| 3452 | if (dri2_sync->base.Type == EGL_SYNC_REUSABLE_KHR && |
| 3453 | dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) { |
| 3454 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 3455 | /* unblock all threads currently blocked by sync */ |
| 3456 | err = cnd_broadcast(&dri2_sync->cond); |
| 3457 | |
| 3458 | if (err) { |
| 3459 | _eglError(EGL_BAD_ACCESS, "eglDestroySyncKHR"); |
| 3460 | ret = EGL_FALSE; |
| 3461 | } |
| 3462 | } |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3463 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3464 | dri2_egl_unref_sync(dri2_dpy, dri2_sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3465 | |
| 3466 | return ret; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | static EGLint |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3470 | dri2_dup_native_fence_fd(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync) |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3471 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3472 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3473 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 3474 | |
| 3475 | assert(sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID); |
| 3476 | |
| 3477 | if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { |
| 3478 | /* try to retrieve the actual native fence fd.. if rendering is |
| 3479 | * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD: |
| 3480 | */ |
| 3481 | sync->SyncFd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen, |
| 3482 | dri2_sync->fence); |
| 3483 | } |
| 3484 | |
| 3485 | if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { |
| 3486 | /* if native fence fd still not created, return an error: */ |
| 3487 | _eglError(EGL_BAD_PARAMETER, "eglDupNativeFenceFDANDROID"); |
| 3488 | return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 3489 | } |
| 3490 | |
Eric Engestrom | 419b446 | 2020-06-05 10:22:22 +0200 | [diff] [blame] | 3491 | return os_dupfd_cloexec(sync->SyncFd); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3492 | } |
| 3493 | |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 3494 | static void |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3495 | dri2_set_blob_cache_funcs(const _EGLDriver *drv, _EGLDisplay *disp, |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 3496 | EGLSetBlobFuncANDROID set, |
| 3497 | EGLGetBlobFuncANDROID get) |
| 3498 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3499 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 3500 | dri2_dpy->blob->set_cache_funcs(dri2_dpy->dri_screen, |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3501 | disp->BlobCacheSet, |
| 3502 | disp->BlobCacheGet); |
Tapani Pälli | 6f5b570 | 2017-12-28 10:51:11 +0200 | [diff] [blame] | 3503 | } |
| 3504 | |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3505 | static EGLint |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3506 | dri2_client_wait_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync, |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 3507 | EGLint flags, EGLTime timeout) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3508 | { |
| 3509 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3510 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3511 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 3512 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 3513 | unsigned wait_flags = 0; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3514 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3515 | EGLint ret = EGL_CONDITION_SATISFIED_KHR; |
| 3516 | |
Marek Olšák | 18123a7 | 2015-09-25 22:48:00 +0200 | [diff] [blame] | 3517 | /* The EGL_KHR_fence_sync spec states: |
| 3518 | * |
| 3519 | * "If no context is current for the bound API, |
| 3520 | * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored. |
| 3521 | */ |
| 3522 | if (dri2_ctx && flags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3523 | wait_flags |= __DRI2_FENCE_FLAG_FLUSH_COMMANDS; |
| 3524 | |
| 3525 | /* the sync object should take a reference while waiting */ |
| 3526 | dri2_egl_ref_sync(dri2_sync); |
| 3527 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3528 | switch (sync->Type) { |
| 3529 | case EGL_SYNC_FENCE_KHR: |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 3530 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3531 | case EGL_SYNC_CL_EVENT_KHR: |
| 3532 | if (dri2_dpy->fence->client_wait_sync(dri2_ctx ? dri2_ctx->dri_context : NULL, |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3533 | dri2_sync->fence, wait_flags, |
| 3534 | timeout)) |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3535 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 3536 | else |
| 3537 | ret = EGL_TIMEOUT_EXPIRED_KHR; |
| 3538 | break; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3539 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3540 | case EGL_SYNC_REUSABLE_KHR: |
| 3541 | if (dri2_ctx && dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR && |
| 3542 | (flags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR)) { |
| 3543 | /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */ |
Eric Engestrom | 7823cfe | 2017-09-26 12:16:33 +0100 | [diff] [blame] | 3544 | dri2_gl_flush(); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/ |
| 3548 | if (timeout == EGL_FOREVER_KHR) { |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3549 | mtx_lock(&dri2_sync->mutex); |
| 3550 | cnd_wait(&dri2_sync->cond, &dri2_sync->mutex); |
Matt Turner | 53f64a8 | 2016-05-16 14:43:26 -0700 | [diff] [blame] | 3551 | mtx_unlock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3552 | } else { |
| 3553 | /* if reusable sync has not been yet signaled */ |
| 3554 | if (dri2_sync->base.SyncStatus != EGL_SIGNALED_KHR) { |
Nicolai Hähnle | f1a3648 | 2017-10-22 17:38:45 +0200 | [diff] [blame] | 3555 | /* timespecs for cnd_timedwait */ |
| 3556 | struct timespec current; |
| 3557 | struct timespec expire; |
| 3558 | |
| 3559 | /* We override the clock to monotonic when creating the condition |
| 3560 | * variable. */ |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3561 | clock_gettime(CLOCK_MONOTONIC, ¤t); |
| 3562 | |
| 3563 | /* calculating when to expire */ |
Nicolai Hähnle | f1a3648 | 2017-10-22 17:38:45 +0200 | [diff] [blame] | 3564 | expire.tv_nsec = timeout % 1000000000L; |
| 3565 | expire.tv_sec = timeout / 1000000000L; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3566 | |
Nicolai Hähnle | f1a3648 | 2017-10-22 17:38:45 +0200 | [diff] [blame] | 3567 | expire.tv_nsec += current.tv_nsec; |
| 3568 | expire.tv_sec += current.tv_sec; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3569 | |
| 3570 | /* expire.nsec now is a number between 0 and 1999999998 */ |
Nicolai Hähnle | f1a3648 | 2017-10-22 17:38:45 +0200 | [diff] [blame] | 3571 | if (expire.tv_nsec > 999999999L) { |
| 3572 | expire.tv_sec++; |
| 3573 | expire.tv_nsec -= 1000000000L; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3576 | mtx_lock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3577 | ret = cnd_timedwait(&dri2_sync->cond, &dri2_sync->mutex, &expire); |
Matt Turner | 53f64a8 | 2016-05-16 14:43:26 -0700 | [diff] [blame] | 3578 | mtx_unlock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3579 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3580 | if (ret == thrd_busy) { |
| 3581 | if (dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) { |
| 3582 | ret = EGL_TIMEOUT_EXPIRED_KHR; |
| 3583 | } else { |
| 3584 | _eglError(EGL_BAD_ACCESS, "eglClientWaitSyncKHR"); |
| 3585 | ret = EGL_FALSE; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3586 | } |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3587 | } |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | break; |
| 3591 | } |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3592 | dri2_egl_unref_sync(dri2_dpy, dri2_sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3593 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 3594 | return ret; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 3595 | } |
| 3596 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3597 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3598 | dri2_signal_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync, |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3599 | EGLenum mode) |
| 3600 | { |
| 3601 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 3602 | EGLint ret; |
| 3603 | |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 3604 | if (sync->Type != EGL_SYNC_REUSABLE_KHR) |
| 3605 | return _eglError(EGL_BAD_MATCH, "eglSignalSyncKHR"); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3606 | |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 3607 | if (mode != EGL_SIGNALED_KHR && mode != EGL_UNSIGNALED_KHR) |
| 3608 | return _eglError(EGL_BAD_ATTRIBUTE, "eglSignalSyncKHR"); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3609 | |
| 3610 | dri2_sync->base.SyncStatus = mode; |
| 3611 | |
| 3612 | if (mode == EGL_SIGNALED_KHR) { |
| 3613 | ret = cnd_broadcast(&dri2_sync->cond); |
| 3614 | |
| 3615 | /* fail to broadcast */ |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 3616 | if (ret) |
| 3617 | return _eglError(EGL_BAD_ACCESS, "eglSignalSyncKHR"); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | return EGL_TRUE; |
| 3621 | } |
| 3622 | |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 3623 | static EGLint |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3624 | dri2_server_wait_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync) |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 3625 | { |
| 3626 | _EGLContext *ctx = _eglGetCurrentContext(); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3627 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 3628 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 3629 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 3630 | |
| 3631 | dri2_dpy->fence->server_wait_sync(dri2_ctx->dri_context, |
| 3632 | dri2_sync->fence, 0); |
| 3633 | return EGL_TRUE; |
| 3634 | } |
| 3635 | |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 3636 | static int |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3637 | dri2_interop_query_device_info(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 3638 | struct mesa_glinterop_device_info *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 3639 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3640 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 3641 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 3642 | |
| 3643 | if (!dri2_dpy->interop) |
| 3644 | return MESA_GLINTEROP_UNSUPPORTED; |
| 3645 | |
| 3646 | return dri2_dpy->interop->query_device_info(dri2_ctx->dri_context, out); |
| 3647 | } |
| 3648 | |
| 3649 | static int |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3650 | dri2_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 3651 | struct mesa_glinterop_export_in *in, |
| 3652 | struct mesa_glinterop_export_out *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 3653 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 3654 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 3655 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 3656 | |
| 3657 | if (!dri2_dpy->interop) |
| 3658 | return MESA_GLINTEROP_UNSUPPORTED; |
| 3659 | |
| 3660 | return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out); |
| 3661 | } |
| 3662 | |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 3663 | const _EGLDriver _eglDriver = { |
Eric Engestrom | d24e3ea | 2020-07-22 01:06:05 +0200 | [diff] [blame] | 3664 | .Initialize = dri2_initialize, |
| 3665 | .Terminate = dri2_terminate, |
| 3666 | .CreateContext = dri2_create_context, |
| 3667 | .DestroyContext = dri2_destroy_context, |
| 3668 | .MakeCurrent = dri2_make_current, |
| 3669 | .CreateWindowSurface = dri2_create_window_surface, |
| 3670 | .CreatePixmapSurface = dri2_create_pixmap_surface, |
| 3671 | .CreatePbufferSurface = dri2_create_pbuffer_surface, |
| 3672 | .DestroySurface = dri2_destroy_surface, |
| 3673 | .GetProcAddress = dri2_get_proc_address, |
| 3674 | .WaitClient = dri2_wait_client, |
| 3675 | .WaitNative = dri2_wait_native, |
| 3676 | .BindTexImage = dri2_bind_tex_image, |
| 3677 | .ReleaseTexImage = dri2_release_tex_image, |
| 3678 | .SwapInterval = dri2_swap_interval, |
| 3679 | .SwapBuffers = dri2_swap_buffers, |
| 3680 | .SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage, |
| 3681 | .SwapBuffersRegionNOK = dri2_swap_buffers_region, |
| 3682 | .SetDamageRegion = dri2_set_damage_region, |
| 3683 | .PostSubBufferNV = dri2_post_sub_buffer, |
| 3684 | .CopyBuffers = dri2_copy_buffers, |
| 3685 | .QueryBufferAge = dri2_query_buffer_age, |
| 3686 | .CreateImageKHR = dri2_create_image, |
| 3687 | .DestroyImageKHR = dri2_destroy_image_khr, |
| 3688 | .CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image, |
| 3689 | .QuerySurface = dri2_query_surface, |
| 3690 | .QueryDriverName = dri2_query_driver_name, |
| 3691 | .QueryDriverConfig = dri2_query_driver_config, |
Axel Davy | 63986f9 | 2015-01-14 20:36:04 +0100 | [diff] [blame] | 3692 | #ifdef HAVE_LIBDRM |
Eric Engestrom | d24e3ea | 2020-07-22 01:06:05 +0200 | [diff] [blame] | 3693 | .CreateDRMImageMESA = dri2_create_drm_image_mesa, |
| 3694 | .ExportDRMImageMESA = dri2_export_drm_image_mesa, |
| 3695 | .ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa, |
| 3696 | .ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa, |
| 3697 | .QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats, |
| 3698 | .QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers, |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 3699 | #endif |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3700 | #ifdef HAVE_WAYLAND_PLATFORM |
Eric Engestrom | d24e3ea | 2020-07-22 01:06:05 +0200 | [diff] [blame] | 3701 | .BindWaylandDisplayWL = dri2_bind_wayland_display_wl, |
| 3702 | .UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl, |
| 3703 | .QueryWaylandBufferWL = dri2_query_wayland_buffer_wl, |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 3704 | #endif |
Eric Engestrom | d24e3ea | 2020-07-22 01:06:05 +0200 | [diff] [blame] | 3705 | .GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium, |
| 3706 | .CreateSyncKHR = dri2_create_sync, |
| 3707 | .ClientWaitSyncKHR = dri2_client_wait_sync, |
| 3708 | .SignalSyncKHR = dri2_signal_sync, |
| 3709 | .WaitSyncKHR = dri2_server_wait_sync, |
| 3710 | .DestroySyncKHR = dri2_destroy_sync, |
| 3711 | .GLInteropQueryDeviceInfo = dri2_interop_query_device_info, |
| 3712 | .GLInteropExportObject = dri2_interop_export_object, |
| 3713 | .DupNativeFenceFDANDROID = dri2_dup_native_fence_fd, |
| 3714 | .SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs, |
| 3715 | }; |