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