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