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