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