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