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) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame^] | 493 | #ifdef HAVE_X11_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 494 | case _EGL_PLATFORM_X11: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 495 | if (disp->Options.TestOnly) |
| 496 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 497 | return dri2_initialize_x11(drv, disp); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame^] | 498 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 499 | |
| 500 | #ifdef HAVE_LIBUDEV |
| 501 | case _EGL_PLATFORM_DRM: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 502 | if (disp->Options.TestOnly) |
| 503 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 504 | return dri2_initialize_drm(drv, disp); |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 505 | #ifdef HAVE_WAYLAND_PLATFORM |
| 506 | case _EGL_PLATFORM_WAYLAND: |
| 507 | if (disp->Options.TestOnly) |
| 508 | return EGL_TRUE; |
| 509 | return dri2_initialize_wayland(drv, disp); |
| 510 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 511 | #endif |
| 512 | |
| 513 | default: |
| 514 | return EGL_FALSE; |
| 515 | } |
| 516 | } |
| 517 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 518 | /** |
| 519 | * Called via eglTerminate(), drv->API.Terminate(). |
| 520 | */ |
| 521 | static EGLBoolean |
| 522 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 523 | { |
| 524 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 525 | |
| 526 | _eglReleaseDisplayResources(drv, disp); |
| 527 | _eglCleanupDisplay(disp); |
| 528 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 529 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 530 | if (dri2_dpy->fd) |
| 531 | close(dri2_dpy->fd); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 532 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame^] | 533 | #ifdef HAVE_X11_PLATFORM |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 534 | if (disp->PlatformDisplay == NULL) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 535 | xcb_disconnect(dri2_dpy->conn); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame^] | 536 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 537 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 538 | disp->DriverData = NULL; |
| 539 | |
| 540 | return EGL_TRUE; |
| 541 | } |
| 542 | |
| 543 | |
| 544 | /** |
| 545 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 546 | */ |
| 547 | static _EGLContext * |
| 548 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 549 | _EGLContext *share_list, const EGLint *attrib_list) |
| 550 | { |
| 551 | struct dri2_egl_context *dri2_ctx; |
| 552 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 553 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
| 554 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 555 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 556 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 557 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 558 | (void) drv; |
| 559 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 560 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 561 | if (!dri2_ctx) { |
| 562 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 566 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 567 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 568 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 569 | switch (dri2_ctx->base.ClientAPI) { |
| 570 | case EGL_OPENGL_ES_API: |
| 571 | switch (dri2_ctx->base.ClientVersion) { |
| 572 | case 1: |
| 573 | api = __DRI_API_GLES; |
| 574 | break; |
| 575 | case 2: |
| 576 | api = __DRI_API_GLES2; |
| 577 | break; |
| 578 | default: |
| 579 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 580 | return NULL; |
| 581 | } |
| 582 | break; |
| 583 | case EGL_OPENGL_API: |
| 584 | api = __DRI_API_OPENGL; |
| 585 | break; |
| 586 | default: |
| 587 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 588 | return NULL; |
| 589 | } |
| 590 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 591 | if (conf != NULL) { |
| 592 | /* The config chosen here isn't necessarily |
| 593 | * used for surfaces later. |
| 594 | * A pixmap surface will use the single config. |
| 595 | * This opportunity depends on disabling the |
| 596 | * doubleBufferMode check in |
| 597 | * src/mesa/main/context.c:check_compatible() |
| 598 | */ |
| 599 | if (dri2_config->dri_double_config) |
| 600 | dri_config = dri2_config->dri_double_config; |
| 601 | else |
| 602 | dri_config = dri2_config->dri_single_config; |
| 603 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 604 | else |
| 605 | dri_config = NULL; |
| 606 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 607 | if (dri2_dpy->dri2) { |
| 608 | if (dri2_dpy->dri2->base.version >= 2) { |
| 609 | dri2_ctx->dri_context = |
| 610 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 611 | api, |
| 612 | dri_config, |
| 613 | dri2_ctx_shared ? |
| 614 | dri2_ctx_shared->dri_context : NULL, |
| 615 | dri2_ctx); |
| 616 | } else if (api == __DRI_API_OPENGL) { |
| 617 | dri2_ctx->dri_context = |
| 618 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 619 | dri_config, |
| 620 | dri2_ctx_shared ? |
| 621 | dri2_ctx_shared->dri_context : NULL, |
| 622 | dri2_ctx); |
| 623 | } else { |
| 624 | /* fail */ |
| 625 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 626 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 627 | assert(dri2_dpy->swrast); |
| 628 | if (dri2_dpy->swrast->base.version >= 2) { |
| 629 | dri2_ctx->dri_context = |
| 630 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 631 | api, |
| 632 | dri_config, |
| 633 | dri2_ctx_shared ? |
| 634 | dri2_ctx_shared->dri_context : NULL, |
| 635 | dri2_ctx); |
| 636 | } else if (api == __DRI_API_OPENGL) { |
| 637 | dri2_ctx->dri_context = |
| 638 | dri2_dpy->core->createNewContext(dri2_dpy->dri_screen, |
| 639 | dri_config, |
| 640 | dri2_ctx_shared ? |
| 641 | dri2_ctx_shared->dri_context : NULL, |
| 642 | dri2_ctx); |
| 643 | } else { |
| 644 | /* fail */ |
| 645 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 646 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 647 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 648 | if (!dri2_ctx->dri_context) |
| 649 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 650 | |
| 651 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 652 | |
| 653 | cleanup: |
| 654 | free(dri2_ctx); |
| 655 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 656 | } |
| 657 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 658 | /** |
| 659 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 660 | */ |
| 661 | static EGLBoolean |
| 662 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 663 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 664 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 665 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 666 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 667 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 668 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 669 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 670 | _EGLContext *old_ctx; |
| 671 | _EGLSurface *old_dsurf, *old_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 672 | __DRIdrawable *ddraw, *rdraw; |
| 673 | __DRIcontext *cctx; |
| 674 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 675 | /* make new bindings */ |
| 676 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 677 | return EGL_FALSE; |
| 678 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 679 | /* flush before context switch */ |
Chia-I Wu | 547e761 | 2010-10-26 15:00:56 +0800 | [diff] [blame] | 680 | if (old_ctx && dri2_drv->glFlush) |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 681 | dri2_drv->glFlush(); |
| 682 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 683 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 684 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 685 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 686 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 687 | if (old_ctx) { |
| 688 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 689 | dri2_dpy->core->unbindContext(old_cctx); |
| 690 | } |
| 691 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 692 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 693 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 694 | if (old_dsurf) |
| 695 | drv->API.DestroySurface(drv, disp, old_dsurf); |
| 696 | if (old_rsurf) |
| 697 | drv->API.DestroySurface(drv, disp, old_rsurf); |
| 698 | /* no destroy? */ |
| 699 | if (old_ctx) |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 700 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 701 | |
| 702 | return EGL_TRUE; |
| 703 | } else { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 704 | /* undo the previous _eglBindContext */ |
| 705 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); |
| 706 | assert(&dri2_ctx->base == ctx && |
| 707 | &dri2_dsurf->base == dsurf && |
| 708 | &dri2_rsurf->base == rsurf); |
| 709 | |
| 710 | _eglPutSurface(dsurf); |
| 711 | _eglPutSurface(rsurf); |
| 712 | _eglPutContext(ctx); |
| 713 | |
| 714 | _eglPutSurface(old_dsurf); |
| 715 | _eglPutSurface(old_rsurf); |
| 716 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 717 | |
| 718 | return EGL_FALSE; |
| 719 | } |
| 720 | } |
| 721 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 722 | /* |
| 723 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 724 | */ |
| 725 | static _EGLProc |
| 726 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 727 | { |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 728 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 729 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 730 | return dri2_drv->get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 734 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 735 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 736 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 737 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 738 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 739 | (void) drv; |
| 740 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 741 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 742 | * we need to copy fake to real here.*/ |
| 743 | |
| 744 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 745 | |
| 746 | return EGL_TRUE; |
| 747 | } |
| 748 | |
| 749 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 750 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 751 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 752 | (void) drv; |
| 753 | (void) disp; |
| 754 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 755 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 756 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 757 | /* glXWaitX(); */ |
| 758 | |
| 759 | return EGL_TRUE; |
| 760 | } |
| 761 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 762 | static EGLBoolean |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 763 | dri2_bind_tex_image(_EGLDriver *drv, |
| 764 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 765 | { |
| 766 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 767 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 768 | struct dri2_egl_context *dri2_ctx; |
| 769 | _EGLContext *ctx; |
| 770 | GLint format, target; |
| 771 | |
| 772 | ctx = _eglGetCurrentContext(); |
| 773 | dri2_ctx = dri2_egl_context(ctx); |
| 774 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 775 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 776 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 777 | |
| 778 | switch (dri2_surf->base.TextureFormat) { |
| 779 | case EGL_TEXTURE_RGB: |
| 780 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 781 | break; |
| 782 | case EGL_TEXTURE_RGBA: |
| 783 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 784 | break; |
| 785 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 786 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | switch (dri2_surf->base.TextureTarget) { |
| 790 | case EGL_TEXTURE_2D: |
| 791 | target = GL_TEXTURE_2D; |
| 792 | break; |
| 793 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 794 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 798 | target, format, |
| 799 | dri2_surf->dri_drawable); |
| 800 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 801 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | static EGLBoolean |
| 805 | dri2_release_tex_image(_EGLDriver *drv, |
| 806 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 807 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 808 | #if __DRI_TEX_BUFFER_VERSION >= 3 |
| 809 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 810 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 811 | struct dri2_egl_context *dri2_ctx; |
| 812 | _EGLContext *ctx; |
| 813 | GLint target; |
| 814 | |
| 815 | ctx = _eglGetCurrentContext(); |
| 816 | dri2_ctx = dri2_egl_context(ctx); |
| 817 | |
| 818 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 819 | return EGL_FALSE; |
| 820 | |
| 821 | switch (dri2_surf->base.TextureTarget) { |
| 822 | case EGL_TEXTURE_2D: |
| 823 | target = GL_TEXTURE_2D; |
| 824 | break; |
| 825 | default: |
| 826 | assert(0); |
| 827 | } |
| 828 | if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL) |
| 829 | (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context, |
| 830 | target, |
| 831 | dri2_surf->dri_drawable); |
| 832 | #endif |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 833 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 834 | return EGL_TRUE; |
| 835 | } |
| 836 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 837 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 838 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 839 | EGLClientBuffer buffer, |
| 840 | const EGLint *attr_list) |
| 841 | { |
| 842 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 843 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 844 | struct dri2_egl_image *dri2_img; |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 845 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 846 | |
| 847 | if (renderbuffer == 0) { |
| 848 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 849 | return EGL_NO_IMAGE_KHR; |
| 850 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 851 | |
| 852 | dri2_img = malloc(sizeof *dri2_img); |
| 853 | if (!dri2_img) { |
| 854 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 855 | return EGL_NO_IMAGE_KHR; |
| 856 | } |
| 857 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 858 | if (!_eglInitImage(&dri2_img->base, disp)) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 859 | return EGL_NO_IMAGE_KHR; |
| 860 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 861 | dri2_img->dri_image = |
| 862 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
| 863 | renderbuffer, |
| 864 | dri2_img); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 865 | |
| 866 | return &dri2_img->base; |
| 867 | } |
| 868 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 869 | static _EGLImage * |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 870 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 871 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 872 | { |
| 873 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 874 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 875 | EGLint format, name, pitch, err; |
| 876 | _EGLImageAttribs attrs; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 877 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 878 | (void) ctx; |
| 879 | |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 880 | name = (EGLint) (uintptr_t) buffer; |
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 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 883 | if (err != EGL_SUCCESS) |
| 884 | return NULL; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 885 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 886 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 887 | attrs.DRMBufferStrideMESA <= 0) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 888 | _eglError(EGL_BAD_PARAMETER, |
| 889 | "bad width, height or stride"); |
| 890 | return NULL; |
| 891 | } |
| 892 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 893 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 894 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 895 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 896 | pitch = attrs.DRMBufferStrideMESA; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 897 | break; |
| 898 | default: |
| 899 | _eglError(EGL_BAD_PARAMETER, |
| 900 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 901 | return NULL; |
| 902 | } |
| 903 | |
| 904 | dri2_img = malloc(sizeof *dri2_img); |
| 905 | if (!dri2_img) { |
| 906 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 907 | return NULL; |
| 908 | } |
| 909 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 910 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 911 | free(dri2_img); |
| 912 | return NULL; |
| 913 | } |
| 914 | |
| 915 | dri2_img->dri_image = |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 916 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 917 | attrs.Width, |
| 918 | attrs.Height, |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 919 | format, |
| 920 | name, |
| 921 | pitch, |
| 922 | dri2_img); |
| 923 | if (dri2_img->dri_image == NULL) { |
| 924 | free(dri2_img); |
| 925 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 926 | return NULL; |
| 927 | } |
| 928 | |
| 929 | return &dri2_img->base; |
| 930 | } |
| 931 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 932 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 933 | static _EGLImage * |
| 934 | dri2_reference_drm_image(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 935 | __DRIimage *dri_image, EGLint width, EGLint height) |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 936 | { |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 937 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 938 | EGLint attr_list[] = { |
| 939 | EGL_WIDTH, 0, |
| 940 | EGL_HEIGHT, 0, |
| 941 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
| 942 | EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
| 943 | EGL_NONE |
| 944 | }; |
| 945 | EGLint name, stride; |
| 946 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 947 | dri2_dpy->image->queryImage(dri_image, __DRI_IMAGE_ATTRIB_NAME, &name); |
| 948 | dri2_dpy->image->queryImage(dri_image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 949 | |
| 950 | attr_list[1] = width; |
| 951 | attr_list[3] = height; |
| 952 | attr_list[5] = stride / 4; |
| 953 | |
| 954 | return dri2_create_image_mesa_drm_buffer(disp, ctx, |
| 955 | (EGLClientBuffer)(intptr_t) name, |
| 956 | attr_list); |
| 957 | } |
| 958 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 959 | static _EGLImage * |
| 960 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 961 | EGLClientBuffer _buffer, |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 962 | const EGLint *attr_list) |
| 963 | { |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 964 | struct wl_buffer *buffer = (struct wl_buffer *) _buffer; |
| 965 | (void) attr_list; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 966 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 967 | if (!wayland_buffer_is_drm(buffer)) |
| 968 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 969 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 970 | return dri2_reference_drm_image(disp, ctx, |
| 971 | wayland_drm_buffer_get_buffer(buffer), |
| 972 | buffer->width, |
| 973 | buffer->height); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 974 | } |
| 975 | #endif |
| 976 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 977 | _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 978 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 979 | _EGLContext *ctx, EGLenum target, |
| 980 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 981 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 982 | (void) drv; |
| 983 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 984 | switch (target) { |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 985 | case EGL_GL_RENDERBUFFER_KHR: |
| 986 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 987 | case EGL_DRM_BUFFER_MESA: |
| 988 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 989 | #ifdef HAVE_WAYLAND_PLATFORM |
| 990 | case EGL_WAYLAND_BUFFER_WL: |
| 991 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 992 | #endif |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 993 | default: |
| 994 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 995 | return EGL_NO_IMAGE_KHR; |
| 996 | } |
| 997 | } |
| 998 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 999 | static EGLBoolean |
| 1000 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1001 | { |
| 1002 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1003 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1004 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1005 | (void) drv; |
| 1006 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1007 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1008 | free(dri2_img); |
| 1009 | |
| 1010 | return EGL_TRUE; |
| 1011 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1012 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1013 | static _EGLImage * |
| 1014 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 1015 | const EGLint *attr_list) |
| 1016 | { |
| 1017 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1018 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1019 | _EGLImageAttribs attrs; |
| 1020 | unsigned int dri_use, valid_mask; |
| 1021 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1022 | EGLint err = EGL_SUCCESS; |
| 1023 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1024 | (void) drv; |
| 1025 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1026 | dri2_img = malloc(sizeof *dri2_img); |
| 1027 | if (!dri2_img) { |
| 1028 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1029 | return EGL_NO_IMAGE_KHR; |
| 1030 | } |
| 1031 | |
| 1032 | if (!attr_list) { |
| 1033 | err = EGL_BAD_PARAMETER; |
| 1034 | goto cleanup_img; |
| 1035 | } |
| 1036 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 1037 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1038 | err = EGL_BAD_PARAMETER; |
| 1039 | goto cleanup_img; |
| 1040 | } |
| 1041 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1042 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1043 | if (err != EGL_SUCCESS) |
| 1044 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1045 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1046 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 1047 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 1048 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1049 | goto cleanup_img; |
| 1050 | } |
| 1051 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1052 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1053 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1054 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1055 | break; |
| 1056 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1057 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 1058 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1059 | goto cleanup_img; |
| 1060 | } |
| 1061 | |
| 1062 | valid_mask = |
| 1063 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1064 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 1065 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1066 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 1067 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 1068 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1069 | goto cleanup_img; |
| 1070 | } |
| 1071 | |
| 1072 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1073 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1074 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1075 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1076 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1077 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 1078 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1079 | |
| 1080 | dri2_img->dri_image = |
| 1081 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1082 | attrs.Width, attrs.Height, |
| 1083 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1084 | if (dri2_img->dri_image == NULL) { |
| 1085 | err = EGL_BAD_ALLOC; |
| 1086 | goto cleanup_img; |
| 1087 | } |
| 1088 | |
| 1089 | return &dri2_img->base; |
| 1090 | |
| 1091 | cleanup_img: |
| 1092 | free(dri2_img); |
| 1093 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 1094 | |
| 1095 | return EGL_NO_IMAGE_KHR; |
| 1096 | } |
| 1097 | |
| 1098 | static EGLBoolean |
| 1099 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 1100 | EGLint *name, EGLint *handle, EGLint *stride) |
| 1101 | { |
| 1102 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1103 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 1104 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1105 | (void) drv; |
| 1106 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1107 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1108 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
| 1109 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 1110 | return EGL_FALSE; |
| 1111 | } |
| 1112 | |
| 1113 | if (handle) |
| 1114 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1115 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
| 1116 | |
| 1117 | if (stride) |
| 1118 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1119 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
| 1120 | |
| 1121 | return EGL_TRUE; |
| 1122 | } |
| 1123 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1124 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1125 | |
| 1126 | static void * |
| 1127 | dri2_wl_reference_buffer(void *user_data, uint32_t name, |
| 1128 | int32_t width, int32_t height, |
| 1129 | uint32_t stride, struct wl_visual *visual) |
| 1130 | { |
| 1131 | _EGLDisplay *disp = user_data; |
| 1132 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1133 | __DRIimage *image; |
| 1134 | |
| 1135 | image = dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 1136 | width, height, |
| 1137 | __DRI_IMAGE_FORMAT_ARGB8888, |
| 1138 | name, stride / 4, |
| 1139 | NULL); |
| 1140 | |
| 1141 | return image; |
| 1142 | } |
| 1143 | |
| 1144 | static void |
| 1145 | dri2_wl_release_buffer(void *user_data, void *buffer) |
| 1146 | { |
| 1147 | _EGLDisplay *disp = user_data; |
| 1148 | __DRIimage *image = buffer; |
| 1149 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1150 | |
| 1151 | dri2_dpy->image->destroyImage(image); |
| 1152 | } |
| 1153 | |
| 1154 | static struct wayland_drm_callbacks wl_drm_callbacks = { |
| 1155 | .authenticate = NULL, |
| 1156 | .reference_buffer = dri2_wl_reference_buffer, |
| 1157 | .release_buffer = dri2_wl_release_buffer |
| 1158 | }; |
| 1159 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1160 | static EGLBoolean |
| 1161 | dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1162 | struct wl_display *wl_dpy) |
| 1163 | { |
| 1164 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1165 | |
| 1166 | (void) drv; |
| 1167 | |
| 1168 | if (dri2_dpy->wl_server_drm) |
| 1169 | return EGL_FALSE; |
| 1170 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1171 | wl_drm_callbacks.authenticate = |
| 1172 | (int(*)(void *, uint32_t)) dri2_dpy->authenticate; |
| 1173 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1174 | dri2_dpy->wl_server_drm = |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1175 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
| 1176 | &wl_drm_callbacks, disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1177 | |
| 1178 | if (!dri2_dpy->wl_server_drm) |
| 1179 | return EGL_FALSE; |
| 1180 | |
| 1181 | return EGL_TRUE; |
| 1182 | } |
| 1183 | |
| 1184 | static EGLBoolean |
| 1185 | dri2_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1186 | struct wl_display *wl_dpy) |
| 1187 | { |
| 1188 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1189 | |
| 1190 | (void) drv; |
| 1191 | |
| 1192 | if (!dri2_dpy->wl_server_drm) |
| 1193 | return EGL_FALSE; |
| 1194 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1195 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1196 | dri2_dpy->wl_server_drm = NULL; |
| 1197 | |
| 1198 | return EGL_TRUE; |
| 1199 | } |
| 1200 | #endif |
| 1201 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1202 | static void |
| 1203 | dri2_unload(_EGLDriver *drv) |
| 1204 | { |
| 1205 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1206 | |
| 1207 | if (dri2_drv->handle) |
| 1208 | dlclose(dri2_drv->handle); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1209 | free(dri2_drv); |
| 1210 | } |
| 1211 | |
| 1212 | static EGLBoolean |
| 1213 | dri2_load(_EGLDriver *drv) |
| 1214 | { |
| 1215 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1216 | #ifdef HAVE_SHARED_GLAPI |
| 1217 | const char *libname = "libglapi.so.0"; |
| 1218 | #else |
| 1219 | /* |
| 1220 | * Both libGL.so and libglapi.so are glapi providers. There is no way to |
| 1221 | * tell which one to load. |
| 1222 | */ |
| 1223 | const char *libname = NULL; |
| 1224 | #endif |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1225 | void *handle; |
| 1226 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1227 | /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */ |
| 1228 | handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1229 | if (handle) { |
| 1230 | dri2_drv->get_proc_address = (_EGLProc (*)(const char *)) |
| 1231 | dlsym(handle, "_glapi_get_proc_address"); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1232 | if (!dri2_drv->get_proc_address || !libname) { |
| 1233 | /* no need to keep a reference */ |
| 1234 | dlclose(handle); |
| 1235 | handle = NULL; |
| 1236 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1239 | /* if glapi is not available, loading DRI drivers will fail */ |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1240 | if (!dri2_drv->get_proc_address) { |
| 1241 | _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address"); |
| 1242 | return EGL_FALSE; |
| 1243 | } |
| 1244 | |
| 1245 | dri2_drv->glFlush = (void (*)(void)) |
| 1246 | dri2_drv->get_proc_address("glFlush"); |
| 1247 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1248 | dri2_drv->handle = handle; |
| 1249 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1250 | return EGL_TRUE; |
| 1251 | } |
| 1252 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1253 | /** |
| 1254 | * This is the main entrypoint into the driver, called by libEGL. |
| 1255 | * Create a new _EGLDriver object and init its dispatch table. |
| 1256 | */ |
| 1257 | _EGLDriver * |
Chia-I Wu | c98ea26 | 2011-01-07 16:30:08 +0800 | [diff] [blame] | 1258 | _EGL_MAIN(const char *args) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1259 | { |
| 1260 | struct dri2_egl_driver *dri2_drv; |
| 1261 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1262 | (void) args; |
| 1263 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1264 | dri2_drv = malloc(sizeof *dri2_drv); |
| 1265 | if (!dri2_drv) |
| 1266 | return NULL; |
| 1267 | |
Chia-I Wu | 39812c4 | 2011-01-12 18:06:47 +0800 | [diff] [blame] | 1268 | memset(dri2_drv, 0, sizeof *dri2_drv); |
| 1269 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1270 | if (!dri2_load(&dri2_drv->base)) |
| 1271 | return NULL; |
| 1272 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1273 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1274 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1275 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1276 | dri2_drv->base.API.CreateContext = dri2_create_context; |
| 1277 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1278 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1279 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1280 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1281 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1282 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1283 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1284 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1285 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 1286 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1287 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1288 | dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl; |
| 1289 | dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl; |
| 1290 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1291 | |
| 1292 | dri2_drv->base.Name = "DRI2"; |
| 1293 | dri2_drv->base.Unload = dri2_unload; |
| 1294 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1295 | return &dri2_drv->base; |
| 1296 | } |