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