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