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