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