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 | |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <stdio.h> |
| 31 | #include <limits.h> |
| 32 | #include <dlfcn.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <errno.h> |
| 35 | #include <unistd.h> |
| 36 | #include <xf86drm.h> |
| 37 | #include <GL/gl.h> |
| 38 | #include <GL/internal/dri_interface.h> |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | #include <sys/stat.h> |
| 41 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 42 | #include "egl_dri2.h" |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 43 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 44 | const __DRIuseInvalidateExtension use_invalidate = { |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 45 | { __DRI_USE_INVALIDATE, 1 } |
| 46 | }; |
| 47 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 48 | EGLint dri2_to_egl_attribute_map[] = { |
| 49 | 0, |
| 50 | EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ |
| 51 | EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ |
| 52 | EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ |
| 53 | EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ |
| 54 | EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 55 | EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 56 | EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ |
| 57 | 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ |
| 58 | EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ |
| 59 | EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ |
| 60 | 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ |
| 61 | 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ |
| 62 | 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ |
| 63 | 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ |
| 64 | EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ |
| 65 | EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ |
| 66 | 0, /* __DRI_ATTRIB_RENDER_TYPE, */ |
| 67 | 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ |
| 68 | 0, /* __DRI_ATTRIB_CONFORMANT */ |
| 69 | 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ |
| 70 | 0, /* __DRI_ATTRIB_STEREO */ |
| 71 | 0, /* __DRI_ATTRIB_AUX_BUFFERS */ |
| 72 | 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ |
| 73 | 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ |
| 74 | 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ |
| 75 | 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ |
| 76 | 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ |
| 77 | 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ |
| 78 | 0, /* __DRI_ATTRIB_FLOAT_MODE */ |
| 79 | 0, /* __DRI_ATTRIB_RED_MASK */ |
| 80 | 0, /* __DRI_ATTRIB_GREEN_MASK */ |
| 81 | 0, /* __DRI_ATTRIB_BLUE_MASK */ |
| 82 | 0, /* __DRI_ATTRIB_ALPHA_MASK */ |
| 83 | EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ |
| 84 | EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ |
| 85 | EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ |
| 86 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ |
| 87 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ |
| 88 | 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ |
| 89 | 0, /* __DRI_ATTRIB_SWAP_METHOD */ |
| 90 | EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ |
| 91 | EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 92 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ |
| 93 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 94 | 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ |
| 95 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 96 | EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */ |
Benjamin Franzke | 4f6fbfa | 2011-03-07 00:29:13 +0100 | [diff] [blame] | 97 | 0, /* __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 100 | static EGLBoolean |
| 101 | dri2_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) |
| 102 | { |
| 103 | if (_eglCompareConfigs(conf, criteria, NULL, EGL_FALSE) != 0) |
| 104 | return EGL_FALSE; |
| 105 | |
| 106 | if (!_eglMatchConfig(conf, criteria)) |
| 107 | return EGL_FALSE; |
| 108 | |
| 109 | return EGL_TRUE; |
| 110 | } |
| 111 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 112 | struct dri2_egl_config * |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 113 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 114 | int depth, EGLint surface_type, const EGLint *attr_list, |
| 115 | const unsigned int *rgba_masks) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 116 | { |
| 117 | struct dri2_egl_config *conf; |
| 118 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 119 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 120 | unsigned int attrib, value, double_buffer; |
| 121 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 122 | unsigned int dri_masks[4] = { 0, 0, 0, 0 }; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 123 | _EGLConfig *matching_config; |
| 124 | EGLint num_configs = 0; |
| 125 | EGLint config_id; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 126 | int i; |
| 127 | |
| 128 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 129 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 130 | |
| 131 | i = 0; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 132 | double_buffer = 0; |
| 133 | bind_to_texture_rgb = 0; |
| 134 | bind_to_texture_rgba = 0; |
| 135 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 136 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 137 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 138 | case __DRI_ATTRIB_RENDER_TYPE: |
| 139 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 140 | value = EGL_RGB_BUFFER; |
| 141 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 142 | value = EGL_LUMINANCE_BUFFER; |
| 143 | else |
| 144 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 145 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 146 | break; |
| 147 | |
| 148 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 149 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 150 | value = EGL_NON_CONFORMANT_CONFIG; |
| 151 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 152 | value = EGL_SLOW_CONFIG; |
| 153 | else |
| 154 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 155 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 156 | break; |
| 157 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 158 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 159 | bind_to_texture_rgb = value; |
| 160 | break; |
| 161 | |
| 162 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 163 | bind_to_texture_rgba = value; |
| 164 | break; |
| 165 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 166 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 167 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 168 | break; |
| 169 | |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 170 | case __DRI_ATTRIB_RED_MASK: |
| 171 | dri_masks[0] = value; |
| 172 | break; |
| 173 | |
| 174 | case __DRI_ATTRIB_GREEN_MASK: |
| 175 | dri_masks[1] = value; |
| 176 | break; |
| 177 | |
| 178 | case __DRI_ATTRIB_BLUE_MASK: |
| 179 | dri_masks[2] = value; |
| 180 | break; |
| 181 | |
| 182 | case __DRI_ATTRIB_ALPHA_MASK: |
| 183 | dri_masks[3] = value; |
| 184 | break; |
| 185 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 186 | default: |
| 187 | key = dri2_to_egl_attribute_map[attrib]; |
| 188 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 189 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 194 | if (attr_list) |
| 195 | for (i = 0; attr_list[i] != EGL_NONE; i += 2) |
| 196 | _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 197 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 198 | if (depth > 0 && depth != base.BufferSize) |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 199 | return NULL; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 200 | |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 201 | if (rgba_masks && memcmp(rgba_masks, dri_masks, sizeof(dri_masks))) |
| 202 | return NULL; |
| 203 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 204 | base.NativeRenderable = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 205 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 206 | base.SurfaceType = surface_type; |
Benjamin Franzke | a8128d7 | 2011-02-04 12:32:30 +0100 | [diff] [blame] | 207 | if (surface_type & (EGL_PBUFFER_BIT | |
| 208 | (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 209 | base.BindToTextureRGB = bind_to_texture_rgb; |
| 210 | if (base.AlphaSize > 0) |
| 211 | base.BindToTextureRGBA = bind_to_texture_rgba; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 212 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 213 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 214 | base.RenderableType = disp->ClientAPIs; |
| 215 | base.Conformant = disp->ClientAPIs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 216 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 217 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 218 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 219 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 222 | config_id = base.ConfigID; |
| 223 | base.ConfigID = EGL_DONT_CARE; |
| 224 | base.SurfaceType = EGL_DONT_CARE; |
| 225 | num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 226 | (_EGLArrayForEach) dri2_match_config, &base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 227 | |
| 228 | if (num_configs == 1) { |
| 229 | conf = (struct dri2_egl_config *) matching_config; |
| 230 | |
| 231 | if (double_buffer && !conf->dri_double_config) |
| 232 | conf->dri_double_config = dri_config; |
| 233 | else if (!double_buffer && !conf->dri_single_config) |
| 234 | conf->dri_single_config = dri_config; |
| 235 | else |
Benjamin Franzke | 83c6875 | 2011-05-12 19:30:05 +0200 | [diff] [blame] | 236 | /* a similar config type is already added (unlikely) => discard */ |
| 237 | return NULL; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 238 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 239 | else if (num_configs == 0) { |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 240 | conf = malloc(sizeof *conf); |
| 241 | if (conf == NULL) |
| 242 | return NULL; |
| 243 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 244 | memcpy(&conf->base, &base, sizeof base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 245 | if (double_buffer) { |
| 246 | conf->dri_double_config = dri_config; |
| 247 | conf->dri_single_config = NULL; |
| 248 | } else { |
| 249 | conf->dri_single_config = dri_config; |
| 250 | conf->dri_double_config = NULL; |
| 251 | } |
| 252 | conf->base.SurfaceType = 0; |
| 253 | conf->base.ConfigID = config_id; |
| 254 | |
Chia-I Wu | 8a6bdf3 | 2010-10-23 00:47:22 +0800 | [diff] [blame] | 255 | _eglLinkConfig(&conf->base); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 256 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 257 | else { |
| 258 | assert(0); |
| 259 | return NULL; |
| 260 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 261 | |
Fredrik Höglund | 655f2c1 | 2011-12-20 17:17:02 +0100 | [diff] [blame] | 262 | if (double_buffer) { |
Kristian Høgsberg | 447bb45 | 2011-08-31 18:20:06 -0400 | [diff] [blame] | 263 | surface_type &= ~EGL_PIXMAP_BIT; |
| 264 | |
Eric Anholt | 7e9bd2b | 2012-09-25 14:05:30 -0700 | [diff] [blame] | 265 | conf->base.MinSwapInterval = dri2_dpy->min_swap_interval; |
| 266 | conf->base.MaxSwapInterval = dri2_dpy->max_swap_interval; |
Fredrik Höglund | 655f2c1 | 2011-12-20 17:17:02 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Kristian Høgsberg | 447bb45 | 2011-08-31 18:20:06 -0400 | [diff] [blame] | 269 | conf->base.SurfaceType |= surface_type; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 270 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 271 | return conf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 272 | } |
| 273 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 274 | __DRIimage * |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 275 | dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 276 | { |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 277 | _EGLDisplay *disp = data; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 278 | struct dri2_egl_image *dri2_img; |
| 279 | _EGLImage *img; |
| 280 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 281 | (void) screen; |
| 282 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 283 | img = _eglLookupImage(image, disp); |
| 284 | if (img == NULL) { |
| 285 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 286 | return NULL; |
| 287 | } |
| 288 | |
| 289 | dri2_img = dri2_egl_image(image); |
| 290 | |
| 291 | return dri2_img->dri_image; |
| 292 | } |
| 293 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 294 | const __DRIimageLookupExtension image_lookup_extension = { |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 295 | { __DRI_IMAGE_LOOKUP, 1 }, |
| 296 | dri2_lookup_egl_image |
| 297 | }; |
| 298 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 299 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 300 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 301 | struct dri2_extension_match { |
| 302 | const char *name; |
| 303 | int version; |
| 304 | int offset; |
| 305 | }; |
| 306 | |
| 307 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 308 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 309 | { __DRI_DRI2, 2, offsetof(struct dri2_egl_display, dri2) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 310 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 314 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 315 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 316 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 317 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 318 | }; |
| 319 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 320 | static struct dri2_extension_match swrast_driver_extensions[] = { |
| 321 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 322 | { __DRI_SWRAST, 2, offsetof(struct dri2_egl_display, swrast) }, |
Ian Romanick | 9d76ad2 | 2012-07-19 11:08:02 -0700 | [diff] [blame] | 323 | { NULL, 0, 0 } |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | static struct dri2_extension_match swrast_core_extensions[] = { |
| 327 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Ian Romanick | 9d76ad2 | 2012-07-19 11:08:02 -0700 | [diff] [blame] | 328 | { NULL, 0, 0 } |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 329 | }; |
| 330 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 331 | static EGLBoolean |
| 332 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 333 | struct dri2_extension_match *matches, |
| 334 | const __DRIextension **extensions) |
| 335 | { |
| 336 | int i, j, ret = EGL_TRUE; |
| 337 | void *field; |
| 338 | |
| 339 | for (i = 0; extensions[i]; i++) { |
| 340 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 341 | for (j = 0; matches[j].name; j++) { |
| 342 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 343 | extensions[i]->version >= matches[j].version) { |
| 344 | field = ((char *) dri2_dpy + matches[j].offset); |
| 345 | *(const __DRIextension **) field = extensions[i]; |
| 346 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 347 | extensions[i]->name, extensions[i]->version); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | for (j = 0; matches[j].name; j++) { |
| 353 | field = ((char *) dri2_dpy + matches[j].offset); |
| 354 | if (*(const __DRIextension **) field == NULL) { |
| 355 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 356 | matches[j].name, matches[j].version); |
| 357 | ret = EGL_FALSE; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 364 | static const __DRIextension ** |
| 365 | dri2_open_driver(_EGLDisplay *disp) |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 366 | { |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 367 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 368 | const __DRIextension **extensions; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 369 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 370 | |
| 371 | search_paths = NULL; |
| 372 | if (geteuid() == getuid()) { |
| 373 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 374 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 375 | } |
| 376 | if (search_paths == NULL) |
| 377 | search_paths = DEFAULT_DRIVER_DIR; |
| 378 | |
| 379 | dri2_dpy->driver = NULL; |
| 380 | end = search_paths + strlen(search_paths); |
| 381 | for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 382 | int len; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 383 | next = strchr(p, ':'); |
| 384 | if (next == NULL) |
| 385 | next = end; |
| 386 | |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 387 | len = next - p; |
| 388 | #if GLX_USE_TLS |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 389 | snprintf(path, sizeof path, |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 390 | "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 391 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 392 | #endif |
| 393 | if (dri2_dpy->driver == NULL) { |
| 394 | snprintf(path, sizeof path, |
| 395 | "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name); |
| 396 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
| 397 | if (dri2_dpy->driver == NULL) |
| 398 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
| 399 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | if (dri2_dpy->driver == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 403 | _eglLog(_EGL_WARNING, |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 404 | "DRI2: failed to open %s (search paths %s)", |
| 405 | dri2_dpy->driver_name, search_paths); |
| 406 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 410 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 411 | if (extensions == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 412 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 413 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 414 | dlclose(dri2_dpy->driver); |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | return extensions; |
| 418 | } |
| 419 | |
| 420 | EGLBoolean |
| 421 | dri2_load_driver(_EGLDisplay *disp) |
| 422 | { |
| 423 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
| 424 | const __DRIextension **extensions; |
| 425 | |
| 426 | extensions = dri2_open_driver(disp); |
| 427 | if (!extensions) |
| 428 | return EGL_FALSE; |
| 429 | |
| 430 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) { |
| 431 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 432 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 433 | } |
| 434 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 435 | return EGL_TRUE; |
| 436 | } |
| 437 | |
| 438 | EGLBoolean |
| 439 | dri2_load_driver_swrast(_EGLDisplay *disp) |
| 440 | { |
| 441 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
| 442 | const __DRIextension **extensions; |
| 443 | |
| 444 | dri2_dpy->driver_name = "swrast"; |
| 445 | extensions = dri2_open_driver(disp); |
Chia-I Wu | 77e031a | 2011-06-08 16:33:56 +0800 | [diff] [blame] | 446 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 447 | if (!extensions) |
| 448 | return EGL_FALSE; |
| 449 | |
| 450 | if (!dri2_bind_extensions(dri2_dpy, swrast_driver_extensions, extensions)) { |
| 451 | dlclose(dri2_dpy->driver); |
| 452 | return EGL_FALSE; |
| 453 | } |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 454 | |
| 455 | return EGL_TRUE; |
| 456 | } |
| 457 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 458 | void |
| 459 | dri2_setup_screen(_EGLDisplay *disp) |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 460 | { |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 461 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 462 | unsigned int api_mask; |
| 463 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 464 | if (dri2_dpy->dri2) { |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 465 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 466 | } else { |
| 467 | assert(dri2_dpy->swrast); |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 468 | api_mask = 1 << __DRI_API_OPENGL | 1 << __DRI_API_GLES | 1 << __DRI_API_GLES2; |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 469 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 470 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 471 | disp->ClientAPIs = 0; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 472 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 473 | disp->ClientAPIs |= EGL_OPENGL_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 474 | if (api_mask & (1 <<__DRI_API_GLES)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 475 | disp->ClientAPIs |= EGL_OPENGL_ES_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 476 | if (api_mask & (1 << __DRI_API_GLES2)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 477 | disp->ClientAPIs |= EGL_OPENGL_ES2_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 478 | |
Ian Romanick | 38f91f2 | 2012-07-18 13:17:50 -0700 | [diff] [blame] | 479 | assert(dri2_dpy->dri2 || dri2_dpy->swrast); |
| 480 | disp->Extensions.KHR_surfaceless_context = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 481 | |
Paulo Alcantara | b41f36b | 2012-08-17 14:08:10 -0300 | [diff] [blame] | 482 | if (dri2_dpy->dri2 && dri2_dpy->dri2->base.version >= 3) { |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 483 | disp->Extensions.KHR_create_context = EGL_TRUE; |
| 484 | |
| 485 | if (dri2_dpy->robustness) |
| 486 | disp->Extensions.EXT_create_context_robustness = EGL_TRUE; |
| 487 | } |
| 488 | |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 489 | if (dri2_dpy->image) { |
| 490 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
| 491 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 492 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 493 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | EGLBoolean |
| 497 | dri2_create_screen(_EGLDisplay *disp) |
| 498 | { |
| 499 | const __DRIextension **extensions; |
| 500 | struct dri2_egl_display *dri2_dpy; |
| 501 | |
| 502 | dri2_dpy = disp->DriverData; |
| 503 | |
| 504 | if (dri2_dpy->dri2) { |
| 505 | dri2_dpy->dri_screen = |
| 506 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
| 507 | &dri2_dpy->driver_configs, disp); |
| 508 | } else { |
| 509 | assert(dri2_dpy->swrast); |
| 510 | dri2_dpy->dri_screen = |
| 511 | dri2_dpy->swrast->createNewScreen(0, dri2_dpy->extensions, |
| 512 | &dri2_dpy->driver_configs, disp); |
| 513 | } |
| 514 | |
| 515 | if (dri2_dpy->dri_screen == NULL) { |
| 516 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
| 517 | return EGL_FALSE; |
| 518 | } |
| 519 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 520 | dri2_dpy->own_dri_screen = 1; |
| 521 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 522 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
| 523 | |
| 524 | if (dri2_dpy->dri2) { |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 525 | unsigned i; |
| 526 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 527 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
| 528 | goto cleanup_dri_screen; |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 529 | |
| 530 | for (i = 0; extensions[i]; i++) { |
| 531 | if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0) { |
| 532 | dri2_dpy->robustness = (__DRIrobustnessExtension *) extensions[i]; |
| 533 | } |
Eric Anholt | 7e9bd2b | 2012-09-25 14:05:30 -0700 | [diff] [blame] | 534 | if (strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0) { |
| 535 | dri2_dpy->config = (__DRI2configQueryExtension *) extensions[i]; |
| 536 | } |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 537 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 538 | } else { |
| 539 | assert(dri2_dpy->swrast); |
| 540 | if (!dri2_bind_extensions(dri2_dpy, swrast_core_extensions, extensions)) |
| 541 | goto cleanup_dri_screen; |
| 542 | } |
| 543 | |
| 544 | dri2_setup_screen(disp); |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 545 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 546 | return EGL_TRUE; |
| 547 | |
| 548 | cleanup_dri_screen: |
| 549 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 550 | |
| 551 | return EGL_FALSE; |
| 552 | } |
| 553 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 554 | /** |
| 555 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 556 | */ |
| 557 | static EGLBoolean |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 558 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 559 | { |
Chia-I Wu | a22a332 | 2011-01-13 04:40:38 +0800 | [diff] [blame] | 560 | /* not until swrast_dri is supported */ |
| 561 | if (disp->Options.UseFallback) |
| 562 | return EGL_FALSE; |
| 563 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 564 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 565 | #ifdef HAVE_X11_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 566 | case _EGL_PLATFORM_X11: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 567 | if (disp->Options.TestOnly) |
| 568 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 569 | return dri2_initialize_x11(drv, disp); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 570 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 571 | |
| 572 | #ifdef HAVE_LIBUDEV |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 573 | #ifdef HAVE_DRM_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 574 | case _EGL_PLATFORM_DRM: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 575 | if (disp->Options.TestOnly) |
| 576 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 577 | return dri2_initialize_drm(drv, disp); |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 578 | #endif |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 579 | #ifdef HAVE_WAYLAND_PLATFORM |
| 580 | case _EGL_PLATFORM_WAYLAND: |
| 581 | if (disp->Options.TestOnly) |
| 582 | return EGL_TRUE; |
| 583 | return dri2_initialize_wayland(drv, disp); |
| 584 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 585 | #endif |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 586 | #ifdef HAVE_ANDROID_PLATFORM |
| 587 | case _EGL_PLATFORM_ANDROID: |
| 588 | if (disp->Options.TestOnly) |
| 589 | return EGL_TRUE; |
| 590 | return dri2_initialize_android(drv, disp); |
| 591 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 592 | |
| 593 | default: |
| 594 | return EGL_FALSE; |
| 595 | } |
| 596 | } |
| 597 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 598 | /** |
| 599 | * Called via eglTerminate(), drv->API.Terminate(). |
| 600 | */ |
| 601 | static EGLBoolean |
| 602 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 603 | { |
| 604 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 605 | |
| 606 | _eglReleaseDisplayResources(drv, disp); |
| 607 | _eglCleanupDisplay(disp); |
| 608 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 609 | if (dri2_dpy->own_dri_screen) |
| 610 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 611 | if (dri2_dpy->fd) |
| 612 | close(dri2_dpy->fd); |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 613 | if (dri2_dpy->driver) |
| 614 | dlclose(dri2_dpy->driver); |
Matt Turner | 5067506 | 2012-09-03 20:24:35 -0700 | [diff] [blame] | 615 | free(dri2_dpy->device_name); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 616 | |
| 617 | if (disp->PlatformDisplay == NULL) { |
| 618 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 619 | #ifdef HAVE_X11_PLATFORM |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 620 | case _EGL_PLATFORM_X11: |
| 621 | xcb_disconnect(dri2_dpy->conn); |
| 622 | break; |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 623 | #endif |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 624 | #ifdef HAVE_DRM_PLATFORM |
| 625 | case _EGL_PLATFORM_DRM: |
Benjamin Franzke | 2a58453 | 2011-12-13 14:43:48 +0100 | [diff] [blame] | 626 | if (dri2_dpy->own_device) { |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 627 | gbm_device_destroy(&dri2_dpy->gbm_dri->base.base); |
| 628 | } |
| 629 | break; |
| 630 | #endif |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 631 | default: |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 636 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 637 | disp->DriverData = NULL; |
| 638 | |
| 639 | return EGL_TRUE; |
| 640 | } |
| 641 | |
Chad Versace | 5cf8536 | 2012-11-09 14:06:41 -0800 | [diff] [blame^] | 642 | /** |
| 643 | * Set the error code after a call to |
| 644 | * dri2_egl_display::dri2::createContextAttribs. |
| 645 | */ |
| 646 | static void |
| 647 | dri2_create_context_attribs_error(int dri_error) |
| 648 | { |
| 649 | EGLint egl_error; |
| 650 | |
| 651 | switch (dri_error) { |
| 652 | case __DRI_CTX_ERROR_SUCCESS: |
| 653 | return; |
| 654 | |
| 655 | case __DRI_CTX_ERROR_NO_MEMORY: |
| 656 | egl_error = EGL_BAD_ALLOC; |
| 657 | break; |
| 658 | |
| 659 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 660 | * |
| 661 | * * If <config> does not support a client API context compatible |
| 662 | * with the requested API major and minor version, [...] context flags, |
| 663 | * and context reset notification behavior (for client API types where |
| 664 | * these attributes are supported), then an EGL_BAD_MATCH error is |
| 665 | * generated. |
| 666 | * |
| 667 | * * If an OpenGL ES context is requested and the values for |
| 668 | * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and |
| 669 | * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that |
| 670 | * is not defined, than an EGL_BAD_MATCH error is generated. |
| 671 | * |
| 672 | * * If an OpenGL context is requested, the requested version is |
| 673 | * greater than 3.2, and the value for attribute |
| 674 | * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any |
| 675 | * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and |
| 676 | * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than |
| 677 | * one of these bits set; or if the implementation does not support |
| 678 | * the requested profile, then an EGL_BAD_MATCH error is generated. |
| 679 | */ |
| 680 | case __DRI_CTX_ERROR_BAD_API: |
| 681 | case __DRI_CTX_ERROR_BAD_VERSION: |
| 682 | case __DRI_CTX_ERROR_BAD_FLAG: |
| 683 | egl_error = EGL_BAD_MATCH; |
| 684 | break; |
| 685 | |
| 686 | /* From the EGL_KHR_create_context spec, section "Errors": |
| 687 | * |
| 688 | * * If an attribute name or attribute value in <attrib_list> is not |
| 689 | * recognized (including unrecognized bits in bitmask attributes), |
| 690 | * then an EGL_BAD_ATTRIBUTE error is generated." |
| 691 | */ |
| 692 | case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE: |
| 693 | case __DRI_CTX_ERROR_UNKNOWN_FLAG: |
| 694 | egl_error = EGL_BAD_ATTRIBUTE; |
| 695 | break; |
| 696 | |
| 697 | default: |
| 698 | assert(0); |
| 699 | egl_error = EGL_BAD_MATCH; |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | _eglError(egl_error, "dri2_create_context"); |
| 704 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 705 | |
| 706 | /** |
| 707 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 708 | */ |
| 709 | static _EGLContext * |
| 710 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 711 | _EGLContext *share_list, const EGLint *attrib_list) |
| 712 | { |
| 713 | struct dri2_egl_context *dri2_ctx; |
| 714 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 715 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 716 | __DRIcontext *shared = |
| 717 | dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 718 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 719 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 720 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 721 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 722 | (void) drv; |
| 723 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 724 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 725 | if (!dri2_ctx) { |
| 726 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 727 | return NULL; |
| 728 | } |
| 729 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 730 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 731 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 732 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 733 | switch (dri2_ctx->base.ClientAPI) { |
| 734 | case EGL_OPENGL_ES_API: |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 735 | switch (dri2_ctx->base.ClientMajorVersion) { |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 736 | case 1: |
| 737 | api = __DRI_API_GLES; |
| 738 | break; |
| 739 | case 2: |
Ian Romanick | dbecb41 | 2012-07-19 16:12:13 -0700 | [diff] [blame] | 740 | case 3: |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 741 | api = __DRI_API_GLES2; |
| 742 | break; |
| 743 | default: |
| 744 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 745 | return NULL; |
| 746 | } |
| 747 | break; |
| 748 | case EGL_OPENGL_API: |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 749 | if ((dri2_ctx->base.ClientMajorVersion >= 4 |
| 750 | || (dri2_ctx->base.ClientMajorVersion == 3 |
| 751 | && dri2_ctx->base.ClientMinorVersion >= 2)) |
| 752 | && dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) |
| 753 | api = __DRI_API_OPENGL_CORE; |
| 754 | else |
| 755 | api = __DRI_API_OPENGL; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 756 | break; |
| 757 | default: |
| 758 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 759 | return NULL; |
| 760 | } |
| 761 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 762 | if (conf != NULL) { |
| 763 | /* The config chosen here isn't necessarily |
| 764 | * used for surfaces later. |
| 765 | * A pixmap surface will use the single config. |
| 766 | * This opportunity depends on disabling the |
| 767 | * doubleBufferMode check in |
| 768 | * src/mesa/main/context.c:check_compatible() |
| 769 | */ |
| 770 | if (dri2_config->dri_double_config) |
| 771 | dri_config = dri2_config->dri_double_config; |
| 772 | else |
| 773 | dri_config = dri2_config->dri_single_config; |
Chia-I Wu | 357d3f3 | 2011-08-27 01:42:16 +0800 | [diff] [blame] | 774 | |
| 775 | /* EGL_WINDOW_BIT is set only when there is a dri_double_config. This |
| 776 | * makes sure the back buffer will always be used. |
| 777 | */ |
| 778 | if (conf->SurfaceType & EGL_WINDOW_BIT) |
| 779 | dri2_ctx->base.WindowRenderBuffer = EGL_BACK_BUFFER; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 780 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 781 | else |
| 782 | dri_config = NULL; |
| 783 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 784 | if (dri2_dpy->dri2) { |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 785 | if (dri2_dpy->dri2->base.version >= 3) { |
| 786 | unsigned error; |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 787 | unsigned num_attribs = 0; |
| 788 | uint32_t ctx_attribs[8]; |
| 789 | |
| 790 | ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION; |
| 791 | ctx_attribs[num_attribs++] = dri2_ctx->base.ClientMajorVersion; |
| 792 | ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION; |
| 793 | ctx_attribs[num_attribs++] = dri2_ctx->base.ClientMinorVersion; |
| 794 | |
| 795 | if (dri2_ctx->base.Flags != 0) { |
| 796 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 797 | * extension, don't even try to send it the robust-access flag. |
| 798 | * It may explode. Instead, generate the required EGL error here. |
| 799 | */ |
| 800 | if ((dri2_ctx->base.Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0 |
| 801 | && !dri2_dpy->robustness) { |
| 802 | _eglError(EGL_BAD_MATCH, "eglCreateContext"); |
| 803 | goto cleanup; |
| 804 | } |
| 805 | |
| 806 | ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_FLAGS; |
| 807 | ctx_attribs[num_attribs++] = dri2_ctx->base.Flags; |
| 808 | } |
| 809 | |
| 810 | if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) { |
| 811 | /* If the implementation doesn't support the __DRI2_ROBUSTNESS |
| 812 | * extension, don't even try to send it a reset strategy. It may |
| 813 | * explode. Instead, generate the required EGL error here. |
| 814 | */ |
| 815 | if (!dri2_dpy->robustness) { |
| 816 | _eglError(EGL_BAD_CONFIG, "eglCreateContext"); |
| 817 | goto cleanup; |
| 818 | } |
| 819 | |
| 820 | ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_RESET_STRATEGY; |
| 821 | ctx_attribs[num_attribs++] = __DRI_CTX_RESET_LOSE_CONTEXT; |
| 822 | } |
| 823 | |
| 824 | assert(num_attribs <= ARRAY_SIZE(ctx_attribs)); |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 825 | |
| 826 | dri2_ctx->dri_context = |
| 827 | dri2_dpy->dri2->createContextAttribs(dri2_dpy->dri_screen, |
| 828 | api, |
| 829 | dri_config, |
| 830 | shared, |
Ian Romanick | 7b4b4f8 | 2012-07-19 16:04:01 -0700 | [diff] [blame] | 831 | num_attribs / 2, |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 832 | ctx_attribs, |
| 833 | & error, |
| 834 | dri2_ctx); |
Chad Versace | 5cf8536 | 2012-11-09 14:06:41 -0800 | [diff] [blame^] | 835 | dri2_create_context_attribs_error(error); |
Ian Romanick | ce55741 | 2012-07-18 14:41:28 -0700 | [diff] [blame] | 836 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 837 | dri2_ctx->dri_context = |
| 838 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 839 | api, |
| 840 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 841 | shared, |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 842 | dri2_ctx); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 843 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 844 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 845 | assert(dri2_dpy->swrast); |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 846 | dri2_ctx->dri_context = |
| 847 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 848 | api, |
| 849 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame] | 850 | shared, |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 851 | dri2_ctx); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 852 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 853 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 854 | if (!dri2_ctx->dri_context) |
| 855 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 856 | |
| 857 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 858 | |
| 859 | cleanup: |
| 860 | free(dri2_ctx); |
| 861 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 862 | } |
| 863 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 864 | /** |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 865 | * Called via eglDestroyContext(), drv->API.DestroyContext(). |
| 866 | */ |
| 867 | static EGLBoolean |
| 868 | dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
| 869 | { |
| 870 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 871 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 872 | |
| 873 | if (_eglPutContext(ctx)) { |
| 874 | dri2_dpy->core->destroyContext(dri2_ctx->dri_context); |
| 875 | free(dri2_ctx); |
| 876 | } |
| 877 | |
| 878 | return EGL_TRUE; |
| 879 | } |
| 880 | |
| 881 | /** |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 882 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 883 | */ |
| 884 | static EGLBoolean |
| 885 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 886 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 887 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 888 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 889 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 890 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 891 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 892 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 893 | _EGLContext *old_ctx; |
| 894 | _EGLSurface *old_dsurf, *old_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 895 | __DRIdrawable *ddraw, *rdraw; |
| 896 | __DRIcontext *cctx; |
| 897 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 898 | /* make new bindings */ |
| 899 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 900 | return EGL_FALSE; |
| 901 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 902 | /* flush before context switch */ |
Chia-I Wu | 547e761 | 2010-10-26 15:00:56 +0800 | [diff] [blame] | 903 | if (old_ctx && dri2_drv->glFlush) |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 904 | dri2_drv->glFlush(); |
| 905 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 906 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 907 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 908 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 909 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 910 | if (old_ctx) { |
| 911 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 912 | dri2_dpy->core->unbindContext(old_cctx); |
| 913 | } |
| 914 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 915 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 916 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 917 | if (old_dsurf) |
| 918 | drv->API.DestroySurface(drv, disp, old_dsurf); |
| 919 | if (old_rsurf) |
| 920 | drv->API.DestroySurface(drv, disp, old_rsurf); |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 921 | if (old_ctx) |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 922 | drv->API.DestroyContext(drv, disp, old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 923 | |
| 924 | return EGL_TRUE; |
| 925 | } else { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 926 | /* undo the previous _eglBindContext */ |
| 927 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); |
| 928 | assert(&dri2_ctx->base == ctx && |
| 929 | &dri2_dsurf->base == dsurf && |
| 930 | &dri2_rsurf->base == rsurf); |
| 931 | |
| 932 | _eglPutSurface(dsurf); |
| 933 | _eglPutSurface(rsurf); |
| 934 | _eglPutContext(ctx); |
| 935 | |
| 936 | _eglPutSurface(old_dsurf); |
| 937 | _eglPutSurface(old_rsurf); |
| 938 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 939 | |
| 940 | return EGL_FALSE; |
| 941 | } |
| 942 | } |
| 943 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 944 | /* |
| 945 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 946 | */ |
| 947 | static _EGLProc |
| 948 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 949 | { |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 950 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 951 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 952 | return dri2_drv->get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 956 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 957 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 958 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 959 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 960 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 961 | (void) drv; |
| 962 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 963 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 964 | * we need to copy fake to real here.*/ |
| 965 | |
| 966 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 967 | |
| 968 | return EGL_TRUE; |
| 969 | } |
| 970 | |
| 971 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 972 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 973 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 974 | (void) drv; |
| 975 | (void) disp; |
| 976 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 977 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 978 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 979 | /* glXWaitX(); */ |
| 980 | |
| 981 | return EGL_TRUE; |
| 982 | } |
| 983 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 984 | static EGLBoolean |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 985 | dri2_bind_tex_image(_EGLDriver *drv, |
| 986 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 987 | { |
| 988 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 989 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 990 | struct dri2_egl_context *dri2_ctx; |
| 991 | _EGLContext *ctx; |
| 992 | GLint format, target; |
| 993 | |
| 994 | ctx = _eglGetCurrentContext(); |
| 995 | dri2_ctx = dri2_egl_context(ctx); |
| 996 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 997 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 998 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 999 | |
| 1000 | switch (dri2_surf->base.TextureFormat) { |
| 1001 | case EGL_TEXTURE_RGB: |
| 1002 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 1003 | break; |
| 1004 | case EGL_TEXTURE_RGBA: |
| 1005 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 1006 | break; |
| 1007 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1008 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | switch (dri2_surf->base.TextureTarget) { |
| 1012 | case EGL_TEXTURE_2D: |
| 1013 | target = GL_TEXTURE_2D; |
| 1014 | break; |
| 1015 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1016 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 1020 | target, format, |
| 1021 | dri2_surf->dri_drawable); |
| 1022 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1023 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static EGLBoolean |
| 1027 | dri2_release_tex_image(_EGLDriver *drv, |
| 1028 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1029 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 1030 | #if __DRI_TEX_BUFFER_VERSION >= 3 |
| 1031 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1032 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1033 | struct dri2_egl_context *dri2_ctx; |
| 1034 | _EGLContext *ctx; |
| 1035 | GLint target; |
| 1036 | |
| 1037 | ctx = _eglGetCurrentContext(); |
| 1038 | dri2_ctx = dri2_egl_context(ctx); |
| 1039 | |
| 1040 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 1041 | return EGL_FALSE; |
| 1042 | |
| 1043 | switch (dri2_surf->base.TextureTarget) { |
| 1044 | case EGL_TEXTURE_2D: |
| 1045 | target = GL_TEXTURE_2D; |
| 1046 | break; |
| 1047 | default: |
| 1048 | assert(0); |
| 1049 | } |
| 1050 | if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL) |
| 1051 | (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context, |
| 1052 | target, |
| 1053 | dri2_surf->dri_drawable); |
| 1054 | #endif |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1055 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1056 | return EGL_TRUE; |
| 1057 | } |
| 1058 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1059 | static _EGLImage * |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1060 | dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image) |
| 1061 | { |
| 1062 | struct dri2_egl_image *dri2_img; |
| 1063 | |
| 1064 | if (dri_image == NULL) { |
| 1065 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 1066 | return NULL; |
| 1067 | } |
| 1068 | |
| 1069 | dri2_img = malloc(sizeof *dri2_img); |
| 1070 | if (!dri2_img) { |
| 1071 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 1072 | return NULL; |
| 1073 | } |
| 1074 | |
| 1075 | if (!_eglInitImage(&dri2_img->base, disp)) { |
| 1076 | free(dri2_img); |
| 1077 | return NULL; |
| 1078 | } |
| 1079 | |
| 1080 | dri2_img->dri_image = dri_image; |
| 1081 | |
| 1082 | return &dri2_img->base; |
| 1083 | } |
| 1084 | |
| 1085 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1086 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 1087 | EGLClientBuffer buffer, |
| 1088 | const EGLint *attr_list) |
| 1089 | { |
| 1090 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1091 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 1092 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1093 | __DRIimage *dri_image; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1094 | |
| 1095 | if (renderbuffer == 0) { |
| 1096 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1097 | return EGL_NO_IMAGE_KHR; |
| 1098 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1099 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1100 | dri_image = |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1101 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1102 | renderbuffer, NULL); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1103 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1104 | return dri2_create_image(disp, dri_image); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | static _EGLImage * |
| 1108 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 1109 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1110 | { |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1111 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1112 | EGLint format, name, pitch, err; |
| 1113 | _EGLImageAttribs attrs; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1114 | __DRIimage *dri_image; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1115 | |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 1116 | name = (EGLint) (uintptr_t) buffer; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1117 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1118 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1119 | if (err != EGL_SUCCESS) |
| 1120 | return NULL; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1121 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1122 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 1123 | attrs.DRMBufferStrideMESA <= 0) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1124 | _eglError(EGL_BAD_PARAMETER, |
| 1125 | "bad width, height or stride"); |
| 1126 | return NULL; |
| 1127 | } |
| 1128 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1129 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1130 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1131 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1132 | pitch = attrs.DRMBufferStrideMESA; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1133 | break; |
| 1134 | default: |
| 1135 | _eglError(EGL_BAD_PARAMETER, |
| 1136 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 1137 | return NULL; |
| 1138 | } |
| 1139 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1140 | dri_image = |
| 1141 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 1142 | attrs.Width, |
| 1143 | attrs.Height, |
| 1144 | format, |
| 1145 | name, |
| 1146 | pitch, |
| 1147 | NULL); |
| 1148 | |
| 1149 | return dri2_create_image(disp, dri_image); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 1152 | #ifdef HAVE_WAYLAND_PLATFORM |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1153 | |
| 1154 | /* This structure describes how a wl_buffer maps to one or more |
| 1155 | * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the |
| 1156 | * offsets and strides of the planes in the buffer. This table maps a |
| 1157 | * wl_drm format code to a description of the planes in the buffer |
| 1158 | * that lets us create a __DRIimage for each of the planes. */ |
| 1159 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1160 | static const struct wl_drm_components_descriptor { |
| 1161 | uint32_t dri_components; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1162 | EGLint components; |
| 1163 | int nplanes; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1164 | } wl_drm_components[] = { |
| 1165 | { __DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1 }, |
| 1166 | { __DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1 }, |
| 1167 | { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 }, |
| 1168 | { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 }, |
| 1169 | { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 }, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1170 | }; |
| 1171 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1172 | static _EGLImage * |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1173 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1174 | EGLClientBuffer _buffer, |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1175 | const EGLint *attr_list) |
| 1176 | { |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1177 | struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1178 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1179 | const struct wl_drm_components_descriptor *f; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1180 | __DRIimage *dri_image; |
| 1181 | _EGLImageAttribs attrs; |
| 1182 | EGLint err; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1183 | int32_t plane; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1184 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1185 | if (!wayland_buffer_is_drm(&buffer->buffer)) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1186 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1187 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1188 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1189 | plane = attrs.PlaneWL; |
| 1190 | if (err != EGL_SUCCESS) { |
| 1191 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 1192 | return NULL; |
| 1193 | } |
| 1194 | |
| 1195 | f = buffer->driver_format; |
| 1196 | if (plane < 0 || plane >= f->nplanes) { |
| 1197 | _eglError(EGL_BAD_PARAMETER, |
| 1198 | "dri2_create_image_wayland_wl_buffer (plane out of bounds)"); |
| 1199 | return NULL; |
| 1200 | } |
| 1201 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1202 | dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1203 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1204 | if (dri_image == NULL) { |
| 1205 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 1206 | return NULL; |
| 1207 | } |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1208 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1209 | return dri2_create_image(disp, dri_image); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1210 | } |
| 1211 | #endif |
| 1212 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 1213 | _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1214 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 1215 | _EGLContext *ctx, EGLenum target, |
| 1216 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1217 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1218 | (void) drv; |
| 1219 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1220 | switch (target) { |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1221 | case EGL_GL_RENDERBUFFER_KHR: |
| 1222 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1223 | case EGL_DRM_BUFFER_MESA: |
| 1224 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1225 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1226 | case EGL_WAYLAND_BUFFER_WL: |
| 1227 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 1228 | #endif |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1229 | default: |
| 1230 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1231 | return EGL_NO_IMAGE_KHR; |
| 1232 | } |
| 1233 | } |
| 1234 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1235 | static EGLBoolean |
| 1236 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1237 | { |
| 1238 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1239 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1240 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1241 | (void) drv; |
| 1242 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1243 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1244 | free(dri2_img); |
| 1245 | |
| 1246 | return EGL_TRUE; |
| 1247 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1248 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1249 | static _EGLImage * |
| 1250 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 1251 | const EGLint *attr_list) |
| 1252 | { |
| 1253 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1254 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1255 | _EGLImageAttribs attrs; |
| 1256 | unsigned int dri_use, valid_mask; |
| 1257 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1258 | EGLint err = EGL_SUCCESS; |
| 1259 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1260 | (void) drv; |
| 1261 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1262 | dri2_img = malloc(sizeof *dri2_img); |
| 1263 | if (!dri2_img) { |
| 1264 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1265 | return EGL_NO_IMAGE_KHR; |
| 1266 | } |
| 1267 | |
| 1268 | if (!attr_list) { |
| 1269 | err = EGL_BAD_PARAMETER; |
| 1270 | goto cleanup_img; |
| 1271 | } |
| 1272 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 1273 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1274 | err = EGL_BAD_PARAMETER; |
| 1275 | goto cleanup_img; |
| 1276 | } |
| 1277 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1278 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1279 | if (err != EGL_SUCCESS) |
| 1280 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1281 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1282 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 1283 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 1284 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1285 | goto cleanup_img; |
| 1286 | } |
| 1287 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1288 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1289 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1290 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1291 | break; |
| 1292 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1293 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 1294 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1295 | goto cleanup_img; |
| 1296 | } |
| 1297 | |
| 1298 | valid_mask = |
| 1299 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1300 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 1301 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1302 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 1303 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 1304 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1305 | goto cleanup_img; |
| 1306 | } |
| 1307 | |
| 1308 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1309 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1310 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1311 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1312 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1313 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 1314 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1315 | |
| 1316 | dri2_img->dri_image = |
| 1317 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1318 | attrs.Width, attrs.Height, |
| 1319 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1320 | if (dri2_img->dri_image == NULL) { |
| 1321 | err = EGL_BAD_ALLOC; |
| 1322 | goto cleanup_img; |
| 1323 | } |
| 1324 | |
| 1325 | return &dri2_img->base; |
| 1326 | |
| 1327 | cleanup_img: |
| 1328 | free(dri2_img); |
| 1329 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 1330 | |
| 1331 | return EGL_NO_IMAGE_KHR; |
| 1332 | } |
| 1333 | |
| 1334 | static EGLBoolean |
| 1335 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 1336 | EGLint *name, EGLint *handle, EGLint *stride) |
| 1337 | { |
| 1338 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1339 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 1340 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1341 | (void) drv; |
| 1342 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1343 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1344 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
| 1345 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 1346 | return EGL_FALSE; |
| 1347 | } |
| 1348 | |
| 1349 | if (handle) |
| 1350 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1351 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
| 1352 | |
| 1353 | if (stride) |
| 1354 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1355 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
| 1356 | |
| 1357 | return EGL_TRUE; |
| 1358 | } |
| 1359 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1360 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1361 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1362 | static void |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1363 | dri2_wl_reference_buffer(void *user_data, uint32_t name, |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1364 | struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1365 | { |
| 1366 | _EGLDisplay *disp = user_data; |
| 1367 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1368 | __DRIimage *img; |
| 1369 | int i, dri_components = 0; |
Kristian Høgsberg | 7b1d94e | 2011-08-31 16:45:04 -0400 | [diff] [blame] | 1370 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1371 | img = dri2_dpy->image->createImageFromNames(dri2_dpy->dri_screen, |
| 1372 | buffer->buffer.width, |
| 1373 | buffer->buffer.height, |
| 1374 | buffer->format, (int*)&name, 1, |
| 1375 | buffer->stride, |
| 1376 | buffer->offset, |
| 1377 | NULL); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1378 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1379 | if (img == NULL) |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1380 | return; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1381 | |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1382 | dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, &dri_components); |
| 1383 | |
| 1384 | buffer->driver_format = NULL; |
| 1385 | for (i = 0; i < ARRAY_SIZE(wl_drm_components); i++) |
| 1386 | if (wl_drm_components[i].dri_components == dri_components) |
| 1387 | buffer->driver_format = &wl_drm_components[i]; |
| 1388 | |
| 1389 | if (buffer->driver_format == NULL) |
| 1390 | dri2_dpy->image->destroyImage(img); |
| 1391 | else |
| 1392 | buffer->driver_buffer = img; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static void |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1396 | dri2_wl_release_buffer(void *user_data, struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1397 | { |
| 1398 | _EGLDisplay *disp = user_data; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1399 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1400 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1401 | dri2_dpy->image->destroyImage(buffer->driver_buffer); |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | static struct wayland_drm_callbacks wl_drm_callbacks = { |
| 1405 | .authenticate = NULL, |
| 1406 | .reference_buffer = dri2_wl_reference_buffer, |
| 1407 | .release_buffer = dri2_wl_release_buffer |
| 1408 | }; |
| 1409 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1410 | static EGLBoolean |
| 1411 | dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1412 | struct wl_display *wl_dpy) |
| 1413 | { |
| 1414 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1415 | |
| 1416 | (void) drv; |
| 1417 | |
| 1418 | if (dri2_dpy->wl_server_drm) |
| 1419 | return EGL_FALSE; |
| 1420 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1421 | wl_drm_callbacks.authenticate = |
| 1422 | (int(*)(void *, uint32_t)) dri2_dpy->authenticate; |
| 1423 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1424 | dri2_dpy->wl_server_drm = |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1425 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
| 1426 | &wl_drm_callbacks, disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1427 | |
| 1428 | if (!dri2_dpy->wl_server_drm) |
| 1429 | return EGL_FALSE; |
| 1430 | |
| 1431 | return EGL_TRUE; |
| 1432 | } |
| 1433 | |
| 1434 | static EGLBoolean |
| 1435 | dri2_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1436 | struct wl_display *wl_dpy) |
| 1437 | { |
| 1438 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1439 | |
| 1440 | (void) drv; |
| 1441 | |
| 1442 | if (!dri2_dpy->wl_server_drm) |
| 1443 | return EGL_FALSE; |
| 1444 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1445 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1446 | dri2_dpy->wl_server_drm = NULL; |
| 1447 | |
| 1448 | return EGL_TRUE; |
| 1449 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1450 | |
| 1451 | static EGLBoolean |
| 1452 | dri2_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1453 | struct wl_buffer *_buffer, |
| 1454 | EGLint attribute, EGLint *value) |
| 1455 | { |
| 1456 | struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; |
Jakob Bornecrantz | 6a7dea9 | 2012-08-31 19:48:26 +0200 | [diff] [blame] | 1457 | const struct wl_drm_components_descriptor *format; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1458 | |
| 1459 | if (!wayland_buffer_is_drm(&buffer->buffer)) |
| 1460 | return EGL_FALSE; |
| 1461 | |
| 1462 | format = buffer->driver_format; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 1463 | switch (attribute) { |
| 1464 | case EGL_TEXTURE_FORMAT: |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1465 | *value = format->components; |
| 1466 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 1467 | case EGL_WIDTH: |
| 1468 | *value = buffer->buffer.width; |
| 1469 | break; |
| 1470 | case EGL_HEIGHT: |
| 1471 | *value = buffer->buffer.height; |
| 1472 | break; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | return EGL_FALSE; |
| 1476 | } |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1477 | #endif |
| 1478 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1479 | static void |
| 1480 | dri2_unload(_EGLDriver *drv) |
| 1481 | { |
| 1482 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1483 | |
| 1484 | if (dri2_drv->handle) |
| 1485 | dlclose(dri2_drv->handle); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1486 | free(dri2_drv); |
| 1487 | } |
| 1488 | |
| 1489 | static EGLBoolean |
| 1490 | dri2_load(_EGLDriver *drv) |
| 1491 | { |
| 1492 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Matt Turner | 027ce0c | 2012-01-24 11:34:42 -0500 | [diff] [blame] | 1493 | #ifdef HAVE_SHARED_GLAPI |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1494 | #ifdef HAVE_ANDROID_PLATFORM |
| 1495 | const char *libname = "libglapi.so"; |
| 1496 | #else |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1497 | const char *libname = "libglapi.so.0"; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1498 | #endif |
Matt Turner | 027ce0c | 2012-01-24 11:34:42 -0500 | [diff] [blame] | 1499 | #else |
| 1500 | /* |
| 1501 | * Both libGL.so and libglapi.so are glapi providers. There is no way to |
| 1502 | * tell which one to load. |
| 1503 | */ |
| 1504 | const char *libname = NULL; |
| 1505 | #endif |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1506 | void *handle; |
| 1507 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1508 | /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */ |
| 1509 | handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1510 | if (handle) { |
| 1511 | dri2_drv->get_proc_address = (_EGLProc (*)(const char *)) |
| 1512 | dlsym(handle, "_glapi_get_proc_address"); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1513 | if (!dri2_drv->get_proc_address || !libname) { |
| 1514 | /* no need to keep a reference */ |
| 1515 | dlclose(handle); |
| 1516 | handle = NULL; |
| 1517 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1518 | } |
| 1519 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1520 | /* if glapi is not available, loading DRI drivers will fail */ |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1521 | if (!dri2_drv->get_proc_address) { |
| 1522 | _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address"); |
| 1523 | return EGL_FALSE; |
| 1524 | } |
| 1525 | |
| 1526 | dri2_drv->glFlush = (void (*)(void)) |
| 1527 | dri2_drv->get_proc_address("glFlush"); |
| 1528 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1529 | dri2_drv->handle = handle; |
| 1530 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1531 | return EGL_TRUE; |
| 1532 | } |
| 1533 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1534 | /** |
| 1535 | * This is the main entrypoint into the driver, called by libEGL. |
| 1536 | * Create a new _EGLDriver object and init its dispatch table. |
| 1537 | */ |
| 1538 | _EGLDriver * |
Eric Anholt | 9f0f00c | 2012-02-05 07:01:17 +0100 | [diff] [blame] | 1539 | _eglBuiltInDriverDRI2(const char *args) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1540 | { |
| 1541 | struct dri2_egl_driver *dri2_drv; |
| 1542 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1543 | (void) args; |
| 1544 | |
Matt Turner | 6bda027 | 2012-09-04 23:09:22 -0700 | [diff] [blame] | 1545 | dri2_drv = calloc(1, sizeof *dri2_drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1546 | if (!dri2_drv) |
| 1547 | return NULL; |
| 1548 | |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 1549 | if (!dri2_load(&dri2_drv->base)) { |
| 1550 | free(dri2_drv); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1551 | return NULL; |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 1552 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1553 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1554 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1555 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1556 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1557 | dri2_drv->base.API.CreateContext = dri2_create_context; |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1558 | dri2_drv->base.API.DestroyContext = dri2_destroy_context; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1559 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1560 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1561 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1562 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1563 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1564 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1565 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1566 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1567 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 1568 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1569 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1570 | dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl; |
| 1571 | dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1572 | dri2_drv->base.API.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1573 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1574 | |
| 1575 | dri2_drv->base.Name = "DRI2"; |
| 1576 | dri2_drv->base.Unload = dri2_unload; |
| 1577 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1578 | return &dri2_drv->base; |
| 1579 | } |