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