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