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