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