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