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 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 100 | struct dri2_egl_config * |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 101 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 102 | int depth, EGLint surface_type, const EGLint *attr_list) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 103 | { |
| 104 | struct dri2_egl_config *conf; |
| 105 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 106 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 107 | unsigned int attrib, value, double_buffer; |
| 108 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 109 | _EGLConfig *matching_config; |
| 110 | EGLint num_configs = 0; |
| 111 | EGLint config_id; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 112 | int i; |
| 113 | |
| 114 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 115 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 116 | |
| 117 | i = 0; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 118 | double_buffer = 0; |
| 119 | bind_to_texture_rgb = 0; |
| 120 | bind_to_texture_rgba = 0; |
| 121 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 122 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 123 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 124 | case __DRI_ATTRIB_RENDER_TYPE: |
| 125 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 126 | value = EGL_RGB_BUFFER; |
| 127 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 128 | value = EGL_LUMINANCE_BUFFER; |
| 129 | else |
| 130 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 131 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 132 | break; |
| 133 | |
| 134 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 135 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 136 | value = EGL_NON_CONFORMANT_CONFIG; |
| 137 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 138 | value = EGL_SLOW_CONFIG; |
| 139 | else |
| 140 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 141 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 142 | break; |
| 143 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 144 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 145 | bind_to_texture_rgb = value; |
| 146 | break; |
| 147 | |
| 148 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 149 | bind_to_texture_rgba = value; |
| 150 | break; |
| 151 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 152 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 153 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 154 | break; |
| 155 | |
| 156 | default: |
| 157 | key = dri2_to_egl_attribute_map[attrib]; |
| 158 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 159 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 164 | if (attr_list) |
| 165 | for (i = 0; attr_list[i] != EGL_NONE; i += 2) |
| 166 | _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 167 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 168 | if (depth > 0 && depth != base.BufferSize) |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 169 | return NULL; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 170 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 171 | base.NativeRenderable = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 172 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 173 | base.SurfaceType = surface_type; |
Benjamin Franzke | a8128d7 | 2011-02-04 12:32:30 +0100 | [diff] [blame] | 174 | if (surface_type & (EGL_PBUFFER_BIT | |
| 175 | (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 176 | base.BindToTextureRGB = bind_to_texture_rgb; |
| 177 | if (base.AlphaSize > 0) |
| 178 | base.BindToTextureRGBA = bind_to_texture_rgba; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 179 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 180 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 181 | base.RenderableType = disp->ClientAPIs; |
| 182 | base.Conformant = disp->ClientAPIs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 183 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 184 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 185 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 186 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 189 | config_id = base.ConfigID; |
| 190 | base.ConfigID = EGL_DONT_CARE; |
| 191 | base.SurfaceType = EGL_DONT_CARE; |
| 192 | num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, |
| 193 | (_EGLArrayForEach) _eglMatchConfig, &base); |
| 194 | |
| 195 | if (num_configs == 1) { |
| 196 | conf = (struct dri2_egl_config *) matching_config; |
| 197 | |
| 198 | if (double_buffer && !conf->dri_double_config) |
| 199 | conf->dri_double_config = dri_config; |
| 200 | else if (!double_buffer && !conf->dri_single_config) |
| 201 | conf->dri_single_config = dri_config; |
| 202 | else |
Benjamin Franzke | 83c6875 | 2011-05-12 19:30:05 +0200 | [diff] [blame] | 203 | /* a similar config type is already added (unlikely) => discard */ |
| 204 | return NULL; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 205 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 206 | else if (num_configs == 0) { |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 207 | conf = malloc(sizeof *conf); |
| 208 | if (conf == NULL) |
| 209 | return NULL; |
| 210 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 211 | memcpy(&conf->base, &base, sizeof base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 212 | if (double_buffer) { |
| 213 | conf->dri_double_config = dri_config; |
| 214 | conf->dri_single_config = NULL; |
| 215 | } else { |
| 216 | conf->dri_single_config = dri_config; |
| 217 | conf->dri_double_config = NULL; |
| 218 | } |
| 219 | conf->base.SurfaceType = 0; |
| 220 | conf->base.ConfigID = config_id; |
| 221 | |
Chia-I Wu | 8a6bdf3 | 2010-10-23 00:47:22 +0800 | [diff] [blame] | 222 | _eglLinkConfig(&conf->base); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 223 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 224 | else { |
| 225 | assert(0); |
| 226 | return NULL; |
| 227 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 228 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 229 | conf->base.SurfaceType |= surface_type & (!double_buffer ? EGL_PIXMAP_BIT: |
| 230 | (EGL_WINDOW_BIT | EGL_PBUFFER_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT)); |
| 231 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 232 | return conf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 233 | } |
| 234 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 235 | static __DRIimage * |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 236 | dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 237 | { |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 238 | _EGLDisplay *disp = data; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 239 | struct dri2_egl_image *dri2_img; |
| 240 | _EGLImage *img; |
| 241 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 242 | (void) screen; |
| 243 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 244 | img = _eglLookupImage(image, disp); |
| 245 | if (img == NULL) { |
| 246 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | dri2_img = dri2_egl_image(image); |
| 251 | |
| 252 | return dri2_img->dri_image; |
| 253 | } |
| 254 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 255 | const __DRIimageLookupExtension image_lookup_extension = { |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 256 | { __DRI_IMAGE_LOOKUP, 1 }, |
| 257 | dri2_lookup_egl_image |
| 258 | }; |
| 259 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 260 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 261 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 262 | struct dri2_extension_match { |
| 263 | const char *name; |
| 264 | int version; |
| 265 | int offset; |
| 266 | }; |
| 267 | |
| 268 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 269 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 270 | { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 271 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 275 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 276 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 277 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 278 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 279 | }; |
| 280 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 281 | static struct dri2_extension_match swrast_driver_extensions[] = { |
| 282 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 283 | { __DRI_SWRAST, 2, offsetof(struct dri2_egl_display, swrast) }, |
| 284 | { NULL } |
| 285 | }; |
| 286 | |
| 287 | static struct dri2_extension_match swrast_core_extensions[] = { |
| 288 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
| 289 | { NULL } |
| 290 | }; |
| 291 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 292 | static EGLBoolean |
| 293 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 294 | struct dri2_extension_match *matches, |
| 295 | const __DRIextension **extensions) |
| 296 | { |
| 297 | int i, j, ret = EGL_TRUE; |
| 298 | void *field; |
| 299 | |
| 300 | for (i = 0; extensions[i]; i++) { |
| 301 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 302 | for (j = 0; matches[j].name; j++) { |
| 303 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 304 | extensions[i]->version >= matches[j].version) { |
| 305 | field = ((char *) dri2_dpy + matches[j].offset); |
| 306 | *(const __DRIextension **) field = extensions[i]; |
| 307 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 308 | extensions[i]->name, extensions[i]->version); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | for (j = 0; matches[j].name; j++) { |
| 314 | field = ((char *) dri2_dpy + matches[j].offset); |
| 315 | if (*(const __DRIextension **) field == NULL) { |
| 316 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 317 | matches[j].name, matches[j].version); |
| 318 | ret = EGL_FALSE; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return ret; |
| 323 | } |
| 324 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 325 | EGLBoolean |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 326 | dri2_load_driver(_EGLDisplay *disp) |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 327 | { |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 328 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 329 | const __DRIextension **extensions; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 330 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 331 | |
| 332 | search_paths = NULL; |
| 333 | if (geteuid() == getuid()) { |
| 334 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 335 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 336 | } |
| 337 | if (search_paths == NULL) |
| 338 | search_paths = DEFAULT_DRIVER_DIR; |
| 339 | |
| 340 | dri2_dpy->driver = NULL; |
| 341 | end = search_paths + strlen(search_paths); |
| 342 | 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] | 343 | int len; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 344 | next = strchr(p, ':'); |
| 345 | if (next == NULL) |
| 346 | next = end; |
| 347 | |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 348 | len = next - p; |
| 349 | #if GLX_USE_TLS |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 350 | snprintf(path, sizeof path, |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 351 | "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 352 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 353 | #endif |
| 354 | if (dri2_dpy->driver == NULL) { |
| 355 | snprintf(path, sizeof path, |
| 356 | "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name); |
| 357 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
| 358 | if (dri2_dpy->driver == NULL) |
| 359 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
| 360 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | if (dri2_dpy->driver == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 364 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 365 | "DRI2: failed to open any driver (search paths %s)", |
| 366 | search_paths); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 367 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 371 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 372 | if (extensions == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 373 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 374 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 375 | dlclose(dri2_dpy->driver); |
| 376 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 377 | } |
| 378 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 379 | if (strcmp(dri2_dpy->driver_name, "swrast") == 0) { |
| 380 | if (!dri2_bind_extensions(dri2_dpy, swrast_driver_extensions, extensions)) { |
| 381 | dlclose(dri2_dpy->driver); |
| 382 | return EGL_FALSE; |
| 383 | } |
| 384 | } else { |
| 385 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) { |
| 386 | dlclose(dri2_dpy->driver); |
| 387 | return EGL_FALSE; |
| 388 | } |
| 389 | } |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 390 | |
| 391 | return EGL_TRUE; |
| 392 | } |
| 393 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 394 | EGLBoolean |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 395 | dri2_create_screen(_EGLDisplay *disp) |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 396 | { |
| 397 | const __DRIextension **extensions; |
| 398 | struct dri2_egl_display *dri2_dpy; |
| 399 | unsigned int api_mask; |
| 400 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 401 | dri2_dpy = disp->DriverData; |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 402 | |
| 403 | if (dri2_dpy->dri2) { |
| 404 | dri2_dpy->dri_screen = |
| 405 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
| 406 | &dri2_dpy->driver_configs, disp); |
| 407 | } else { |
| 408 | assert(dri2_dpy->swrast); |
| 409 | dri2_dpy->dri_screen = |
| 410 | dri2_dpy->swrast->createNewScreen(0, dri2_dpy->extensions, |
| 411 | &dri2_dpy->driver_configs, disp); |
| 412 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 413 | |
| 414 | if (dri2_dpy->dri_screen == NULL) { |
| 415 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 416 | return EGL_FALSE; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 420 | |
| 421 | if (dri2_dpy->dri2) { |
| 422 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
| 423 | goto cleanup_dri_screen; |
| 424 | } else { |
| 425 | assert(dri2_dpy->swrast); |
| 426 | if (!dri2_bind_extensions(dri2_dpy, swrast_core_extensions, extensions)) |
| 427 | goto cleanup_dri_screen; |
| 428 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 429 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 430 | if (dri2_dpy->dri2) { |
| 431 | if (dri2_dpy->dri2->base.version >= 2) |
| 432 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
| 433 | else |
| 434 | api_mask = 1 << __DRI_API_OPENGL; |
| 435 | } else { |
| 436 | assert(dri2_dpy->swrast); |
| 437 | if (dri2_dpy->swrast->base.version >= 2) |
| 438 | api_mask = 1 << __DRI_API_OPENGL | 1 << __DRI_API_GLES | 1 << __DRI_API_GLES2; |
| 439 | else |
| 440 | api_mask = 1 << __DRI_API_OPENGL; |
| 441 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 442 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 443 | disp->ClientAPIs = 0; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 444 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 445 | disp->ClientAPIs |= EGL_OPENGL_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 446 | if (api_mask & (1 <<__DRI_API_GLES)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 447 | disp->ClientAPIs |= EGL_OPENGL_ES_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 448 | if (api_mask & (1 << __DRI_API_GLES2)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 449 | disp->ClientAPIs |= EGL_OPENGL_ES2_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 450 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 451 | if (dri2_dpy->dri2) { |
| 452 | if (dri2_dpy->dri2->base.version >= 2) { |
| 453 | disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; |
| 454 | disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; |
| 455 | disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; |
| 456 | } |
| 457 | } else { |
| 458 | assert(dri2_dpy->swrast); |
| 459 | if (dri2_dpy->swrast->base.version >= 2) { |
| 460 | disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; |
| 461 | disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; |
| 462 | disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; |
| 463 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 464 | } |
| 465 | |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 466 | if (dri2_dpy->image) { |
| 467 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
| 468 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 469 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 470 | } |
| 471 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 472 | return EGL_TRUE; |
| 473 | |
| 474 | cleanup_dri_screen: |
| 475 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 476 | |
| 477 | return EGL_FALSE; |
| 478 | } |
| 479 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 480 | /** |
| 481 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 482 | */ |
| 483 | static EGLBoolean |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 484 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 485 | { |
Chia-I Wu | a22a332 | 2011-01-13 04:40:38 +0800 | [diff] [blame] | 486 | /* not until swrast_dri is supported */ |
| 487 | if (disp->Options.UseFallback) |
| 488 | return EGL_FALSE; |
| 489 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 490 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 491 | #ifdef HAVE_X11_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 492 | case _EGL_PLATFORM_X11: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 493 | if (disp->Options.TestOnly) |
| 494 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 495 | return dri2_initialize_x11(drv, disp); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 496 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 497 | |
| 498 | #ifdef HAVE_LIBUDEV |
| 499 | case _EGL_PLATFORM_DRM: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 500 | if (disp->Options.TestOnly) |
| 501 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 502 | return dri2_initialize_drm(drv, disp); |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 503 | #ifdef HAVE_WAYLAND_PLATFORM |
| 504 | case _EGL_PLATFORM_WAYLAND: |
| 505 | if (disp->Options.TestOnly) |
| 506 | return EGL_TRUE; |
| 507 | return dri2_initialize_wayland(drv, disp); |
| 508 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 509 | #endif |
| 510 | |
| 511 | default: |
| 512 | return EGL_FALSE; |
| 513 | } |
| 514 | } |
| 515 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 516 | /** |
| 517 | * Called via eglTerminate(), drv->API.Terminate(). |
| 518 | */ |
| 519 | static EGLBoolean |
| 520 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 521 | { |
| 522 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 523 | |
| 524 | _eglReleaseDisplayResources(drv, disp); |
| 525 | _eglCleanupDisplay(disp); |
| 526 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 527 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 528 | if (dri2_dpy->fd) |
| 529 | close(dri2_dpy->fd); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 530 | dlclose(dri2_dpy->driver); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame^] | 531 | |
| 532 | if (disp->PlatformDisplay == NULL) { |
| 533 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 534 | #ifdef HAVE_X11_PLATFORM |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame^] | 535 | case _EGL_PLATFORM_X11: |
| 536 | xcb_disconnect(dri2_dpy->conn); |
| 537 | break; |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 538 | #endif |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame^] | 539 | #ifdef HAVE_WAYLAND_PLATFORM |
| 540 | case _EGL_PLATFORM_WAYLAND: |
| 541 | wl_display_destroy(dri2_dpy->wl_dpy); |
| 542 | break; |
| 543 | #endif |
| 544 | default: |
| 545 | break; |
| 546 | } |
| 547 | } |
| 548 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 549 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 550 | disp->DriverData = NULL; |
| 551 | |
| 552 | return EGL_TRUE; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | /** |
| 557 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 558 | */ |
| 559 | static _EGLContext * |
| 560 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 561 | _EGLContext *share_list, const EGLint *attrib_list) |
| 562 | { |
| 563 | struct dri2_egl_context *dri2_ctx; |
| 564 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 565 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
| 566 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 567 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 568 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 569 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 570 | (void) drv; |
| 571 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 572 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 573 | if (!dri2_ctx) { |
| 574 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 575 | return NULL; |
| 576 | } |
| 577 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 578 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 579 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 580 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 581 | switch (dri2_ctx->base.ClientAPI) { |
| 582 | case EGL_OPENGL_ES_API: |
| 583 | switch (dri2_ctx->base.ClientVersion) { |
| 584 | case 1: |
| 585 | api = __DRI_API_GLES; |
| 586 | break; |
| 587 | case 2: |
| 588 | api = __DRI_API_GLES2; |
| 589 | break; |
| 590 | default: |
| 591 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 592 | return NULL; |
| 593 | } |
| 594 | break; |
| 595 | case EGL_OPENGL_API: |
| 596 | api = __DRI_API_OPENGL; |
| 597 | break; |
| 598 | default: |
| 599 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 600 | return NULL; |
| 601 | } |
| 602 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 603 | if (conf != NULL) { |
| 604 | /* The config chosen here isn't necessarily |
| 605 | * used for surfaces later. |
| 606 | * A pixmap surface will use the single config. |
| 607 | * This opportunity depends on disabling the |
| 608 | * doubleBufferMode check in |
| 609 | * src/mesa/main/context.c:check_compatible() |
| 610 | */ |
| 611 | if (dri2_config->dri_double_config) |
| 612 | dri_config = dri2_config->dri_double_config; |
| 613 | else |
| 614 | dri_config = dri2_config->dri_single_config; |
| 615 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 616 | else |
| 617 | dri_config = NULL; |
| 618 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 619 | if (dri2_dpy->dri2) { |
| 620 | if (dri2_dpy->dri2->base.version >= 2) { |
| 621 | dri2_ctx->dri_context = |
| 622 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 623 | api, |
| 624 | dri_config, |
| 625 | dri2_ctx_shared ? |
| 626 | dri2_ctx_shared->dri_context : NULL, |
| 627 | dri2_ctx); |
| 628 | } else if (api == __DRI_API_OPENGL) { |
| 629 | dri2_ctx->dri_context = |
| 630 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 631 | dri_config, |
| 632 | dri2_ctx_shared ? |
| 633 | dri2_ctx_shared->dri_context : NULL, |
| 634 | dri2_ctx); |
| 635 | } else { |
| 636 | /* fail */ |
| 637 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 638 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 639 | assert(dri2_dpy->swrast); |
| 640 | if (dri2_dpy->swrast->base.version >= 2) { |
| 641 | dri2_ctx->dri_context = |
| 642 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 643 | api, |
| 644 | dri_config, |
| 645 | dri2_ctx_shared ? |
| 646 | dri2_ctx_shared->dri_context : NULL, |
| 647 | dri2_ctx); |
| 648 | } else if (api == __DRI_API_OPENGL) { |
| 649 | dri2_ctx->dri_context = |
| 650 | dri2_dpy->core->createNewContext(dri2_dpy->dri_screen, |
| 651 | dri_config, |
| 652 | dri2_ctx_shared ? |
| 653 | dri2_ctx_shared->dri_context : NULL, |
| 654 | dri2_ctx); |
| 655 | } else { |
| 656 | /* fail */ |
| 657 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 658 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 659 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 660 | if (!dri2_ctx->dri_context) |
| 661 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 662 | |
| 663 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 664 | |
| 665 | cleanup: |
| 666 | free(dri2_ctx); |
| 667 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 668 | } |
| 669 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 670 | /** |
| 671 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 672 | */ |
| 673 | static EGLBoolean |
| 674 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 675 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 676 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 677 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 678 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 679 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 680 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 681 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 682 | _EGLContext *old_ctx; |
| 683 | _EGLSurface *old_dsurf, *old_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 684 | __DRIdrawable *ddraw, *rdraw; |
| 685 | __DRIcontext *cctx; |
| 686 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 687 | /* make new bindings */ |
| 688 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 689 | return EGL_FALSE; |
| 690 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 691 | /* flush before context switch */ |
Chia-I Wu | 547e761 | 2010-10-26 15:00:56 +0800 | [diff] [blame] | 692 | if (old_ctx && dri2_drv->glFlush) |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 693 | dri2_drv->glFlush(); |
| 694 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 695 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 696 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 697 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 698 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 699 | if (old_ctx) { |
| 700 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 701 | dri2_dpy->core->unbindContext(old_cctx); |
| 702 | } |
| 703 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 704 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 705 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 706 | if (old_dsurf) |
| 707 | drv->API.DestroySurface(drv, disp, old_dsurf); |
| 708 | if (old_rsurf) |
| 709 | drv->API.DestroySurface(drv, disp, old_rsurf); |
| 710 | /* no destroy? */ |
| 711 | if (old_ctx) |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 712 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 713 | |
| 714 | return EGL_TRUE; |
| 715 | } else { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 716 | /* undo the previous _eglBindContext */ |
| 717 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); |
| 718 | assert(&dri2_ctx->base == ctx && |
| 719 | &dri2_dsurf->base == dsurf && |
| 720 | &dri2_rsurf->base == rsurf); |
| 721 | |
| 722 | _eglPutSurface(dsurf); |
| 723 | _eglPutSurface(rsurf); |
| 724 | _eglPutContext(ctx); |
| 725 | |
| 726 | _eglPutSurface(old_dsurf); |
| 727 | _eglPutSurface(old_rsurf); |
| 728 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 729 | |
| 730 | return EGL_FALSE; |
| 731 | } |
| 732 | } |
| 733 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 734 | /* |
| 735 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 736 | */ |
| 737 | static _EGLProc |
| 738 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 739 | { |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 740 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 741 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 742 | return dri2_drv->get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 746 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 747 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 748 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 749 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 750 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 751 | (void) drv; |
| 752 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 753 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 754 | * we need to copy fake to real here.*/ |
| 755 | |
| 756 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 757 | |
| 758 | return EGL_TRUE; |
| 759 | } |
| 760 | |
| 761 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 762 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 763 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 764 | (void) drv; |
| 765 | (void) disp; |
| 766 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 767 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 768 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 769 | /* glXWaitX(); */ |
| 770 | |
| 771 | return EGL_TRUE; |
| 772 | } |
| 773 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 774 | static EGLBoolean |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 775 | dri2_bind_tex_image(_EGLDriver *drv, |
| 776 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 777 | { |
| 778 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 779 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 780 | struct dri2_egl_context *dri2_ctx; |
| 781 | _EGLContext *ctx; |
| 782 | GLint format, target; |
| 783 | |
| 784 | ctx = _eglGetCurrentContext(); |
| 785 | dri2_ctx = dri2_egl_context(ctx); |
| 786 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 787 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 788 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 789 | |
| 790 | switch (dri2_surf->base.TextureFormat) { |
| 791 | case EGL_TEXTURE_RGB: |
| 792 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 793 | break; |
| 794 | case EGL_TEXTURE_RGBA: |
| 795 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 796 | break; |
| 797 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 798 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | switch (dri2_surf->base.TextureTarget) { |
| 802 | case EGL_TEXTURE_2D: |
| 803 | target = GL_TEXTURE_2D; |
| 804 | break; |
| 805 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 806 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 810 | target, format, |
| 811 | dri2_surf->dri_drawable); |
| 812 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 813 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static EGLBoolean |
| 817 | dri2_release_tex_image(_EGLDriver *drv, |
| 818 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 819 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 820 | #if __DRI_TEX_BUFFER_VERSION >= 3 |
| 821 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 822 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 823 | struct dri2_egl_context *dri2_ctx; |
| 824 | _EGLContext *ctx; |
| 825 | GLint target; |
| 826 | |
| 827 | ctx = _eglGetCurrentContext(); |
| 828 | dri2_ctx = dri2_egl_context(ctx); |
| 829 | |
| 830 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 831 | return EGL_FALSE; |
| 832 | |
| 833 | switch (dri2_surf->base.TextureTarget) { |
| 834 | case EGL_TEXTURE_2D: |
| 835 | target = GL_TEXTURE_2D; |
| 836 | break; |
| 837 | default: |
| 838 | assert(0); |
| 839 | } |
| 840 | if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL) |
| 841 | (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context, |
| 842 | target, |
| 843 | dri2_surf->dri_drawable); |
| 844 | #endif |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 845 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 846 | return EGL_TRUE; |
| 847 | } |
| 848 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 849 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 850 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 851 | EGLClientBuffer buffer, |
| 852 | const EGLint *attr_list) |
| 853 | { |
| 854 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 855 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 856 | struct dri2_egl_image *dri2_img; |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 857 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 858 | |
| 859 | if (renderbuffer == 0) { |
| 860 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 861 | return EGL_NO_IMAGE_KHR; |
| 862 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 863 | |
| 864 | dri2_img = malloc(sizeof *dri2_img); |
| 865 | if (!dri2_img) { |
| 866 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 867 | return EGL_NO_IMAGE_KHR; |
| 868 | } |
| 869 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 870 | if (!_eglInitImage(&dri2_img->base, disp)) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 871 | return EGL_NO_IMAGE_KHR; |
| 872 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 873 | dri2_img->dri_image = |
| 874 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
| 875 | renderbuffer, |
| 876 | dri2_img); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 877 | |
| 878 | return &dri2_img->base; |
| 879 | } |
| 880 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 881 | static _EGLImage * |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 882 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 883 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 884 | { |
| 885 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 886 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 887 | EGLint format, name, pitch, err; |
| 888 | _EGLImageAttribs attrs; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 889 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 890 | (void) ctx; |
| 891 | |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 892 | name = (EGLint) (uintptr_t) buffer; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 893 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 894 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 895 | if (err != EGL_SUCCESS) |
| 896 | return NULL; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 897 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 898 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 899 | attrs.DRMBufferStrideMESA <= 0) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 900 | _eglError(EGL_BAD_PARAMETER, |
| 901 | "bad width, height or stride"); |
| 902 | return NULL; |
| 903 | } |
| 904 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 905 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 906 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 907 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 908 | pitch = attrs.DRMBufferStrideMESA; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 909 | break; |
| 910 | default: |
| 911 | _eglError(EGL_BAD_PARAMETER, |
| 912 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 913 | return NULL; |
| 914 | } |
| 915 | |
| 916 | dri2_img = malloc(sizeof *dri2_img); |
| 917 | if (!dri2_img) { |
| 918 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 919 | return NULL; |
| 920 | } |
| 921 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 922 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 923 | free(dri2_img); |
| 924 | return NULL; |
| 925 | } |
| 926 | |
| 927 | dri2_img->dri_image = |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 928 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 929 | attrs.Width, |
| 930 | attrs.Height, |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 931 | format, |
| 932 | name, |
| 933 | pitch, |
| 934 | dri2_img); |
| 935 | if (dri2_img->dri_image == NULL) { |
| 936 | free(dri2_img); |
| 937 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 938 | return NULL; |
| 939 | } |
| 940 | |
| 941 | return &dri2_img->base; |
| 942 | } |
| 943 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 944 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 945 | static _EGLImage * |
| 946 | dri2_reference_drm_image(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 947 | __DRIimage *dri_image, EGLint width, EGLint height) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 948 | { |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 949 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 950 | EGLint attr_list[] = { |
| 951 | EGL_WIDTH, 0, |
| 952 | EGL_HEIGHT, 0, |
| 953 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
| 954 | EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
| 955 | EGL_NONE |
| 956 | }; |
| 957 | EGLint name, stride; |
| 958 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 959 | dri2_dpy->image->queryImage(dri_image, __DRI_IMAGE_ATTRIB_NAME, &name); |
| 960 | dri2_dpy->image->queryImage(dri_image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 961 | |
| 962 | attr_list[1] = width; |
| 963 | attr_list[3] = height; |
| 964 | attr_list[5] = stride / 4; |
| 965 | |
| 966 | return dri2_create_image_mesa_drm_buffer(disp, ctx, |
| 967 | (EGLClientBuffer)(intptr_t) name, |
| 968 | attr_list); |
| 969 | } |
| 970 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 971 | static _EGLImage * |
| 972 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 973 | EGLClientBuffer _buffer, |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 974 | const EGLint *attr_list) |
| 975 | { |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 976 | struct wl_buffer *buffer = (struct wl_buffer *) _buffer; |
| 977 | (void) attr_list; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 978 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 979 | if (!wayland_buffer_is_drm(buffer)) |
| 980 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 981 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 982 | return dri2_reference_drm_image(disp, ctx, |
| 983 | wayland_drm_buffer_get_buffer(buffer), |
| 984 | buffer->width, |
| 985 | buffer->height); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 986 | } |
| 987 | #endif |
| 988 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 989 | _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 990 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 991 | _EGLContext *ctx, EGLenum target, |
| 992 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 993 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 994 | (void) drv; |
| 995 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 996 | switch (target) { |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 997 | case EGL_GL_RENDERBUFFER_KHR: |
| 998 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 999 | case EGL_DRM_BUFFER_MESA: |
| 1000 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1001 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1002 | case EGL_WAYLAND_BUFFER_WL: |
| 1003 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 1004 | #endif |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1005 | default: |
| 1006 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1007 | return EGL_NO_IMAGE_KHR; |
| 1008 | } |
| 1009 | } |
| 1010 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1011 | static EGLBoolean |
| 1012 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1013 | { |
| 1014 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1015 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1016 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1017 | (void) drv; |
| 1018 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1019 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1020 | free(dri2_img); |
| 1021 | |
| 1022 | return EGL_TRUE; |
| 1023 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1024 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1025 | static _EGLImage * |
| 1026 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 1027 | const EGLint *attr_list) |
| 1028 | { |
| 1029 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1030 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1031 | _EGLImageAttribs attrs; |
| 1032 | unsigned int dri_use, valid_mask; |
| 1033 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1034 | EGLint err = EGL_SUCCESS; |
| 1035 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1036 | (void) drv; |
| 1037 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1038 | dri2_img = malloc(sizeof *dri2_img); |
| 1039 | if (!dri2_img) { |
| 1040 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1041 | return EGL_NO_IMAGE_KHR; |
| 1042 | } |
| 1043 | |
| 1044 | if (!attr_list) { |
| 1045 | err = EGL_BAD_PARAMETER; |
| 1046 | goto cleanup_img; |
| 1047 | } |
| 1048 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 1049 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1050 | err = EGL_BAD_PARAMETER; |
| 1051 | goto cleanup_img; |
| 1052 | } |
| 1053 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1054 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1055 | if (err != EGL_SUCCESS) |
| 1056 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1057 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1058 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 1059 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 1060 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1061 | goto cleanup_img; |
| 1062 | } |
| 1063 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1064 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1065 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1066 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1067 | break; |
| 1068 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1069 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 1070 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1071 | goto cleanup_img; |
| 1072 | } |
| 1073 | |
| 1074 | valid_mask = |
| 1075 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1076 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 1077 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1078 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 1079 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 1080 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1081 | goto cleanup_img; |
| 1082 | } |
| 1083 | |
| 1084 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1085 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1086 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1087 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1088 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1089 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 1090 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1091 | |
| 1092 | dri2_img->dri_image = |
| 1093 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1094 | attrs.Width, attrs.Height, |
| 1095 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1096 | if (dri2_img->dri_image == NULL) { |
| 1097 | err = EGL_BAD_ALLOC; |
| 1098 | goto cleanup_img; |
| 1099 | } |
| 1100 | |
| 1101 | return &dri2_img->base; |
| 1102 | |
| 1103 | cleanup_img: |
| 1104 | free(dri2_img); |
| 1105 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 1106 | |
| 1107 | return EGL_NO_IMAGE_KHR; |
| 1108 | } |
| 1109 | |
| 1110 | static EGLBoolean |
| 1111 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 1112 | EGLint *name, EGLint *handle, EGLint *stride) |
| 1113 | { |
| 1114 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1115 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 1116 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1117 | (void) drv; |
| 1118 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1119 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1120 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
| 1121 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 1122 | return EGL_FALSE; |
| 1123 | } |
| 1124 | |
| 1125 | if (handle) |
| 1126 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1127 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
| 1128 | |
| 1129 | if (stride) |
| 1130 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1131 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
| 1132 | |
| 1133 | return EGL_TRUE; |
| 1134 | } |
| 1135 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1136 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1137 | |
| 1138 | static void * |
| 1139 | dri2_wl_reference_buffer(void *user_data, uint32_t name, |
| 1140 | int32_t width, int32_t height, |
| 1141 | uint32_t stride, struct wl_visual *visual) |
| 1142 | { |
| 1143 | _EGLDisplay *disp = user_data; |
| 1144 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1145 | __DRIimage *image; |
| 1146 | |
| 1147 | image = dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 1148 | width, height, |
| 1149 | __DRI_IMAGE_FORMAT_ARGB8888, |
| 1150 | name, stride / 4, |
| 1151 | NULL); |
| 1152 | |
| 1153 | return image; |
| 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | dri2_wl_release_buffer(void *user_data, void *buffer) |
| 1158 | { |
| 1159 | _EGLDisplay *disp = user_data; |
| 1160 | __DRIimage *image = buffer; |
| 1161 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1162 | |
| 1163 | dri2_dpy->image->destroyImage(image); |
| 1164 | } |
| 1165 | |
| 1166 | static struct wayland_drm_callbacks wl_drm_callbacks = { |
| 1167 | .authenticate = NULL, |
| 1168 | .reference_buffer = dri2_wl_reference_buffer, |
| 1169 | .release_buffer = dri2_wl_release_buffer |
| 1170 | }; |
| 1171 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1172 | static EGLBoolean |
| 1173 | dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1174 | struct wl_display *wl_dpy) |
| 1175 | { |
| 1176 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1177 | |
| 1178 | (void) drv; |
| 1179 | |
| 1180 | if (dri2_dpy->wl_server_drm) |
| 1181 | return EGL_FALSE; |
| 1182 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1183 | wl_drm_callbacks.authenticate = |
| 1184 | (int(*)(void *, uint32_t)) dri2_dpy->authenticate; |
| 1185 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1186 | dri2_dpy->wl_server_drm = |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1187 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
| 1188 | &wl_drm_callbacks, disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1189 | |
| 1190 | if (!dri2_dpy->wl_server_drm) |
| 1191 | return EGL_FALSE; |
| 1192 | |
| 1193 | return EGL_TRUE; |
| 1194 | } |
| 1195 | |
| 1196 | static EGLBoolean |
| 1197 | dri2_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1198 | struct wl_display *wl_dpy) |
| 1199 | { |
| 1200 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1201 | |
| 1202 | (void) drv; |
| 1203 | |
| 1204 | if (!dri2_dpy->wl_server_drm) |
| 1205 | return EGL_FALSE; |
| 1206 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1207 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1208 | dri2_dpy->wl_server_drm = NULL; |
| 1209 | |
| 1210 | return EGL_TRUE; |
| 1211 | } |
| 1212 | #endif |
| 1213 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1214 | static void |
| 1215 | dri2_unload(_EGLDriver *drv) |
| 1216 | { |
| 1217 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1218 | |
| 1219 | if (dri2_drv->handle) |
| 1220 | dlclose(dri2_drv->handle); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1221 | free(dri2_drv); |
| 1222 | } |
| 1223 | |
| 1224 | static EGLBoolean |
| 1225 | dri2_load(_EGLDriver *drv) |
| 1226 | { |
| 1227 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1228 | #ifdef HAVE_SHARED_GLAPI |
| 1229 | const char *libname = "libglapi.so.0"; |
| 1230 | #else |
| 1231 | /* |
| 1232 | * Both libGL.so and libglapi.so are glapi providers. There is no way to |
| 1233 | * tell which one to load. |
| 1234 | */ |
| 1235 | const char *libname = NULL; |
| 1236 | #endif |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1237 | void *handle; |
| 1238 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1239 | /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */ |
| 1240 | handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1241 | if (handle) { |
| 1242 | dri2_drv->get_proc_address = (_EGLProc (*)(const char *)) |
| 1243 | dlsym(handle, "_glapi_get_proc_address"); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1244 | if (!dri2_drv->get_proc_address || !libname) { |
| 1245 | /* no need to keep a reference */ |
| 1246 | dlclose(handle); |
| 1247 | handle = NULL; |
| 1248 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1249 | } |
| 1250 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1251 | /* if glapi is not available, loading DRI drivers will fail */ |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1252 | if (!dri2_drv->get_proc_address) { |
| 1253 | _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address"); |
| 1254 | return EGL_FALSE; |
| 1255 | } |
| 1256 | |
| 1257 | dri2_drv->glFlush = (void (*)(void)) |
| 1258 | dri2_drv->get_proc_address("glFlush"); |
| 1259 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1260 | dri2_drv->handle = handle; |
| 1261 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1262 | return EGL_TRUE; |
| 1263 | } |
| 1264 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1265 | /** |
| 1266 | * This is the main entrypoint into the driver, called by libEGL. |
| 1267 | * Create a new _EGLDriver object and init its dispatch table. |
| 1268 | */ |
| 1269 | _EGLDriver * |
Chia-I Wu | c98ea26 | 2011-01-07 16:30:08 +0800 | [diff] [blame] | 1270 | _EGL_MAIN(const char *args) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1271 | { |
| 1272 | struct dri2_egl_driver *dri2_drv; |
| 1273 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1274 | (void) args; |
| 1275 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1276 | dri2_drv = malloc(sizeof *dri2_drv); |
| 1277 | if (!dri2_drv) |
| 1278 | return NULL; |
| 1279 | |
Chia-I Wu | 39812c4 | 2011-01-12 18:06:47 +0800 | [diff] [blame] | 1280 | memset(dri2_drv, 0, sizeof *dri2_drv); |
| 1281 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1282 | if (!dri2_load(&dri2_drv->base)) |
| 1283 | return NULL; |
| 1284 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1285 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1286 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1287 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1288 | dri2_drv->base.API.CreateContext = dri2_create_context; |
| 1289 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1290 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1291 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1292 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1293 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1294 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1295 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1296 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1297 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 1298 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1299 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1300 | dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl; |
| 1301 | dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl; |
| 1302 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1303 | |
| 1304 | dri2_drv->base.Name = "DRI2"; |
| 1305 | dri2_drv->base.Unload = dri2_unload; |
| 1306 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1307 | return &dri2_drv->base; |
| 1308 | } |