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