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