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