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