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