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 | 8ed08e6 | 2014-11-07 03:42:15 +0000 | [diff] [blame] | 697 | /* All platforms but DRM call this function to create the screen, query the |
| 698 | * dri extensions, setup the vtables and populate the driver_configs. |
| 699 | * DRM inherits all that information from its display - GBM. |
| 700 | */ |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 701 | EGLBoolean |
| 702 | dri2_create_screen(_EGLDisplay *disp) |
| 703 | { |
| 704 | const __DRIextension **extensions; |
Emil Velikov | 532ec2e | 2016-07-15 12:47:37 +0100 | [diff] [blame] | 705 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 706 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 707 | if (dri2_dpy->image_driver) { |
| 708 | dri2_dpy->dri_screen = |
| 709 | dri2_dpy->image_driver->createNewScreen2(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 710 | dri2_dpy->loader_extensions, |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 711 | dri2_dpy->driver_extensions, |
| 712 | &dri2_dpy->driver_configs, |
| 713 | disp); |
| 714 | } else if (dri2_dpy->dri2) { |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 715 | if (dri2_dpy->dri2->base.version >= 4) { |
| 716 | dri2_dpy->dri_screen = |
| 717 | dri2_dpy->dri2->createNewScreen2(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 718 | dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 719 | dri2_dpy->driver_extensions, |
| 720 | &dri2_dpy->driver_configs, disp); |
| 721 | } else { |
| 722 | dri2_dpy->dri_screen = |
| 723 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 724 | dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 725 | &dri2_dpy->driver_configs, disp); |
| 726 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 727 | } else { |
| 728 | assert(dri2_dpy->swrast); |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 729 | if (dri2_dpy->swrast->base.version >= 4) { |
| 730 | dri2_dpy->dri_screen = |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 731 | dri2_dpy->swrast->createNewScreen2(0, dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 732 | dri2_dpy->driver_extensions, |
| 733 | &dri2_dpy->driver_configs, disp); |
| 734 | } else { |
| 735 | dri2_dpy->dri_screen = |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 736 | dri2_dpy->swrast->createNewScreen(0, dri2_dpy->loader_extensions, |
Eric Anholt | f93533d | 2013-09-27 11:39:25 -0700 | [diff] [blame] | 737 | &dri2_dpy->driver_configs, disp); |
| 738 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | if (dri2_dpy->dri_screen == NULL) { |
| 742 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
| 743 | return EGL_FALSE; |
| 744 | } |
| 745 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 746 | dri2_dpy->own_dri_screen = 1; |
| 747 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 748 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 749 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 750 | if (dri2_dpy->image_driver || dri2_dpy->dri2) { |
Emil Velikov | 38526bd | 2016-08-25 00:16:01 +0100 | [diff] [blame] | 751 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions, false)) |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 752 | goto cleanup_dri_screen; |
| 753 | } else { |
| 754 | assert(dri2_dpy->swrast); |
Emil Velikov | 38526bd | 2016-08-25 00:16:01 +0100 | [diff] [blame] | 755 | if (!dri2_bind_extensions(dri2_dpy, swrast_core_extensions, extensions, false)) |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 756 | goto cleanup_dri_screen; |
| 757 | } |
| 758 | |
Emil Velikov | 3948ad8 | 2016-08-25 00:51:05 +0100 | [diff] [blame] | 759 | dri2_bind_extensions(dri2_dpy, optional_core_extensions, extensions, true); |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 760 | dri2_setup_screen(disp); |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 761 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 762 | return EGL_TRUE; |
| 763 | |
| 764 | cleanup_dri_screen: |
| 765 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 766 | |
| 767 | return EGL_FALSE; |
| 768 | } |
| 769 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 770 | /** |
| 771 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 772 | * |
| 773 | * This must be guaranteed to be called exactly once, even if eglInitialize is |
| 774 | * called many times (without a eglTerminate in between). |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 775 | */ |
| 776 | static EGLBoolean |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 777 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 778 | { |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 779 | EGLBoolean ret = EGL_FALSE; |
| 780 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 781 | |
| 782 | /* In the case where the application calls eglMakeCurrent(context1), |
| 783 | * eglTerminate, then eglInitialize again (without a call to eglReleaseThread |
| 784 | * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still |
| 785 | * initialized, as we need it to be able to free context1 correctly. |
| 786 | * |
| 787 | * It would probably be safest to forcibly release the display with |
| 788 | * dri2_display_release, to make sure the display is reinitialized correctly. |
| 789 | * However, the EGL spec states that we need to keep a reference to the |
| 790 | * current context (so we cannot call dri2_make_current(NULL)), and therefore |
| 791 | * we would leak context1 as we would be missing the old display connection |
| 792 | * to free it up correctly. |
| 793 | */ |
| 794 | if (dri2_dpy) { |
| 795 | dri2_dpy->ref_count++; |
| 796 | return EGL_TRUE; |
| 797 | } |
| 798 | |
Chia-I Wu | a22a332 | 2011-01-13 04:40:38 +0800 | [diff] [blame] | 799 | /* not until swrast_dri is supported */ |
| 800 | if (disp->Options.UseFallback) |
| 801 | return EGL_FALSE; |
| 802 | |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 803 | /* Nothing to initialize for a test only display */ |
| 804 | if (disp->Options.TestOnly) |
| 805 | return EGL_TRUE; |
| 806 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 807 | switch (disp->Platform) { |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 808 | #ifdef HAVE_SURFACELESS_PLATFORM |
| 809 | case _EGL_PLATFORM_SURFACELESS: |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 810 | ret = dri2_initialize_surfaceless(drv, disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 811 | break; |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 812 | #endif |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 813 | #ifdef HAVE_X11_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 814 | case _EGL_PLATFORM_X11: |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 815 | ret = dri2_initialize_x11(drv, disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 816 | break; |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 817 | #endif |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 818 | #ifdef HAVE_DRM_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 819 | case _EGL_PLATFORM_DRM: |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 820 | ret = dri2_initialize_drm(drv, disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 821 | break; |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 822 | #endif |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 823 | #ifdef HAVE_WAYLAND_PLATFORM |
| 824 | case _EGL_PLATFORM_WAYLAND: |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 825 | ret = dri2_initialize_wayland(drv, disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 826 | break; |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 827 | #endif |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 828 | #ifdef HAVE_ANDROID_PLATFORM |
| 829 | case _EGL_PLATFORM_ANDROID: |
Nicolas Boichat | 4f3f8bb | 2016-08-03 21:54:22 +0800 | [diff] [blame] | 830 | ret = dri2_initialize_android(drv, disp); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 831 | break; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 832 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 833 | default: |
Matt Turner | 0b4a688 | 2014-12-03 16:32:39 -0800 | [diff] [blame] | 834 | _eglLog(_EGL_WARNING, "No EGL platform enabled."); |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 835 | return EGL_FALSE; |
| 836 | } |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 837 | |
| 838 | if (ret) { |
| 839 | dri2_dpy = dri2_egl_display(disp); |
| 840 | |
| 841 | if (!dri2_dpy) { |
| 842 | return EGL_FALSE; |
| 843 | } |
| 844 | |
| 845 | dri2_dpy->ref_count++; |
| 846 | } |
| 847 | |
| 848 | return ret; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 849 | } |
| 850 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 851 | /** |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 852 | * Decrement display reference count, and free up display if necessary. |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 853 | */ |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 854 | static void |
Emil Velikov | 02f1158 | 2016-08-16 11:03:33 +0100 | [diff] [blame] | 855 | dri2_display_release(_EGLDisplay *disp) |
| 856 | { |
Emil Velikov | d6dcf3b | 2016-08-18 16:43:36 +0100 | [diff] [blame] | 857 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 858 | |
Emil Velikov | d6dcf3b | 2016-08-18 16:43:36 +0100 | [diff] [blame] | 859 | if (!disp) |
| 860 | return; |
| 861 | |
| 862 | dri2_dpy = dri2_egl_display(disp); |
| 863 | |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 864 | assert(dri2_dpy->ref_count > 0); |
| 865 | dri2_dpy->ref_count--; |
| 866 | |
| 867 | if (dri2_dpy->ref_count > 0) |
| 868 | return; |
| 869 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 870 | _eglCleanupDisplay(disp); |
Emil Velikov | 3e73c02 | 2017-05-11 17:13:33 +0100 | [diff] [blame^] | 871 | dri2_display_destroy(disp); |
| 872 | } |
| 873 | |
| 874 | void |
| 875 | dri2_display_destroy(_EGLDisplay *disp) |
| 876 | { |
| 877 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 878 | unsigned i; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 879 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 880 | if (dri2_dpy->own_dri_screen) |
| 881 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Emil Velikov | a1ac742 | 2015-09-10 14:41:38 +0100 | [diff] [blame] | 882 | if (dri2_dpy->fd >= 0) |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 883 | close(dri2_dpy->fd); |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 884 | if (dri2_dpy->driver) |
| 885 | dlclose(dri2_dpy->driver); |
Emil Velikov | 5cb1cad | 2014-06-02 12:26:17 +0100 | [diff] [blame] | 886 | free(dri2_dpy->driver_name); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 887 | |
Frank Binns | d6f669b | 2016-06-17 18:41:22 +0100 | [diff] [blame] | 888 | #ifdef HAVE_WAYLAND_PLATFORM |
| 889 | free(dri2_dpy->device_name); |
| 890 | #endif |
| 891 | |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 892 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 893 | #ifdef HAVE_X11_PLATFORM |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 894 | case _EGL_PLATFORM_X11: |
| 895 | if (dri2_dpy->own_device) { |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 896 | xcb_disconnect(dri2_dpy->conn); |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 897 | } |
| 898 | break; |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 899 | #endif |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 900 | #ifdef HAVE_DRM_PLATFORM |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 901 | case _EGL_PLATFORM_DRM: |
| 902 | if (dri2_dpy->own_device) { |
Emil Velikov | 628af2b | 2017-05-09 18:47:20 +0100 | [diff] [blame] | 903 | gbm_device_destroy(&dri2_dpy->gbm_dri->base); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 904 | } |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 905 | break; |
| 906 | #endif |
| 907 | #ifdef HAVE_WAYLAND_PLATFORM |
| 908 | case _EGL_PLATFORM_WAYLAND: |
Axel Davy | cdcfe48 | 2015-05-01 11:11:20 +0200 | [diff] [blame] | 909 | if (dri2_dpy->wl_drm) |
| 910 | wl_drm_destroy(dri2_dpy->wl_drm); |
| 911 | if (dri2_dpy->wl_shm) |
| 912 | wl_shm_destroy(dri2_dpy->wl_shm); |
Axel Davy | 6aaf09b | 2015-05-01 00:03:32 +0200 | [diff] [blame] | 913 | wl_registry_destroy(dri2_dpy->wl_registry); |
| 914 | wl_event_queue_destroy(dri2_dpy->wl_queue); |
Jonas Ådahl | 36b9976 | 2017-01-13 23:05:10 +0800 | [diff] [blame] | 915 | wl_proxy_wrapper_destroy(dri2_dpy->wl_dpy_wrapper); |
Chad Versace | f506ef6 | 2014-01-28 18:53:56 -0800 | [diff] [blame] | 916 | if (dri2_dpy->own_device) { |
| 917 | wl_display_disconnect(dri2_dpy->wl_dpy); |
| 918 | } |
| 919 | break; |
| 920 | #endif |
| 921 | default: |
| 922 | break; |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 923 | } |
| 924 | |
Emil Velikov | 38cec03 | 2014-11-07 03:33:56 +0000 | [diff] [blame] | 925 | /* The drm platform does not create the screen/driver_configs but reuses |
| 926 | * the ones from the gbm device. As such the gbm itself is responsible |
| 927 | * for the cleanup. |
| 928 | */ |
Tapani Pälli | 12196d1 | 2017-05-12 12:18:32 +0300 | [diff] [blame] | 929 | if (disp->Platform != _EGL_PLATFORM_DRM && dri2_dpy->driver_configs) { |
Emil Velikov | 38cec03 | 2014-11-07 03:33:56 +0000 | [diff] [blame] | 930 | for (i = 0; dri2_dpy->driver_configs[i]; i++) |
| 931 | free((__DRIconfig *) dri2_dpy->driver_configs[i]); |
| 932 | free(dri2_dpy->driver_configs); |
| 933 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 934 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 935 | disp->DriverData = NULL; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /** |
| 939 | * Called via eglTerminate(), drv->API.Terminate(). |
| 940 | * |
| 941 | * This must be guaranteed to be called exactly once, even if eglTerminate is |
| 942 | * called many times (without a eglInitialize in between). |
| 943 | */ |
| 944 | static EGLBoolean |
| 945 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 946 | { |
| 947 | /* Release all non-current Context/Surfaces. */ |
| 948 | _eglReleaseDisplayResources(drv, disp); |
| 949 | |
| 950 | dri2_display_release(disp); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 951 | |
| 952 | return EGL_TRUE; |
| 953 | } |
| 954 | |
Chad Versace | 5cf8536 | 2012-11-09 14:06:41 -0800 | [diff] [blame] | 955 | /** |
| 956 | * Set the error code after a call to |
| 957 | * dri2_egl_display::dri2::createContextAttribs. |
| 958 | */ |
| 959 | static void |
| 960 | dri2_create_context_attribs_error(int dri_error) |
| 961 | { |
| 962 | EGLint egl_error; |
| 963 | |
| 964 | switch (dri_error) { |
| 965 | case __DRI_CTX_ERROR_SUCCESS: |
| 966 | return; |
| 967 | |
| 968 | case __DRI_CTX_ERROR_NO_MEMORY: |
| 969 | egl_error = EGL_BAD_ALLOC; |
| 970 | break; |
| 971 | |
| 972 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 973 | * |
| 974 | * * If <config> does not support a client API context compatible |
| 975 | * with the requested API major and minor version, [...] context flags, |
| 976 | * and context reset notification behavior (for client API types where |
| 977 | * these attributes are supported), then an EGL_BAD_MATCH error is |
| 978 | * generated. |
| 979 | * |
| 980 | * * If an OpenGL ES context is requested and the values for |
| 981 | * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 982 | * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that |
| 983 | * is not defined, than an EGL_BAD_MATCH error is generated. |
| 984 | * |
| 985 | * * If an OpenGL context is requested, the requested version is |
| 986 | * greater than 3.2, and the value for attribute |
| 987 | * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any |
| 988 | * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and |
| 989 | * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than |
| 990 | * one of these bits set; or if the implementation does not support |
| 991 | * the requested profile, then an EGL_BAD_MATCH error is generated. |
| 992 | */ |
| 993 | case __DRI_CTX_ERROR_BAD_API: |
| 994 | case __DRI_CTX_ERROR_BAD_VERSION: |
| 995 | case __DRI_CTX_ERROR_BAD_FLAG: |
| 996 | egl_error = EGL_BAD_MATCH; |
| 997 | break; |
| 998 | |
| 999 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 1000 | * |
| 1001 | * * If an attribute name or attribute value in <attrib_list> is not |
| 1002 | * recognized (including unrecognized bits in bitmask attributes), |
| 1003 | * then an EGL_BAD_ATTRIBUTE error is generated." |
| 1004 | */ |
| 1005 | case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE: |
| 1006 | case __DRI_CTX_ERROR_UNKNOWN_FLAG: |
| 1007 | egl_error = EGL_BAD_ATTRIBUTE; |
| 1008 | break; |
| 1009 | |
| 1010 | default: |
| 1011 | assert(0); |
| 1012 | egl_error = EGL_BAD_MATCH; |
| 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | _eglError(egl_error, "dri2_create_context"); |
| 1017 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1018 | |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1019 | static bool |
| 1020 | dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx, |
| 1021 | struct dri2_egl_display *dri2_dpy, |
| 1022 | uint32_t *ctx_attribs, |
| 1023 | unsigned *num_attribs) |
| 1024 | { |
| 1025 | int pos = 0; |
| 1026 | |
| 1027 | assert(*num_attribs >= 8); |
| 1028 | |
| 1029 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MAJOR_VERSION; |
| 1030 | ctx_attribs[pos++] = dri2_ctx->base.ClientMajorVersion; |
| 1031 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MINOR_VERSION; |
| 1032 | ctx_attribs[pos++] = dri2_ctx->base.ClientMinorVersion; |
| 1033 | |
| 1034 | if (dri2_ctx->base.Flags != 0) { |
| 1035 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 1036 | * extension, don't even try to send it the robust-access flag. |
| 1037 | * It may explode. Instead, generate the required EGL error here. |
| 1038 | */ |
| 1039 | if ((dri2_ctx->base.Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0 |
| 1040 | && !dri2_dpy->robustness) { |
| 1041 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_FLAGS; |
| 1046 | ctx_attribs[pos++] = dri2_ctx->base.Flags; |
| 1047 | } |
| 1048 | |
| 1049 | if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) { |
| 1050 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 1051 | * extension, don't even try to send it a reset strategy. It may |
| 1052 | * explode. Instead, generate the required EGL error here. |
| 1053 | */ |
| 1054 | if (!dri2_dpy->robustness) { |
| 1055 | _eglError(EGL_BAD_CONFIG, "eglCreateContext"); |
| 1056 | return false; |
| 1057 | } |
| 1058 | |
| 1059 | ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RESET_STRATEGY; |
| 1060 | ctx_attribs[pos++] = __DRI_CTX_RESET_LOSE_CONTEXT; |
| 1061 | } |
| 1062 | |
| 1063 | *num_attribs = pos; |
| 1064 | |
| 1065 | return true; |
| 1066 | } |
| 1067 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1068 | /** |
| 1069 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 1070 | */ |
| 1071 | static _EGLContext * |
| 1072 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1073 | _EGLContext *share_list, const EGLint *attrib_list) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1074 | { |
| 1075 | struct dri2_egl_context *dri2_ctx; |
| 1076 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1077 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 1078 | __DRIcontext *shared = |
| 1079 | dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1080 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1081 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1082 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1083 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1084 | (void) drv; |
| 1085 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1086 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 1087 | if (!dri2_ctx) { |
| 1088 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 1089 | return NULL; |
| 1090 | } |
| 1091 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1092 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 1093 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1094 | |
Kenneth Graunke | 4061bbc | 2017-02-28 17:20:52 -0800 | [diff] [blame] | 1095 | /* The EGL_EXT_create_context_robustness spec says: |
| 1096 | * |
| 1097 | * "Add to the eglCreateContext context creation errors: [...] |
| 1098 | * |
| 1099 | * * If the reset notification behavior of <share_context> and the |
| 1100 | * newly created context are different then an EGL_BAD_MATCH error is |
| 1101 | * generated." |
| 1102 | */ |
| 1103 | if (share_list && share_list->ResetNotificationStrategy != |
| 1104 | dri2_ctx->base.ResetNotificationStrategy) { |
| 1105 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 1106 | goto cleanup; |
| 1107 | } |
| 1108 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1109 | switch (dri2_ctx->base.ClientAPI) { |
| 1110 | case EGL_OPENGL_ES_API: |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 1111 | switch (dri2_ctx->base.ClientMajorVersion) { |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1112 | case 1: |
| 1113 | api = __DRI_API_GLES; |
| 1114 | break; |
| 1115 | case 2: |
Ian Romanick | d786bf2 | 2013-01-15 14:17:46 -0800 | [diff] [blame] | 1116 | api = __DRI_API_GLES2; |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 1117 | break; |
Ian Romanick | dbecb41 | 2012-07-19 16:12:13 -0700 | [diff] [blame] | 1118 | case 3: |
Chad Versace | eb09940 | 2012-11-20 13:43:11 -0800 | [diff] [blame] | 1119 | api = __DRI_API_GLES3; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1120 | break; |
| 1121 | default: |
Emil Velikov | a3e78ba | 2014-05-08 16:49:45 +0100 | [diff] [blame] | 1122 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 1123 | free(dri2_ctx); |
| 1124 | return NULL; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1125 | } |
| 1126 | break; |
| 1127 | case EGL_OPENGL_API: |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1128 | if ((dri2_ctx->base.ClientMajorVersion >= 4 |
| 1129 | || (dri2_ctx->base.ClientMajorVersion == 3 |
| 1130 | && dri2_ctx->base.ClientMinorVersion >= 2)) |
| 1131 | && dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) |
| 1132 | api = __DRI_API_OPENGL_CORE; |
| 1133 | else |
| 1134 | api = __DRI_API_OPENGL; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1135 | break; |
| 1136 | default: |
| 1137 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
Vinson Lee | 080e91a | 2013-01-31 23:41:14 -0800 | [diff] [blame] | 1138 | free(dri2_ctx); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1139 | return NULL; |
| 1140 | } |
| 1141 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1142 | if (conf != NULL) { |
| 1143 | /* The config chosen here isn't necessarily |
| 1144 | * used for surfaces later. |
| 1145 | * A pixmap surface will use the single config. |
| 1146 | * This opportunity depends on disabling the |
| 1147 | * doubleBufferMode check in |
| 1148 | * src/mesa/main/context.c:check_compatible() |
| 1149 | */ |
Matt Turner | 164c827 | 2015-10-07 11:43:58 -0700 | [diff] [blame] | 1150 | if (dri2_config->dri_double_config[0]) |
| 1151 | dri_config = dri2_config->dri_double_config[0]; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1152 | else |
Matt Turner | 164c827 | 2015-10-07 11:43:58 -0700 | [diff] [blame] | 1153 | dri_config = dri2_config->dri_single_config[0]; |
Chia-I Wu | 357d3f3 | 2011-08-27 01:42:16 +0800 | [diff] [blame] | 1154 | |
| 1155 | /* EGL_WINDOW_BIT is set only when there is a dri_double_config. This |
| 1156 | * makes sure the back buffer will always be used. |
| 1157 | */ |
| 1158 | if (conf->SurfaceType & EGL_WINDOW_BIT) |
| 1159 | dri2_ctx->base.WindowRenderBuffer = EGL_BACK_BUFFER; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 1160 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1161 | else |
| 1162 | dri_config = NULL; |
| 1163 | |
Boyan Ding | f35198b | 2015-07-21 23:44:00 +0800 | [diff] [blame] | 1164 | if (dri2_dpy->image_driver) { |
| 1165 | unsigned error; |
| 1166 | unsigned num_attribs = 8; |
| 1167 | uint32_t ctx_attribs[8]; |
| 1168 | |
| 1169 | if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs, |
| 1170 | &num_attribs)) |
| 1171 | goto cleanup; |
| 1172 | |
| 1173 | dri2_ctx->dri_context = |
| 1174 | dri2_dpy->image_driver->createContextAttribs(dri2_dpy->dri_screen, |
| 1175 | api, |
| 1176 | dri_config, |
| 1177 | shared, |
| 1178 | num_attribs / 2, |
| 1179 | ctx_attribs, |
| 1180 | & error, |
| 1181 | dri2_ctx); |
| 1182 | dri2_create_context_attribs_error(error); |
| 1183 | } else if (dri2_dpy->dri2) { |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1184 | if (dri2_dpy->dri2->base.version >= 3) { |
| 1185 | unsigned error; |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1186 | unsigned num_attribs = 8; |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1187 | uint32_t ctx_attribs[8]; |
| 1188 | |
Boyan Ding | b9ea608 | 2015-07-21 23:43:56 +0800 | [diff] [blame] | 1189 | if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs, |
| 1190 | &num_attribs)) |
| 1191 | goto cleanup; |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1192 | |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1193 | dri2_ctx->dri_context = |
| 1194 | dri2_dpy->dri2->createContextAttribs(dri2_dpy->dri_screen, |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1195 | api, |
| 1196 | dri_config, |
| 1197 | shared, |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 1198 | num_attribs / 2, |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1199 | ctx_attribs, |
| 1200 | & error, |
| 1201 | dri2_ctx); |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1202 | dri2_create_context_attribs_error(error); |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 1203 | } else { |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1204 | dri2_ctx->dri_context = |
| 1205 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 1206 | api, |
| 1207 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 1208 | shared, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1209 | dri2_ctx); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 1210 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1211 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 1212 | assert(dri2_dpy->swrast); |
Boyan Ding | 6345d2d | 2015-07-21 23:43:57 +0800 | [diff] [blame] | 1213 | if (dri2_dpy->swrast->base.version >= 3) { |
| 1214 | unsigned error; |
| 1215 | unsigned num_attribs = 8; |
| 1216 | uint32_t ctx_attribs[8]; |
| 1217 | |
| 1218 | if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs, |
| 1219 | &num_attribs)) |
| 1220 | goto cleanup; |
| 1221 | |
| 1222 | dri2_ctx->dri_context = |
| 1223 | dri2_dpy->swrast->createContextAttribs(dri2_dpy->dri_screen, |
| 1224 | api, |
| 1225 | dri_config, |
| 1226 | shared, |
| 1227 | num_attribs / 2, |
| 1228 | ctx_attribs, |
| 1229 | & error, |
| 1230 | dri2_ctx); |
| 1231 | dri2_create_context_attribs_error(error); |
| 1232 | } else { |
| 1233 | dri2_ctx->dri_context = |
| 1234 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 1235 | api, |
| 1236 | dri_config, |
| 1237 | shared, |
| 1238 | dri2_ctx); |
| 1239 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1240 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1241 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1242 | if (!dri2_ctx->dri_context) |
| 1243 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1244 | |
| 1245 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1246 | |
| 1247 | cleanup: |
| 1248 | free(dri2_ctx); |
| 1249 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1250 | } |
| 1251 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1252 | /** |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1253 | * Called via eglDestroyContext(), drv->API.DestroyContext(). |
| 1254 | */ |
| 1255 | static EGLBoolean |
| 1256 | dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
| 1257 | { |
| 1258 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1259 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1260 | |
| 1261 | if (_eglPutContext(ctx)) { |
| 1262 | dri2_dpy->core->destroyContext(dri2_ctx->dri_context); |
| 1263 | free(dri2_ctx); |
| 1264 | } |
| 1265 | |
| 1266 | return EGL_TRUE; |
| 1267 | } |
| 1268 | |
Emil Velikov | 8cf83f9 | 2016-08-18 16:33:39 +0100 | [diff] [blame] | 1269 | static EGLBoolean |
| 1270 | dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) |
| 1271 | { |
| 1272 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1273 | |
| 1274 | if (!_eglPutSurface(surf)) |
| 1275 | return EGL_TRUE; |
| 1276 | |
| 1277 | return dri2_dpy->vtbl->destroy_surface(drv, dpy, surf); |
| 1278 | } |
| 1279 | |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1280 | /** |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1281 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 1282 | */ |
| 1283 | static EGLBoolean |
| 1284 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1285 | _EGLSurface *rsurf, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1286 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1287 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1288 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1289 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1290 | _EGLContext *old_ctx; |
| 1291 | _EGLSurface *old_dsurf, *old_rsurf; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1292 | _EGLSurface *tmp_dsurf, *tmp_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1293 | __DRIdrawable *ddraw, *rdraw; |
| 1294 | __DRIcontext *cctx; |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1295 | EGLBoolean unbind; |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1296 | |
| 1297 | if (!dri2_dpy) |
| 1298 | return _eglError(EGL_NOT_INITIALIZED, "eglMakeCurrent"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1299 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1300 | /* make new bindings */ |
Nicolas Boichat | 9bebef4 | 2016-07-15 16:24:20 +0800 | [diff] [blame] | 1301 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) { |
| 1302 | /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1303 | return EGL_FALSE; |
Nicolas Boichat | 9bebef4 | 2016-07-15 16:24:20 +0800 | [diff] [blame] | 1304 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1305 | |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1306 | /* flush before context switch */ |
| 1307 | if (old_ctx) |
| 1308 | dri2_drv->glFlush(); |
| 1309 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1310 | ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL; |
| 1311 | rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1312 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 1313 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 1314 | if (old_ctx) { |
| 1315 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 1316 | dri2_dpy->core->unbindContext(old_cctx); |
| 1317 | } |
| 1318 | |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1319 | unbind = (cctx == NULL && ddraw == NULL && rdraw == NULL); |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1320 | |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1321 | if (unbind || dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
| 1322 | dri2_destroy_surface(drv, disp, old_dsurf); |
| 1323 | dri2_destroy_surface(drv, disp, old_rsurf); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1324 | |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1325 | if (!unbind) |
| 1326 | dri2_dpy->ref_count++; |
| 1327 | if (old_ctx) { |
| 1328 | EGLDisplay old_disp = _eglGetDisplayHandle(old_ctx->Resource.Display); |
| 1329 | dri2_destroy_context(drv, disp, old_ctx); |
| 1330 | dri2_display_release(old_disp); |
Nicolas Boichat | 78e3cea | 2016-08-11 16:43:32 +0800 | [diff] [blame] | 1331 | } |
Nicolas Boichat | 9ee683f | 2016-07-22 11:27:41 +0800 | [diff] [blame] | 1332 | |
Emil Velikov | ebffa7b | 2016-10-14 16:07:33 +0100 | [diff] [blame] | 1333 | return EGL_TRUE; |
| 1334 | } else { |
| 1335 | /* undo the previous _eglBindContext */ |
| 1336 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); |
| 1337 | assert(&dri2_ctx->base == ctx && |
| 1338 | tmp_dsurf == dsurf && |
| 1339 | tmp_rsurf == rsurf); |
| 1340 | |
| 1341 | _eglPutSurface(dsurf); |
| 1342 | _eglPutSurface(rsurf); |
| 1343 | _eglPutContext(ctx); |
| 1344 | |
| 1345 | _eglPutSurface(old_dsurf); |
| 1346 | _eglPutSurface(old_rsurf); |
| 1347 | _eglPutContext(old_ctx); |
| 1348 | |
| 1349 | /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but |
| 1350 | * setting the error to EGL_BAD_MATCH is surely better than leaving it |
| 1351 | * as EGL_SUCCESS. |
| 1352 | */ |
| 1353 | return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1357 | __DRIdrawable * |
| 1358 | dri2_surface_get_dri_drawable(_EGLSurface *surf) |
| 1359 | { |
| 1360 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1361 | |
| 1362 | return dri2_surf->dri_drawable; |
| 1363 | } |
| 1364 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1365 | /* |
| 1366 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 1367 | */ |
| 1368 | static _EGLProc |
| 1369 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 1370 | { |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1371 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1372 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1373 | return dri2_drv->get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1374 | } |
| 1375 | |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1376 | static _EGLSurface* |
| 1377 | dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1378 | _EGLConfig *conf, void *native_window, |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1379 | const EGLint *attrib_list) |
| 1380 | { |
| 1381 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1382 | return dri2_dpy->vtbl->create_window_surface(drv, dpy, conf, native_window, |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1383 | attrib_list); |
| 1384 | } |
| 1385 | |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1386 | static _EGLSurface* |
| 1387 | dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1388 | _EGLConfig *conf, void *native_pixmap, |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1389 | const EGLint *attrib_list) |
| 1390 | { |
| 1391 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1392 | return dri2_dpy->vtbl->create_pixmap_surface(drv, dpy, conf, native_pixmap, |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 1393 | attrib_list); |
| 1394 | } |
| 1395 | |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1396 | static _EGLSurface* |
| 1397 | dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, |
| 1398 | _EGLConfig *conf, const EGLint *attrib_list) |
| 1399 | { |
| 1400 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1401 | return dri2_dpy->vtbl->create_pbuffer_surface(drv, dpy, conf, attrib_list); |
| 1402 | } |
| 1403 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1404 | static EGLBoolean |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 1405 | dri2_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
| 1406 | EGLint interval) |
| 1407 | { |
| 1408 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1409 | return dri2_dpy->vtbl->swap_interval(drv, dpy, surf, interval); |
| 1410 | } |
| 1411 | |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1412 | /** |
| 1413 | * Asks the client API to flush any rendering to the drawable so that we can |
| 1414 | * do our swapbuffers. |
| 1415 | */ |
| 1416 | void |
| 1417 | dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw) |
| 1418 | { |
| 1419 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1420 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(draw); |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1421 | |
| 1422 | if (dri2_dpy->flush) { |
| 1423 | if (dri2_dpy->flush->base.version >= 4) { |
| 1424 | /* We know there's a current context because: |
| 1425 | * |
| 1426 | * "If surface is not bound to the calling thread’s current |
| 1427 | * context, an EGL_BAD_SURFACE error is generated." |
| 1428 | */ |
| 1429 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 1430 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1431 | |
| 1432 | /* From the EGL 1.4 spec (page 52): |
| 1433 | * |
| 1434 | * "The contents of ancillary buffers are always undefined |
| 1435 | * after calling eglSwapBuffers." |
| 1436 | */ |
| 1437 | dri2_dpy->flush->flush_with_flags(dri2_ctx->dri_context, |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1438 | dri_drawable, |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1439 | __DRI2_FLUSH_DRAWABLE | |
| 1440 | __DRI2_FLUSH_INVALIDATE_ANCILLARY, |
| 1441 | __DRI2_THROTTLE_SWAPBUFFER); |
| 1442 | } else { |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1443 | dri2_dpy->flush->flush(dri_drawable); |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 1448 | static EGLBoolean |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 1449 | dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) |
| 1450 | { |
| 1451 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1452 | return dri2_dpy->vtbl->swap_buffers(drv, dpy, surf); |
| 1453 | } |
| 1454 | |
| 1455 | static EGLBoolean |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 1456 | dri2_swap_buffers_with_damage(_EGLDriver *drv, _EGLDisplay *dpy, |
| 1457 | _EGLSurface *surf, |
| 1458 | const EGLint *rects, EGLint n_rects) |
| 1459 | { |
| 1460 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1461 | return dri2_dpy->vtbl->swap_buffers_with_damage(drv, dpy, surf, |
| 1462 | rects, n_rects); |
| 1463 | } |
| 1464 | |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1465 | static EGLBoolean |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1466 | dri2_swap_buffers_region(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
| 1467 | EGLint numRects, const EGLint *rects) |
| 1468 | { |
| 1469 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1470 | return dri2_dpy->vtbl->swap_buffers_region(drv, dpy, surf, numRects, rects); |
| 1471 | } |
| 1472 | |
| 1473 | static EGLBoolean |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1474 | dri2_post_sub_buffer(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
| 1475 | EGLint x, EGLint y, EGLint width, EGLint height) |
| 1476 | { |
| 1477 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1478 | return dri2_dpy->vtbl->post_sub_buffer(drv, dpy, surf, x, y, width, height); |
| 1479 | } |
| 1480 | |
| 1481 | static EGLBoolean |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1482 | dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1483 | void *native_pixmap_target) |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1484 | { |
| 1485 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 1486 | return dri2_dpy->vtbl->copy_buffers(drv, dpy, surf, native_pixmap_target); |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1489 | static EGLint |
| 1490 | dri2_query_buffer_age(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) |
| 1491 | { |
| 1492 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1493 | return dri2_dpy->vtbl->query_buffer_age(drv, dpy, surf); |
| 1494 | } |
| 1495 | |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 1496 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1497 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1498 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1499 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1500 | _EGLSurface *surf = ctx->DrawSurface; |
| 1501 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1502 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1503 | (void) drv; |
| 1504 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1505 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 1506 | * we need to copy fake to real here.*/ |
| 1507 | |
José Fonseca | 5048e69 | 2013-02-05 13:43:01 +0000 | [diff] [blame] | 1508 | if (dri2_dpy->flush != NULL) |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1509 | dri2_dpy->flush->flush(dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1510 | |
| 1511 | return EGL_TRUE; |
| 1512 | } |
| 1513 | |
| 1514 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1515 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1516 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1517 | (void) drv; |
| 1518 | (void) disp; |
| 1519 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1520 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 1521 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 1522 | /* glXWaitX(); */ |
| 1523 | |
| 1524 | return EGL_TRUE; |
| 1525 | } |
| 1526 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1527 | static EGLBoolean |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1528 | dri2_bind_tex_image(_EGLDriver *drv, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1529 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1530 | { |
| 1531 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1532 | struct dri2_egl_context *dri2_ctx; |
| 1533 | _EGLContext *ctx; |
| 1534 | GLint format, target; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1535 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1536 | |
| 1537 | ctx = _eglGetCurrentContext(); |
| 1538 | dri2_ctx = dri2_egl_context(ctx); |
| 1539 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1540 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1541 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1542 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1543 | switch (surf->TextureFormat) { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1544 | case EGL_TEXTURE_RGB: |
| 1545 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 1546 | break; |
| 1547 | case EGL_TEXTURE_RGBA: |
| 1548 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 1549 | break; |
| 1550 | default: |
Brian Paul | 54070a9 | 2015-05-29 16:01:37 -0600 | [diff] [blame] | 1551 | assert(!"Unexpected texture format in dri2_bind_tex_image()"); |
| 1552 | format = __DRI_TEXTURE_FORMAT_RGBA; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1553 | } |
| 1554 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1555 | switch (surf->TextureTarget) { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1556 | case EGL_TEXTURE_2D: |
| 1557 | target = GL_TEXTURE_2D; |
| 1558 | break; |
| 1559 | default: |
Brian Paul | 54070a9 | 2015-05-29 16:01:37 -0600 | [diff] [blame] | 1560 | target = GL_TEXTURE_2D; |
| 1561 | assert(!"Unexpected texture target in dri2_bind_tex_image()"); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 1564 | dri2_dpy->tex_buffer->setTexBuffer2(dri2_ctx->dri_context, |
| 1565 | target, format, |
| 1566 | dri_drawable); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1567 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1568 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static EGLBoolean |
| 1572 | dri2_release_tex_image(_EGLDriver *drv, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1573 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1574 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 1575 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 1576 | struct dri2_egl_context *dri2_ctx; |
| 1577 | _EGLContext *ctx; |
| 1578 | GLint target; |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1579 | __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 1580 | |
| 1581 | ctx = _eglGetCurrentContext(); |
| 1582 | dri2_ctx = dri2_egl_context(ctx); |
| 1583 | |
| 1584 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 1585 | return EGL_FALSE; |
| 1586 | |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1587 | switch (surf->TextureTarget) { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 1588 | case EGL_TEXTURE_2D: |
| 1589 | target = GL_TEXTURE_2D; |
| 1590 | break; |
| 1591 | default: |
| 1592 | assert(0); |
| 1593 | } |
Emil Velikov | 9b42fd1 | 2014-02-18 03:04:03 +0000 | [diff] [blame] | 1594 | |
| 1595 | if (dri2_dpy->tex_buffer->base.version >= 3 && |
| 1596 | dri2_dpy->tex_buffer->releaseTexBuffer != NULL) { |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 1597 | dri2_dpy->tex_buffer->releaseTexBuffer(dri2_ctx->dri_context, |
| 1598 | target, dri_drawable); |
Emil Velikov | 9b42fd1 | 2014-02-18 03:04:03 +0000 | [diff] [blame] | 1599 | } |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1600 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1601 | return EGL_TRUE; |
| 1602 | } |
| 1603 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1604 | static _EGLImage* |
| 1605 | dri2_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, |
| 1606 | EGLenum target, EGLClientBuffer buffer, |
| 1607 | const EGLint *attr_list) |
| 1608 | { |
| 1609 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1610 | return dri2_dpy->vtbl->create_image(drv, dpy, ctx, target, buffer, |
| 1611 | attr_list); |
| 1612 | } |
| 1613 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1614 | static _EGLImage * |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1615 | dri2_create_image_from_dri(_EGLDisplay *disp, __DRIimage *dri_image) |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1616 | { |
| 1617 | struct dri2_egl_image *dri2_img; |
| 1618 | |
| 1619 | if (dri_image == NULL) { |
| 1620 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 1621 | return NULL; |
| 1622 | } |
| 1623 | |
| 1624 | dri2_img = malloc(sizeof *dri2_img); |
| 1625 | if (!dri2_img) { |
| 1626 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 1627 | return NULL; |
| 1628 | } |
| 1629 | |
| 1630 | if (!_eglInitImage(&dri2_img->base, disp)) { |
| 1631 | free(dri2_img); |
| 1632 | return NULL; |
| 1633 | } |
| 1634 | |
| 1635 | dri2_img->dri_image = dri_image; |
| 1636 | |
| 1637 | return &dri2_img->base; |
| 1638 | } |
| 1639 | |
| 1640 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1641 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1642 | EGLClientBuffer buffer, |
| 1643 | const EGLint *attr_list) |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1644 | { |
| 1645 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1646 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 1647 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1648 | __DRIimage *dri_image; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1649 | |
| 1650 | if (renderbuffer == 0) { |
| 1651 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1652 | return EGL_NO_IMAGE_KHR; |
| 1653 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1654 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1655 | dri_image = |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1656 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1657 | renderbuffer, NULL); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1658 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1659 | return dri2_create_image_from_dri(disp, dri_image); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 1662 | #ifdef HAVE_WAYLAND_PLATFORM |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1663 | |
| 1664 | /* This structure describes how a wl_buffer maps to one or more |
| 1665 | * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the |
| 1666 | * offsets and strides of the planes in the buffer. This table maps a |
| 1667 | * wl_drm format code to a description of the planes in the buffer |
| 1668 | * that lets us create a __DRIimage for each of the planes. */ |
| 1669 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1670 | static const struct wl_drm_components_descriptor { |
| 1671 | uint32_t dri_components; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1672 | EGLint components; |
| 1673 | int nplanes; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1674 | } wl_drm_components[] = { |
| 1675 | { __DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1 }, |
| 1676 | { __DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1 }, |
| 1677 | { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 }, |
| 1678 | { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 }, |
| 1679 | { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 }, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1680 | }; |
| 1681 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1682 | static _EGLImage * |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1683 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1684 | EGLClientBuffer _buffer, |
| 1685 | const EGLint *attr_list) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1686 | { |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 1687 | struct wl_drm_buffer *buffer; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1688 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1689 | const struct wl_drm_components_descriptor *f; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1690 | __DRIimage *dri_image; |
| 1691 | _EGLImageAttribs attrs; |
| 1692 | EGLint err; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1693 | int32_t plane; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1694 | |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 1695 | buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_drm, |
| 1696 | (struct wl_resource *) _buffer); |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 1697 | if (!buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1698 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1699 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1700 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1701 | plane = attrs.PlaneWL; |
| 1702 | if (err != EGL_SUCCESS) { |
| 1703 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 1704 | return NULL; |
| 1705 | } |
| 1706 | |
| 1707 | f = buffer->driver_format; |
| 1708 | if (plane < 0 || plane >= f->nplanes) { |
| 1709 | _eglError(EGL_BAD_PARAMETER, |
| 1710 | "dri2_create_image_wayland_wl_buffer (plane out of bounds)"); |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1714 | dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1715 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1716 | if (dri_image == NULL) { |
| 1717 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 1718 | return NULL; |
| 1719 | } |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1720 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1721 | return dri2_create_image_from_dri(disp, dri_image); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1722 | } |
| 1723 | #endif |
| 1724 | |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 1725 | static EGLBoolean |
| 1726 | dri2_get_sync_values_chromium(_EGLDisplay *dpy, _EGLSurface *surf, |
| 1727 | EGLuint64KHR *ust, EGLuint64KHR *msc, |
| 1728 | EGLuint64KHR *sbc) |
| 1729 | { |
| 1730 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1731 | return dri2_dpy->vtbl->get_sync_values(dpy, surf, ust, msc, sbc); |
| 1732 | } |
| 1733 | |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 1734 | /** |
| 1735 | * Set the error code after a call to |
| 1736 | * dri2_egl_image::dri_image::createImageFromTexture. |
| 1737 | */ |
| 1738 | static void |
| 1739 | dri2_create_image_khr_texture_error(int dri_error) |
| 1740 | { |
| 1741 | EGLint egl_error; |
| 1742 | |
| 1743 | switch (dri_error) { |
| 1744 | case __DRI_IMAGE_ERROR_SUCCESS: |
| 1745 | return; |
| 1746 | |
| 1747 | case __DRI_IMAGE_ERROR_BAD_ALLOC: |
| 1748 | egl_error = EGL_BAD_ALLOC; |
| 1749 | break; |
| 1750 | |
| 1751 | case __DRI_IMAGE_ERROR_BAD_MATCH: |
| 1752 | egl_error = EGL_BAD_MATCH; |
| 1753 | break; |
| 1754 | |
| 1755 | case __DRI_IMAGE_ERROR_BAD_PARAMETER: |
| 1756 | egl_error = EGL_BAD_PARAMETER; |
| 1757 | break; |
| 1758 | |
Frank Binns | cfc3200 | 2015-07-31 09:11:46 +0100 | [diff] [blame] | 1759 | case __DRI_IMAGE_ERROR_BAD_ACCESS: |
| 1760 | egl_error = EGL_BAD_ACCESS; |
| 1761 | break; |
| 1762 | |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 1763 | default: |
| 1764 | assert(0); |
| 1765 | egl_error = EGL_BAD_MATCH; |
| 1766 | break; |
| 1767 | } |
| 1768 | |
| 1769 | _eglError(egl_error, "dri2_create_image_khr_texture"); |
| 1770 | } |
| 1771 | |
| 1772 | static _EGLImage * |
| 1773 | dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1774 | EGLenum target, |
| 1775 | EGLClientBuffer buffer, |
| 1776 | const EGLint *attr_list) |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 1777 | { |
| 1778 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1779 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1780 | struct dri2_egl_image *dri2_img; |
| 1781 | GLuint texture = (GLuint) (uintptr_t) buffer; |
| 1782 | _EGLImageAttribs attrs; |
| 1783 | GLuint depth; |
| 1784 | GLenum gl_target; |
| 1785 | unsigned error; |
| 1786 | |
| 1787 | if (texture == 0) { |
| 1788 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1789 | return EGL_NO_IMAGE_KHR; |
| 1790 | } |
| 1791 | |
| 1792 | if (_eglParseImageAttribList(&attrs, disp, attr_list) != EGL_SUCCESS) |
| 1793 | return EGL_NO_IMAGE_KHR; |
| 1794 | |
| 1795 | switch (target) { |
| 1796 | case EGL_GL_TEXTURE_2D_KHR: |
| 1797 | depth = 0; |
| 1798 | gl_target = GL_TEXTURE_2D; |
| 1799 | break; |
| 1800 | case EGL_GL_TEXTURE_3D_KHR: |
Anatoli Antonovitch | b193f2b | 2015-06-10 14:42:31 +0200 | [diff] [blame] | 1801 | if (disp->Extensions.KHR_gl_texture_3D_image) { |
| 1802 | depth = attrs.GLTextureZOffset; |
| 1803 | gl_target = GL_TEXTURE_3D; |
| 1804 | break; |
| 1805 | } |
| 1806 | else { |
| 1807 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1808 | return EGL_NO_IMAGE_KHR; |
| 1809 | } |
Abdiel Janulgue | 7b7af48 | 2012-11-27 15:19:54 +0200 | [diff] [blame] | 1810 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 1811 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 1812 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 1813 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 1814 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 1815 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
| 1816 | depth = target - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR; |
| 1817 | gl_target = GL_TEXTURE_CUBE_MAP; |
| 1818 | break; |
| 1819 | default: |
| 1820 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1821 | return EGL_NO_IMAGE_KHR; |
| 1822 | } |
| 1823 | |
| 1824 | dri2_img = malloc(sizeof *dri2_img); |
| 1825 | if (!dri2_img) { |
| 1826 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1827 | return EGL_NO_IMAGE_KHR; |
| 1828 | } |
| 1829 | |
| 1830 | if (!_eglInitImage(&dri2_img->base, disp)) { |
| 1831 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1832 | free(dri2_img); |
| 1833 | return EGL_NO_IMAGE_KHR; |
| 1834 | } |
| 1835 | |
| 1836 | dri2_img->dri_image = |
| 1837 | dri2_dpy->image->createImageFromTexture(dri2_ctx->dri_context, |
| 1838 | gl_target, |
| 1839 | texture, |
| 1840 | depth, |
| 1841 | attrs.GLTextureLevel, |
| 1842 | &error, |
| 1843 | dri2_img); |
| 1844 | dri2_create_image_khr_texture_error(error); |
| 1845 | |
| 1846 | if (!dri2_img->dri_image) { |
| 1847 | free(dri2_img); |
| 1848 | return EGL_NO_IMAGE_KHR; |
| 1849 | } |
| 1850 | return &dri2_img->base; |
| 1851 | } |
| 1852 | |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 1853 | static EGLBoolean |
| 1854 | dri2_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
| 1855 | EGLint attribute, EGLint *value) |
| 1856 | { |
| 1857 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1858 | if (!dri2_dpy->vtbl->query_surface) |
| 1859 | return _eglQuerySurface(drv, dpy, surf, attribute, value); |
| 1860 | return dri2_dpy->vtbl->query_surface(drv, dpy, surf, attribute, value); |
| 1861 | } |
| 1862 | |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1863 | static struct wl_buffer* |
| 1864 | dri2_create_wayland_buffer_from_image(_EGLDriver *drv, _EGLDisplay *dpy, |
| 1865 | _EGLImage *img) |
| 1866 | { |
| 1867 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 1868 | return dri2_dpy->vtbl->create_wayland_buffer_from_image(drv, dpy, img); |
| 1869 | } |
| 1870 | |
Axel Davy | 63986f9 | 2015-01-14 20:36:04 +0100 | [diff] [blame] | 1871 | #ifdef HAVE_LIBDRM |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 1872 | static _EGLImage * |
| 1873 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1874 | EGLClientBuffer buffer, const EGLint *attr_list) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 1875 | { |
| 1876 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1877 | EGLint format, name, pitch, err; |
| 1878 | _EGLImageAttribs attrs; |
| 1879 | __DRIimage *dri_image; |
| 1880 | |
| 1881 | name = (EGLint) (uintptr_t) buffer; |
| 1882 | |
| 1883 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1884 | if (err != EGL_SUCCESS) |
| 1885 | return NULL; |
| 1886 | |
| 1887 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 1888 | attrs.DRMBufferStrideMESA <= 0) { |
| 1889 | _eglError(EGL_BAD_PARAMETER, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1890 | "bad width, height or stride"); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 1891 | return NULL; |
| 1892 | } |
| 1893 | |
| 1894 | switch (attrs.DRMBufferFormatMESA) { |
| 1895 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1896 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1897 | pitch = attrs.DRMBufferStrideMESA; |
| 1898 | break; |
| 1899 | default: |
| 1900 | _eglError(EGL_BAD_PARAMETER, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1901 | "dri2_create_image_khr: unsupported pixmap depth"); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 1902 | return NULL; |
| 1903 | } |
| 1904 | |
| 1905 | dri_image = |
| 1906 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 1907 | attrs.Width, |
| 1908 | attrs.Height, |
| 1909 | format, |
| 1910 | name, |
| 1911 | pitch, |
| 1912 | NULL); |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 1913 | |
| 1914 | return dri2_create_image_from_dri(disp, dri_image); |
| 1915 | } |
| 1916 | |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 1917 | static EGLBoolean |
| 1918 | dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) |
| 1919 | { |
| 1920 | unsigned i; |
| 1921 | |
| 1922 | /** |
| 1923 | * The spec says: |
| 1924 | * |
| 1925 | * "Required attributes and their values are as follows: |
| 1926 | * |
| 1927 | * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels |
| 1928 | * |
| 1929 | * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified |
| 1930 | * by drm_fourcc.h and used as the pixel_format parameter of the |
| 1931 | * drm_mode_fb_cmd2 ioctl." |
| 1932 | * |
| 1933 | * and |
| 1934 | * |
| 1935 | * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is |
| 1936 | * incomplete, EGL_BAD_PARAMETER is generated." |
| 1937 | */ |
| 1938 | if (attrs->Width <= 0 || attrs->Height <= 0 || |
| 1939 | !attrs->DMABufFourCC.IsPresent) { |
| 1940 | _eglError(EGL_BAD_PARAMETER, "attribute(s) missing"); |
| 1941 | return EGL_FALSE; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Also: |
| 1946 | * |
| 1947 | * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values |
| 1948 | * specified for a plane's pitch or offset isn't supported by EGL, |
| 1949 | * EGL_BAD_ACCESS is generated." |
| 1950 | */ |
| 1951 | for (i = 0; i < ARRAY_SIZE(attrs->DMABufPlanePitches); ++i) { |
| 1952 | if (attrs->DMABufPlanePitches[i].IsPresent && |
| 1953 | attrs->DMABufPlanePitches[i].Value <= 0) { |
| 1954 | _eglError(EGL_BAD_ACCESS, "invalid pitch"); |
| 1955 | return EGL_FALSE; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | return EGL_TRUE; |
| 1960 | } |
| 1961 | |
| 1962 | /* Returns the total number of file descriptors. Zero indicates an error. */ |
| 1963 | static unsigned |
| 1964 | dri2_check_dma_buf_format(const _EGLImageAttribs *attrs) |
| 1965 | { |
| 1966 | unsigned i, plane_n; |
| 1967 | |
| 1968 | switch (attrs->DMABufFourCC.Value) { |
Chad Versace | fd865d5 | 2015-06-23 15:48:17 -0700 | [diff] [blame] | 1969 | case DRM_FORMAT_R8: |
| 1970 | case DRM_FORMAT_RG88: |
| 1971 | case DRM_FORMAT_GR88: |
Rainer Hochecker | 09b140a | 2017-01-05 16:58:56 +0100 | [diff] [blame] | 1972 | case DRM_FORMAT_R16: |
| 1973 | case DRM_FORMAT_GR1616: |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 1974 | case DRM_FORMAT_RGB332: |
| 1975 | case DRM_FORMAT_BGR233: |
| 1976 | case DRM_FORMAT_XRGB4444: |
| 1977 | case DRM_FORMAT_XBGR4444: |
| 1978 | case DRM_FORMAT_RGBX4444: |
| 1979 | case DRM_FORMAT_BGRX4444: |
| 1980 | case DRM_FORMAT_ARGB4444: |
| 1981 | case DRM_FORMAT_ABGR4444: |
| 1982 | case DRM_FORMAT_RGBA4444: |
| 1983 | case DRM_FORMAT_BGRA4444: |
| 1984 | case DRM_FORMAT_XRGB1555: |
| 1985 | case DRM_FORMAT_XBGR1555: |
| 1986 | case DRM_FORMAT_RGBX5551: |
| 1987 | case DRM_FORMAT_BGRX5551: |
| 1988 | case DRM_FORMAT_ARGB1555: |
| 1989 | case DRM_FORMAT_ABGR1555: |
| 1990 | case DRM_FORMAT_RGBA5551: |
| 1991 | case DRM_FORMAT_BGRA5551: |
| 1992 | case DRM_FORMAT_RGB565: |
| 1993 | case DRM_FORMAT_BGR565: |
| 1994 | case DRM_FORMAT_RGB888: |
| 1995 | case DRM_FORMAT_BGR888: |
| 1996 | case DRM_FORMAT_XRGB8888: |
| 1997 | case DRM_FORMAT_XBGR8888: |
| 1998 | case DRM_FORMAT_RGBX8888: |
| 1999 | case DRM_FORMAT_BGRX8888: |
| 2000 | case DRM_FORMAT_ARGB8888: |
| 2001 | case DRM_FORMAT_ABGR8888: |
| 2002 | case DRM_FORMAT_RGBA8888: |
| 2003 | case DRM_FORMAT_BGRA8888: |
| 2004 | case DRM_FORMAT_XRGB2101010: |
| 2005 | case DRM_FORMAT_XBGR2101010: |
| 2006 | case DRM_FORMAT_RGBX1010102: |
| 2007 | case DRM_FORMAT_BGRX1010102: |
| 2008 | case DRM_FORMAT_ARGB2101010: |
| 2009 | case DRM_FORMAT_ABGR2101010: |
| 2010 | case DRM_FORMAT_RGBA1010102: |
| 2011 | case DRM_FORMAT_BGRA1010102: |
| 2012 | case DRM_FORMAT_YUYV: |
| 2013 | case DRM_FORMAT_YVYU: |
| 2014 | case DRM_FORMAT_UYVY: |
| 2015 | case DRM_FORMAT_VYUY: |
| 2016 | plane_n = 1; |
| 2017 | break; |
| 2018 | case DRM_FORMAT_NV12: |
| 2019 | case DRM_FORMAT_NV21: |
| 2020 | case DRM_FORMAT_NV16: |
| 2021 | case DRM_FORMAT_NV61: |
| 2022 | plane_n = 2; |
| 2023 | break; |
| 2024 | case DRM_FORMAT_YUV410: |
| 2025 | case DRM_FORMAT_YVU410: |
| 2026 | case DRM_FORMAT_YUV411: |
| 2027 | case DRM_FORMAT_YVU411: |
| 2028 | case DRM_FORMAT_YUV420: |
| 2029 | case DRM_FORMAT_YVU420: |
| 2030 | case DRM_FORMAT_YUV422: |
| 2031 | case DRM_FORMAT_YVU422: |
| 2032 | case DRM_FORMAT_YUV444: |
| 2033 | case DRM_FORMAT_YVU444: |
| 2034 | plane_n = 3; |
| 2035 | break; |
| 2036 | default: |
| 2037 | _eglError(EGL_BAD_ATTRIBUTE, "invalid format"); |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * The spec says: |
| 2043 | * |
| 2044 | * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is |
| 2045 | * incomplete, EGL_BAD_PARAMETER is generated." |
| 2046 | */ |
| 2047 | for (i = 0; i < plane_n; ++i) { |
| 2048 | if (!attrs->DMABufPlaneFds[i].IsPresent || |
| 2049 | !attrs->DMABufPlaneOffsets[i].IsPresent || |
| 2050 | !attrs->DMABufPlanePitches[i].IsPresent) { |
| 2051 | _eglError(EGL_BAD_PARAMETER, "plane attribute(s) missing"); |
| 2052 | return 0; |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * The spec also says: |
| 2058 | * |
| 2059 | * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT |
| 2060 | * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is |
| 2061 | * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_* |
| 2062 | * attributes are specified." |
| 2063 | */ |
| 2064 | for (i = plane_n; i < 3; ++i) { |
| 2065 | if (attrs->DMABufPlaneFds[i].IsPresent || |
| 2066 | attrs->DMABufPlaneOffsets[i].IsPresent || |
| 2067 | attrs->DMABufPlanePitches[i].IsPresent) { |
| 2068 | _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes"); |
| 2069 | return 0; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | return plane_n; |
| 2074 | } |
| 2075 | |
| 2076 | /** |
| 2077 | * The spec says: |
| 2078 | * |
Pekka Paalanen | 08264e5 | 2014-08-08 16:26:28 +0300 | [diff] [blame] | 2079 | * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the |
| 2080 | * EGL will take a reference to the dma_buf(s) which it will release at any |
| 2081 | * time while the EGLDisplay is initialized. It is the responsibility of the |
| 2082 | * application to close the dma_buf file descriptors." |
| 2083 | * |
| 2084 | * Therefore we must never close or otherwise modify the file descriptors. |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2085 | */ |
Emil Velikov | 38ef6f5 | 2016-05-01 12:42:53 +0100 | [diff] [blame] | 2086 | _EGLImage * |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2087 | dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2088 | EGLClientBuffer buffer, const EGLint *attr_list) |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2089 | { |
| 2090 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2091 | _EGLImage *res; |
| 2092 | EGLint err; |
| 2093 | _EGLImageAttribs attrs; |
| 2094 | __DRIimage *dri_image; |
| 2095 | unsigned num_fds; |
| 2096 | unsigned i; |
| 2097 | int fds[3]; |
| 2098 | int pitches[3]; |
| 2099 | int offsets[3]; |
| 2100 | unsigned error; |
| 2101 | |
| 2102 | /** |
| 2103 | * The spec says: |
| 2104 | * |
| 2105 | * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the |
| 2106 | * error EGL_BAD_PARAMETER is generated." |
| 2107 | */ |
| 2108 | if (buffer != NULL) { |
| 2109 | _eglError(EGL_BAD_PARAMETER, "buffer not NULL"); |
| 2110 | return NULL; |
| 2111 | } |
| 2112 | |
| 2113 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 2114 | if (err != EGL_SUCCESS) { |
| 2115 | _eglError(err, "bad attribute"); |
| 2116 | return NULL; |
| 2117 | } |
| 2118 | |
| 2119 | if (!dri2_check_dma_buf_attribs(&attrs)) |
| 2120 | return NULL; |
| 2121 | |
| 2122 | num_fds = dri2_check_dma_buf_format(&attrs); |
| 2123 | if (!num_fds) |
| 2124 | return NULL; |
| 2125 | |
| 2126 | for (i = 0; i < num_fds; ++i) { |
| 2127 | fds[i] = attrs.DMABufPlaneFds[i].Value; |
| 2128 | pitches[i] = attrs.DMABufPlanePitches[i].Value; |
| 2129 | offsets[i] = attrs.DMABufPlaneOffsets[i].Value; |
| 2130 | } |
| 2131 | |
| 2132 | dri_image = |
| 2133 | dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen, |
| 2134 | attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, |
| 2135 | fds, num_fds, pitches, offsets, |
| 2136 | attrs.DMABufYuvColorSpaceHint.Value, |
| 2137 | attrs.DMABufSampleRangeHint.Value, |
| 2138 | attrs.DMABufChromaHorizontalSiting.Value, |
| 2139 | attrs.DMABufChromaVerticalSiting.Value, |
| 2140 | &error, |
| 2141 | NULL); |
| 2142 | dri2_create_image_khr_texture_error(error); |
| 2143 | |
| 2144 | if (!dri_image) |
| 2145 | return EGL_NO_IMAGE_KHR; |
| 2146 | |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2147 | res = dri2_create_image_from_dri(disp, dri_image); |
Topi Pohjolainen | 20de7f9 | 2013-03-22 15:58:05 +0200 | [diff] [blame] | 2148 | |
| 2149 | return res; |
| 2150 | } |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2151 | static _EGLImage * |
| 2152 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2153 | const EGLint *attr_list) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2154 | { |
| 2155 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2156 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2157 | _EGLImageAttribs attrs; |
| 2158 | unsigned int dri_use, valid_mask; |
| 2159 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2160 | EGLint err = EGL_SUCCESS; |
| 2161 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2162 | (void) drv; |
| 2163 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2164 | dri2_img = malloc(sizeof *dri2_img); |
| 2165 | if (!dri2_img) { |
| 2166 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2167 | return EGL_NO_IMAGE_KHR; |
| 2168 | } |
| 2169 | |
| 2170 | if (!attr_list) { |
| 2171 | err = EGL_BAD_PARAMETER; |
| 2172 | goto cleanup_img; |
| 2173 | } |
| 2174 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 2175 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2176 | err = EGL_BAD_PARAMETER; |
| 2177 | goto cleanup_img; |
| 2178 | } |
| 2179 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2180 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 2181 | if (err != EGL_SUCCESS) |
| 2182 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2183 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2184 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 2185 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 2186 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2187 | goto cleanup_img; |
| 2188 | } |
| 2189 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2190 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2191 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 2192 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 2193 | break; |
| 2194 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2195 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 2196 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2197 | goto cleanup_img; |
| 2198 | } |
| 2199 | |
| 2200 | valid_mask = |
| 2201 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 2202 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 2203 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2204 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 2205 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 2206 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2207 | goto cleanup_img; |
| 2208 | } |
| 2209 | |
| 2210 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2211 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2212 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2213 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2214 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 2215 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 2216 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2217 | |
Boyan Ding | 052b3d4 | 2015-06-13 15:36:27 +0800 | [diff] [blame] | 2218 | dri2_img->dri_image = |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2219 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2220 | attrs.Width, attrs.Height, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2221 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2222 | if (dri2_img->dri_image == NULL) { |
| 2223 | err = EGL_BAD_ALLOC; |
| 2224 | goto cleanup_img; |
| 2225 | } |
| 2226 | |
| 2227 | return &dri2_img->base; |
| 2228 | |
| 2229 | cleanup_img: |
| 2230 | free(dri2_img); |
| 2231 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 2232 | |
| 2233 | return EGL_NO_IMAGE_KHR; |
| 2234 | } |
| 2235 | |
| 2236 | static EGLBoolean |
| 2237 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2238 | EGLint *name, EGLint *handle, EGLint *stride) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2239 | { |
| 2240 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2241 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 2242 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2243 | (void) drv; |
| 2244 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2245 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2246 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2247 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 2248 | return EGL_FALSE; |
| 2249 | } |
| 2250 | |
| 2251 | if (handle) |
| 2252 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2253 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2254 | |
| 2255 | if (stride) |
| 2256 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2257 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2258 | |
| 2259 | return EGL_TRUE; |
| 2260 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2261 | |
| 2262 | static EGLBoolean |
| 2263 | dri2_export_dma_buf_image_query_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 2264 | _EGLImage *img, |
| 2265 | EGLint *fourcc, EGLint *nplanes, |
Dave Airlie | b5045e2 | 2015-05-05 09:10:34 +1000 | [diff] [blame] | 2266 | EGLuint64KHR *modifiers) |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2267 | { |
| 2268 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2269 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 2270 | |
| 2271 | (void) drv; |
| 2272 | |
| 2273 | |
| 2274 | if (nplanes) |
| 2275 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2276 | __DRI_IMAGE_ATTRIB_NUM_PLANES, nplanes); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2277 | if (fourcc) |
| 2278 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2279 | __DRI_IMAGE_ATTRIB_FOURCC, fourcc); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2280 | |
| 2281 | if (modifiers) |
| 2282 | *modifiers = 0; |
| 2283 | |
| 2284 | return EGL_TRUE; |
| 2285 | } |
| 2286 | |
| 2287 | static EGLBoolean |
| 2288 | dri2_export_dma_buf_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 2289 | int *fds, EGLint *strides, EGLint *offsets) |
| 2290 | { |
| 2291 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2292 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 2293 | |
| 2294 | (void) drv; |
| 2295 | |
| 2296 | /* rework later to provide multiple fds/strides/offsets */ |
| 2297 | if (fds) |
| 2298 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2299 | __DRI_IMAGE_ATTRIB_FD, fds); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2300 | |
| 2301 | if (strides) |
| 2302 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2303 | __DRI_IMAGE_ATTRIB_STRIDE, strides); |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2304 | |
Chuanbo Weng | 9e8de86 | 2016-09-14 01:07:10 +0800 | [diff] [blame] | 2305 | if (offsets) { |
| 2306 | int img_offset; |
| 2307 | bool ret = dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 2308 | __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); |
| 2309 | if (ret) |
| 2310 | offsets[0] = img_offset; |
| 2311 | else |
| 2312 | offsets[0] = 0; |
| 2313 | } |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2314 | |
| 2315 | return EGL_TRUE; |
| 2316 | } |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2317 | |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 2318 | #endif |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2319 | |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2320 | _EGLImage * |
| 2321 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2322 | _EGLContext *ctx, EGLenum target, |
| 2323 | EGLClientBuffer buffer, const EGLint *attr_list) |
Emil Velikov | 57c670a | 2015-07-10 11:01:35 +0100 | [diff] [blame] | 2324 | { |
| 2325 | (void) drv; |
| 2326 | |
| 2327 | switch (target) { |
| 2328 | case EGL_GL_TEXTURE_2D_KHR: |
| 2329 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 2330 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 2331 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 2332 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 2333 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 2334 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
| 2335 | return dri2_create_image_khr_texture(disp, ctx, target, buffer, attr_list); |
| 2336 | case EGL_GL_TEXTURE_3D_KHR: |
| 2337 | if (disp->Extensions.KHR_gl_texture_3D_image) { |
| 2338 | return dri2_create_image_khr_texture(disp, ctx, target, buffer, attr_list); |
| 2339 | } |
| 2340 | else { |
| 2341 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2342 | return EGL_NO_IMAGE_KHR; |
| 2343 | } |
| 2344 | case EGL_GL_RENDERBUFFER_KHR: |
| 2345 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
| 2346 | #ifdef HAVE_LIBDRM |
| 2347 | case EGL_DRM_BUFFER_MESA: |
| 2348 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
| 2349 | case EGL_LINUX_DMA_BUF_EXT: |
| 2350 | return dri2_create_image_dma_buf(disp, ctx, buffer, attr_list); |
| 2351 | #endif |
| 2352 | #ifdef HAVE_WAYLAND_PLATFORM |
| 2353 | case EGL_WAYLAND_BUFFER_WL: |
| 2354 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 2355 | #endif |
| 2356 | default: |
| 2357 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2358 | return EGL_NO_IMAGE_KHR; |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | static EGLBoolean |
| 2363 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 2364 | { |
| 2365 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2366 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 2367 | |
| 2368 | (void) drv; |
| 2369 | |
| 2370 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 2371 | free(dri2_img); |
| 2372 | |
| 2373 | return EGL_TRUE; |
| 2374 | } |
| 2375 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2376 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2377 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 2378 | static void |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2379 | 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] | 2380 | struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2381 | { |
| 2382 | _EGLDisplay *disp = user_data; |
| 2383 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2384 | __DRIimage *img; |
| 2385 | int i, dri_components = 0; |
Kristian Høgsberg | 7b1d94e | 2011-08-31 16:45:04 -0400 | [diff] [blame] | 2386 | |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2387 | if (fd == -1) |
| 2388 | img = dri2_dpy->image->createImageFromNames(dri2_dpy->dri_screen, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2389 | buffer->width, |
| 2390 | buffer->height, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2391 | buffer->format, |
| 2392 | (int*)&name, 1, |
| 2393 | buffer->stride, |
| 2394 | buffer->offset, |
| 2395 | NULL); |
| 2396 | else |
| 2397 | img = dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2398 | buffer->width, |
| 2399 | buffer->height, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2400 | buffer->format, |
| 2401 | &fd, 1, |
| 2402 | buffer->stride, |
| 2403 | buffer->offset, |
| 2404 | NULL); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2405 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2406 | if (img == NULL) |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 2407 | return; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2408 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2409 | dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, &dri_components); |
| 2410 | |
| 2411 | buffer->driver_format = NULL; |
| 2412 | for (i = 0; i < ARRAY_SIZE(wl_drm_components); i++) |
| 2413 | if (wl_drm_components[i].dri_components == dri_components) |
| 2414 | buffer->driver_format = &wl_drm_components[i]; |
| 2415 | |
| 2416 | if (buffer->driver_format == NULL) |
| 2417 | dri2_dpy->image->destroyImage(img); |
| 2418 | else |
| 2419 | buffer->driver_buffer = img; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | static void |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 2423 | dri2_wl_release_buffer(void *user_data, struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2424 | { |
| 2425 | _EGLDisplay *disp = user_data; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2426 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2427 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 2428 | dri2_dpy->image->destroyImage(buffer->driver_buffer); |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | static struct wayland_drm_callbacks wl_drm_callbacks = { |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2432 | .authenticate = NULL, |
| 2433 | .reference_buffer = dri2_wl_reference_buffer, |
| 2434 | .release_buffer = dri2_wl_release_buffer |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2435 | }; |
| 2436 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2437 | static EGLBoolean |
| 2438 | dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2439 | struct wl_display *wl_dpy) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2440 | { |
| 2441 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Emil Velikov | 6638c55 | 2014-05-28 14:36:46 +0100 | [diff] [blame] | 2442 | int flags = 0; |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2443 | uint64_t cap; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2444 | |
| 2445 | (void) drv; |
| 2446 | |
| 2447 | if (dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2448 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2449 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2450 | wl_drm_callbacks.authenticate = |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 2451 | (int(*)(void *, uint32_t)) dri2_dpy->vtbl->authenticate; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2452 | |
Emil Velikov | 6638c55 | 2014-05-28 14:36:46 +0100 | [diff] [blame] | 2453 | if (drmGetCap(dri2_dpy->fd, DRM_CAP_PRIME, &cap) == 0 && |
| 2454 | cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) && |
Kristian Høgsberg | 1670737 | 2013-03-19 13:20:36 -0400 | [diff] [blame] | 2455 | dri2_dpy->image->base.version >= 7 && |
| 2456 | dri2_dpy->image->createImageFromFds != NULL) |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2457 | flags |= WAYLAND_DRM_PRIME; |
| 2458 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2459 | dri2_dpy->wl_server_drm = |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2460 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
Kristian Høgsberg | de315f7 | 2013-02-02 12:26:12 -0500 | [diff] [blame] | 2461 | &wl_drm_callbacks, disp, flags); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2462 | |
| 2463 | if (!dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2464 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2465 | |
Ander Conselvan de Oliveira | 1786030 | 2014-04-08 23:28:42 +0300 | [diff] [blame] | 2466 | #ifdef HAVE_DRM_PLATFORM |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 2467 | /* We have to share the wl_drm instance with gbm, so gbm can convert |
| 2468 | * wl_buffers to gbm bos. */ |
Kristian Høgsberg | 1d34927 | 2013-10-11 15:30:09 -0700 | [diff] [blame] | 2469 | if (dri2_dpy->gbm_dri) |
| 2470 | 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] | 2471 | #endif |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 2472 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2473 | return EGL_TRUE; |
| 2474 | } |
| 2475 | |
| 2476 | static EGLBoolean |
| 2477 | dri2_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2478 | struct wl_display *wl_dpy) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2479 | { |
| 2480 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2481 | |
| 2482 | (void) drv; |
| 2483 | |
| 2484 | if (!dri2_dpy->wl_server_drm) |
Emil Velikov | ebc68e3 | 2016-08-25 00:12:13 +0100 | [diff] [blame] | 2485 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2486 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 2487 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2488 | dri2_dpy->wl_server_drm = NULL; |
| 2489 | |
| 2490 | return EGL_TRUE; |
| 2491 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2492 | |
| 2493 | static EGLBoolean |
| 2494 | dri2_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp, |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2495 | struct wl_resource *buffer_resource, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2496 | EGLint attribute, EGLint *value) |
| 2497 | { |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 2498 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2499 | struct wl_drm_buffer *buffer; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 2500 | const struct wl_drm_components_descriptor *format; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2501 | |
Kristian Høgsberg | 360a141 | 2013-09-26 12:25:11 -0700 | [diff] [blame] | 2502 | 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] | 2503 | if (!buffer) |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2504 | return EGL_FALSE; |
| 2505 | |
| 2506 | format = buffer->driver_format; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 2507 | switch (attribute) { |
| 2508 | case EGL_TEXTURE_FORMAT: |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2509 | *value = format->components; |
| 2510 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 2511 | case EGL_WIDTH: |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2512 | *value = buffer->width; |
Rob Bradford | 15e64de | 2013-04-10 11:36:24 +0100 | [diff] [blame] | 2513 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 2514 | case EGL_HEIGHT: |
Ander Conselvan de Oliveira | 8d29b52 | 2013-07-18 15:11:25 +0300 | [diff] [blame] | 2515 | *value = buffer->height; |
Rob Bradford | 15e64de | 2013-04-10 11:36:24 +0100 | [diff] [blame] | 2516 | return EGL_TRUE; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | return EGL_FALSE; |
| 2520 | } |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2521 | #endif |
| 2522 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2523 | static void |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2524 | dri2_egl_ref_sync(struct dri2_egl_sync *sync) |
| 2525 | { |
| 2526 | p_atomic_inc(&sync->refcount); |
| 2527 | } |
| 2528 | |
| 2529 | static void |
| 2530 | dri2_egl_unref_sync(struct dri2_egl_display *dri2_dpy, |
| 2531 | struct dri2_egl_sync *dri2_sync) |
| 2532 | { |
| 2533 | if (p_atomic_dec_zero(&dri2_sync->refcount)) { |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2534 | switch (dri2_sync->base.Type) { |
| 2535 | case EGL_SYNC_REUSABLE_KHR: |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2536 | cnd_destroy(&dri2_sync->cond); |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2537 | break; |
| 2538 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
| 2539 | if (dri2_sync->base.SyncFd != EGL_NO_NATIVE_FENCE_FD_ANDROID) |
| 2540 | close(dri2_sync->base.SyncFd); |
| 2541 | break; |
| 2542 | default: |
| 2543 | break; |
| 2544 | } |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2545 | |
| 2546 | if (dri2_sync->fence) |
| 2547 | dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, dri2_sync->fence); |
| 2548 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2549 | free(dri2_sync); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | static _EGLSync * |
| 2554 | dri2_create_sync(_EGLDriver *drv, _EGLDisplay *dpy, |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 2555 | EGLenum type, const EGLAttrib *attrib_list) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2556 | { |
| 2557 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 2558 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2559 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2560 | struct dri2_egl_sync *dri2_sync; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2561 | EGLint ret; |
| 2562 | pthread_condattr_t attr; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2563 | |
| 2564 | dri2_sync = calloc(1, sizeof(struct dri2_egl_sync)); |
| 2565 | if (!dri2_sync) { |
| 2566 | _eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR"); |
| 2567 | return NULL; |
| 2568 | } |
| 2569 | |
Chad Versace | 8044885 | 2016-09-27 13:27:21 -0700 | [diff] [blame] | 2570 | if (!_eglInitSync(&dri2_sync->base, dpy, type, attrib_list)) { |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2571 | free(dri2_sync); |
| 2572 | return NULL; |
| 2573 | } |
| 2574 | |
| 2575 | switch (type) { |
| 2576 | case EGL_SYNC_FENCE_KHR: |
| 2577 | dri2_sync->fence = dri2_dpy->fence->create_fence(dri2_ctx->dri_context); |
Chad Versace | b0f410a | 2015-05-05 19:05:20 -0700 | [diff] [blame] | 2578 | if (!dri2_sync->fence) { |
| 2579 | /* 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] | 2580 | * a generic EGL error that doesn't communicate user error. |
| 2581 | */ |
Chad Versace | b0f410a | 2015-05-05 19:05:20 -0700 | [diff] [blame] | 2582 | _eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR"); |
| 2583 | free(dri2_sync); |
| 2584 | return NULL; |
| 2585 | } |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2586 | break; |
Marek Olšák | 290a3eb | 2015-04-10 13:16:30 +0200 | [diff] [blame] | 2587 | |
| 2588 | case EGL_SYNC_CL_EVENT_KHR: |
| 2589 | dri2_sync->fence = dri2_dpy->fence->get_fence_from_cl_event( |
| 2590 | dri2_dpy->dri_screen, |
| 2591 | dri2_sync->base.CLEvent); |
| 2592 | /* this can only happen if the cl_event passed in is invalid. */ |
| 2593 | if (!dri2_sync->fence) { |
| 2594 | _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); |
| 2595 | free(dri2_sync); |
| 2596 | return NULL; |
| 2597 | } |
| 2598 | |
| 2599 | /* the initial status must be "signaled" if the cl_event is signaled */ |
| 2600 | if (dri2_dpy->fence->client_wait_sync(dri2_ctx->dri_context, |
| 2601 | dri2_sync->fence, 0, 0)) |
| 2602 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 2603 | break; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2604 | |
| 2605 | case EGL_SYNC_REUSABLE_KHR: |
| 2606 | /* intialize attr */ |
| 2607 | ret = pthread_condattr_init(&attr); |
| 2608 | |
| 2609 | if (ret) { |
| 2610 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 2611 | free(dri2_sync); |
| 2612 | return NULL; |
| 2613 | } |
| 2614 | |
| 2615 | /* change clock attribute to CLOCK_MONOTONIC */ |
| 2616 | ret = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); |
| 2617 | |
| 2618 | if (ret) { |
| 2619 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 2620 | free(dri2_sync); |
| 2621 | return NULL; |
| 2622 | } |
| 2623 | |
| 2624 | ret = pthread_cond_init(&dri2_sync->cond, &attr); |
| 2625 | |
| 2626 | if (ret) { |
| 2627 | _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR"); |
| 2628 | free(dri2_sync); |
| 2629 | return NULL; |
| 2630 | } |
| 2631 | |
| 2632 | /* initial status of reusable sync must be "unsignaled" */ |
| 2633 | dri2_sync->base.SyncStatus = EGL_UNSIGNALED_KHR; |
| 2634 | break; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2635 | |
| 2636 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
| 2637 | if (dri2_dpy->fence->create_fence_fd) { |
| 2638 | dri2_sync->fence = dri2_dpy->fence->create_fence_fd( |
| 2639 | dri2_ctx->dri_context, |
| 2640 | dri2_sync->base.SyncFd); |
| 2641 | } |
| 2642 | if (!dri2_sync->fence) { |
| 2643 | _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); |
| 2644 | free(dri2_sync); |
| 2645 | return NULL; |
| 2646 | } |
| 2647 | break; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | p_atomic_set(&dri2_sync->refcount, 1); |
| 2651 | return &dri2_sync->base; |
| 2652 | } |
| 2653 | |
| 2654 | static EGLBoolean |
| 2655 | dri2_destroy_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync) |
| 2656 | { |
| 2657 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2658 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2659 | EGLint ret = EGL_TRUE; |
| 2660 | EGLint err; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2661 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2662 | /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet, |
| 2663 | * then unlock all threads possibly blocked by the reusable sync before |
| 2664 | * destroying it. |
| 2665 | */ |
| 2666 | if (dri2_sync->base.Type == EGL_SYNC_REUSABLE_KHR && |
| 2667 | dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) { |
| 2668 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 2669 | /* unblock all threads currently blocked by sync */ |
| 2670 | err = cnd_broadcast(&dri2_sync->cond); |
| 2671 | |
| 2672 | if (err) { |
| 2673 | _eglError(EGL_BAD_ACCESS, "eglDestroySyncKHR"); |
| 2674 | ret = EGL_FALSE; |
| 2675 | } |
| 2676 | } |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2677 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2678 | dri2_egl_unref_sync(dri2_dpy, dri2_sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2679 | |
| 2680 | return ret; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | static EGLint |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2684 | dri2_dup_native_fence_fd(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync) |
| 2685 | { |
| 2686 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2687 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 2688 | |
| 2689 | assert(sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID); |
| 2690 | |
| 2691 | if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { |
| 2692 | /* try to retrieve the actual native fence fd.. if rendering is |
| 2693 | * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD: |
| 2694 | */ |
| 2695 | sync->SyncFd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen, |
| 2696 | dri2_sync->fence); |
| 2697 | } |
| 2698 | |
| 2699 | if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { |
| 2700 | /* if native fence fd still not created, return an error: */ |
| 2701 | _eglError(EGL_BAD_PARAMETER, "eglDupNativeFenceFDANDROID"); |
| 2702 | return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 2703 | } |
| 2704 | |
| 2705 | return dup(sync->SyncFd); |
| 2706 | } |
| 2707 | |
| 2708 | static EGLint |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2709 | dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, |
Marek Olšák | d333d30 | 2015-05-12 17:34:57 +0200 | [diff] [blame] | 2710 | EGLint flags, EGLTime timeout) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2711 | { |
| 2712 | _EGLContext *ctx = _eglGetCurrentContext(); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2713 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2714 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2715 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2716 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 2717 | unsigned wait_flags = 0; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2718 | |
| 2719 | /* timespecs for cnd_timedwait */ |
| 2720 | struct timespec current; |
| 2721 | xtime expire; |
| 2722 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2723 | EGLint ret = EGL_CONDITION_SATISFIED_KHR; |
| 2724 | |
Marek Olšák | 18123a7 | 2015-09-25 22:48:00 +0200 | [diff] [blame] | 2725 | /* The EGL_KHR_fence_sync spec states: |
| 2726 | * |
| 2727 | * "If no context is current for the bound API, |
| 2728 | * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored. |
| 2729 | */ |
| 2730 | if (dri2_ctx && flags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2731 | wait_flags |= __DRI2_FENCE_FLAG_FLUSH_COMMANDS; |
| 2732 | |
| 2733 | /* the sync object should take a reference while waiting */ |
| 2734 | dri2_egl_ref_sync(dri2_sync); |
| 2735 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2736 | switch (sync->Type) { |
| 2737 | case EGL_SYNC_FENCE_KHR: |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2738 | case EGL_SYNC_NATIVE_FENCE_ANDROID: |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2739 | case EGL_SYNC_CL_EVENT_KHR: |
| 2740 | 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] | 2741 | dri2_sync->fence, wait_flags, |
| 2742 | timeout)) |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2743 | dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; |
| 2744 | else |
| 2745 | ret = EGL_TIMEOUT_EXPIRED_KHR; |
| 2746 | break; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2747 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2748 | case EGL_SYNC_REUSABLE_KHR: |
| 2749 | if (dri2_ctx && dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR && |
| 2750 | (flags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR)) { |
| 2751 | /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */ |
Emil Velikov | b349c11 | 2016-08-16 14:25:19 +0100 | [diff] [blame] | 2752 | dri2_drv->glFlush(); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/ |
| 2756 | if (timeout == EGL_FOREVER_KHR) { |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2757 | mtx_lock(&dri2_sync->mutex); |
| 2758 | cnd_wait(&dri2_sync->cond, &dri2_sync->mutex); |
Matt Turner | 53f64a8 | 2016-05-16 14:43:26 -0700 | [diff] [blame] | 2759 | mtx_unlock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2760 | } else { |
| 2761 | /* if reusable sync has not been yet signaled */ |
| 2762 | if (dri2_sync->base.SyncStatus != EGL_SIGNALED_KHR) { |
| 2763 | clock_gettime(CLOCK_MONOTONIC, ¤t); |
| 2764 | |
| 2765 | /* calculating when to expire */ |
| 2766 | expire.nsec = timeout % 1000000000L; |
| 2767 | expire.sec = timeout / 1000000000L; |
| 2768 | |
| 2769 | expire.nsec += current.tv_nsec; |
| 2770 | expire.sec += current.tv_sec; |
| 2771 | |
| 2772 | /* expire.nsec now is a number between 0 and 1999999998 */ |
| 2773 | if (expire.nsec > 999999999L) { |
| 2774 | expire.sec++; |
| 2775 | expire.nsec -= 1000000000L; |
| 2776 | } |
| 2777 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2778 | mtx_lock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2779 | ret = cnd_timedwait(&dri2_sync->cond, &dri2_sync->mutex, &expire); |
Matt Turner | 53f64a8 | 2016-05-16 14:43:26 -0700 | [diff] [blame] | 2780 | mtx_unlock(&dri2_sync->mutex); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2781 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2782 | if (ret == thrd_busy) { |
| 2783 | if (dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) { |
| 2784 | ret = EGL_TIMEOUT_EXPIRED_KHR; |
| 2785 | } else { |
| 2786 | _eglError(EGL_BAD_ACCESS, "eglClientWaitSyncKHR"); |
| 2787 | ret = EGL_FALSE; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2788 | } |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2789 | } |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2790 | } |
| 2791 | } |
| 2792 | break; |
| 2793 | } |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2794 | dri2_egl_unref_sync(dri2_dpy, dri2_sync); |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2795 | |
Dongwon Kim | c6e97aa | 2016-08-15 15:12:03 -0700 | [diff] [blame] | 2796 | return ret; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2797 | } |
| 2798 | |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2799 | static EGLBoolean |
| 2800 | dri2_signal_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, |
| 2801 | EGLenum mode) |
| 2802 | { |
| 2803 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 2804 | EGLint ret; |
| 2805 | |
| 2806 | if (sync->Type != EGL_SYNC_REUSABLE_KHR) { |
| 2807 | _eglError(EGL_BAD_MATCH, "eglSignalSyncKHR"); |
| 2808 | return EGL_FALSE; |
| 2809 | } |
| 2810 | |
| 2811 | if (mode != EGL_SIGNALED_KHR && mode != EGL_UNSIGNALED_KHR) { |
| 2812 | _eglError(EGL_BAD_ATTRIBUTE, "eglSignalSyncKHR"); |
| 2813 | return EGL_FALSE; |
| 2814 | } |
| 2815 | |
| 2816 | dri2_sync->base.SyncStatus = mode; |
| 2817 | |
| 2818 | if (mode == EGL_SIGNALED_KHR) { |
| 2819 | ret = cnd_broadcast(&dri2_sync->cond); |
| 2820 | |
| 2821 | /* fail to broadcast */ |
| 2822 | if (ret) { |
| 2823 | _eglError(EGL_BAD_ACCESS, "eglSignalSyncKHR"); |
| 2824 | return EGL_FALSE; |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | return EGL_TRUE; |
| 2829 | } |
| 2830 | |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2831 | static EGLint |
| 2832 | dri2_server_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync) |
| 2833 | { |
| 2834 | _EGLContext *ctx = _eglGetCurrentContext(); |
| 2835 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2836 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2837 | struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); |
| 2838 | |
| 2839 | dri2_dpy->fence->server_wait_sync(dri2_ctx->dri_context, |
| 2840 | dri2_sync->fence, 0); |
| 2841 | return EGL_TRUE; |
| 2842 | } |
| 2843 | |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2844 | static int |
| 2845 | dri2_interop_query_device_info(_EGLDisplay *dpy, _EGLContext *ctx, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2846 | struct mesa_glinterop_device_info *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2847 | { |
| 2848 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2849 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2850 | |
| 2851 | if (!dri2_dpy->interop) |
| 2852 | return MESA_GLINTEROP_UNSUPPORTED; |
| 2853 | |
| 2854 | return dri2_dpy->interop->query_device_info(dri2_ctx->dri_context, out); |
| 2855 | } |
| 2856 | |
| 2857 | static int |
| 2858 | dri2_interop_export_object(_EGLDisplay *dpy, _EGLContext *ctx, |
Emil Velikov | 13faddb | 2016-05-30 10:56:33 +0100 | [diff] [blame] | 2859 | struct mesa_glinterop_export_in *in, |
| 2860 | struct mesa_glinterop_export_out *out) |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2861 | { |
| 2862 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
| 2863 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2864 | |
| 2865 | if (!dri2_dpy->interop) |
| 2866 | return MESA_GLINTEROP_UNSUPPORTED; |
| 2867 | |
| 2868 | return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out); |
| 2869 | } |
| 2870 | |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2871 | static void |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2872 | dri2_unload(_EGLDriver *drv) |
| 2873 | { |
| 2874 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 2875 | |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2876 | dlclose(dri2_drv->handle); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2877 | free(dri2_drv); |
| 2878 | } |
| 2879 | |
| 2880 | static EGLBoolean |
| 2881 | dri2_load(_EGLDriver *drv) |
| 2882 | { |
| 2883 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 2884 | #ifdef HAVE_ANDROID_PLATFORM |
| 2885 | const char *libname = "libglapi.so"; |
Julien Isorce | e27ea99 | 2015-06-18 06:53:52 +0100 | [diff] [blame] | 2886 | #elif defined(__APPLE__) |
| 2887 | const char *libname = "libglapi.0.dylib"; |
Yaakov Selkowitz | 5d30386 | 2016-06-11 14:53:50 +0000 | [diff] [blame] | 2888 | #elif defined(__CYGWIN__) |
| 2889 | const char *libname = "cygglapi-0.dll"; |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2890 | #else |
Eric Engestrom | 8acb79d | 2016-10-19 15:09:26 +0100 | [diff] [blame] | 2891 | const char *libname = "libglapi.so.0"; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 2892 | #endif |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2893 | void *handle; |
| 2894 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 2895 | /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */ |
| 2896 | handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2897 | if (!handle) { |
| 2898 | _eglLog(_EGL_WARNING, "DRI2: failed to open glapi provider"); |
| 2899 | goto no_handle; |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2902 | dri2_drv->get_proc_address = (_EGLProc (*)(const char *)) |
| 2903 | dlsym(handle, "_glapi_get_proc_address"); |
| 2904 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 2905 | /* if glapi is not available, loading DRI drivers will fail */ |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2906 | if (!dri2_drv->get_proc_address) { |
| 2907 | _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address"); |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2908 | goto no_symbol; |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | dri2_drv->glFlush = (void (*)(void)) |
| 2912 | dri2_drv->get_proc_address("glFlush"); |
| 2913 | |
Emil Velikov | b349c11 | 2016-08-16 14:25:19 +0100 | [diff] [blame] | 2914 | /* if glFlush is not available things are horribly broken */ |
| 2915 | if (!dri2_drv->glFlush) { |
| 2916 | _eglLog(_EGL_WARNING, "DRI2: failed to find glFlush entry point"); |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2917 | goto no_symbol; |
Emil Velikov | b349c11 | 2016-08-16 14:25:19 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 2920 | dri2_drv->handle = handle; |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2921 | return EGL_TRUE; |
Emil Velikov | 7a9c92d | 2016-08-16 16:33:49 +0100 | [diff] [blame] | 2922 | |
| 2923 | no_symbol: |
| 2924 | dlclose(handle); |
| 2925 | no_handle: |
| 2926 | return EGL_FALSE; |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2927 | } |
| 2928 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2929 | /** |
| 2930 | * This is the main entrypoint into the driver, called by libEGL. |
| 2931 | * Create a new _EGLDriver object and init its dispatch table. |
| 2932 | */ |
| 2933 | _EGLDriver * |
Eric Anholt | 9f0f00c | 2012-02-05 07:01:17 +0100 | [diff] [blame] | 2934 | _eglBuiltInDriverDRI2(const char *args) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2935 | { |
| 2936 | struct dri2_egl_driver *dri2_drv; |
| 2937 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2938 | (void) args; |
| 2939 | |
Matt Turner | 6bda027 | 2012-09-04 23:09:22 -0700 | [diff] [blame] | 2940 | dri2_drv = calloc(1, sizeof *dri2_drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2941 | if (!dri2_drv) |
| 2942 | return NULL; |
| 2943 | |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 2944 | if (!dri2_load(&dri2_drv->base)) { |
| 2945 | free(dri2_drv); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2946 | return NULL; |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 2947 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 2948 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2949 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 2950 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 2951 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 2952 | dri2_drv->base.API.CreateContext = dri2_create_context; |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 2953 | dri2_drv->base.API.DestroyContext = dri2_destroy_context; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2954 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 2955 | dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; |
Chad Versace | bc8b07a | 2014-01-28 16:45:07 -0800 | [diff] [blame] | 2956 | dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2957 | dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; |
Chad Versace | 958dd80 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2958 | dri2_drv->base.API.DestroySurface = dri2_destroy_surface; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2959 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 2960 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 2961 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2962 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 2963 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 2964 | dri2_drv->base.API.SwapInterval = dri2_swap_interval; |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 2965 | dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 2966 | dri2_drv->base.API.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage; |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2967 | dri2_drv->base.API.SwapBuffersRegionNOK = dri2_swap_buffers_region; |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2968 | dri2_drv->base.API.PostSubBufferNV = dri2_post_sub_buffer; |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2969 | dri2_drv->base.API.CopyBuffers = dri2_copy_buffers, |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2970 | dri2_drv->base.API.QueryBufferAge = dri2_query_buffer_age; |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2971 | dri2_drv->base.API.CreateImageKHR = dri2_create_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2972 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 2973 | dri2_drv->base.API.CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image; |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 2974 | dri2_drv->base.API.QuerySurface = dri2_query_surface; |
Axel Davy | 63986f9 | 2015-01-14 20:36:04 +0100 | [diff] [blame] | 2975 | #ifdef HAVE_LIBDRM |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2976 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 2977 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Dave Airlie | 8f7338f | 2014-03-03 13:57:16 +1000 | [diff] [blame] | 2978 | dri2_drv->base.API.ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa; |
| 2979 | dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa; |
Samuel Thibault | a594cec | 2013-11-10 19:32:01 +0100 | [diff] [blame] | 2980 | #endif |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2981 | #ifdef HAVE_WAYLAND_PLATFORM |
| 2982 | dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl; |
| 2983 | dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 2984 | dri2_drv->base.API.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 2985 | #endif |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 2986 | dri2_drv->base.API.GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2987 | dri2_drv->base.API.CreateSyncKHR = dri2_create_sync; |
| 2988 | dri2_drv->base.API.ClientWaitSyncKHR = dri2_client_wait_sync; |
Dongwon Kim | 7029947 | 2016-04-04 17:14:10 -0700 | [diff] [blame] | 2989 | dri2_drv->base.API.SignalSyncKHR = dri2_signal_sync; |
Marek Olšák | a8617cc | 2015-04-10 12:04:18 +0200 | [diff] [blame] | 2990 | dri2_drv->base.API.WaitSyncKHR = dri2_server_wait_sync; |
Marek Olšák | 9a0bda2 | 2015-04-10 10:56:02 +0200 | [diff] [blame] | 2991 | dri2_drv->base.API.DestroySyncKHR = dri2_destroy_sync; |
Marek Olšák | b6eda70 | 2016-03-03 15:59:48 +0100 | [diff] [blame] | 2992 | dri2_drv->base.API.GLInteropQueryDeviceInfo = dri2_interop_query_device_info; |
| 2993 | dri2_drv->base.API.GLInteropExportObject = dri2_interop_export_object; |
Rob Clark | 0201f01 | 2016-11-18 08:39:33 -0500 | [diff] [blame] | 2994 | dri2_drv->base.API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2995 | |
| 2996 | dri2_drv->base.Name = "DRI2"; |
| 2997 | dri2_drv->base.Unload = dri2_unload; |
| 2998 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2999 | return &dri2_drv->base; |
| 3000 | } |