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