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