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