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