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