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