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