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