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> |
| 39 | #include <xcb/xcb.h> |
| 40 | #include <xcb/dri2.h> |
| 41 | #include <xcb/xfixes.h> |
| 42 | #include <X11/Xlib-xcb.h> |
| 43 | |
| 44 | #include <glapi/glapi.h> |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 45 | #include "eglconfig.h" |
| 46 | #include "eglcontext.h" |
| 47 | #include "egldisplay.h" |
| 48 | #include "egldriver.h" |
| 49 | #include "eglcurrent.h" |
| 50 | #include "egllog.h" |
| 51 | #include "eglsurface.h" |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 52 | #include "eglimage.h" |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 53 | |
| 54 | struct dri2_egl_driver |
| 55 | { |
| 56 | _EGLDriver base; |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 57 | |
| 58 | void (*glFlush)(void); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct dri2_egl_display |
| 62 | { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 63 | xcb_connection_t *conn; |
| 64 | int dri2_major; |
| 65 | int dri2_minor; |
| 66 | __DRIscreen *dri_screen; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 67 | const __DRIconfig **driver_configs; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 68 | void *driver; |
| 69 | __DRIcoreExtension *core; |
| 70 | __DRIdri2Extension *dri2; |
| 71 | __DRI2flushExtension *flush; |
| 72 | __DRItexBufferExtension *tex_buffer; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 73 | __DRIimageExtension *image; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 74 | int fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 75 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 76 | char *device_name; |
| 77 | char *driver_name; |
| 78 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 79 | __DRIdri2LoaderExtension loader_extension; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 80 | __DRIimageLookupExtension image_lookup_extension; |
| 81 | const __DRIextension *extensions[3]; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct dri2_egl_context |
| 85 | { |
| 86 | _EGLContext base; |
| 87 | __DRIcontext *dri_context; |
| 88 | }; |
| 89 | |
| 90 | struct dri2_egl_surface |
| 91 | { |
| 92 | _EGLSurface base; |
| 93 | __DRIdrawable *dri_drawable; |
| 94 | xcb_drawable_t drawable; |
| 95 | __DRIbuffer buffers[5]; |
| 96 | int buffer_count; |
| 97 | xcb_xfixes_region_t region; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 98 | int have_fake_front; |
| 99 | int swap_interval; |
| 100 | }; |
| 101 | |
| 102 | struct dri2_egl_config |
| 103 | { |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 104 | _EGLConfig base; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 105 | const __DRIconfig *dri_config; |
| 106 | }; |
| 107 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 108 | struct dri2_egl_image |
| 109 | { |
| 110 | _EGLImage base; |
| 111 | __DRIimage *dri_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 112 | }; |
| 113 | |
Chia-I Wu | a35e633 | 2010-02-05 11:38:34 +0800 | [diff] [blame] | 114 | /* standard typecasts */ |
| 115 | _EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 116 | _EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 117 | |
| 118 | EGLint dri2_to_egl_attribute_map[] = { |
| 119 | 0, |
| 120 | EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ |
| 121 | EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ |
| 122 | EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ |
| 123 | EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ |
| 124 | EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 125 | EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 126 | EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ |
| 127 | 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ |
| 128 | EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ |
| 129 | EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ |
| 130 | 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ |
| 131 | 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ |
| 132 | 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ |
| 133 | 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ |
| 134 | EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ |
| 135 | EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ |
| 136 | 0, /* __DRI_ATTRIB_RENDER_TYPE, */ |
| 137 | 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ |
| 138 | 0, /* __DRI_ATTRIB_CONFORMANT */ |
| 139 | 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ |
| 140 | 0, /* __DRI_ATTRIB_STEREO */ |
| 141 | 0, /* __DRI_ATTRIB_AUX_BUFFERS */ |
| 142 | 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ |
| 143 | 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ |
| 144 | 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ |
| 145 | 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ |
| 146 | 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ |
| 147 | 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ |
| 148 | 0, /* __DRI_ATTRIB_FLOAT_MODE */ |
| 149 | 0, /* __DRI_ATTRIB_RED_MASK */ |
| 150 | 0, /* __DRI_ATTRIB_GREEN_MASK */ |
| 151 | 0, /* __DRI_ATTRIB_BLUE_MASK */ |
| 152 | 0, /* __DRI_ATTRIB_ALPHA_MASK */ |
| 153 | EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ |
| 154 | EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ |
| 155 | EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ |
| 156 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ |
| 157 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ |
| 158 | 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ |
| 159 | 0, /* __DRI_ATTRIB_SWAP_METHOD */ |
| 160 | EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ |
| 161 | EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 162 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ |
| 163 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 164 | 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ |
| 165 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ |
| 166 | 0, /* __DRI_ATTRIB_YINVERTED */ |
| 167 | }; |
| 168 | |
| 169 | static void |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 170 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
| 171 | int depth, xcb_visualtype_t *visual) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 172 | { |
| 173 | struct dri2_egl_config *conf; |
| 174 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 175 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 176 | unsigned int attrib, value, double_buffer; |
| 177 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 178 | int i; |
| 179 | |
| 180 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 181 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 182 | |
| 183 | i = 0; |
| 184 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 185 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 186 | case __DRI_ATTRIB_RENDER_TYPE: |
| 187 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 188 | value = EGL_RGB_BUFFER; |
| 189 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 190 | value = EGL_LUMINANCE_BUFFER; |
| 191 | else |
| 192 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 193 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 194 | break; |
| 195 | |
| 196 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 197 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 198 | value = EGL_NON_CONFORMANT_CONFIG; |
| 199 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 200 | value = EGL_SLOW_CONFIG; |
| 201 | else |
| 202 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 203 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 204 | break; |
| 205 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 206 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 207 | bind_to_texture_rgb = value; |
| 208 | break; |
| 209 | |
| 210 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 211 | bind_to_texture_rgba = value; |
| 212 | break; |
| 213 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 214 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 215 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 216 | break; |
| 217 | |
| 218 | default: |
| 219 | key = dri2_to_egl_attribute_map[attrib]; |
| 220 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 221 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 226 | /* In EGL, double buffer or not isn't a config attribute. Pixmaps |
| 227 | * surfaces are always single buffered, pbuffer surfaces are always |
| 228 | * back buffers and windows can be either, selected by passing an |
| 229 | * attribute at window surface construction time. To support this |
| 230 | * we ignore all double buffer configs and manipulate the buffer we |
| 231 | * return in the getBuffer callback to get the behaviour we want. */ |
| 232 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 233 | if (double_buffer) |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 234 | return; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 235 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 236 | if (visual != NULL) { |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 237 | if (depth != _eglGetConfigKey(&base, EGL_BUFFER_SIZE)) |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 238 | return; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 239 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 240 | _eglSetConfigKey(&base, EGL_SURFACE_TYPE, |
| 241 | EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | |
| 242 | EGL_SWAP_BEHAVIOR_PRESERVED_BIT); |
| 243 | |
| 244 | _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_ID, visual->visual_id); |
| 245 | _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_TYPE, visual->_class); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 246 | } else { |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 247 | _eglSetConfigKey(&base, EGL_SURFACE_TYPE, |
Kristian Høgsberg | 360faf8 | 2010-02-09 16:06:23 -0500 | [diff] [blame] | 248 | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 249 | } |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 250 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 251 | _eglSetConfigKey(&base, EGL_NATIVE_RENDERABLE, EGL_TRUE); |
| 252 | _eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGB, bind_to_texture_rgb); |
| 253 | if (_eglGetConfigKey(&base, EGL_ALPHA_SIZE) > 0) |
| 254 | _eglSetConfigKey(&base, |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 255 | EGL_BIND_TO_TEXTURE_RGBA, bind_to_texture_rgba); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 256 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 257 | _eglSetConfigKey(&base, EGL_RENDERABLE_TYPE, disp->ClientAPIsMask); |
| 258 | _eglSetConfigKey(&base, EGL_CONFORMANT, disp->ClientAPIsMask); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 259 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 260 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 261 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 265 | conf = malloc(sizeof *conf); |
| 266 | if (conf != NULL) { |
| 267 | memcpy(&conf->base, &base, sizeof base); |
| 268 | conf->dri_config = dri_config; |
| 269 | _eglAddConfig(disp, &conf->base); |
| 270 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Process list of buffer received from the server |
| 275 | * |
| 276 | * Processes the list of buffers received in a reply from the server to either |
| 277 | * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. |
| 278 | */ |
| 279 | static void |
| 280 | dri2_process_buffers(struct dri2_egl_surface *dri2_surf, |
| 281 | xcb_dri2_dri2_buffer_t *buffers, unsigned count) |
| 282 | { |
| 283 | struct dri2_egl_display *dri2_dpy = |
| 284 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 285 | xcb_rectangle_t rectangle; |
| 286 | int i; |
| 287 | |
| 288 | dri2_surf->buffer_count = count; |
| 289 | dri2_surf->have_fake_front = 0; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 290 | |
| 291 | /* This assumes the DRI2 buffer attachment tokens matches the |
| 292 | * __DRIbuffer tokens. */ |
| 293 | for (i = 0; i < count; i++) { |
| 294 | dri2_surf->buffers[i].attachment = buffers[i].attachment; |
| 295 | dri2_surf->buffers[i].name = buffers[i].name; |
| 296 | dri2_surf->buffers[i].pitch = buffers[i].pitch; |
| 297 | dri2_surf->buffers[i].cpp = buffers[i].cpp; |
| 298 | dri2_surf->buffers[i].flags = buffers[i].flags; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 299 | |
| 300 | /* We only use the DRI drivers single buffer configs. This |
| 301 | * means that if we try to render to a window, DRI2 will give us |
| 302 | * the fake front buffer, which we'll use as a back buffer. |
| 303 | * Note that EGL doesn't require that several clients rendering |
| 304 | * to the same window must see the same aux buffers. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 305 | if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) |
| 306 | dri2_surf->have_fake_front = 1; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | if (dri2_surf->region != XCB_NONE) |
| 310 | xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region); |
| 311 | |
| 312 | rectangle.x = 0; |
| 313 | rectangle.y = 0; |
| 314 | rectangle.width = dri2_surf->base.Width; |
| 315 | rectangle.height = dri2_surf->base.Height; |
| 316 | dri2_surf->region = xcb_generate_id(dri2_dpy->conn); |
| 317 | xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle); |
| 318 | } |
| 319 | |
| 320 | static __DRIbuffer * |
| 321 | dri2_get_buffers(__DRIdrawable * driDrawable, |
| 322 | int *width, int *height, |
| 323 | unsigned int *attachments, int count, |
| 324 | int *out_count, void *loaderPrivate) |
| 325 | { |
| 326 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 327 | struct dri2_egl_display *dri2_dpy = |
| 328 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 329 | xcb_dri2_dri2_buffer_t *buffers; |
| 330 | xcb_dri2_get_buffers_reply_t *reply; |
| 331 | xcb_dri2_get_buffers_cookie_t cookie; |
| 332 | |
| 333 | cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 334 | dri2_surf->drawable, |
| 335 | count, count, attachments); |
| 336 | reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); |
| 337 | buffers = xcb_dri2_get_buffers_buffers (reply); |
| 338 | if (buffers == NULL) |
| 339 | return NULL; |
| 340 | |
| 341 | *out_count = reply->count; |
| 342 | dri2_surf->base.Width = *width = reply->width; |
| 343 | dri2_surf->base.Height = *height = reply->height; |
| 344 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 345 | |
| 346 | free(reply); |
| 347 | |
| 348 | return dri2_surf->buffers; |
| 349 | } |
| 350 | |
| 351 | static void |
| 352 | dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
| 353 | { |
| 354 | /* FIXME: Does EGL support front buffer rendering at all? */ |
| 355 | |
| 356 | #if 0 |
| 357 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 358 | |
| 359 | dri2WaitGL(dri2_surf); |
| 360 | #endif |
| 361 | } |
| 362 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 363 | static __DRIimage * |
| 364 | dri2_lookup_egl_image(__DRIcontext *context, void *image, void *data) |
| 365 | { |
| 366 | struct dri2_egl_context *dri2_ctx = data; |
| 367 | _EGLDisplay *disp = dri2_ctx->base.Resource.Display; |
| 368 | struct dri2_egl_image *dri2_img; |
| 369 | _EGLImage *img; |
| 370 | |
| 371 | img = _eglLookupImage(image, disp); |
| 372 | if (img == NULL) { |
| 373 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 374 | return NULL; |
| 375 | } |
| 376 | |
| 377 | dri2_img = dri2_egl_image(image); |
| 378 | |
| 379 | return dri2_img->dri_image; |
| 380 | } |
| 381 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 382 | static __DRIbuffer * |
| 383 | dri2_get_buffers_with_format(__DRIdrawable * driDrawable, |
| 384 | int *width, int *height, |
| 385 | unsigned int *attachments, int count, |
| 386 | int *out_count, void *loaderPrivate) |
| 387 | { |
| 388 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 389 | struct dri2_egl_display *dri2_dpy = |
| 390 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 391 | xcb_dri2_dri2_buffer_t *buffers; |
| 392 | xcb_dri2_get_buffers_with_format_reply_t *reply; |
| 393 | xcb_dri2_get_buffers_with_format_cookie_t cookie; |
| 394 | xcb_dri2_attach_format_t *format_attachments; |
| 395 | |
| 396 | format_attachments = (xcb_dri2_attach_format_t *) attachments; |
| 397 | cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, |
| 398 | dri2_surf->drawable, |
| 399 | count, count, |
| 400 | format_attachments); |
| 401 | |
| 402 | reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, |
| 403 | cookie, NULL); |
| 404 | if (reply == NULL) |
| 405 | return NULL; |
| 406 | |
| 407 | buffers = xcb_dri2_get_buffers_with_format_buffers (reply); |
| 408 | dri2_surf->base.Width = *width = reply->width; |
| 409 | dri2_surf->base.Height = *height = reply->height; |
| 410 | *out_count = reply->count; |
| 411 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 412 | |
| 413 | free(reply); |
| 414 | |
| 415 | return dri2_surf->buffers; |
| 416 | } |
| 417 | |
| 418 | #ifdef GLX_USE_TLS |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 419 | static const char dri_driver_format[] = "%.*s/tls/%s_dri.so"; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 420 | #else |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 421 | static const char dri_driver_format[] = "%.*s/%s_dri.so"; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 422 | #endif |
| 423 | |
| 424 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 425 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 426 | struct dri2_extension_match { |
| 427 | const char *name; |
| 428 | int version; |
| 429 | int offset; |
| 430 | }; |
| 431 | |
| 432 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 433 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 434 | { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, |
| 435 | { NULL } |
| 436 | }; |
| 437 | |
| 438 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 439 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 440 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 441 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 442 | { NULL } |
| 443 | }; |
| 444 | |
| 445 | static EGLBoolean |
| 446 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 447 | struct dri2_extension_match *matches, |
| 448 | const __DRIextension **extensions) |
| 449 | { |
| 450 | int i, j, ret = EGL_TRUE; |
| 451 | void *field; |
| 452 | |
| 453 | for (i = 0; extensions[i]; i++) { |
| 454 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 455 | for (j = 0; matches[j].name; j++) { |
| 456 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 457 | extensions[i]->version >= matches[j].version) { |
| 458 | field = ((char *) dri2_dpy + matches[j].offset); |
| 459 | *(const __DRIextension **) field = extensions[i]; |
| 460 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 461 | extensions[i]->name, extensions[i]->version); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | for (j = 0; matches[j].name; j++) { |
| 467 | field = ((char *) dri2_dpy + matches[j].offset); |
| 468 | if (*(const __DRIextension **) field == NULL) { |
| 469 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 470 | matches[j].name, matches[j].version); |
| 471 | ret = EGL_FALSE; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 478 | static char * |
| 479 | dri2_strndup(const char *s, int length) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 480 | { |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 481 | char *d; |
| 482 | |
| 483 | d = malloc(length + 1); |
| 484 | if (d == NULL) |
| 485 | return NULL; |
| 486 | |
| 487 | memcpy(d, s, length); |
| 488 | d[length] = '\0'; |
| 489 | |
| 490 | return d; |
| 491 | } |
| 492 | |
| 493 | static EGLBoolean |
| 494 | dri2_connect(struct dri2_egl_display *dri2_dpy) |
| 495 | { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 496 | xcb_xfixes_query_version_reply_t *xfixes_query; |
| 497 | xcb_xfixes_query_version_cookie_t xfixes_query_cookie; |
| 498 | xcb_dri2_query_version_reply_t *dri2_query; |
| 499 | xcb_dri2_query_version_cookie_t dri2_query_cookie; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 500 | xcb_dri2_connect_reply_t *connect; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 501 | xcb_dri2_connect_cookie_t connect_cookie; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 502 | xcb_generic_error_t *error; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 503 | xcb_screen_iterator_t s; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 504 | |
| 505 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); |
| 506 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); |
| 507 | |
| 508 | xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, |
| 509 | XCB_XFIXES_MAJOR_VERSION, |
| 510 | XCB_XFIXES_MINOR_VERSION); |
| 511 | |
| 512 | dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, |
| 513 | XCB_DRI2_MAJOR_VERSION, |
| 514 | XCB_DRI2_MINOR_VERSION); |
| 515 | |
| 516 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 517 | connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn, |
| 518 | s.data->root, |
| 519 | XCB_DRI2_DRIVER_TYPE_DRI); |
| 520 | |
| 521 | xfixes_query = |
| 522 | xcb_xfixes_query_version_reply (dri2_dpy->conn, |
| 523 | xfixes_query_cookie, &error); |
| 524 | if (xfixes_query == NULL || |
| 525 | error != NULL || xfixes_query->major_version < 2) { |
| 526 | _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version"); |
| 527 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 528 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 529 | } |
| 530 | free(xfixes_query); |
| 531 | |
| 532 | dri2_query = |
| 533 | xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); |
| 534 | if (dri2_query == NULL || error != NULL) { |
| 535 | _eglLog(_EGL_FATAL, "DRI2: failed to query version"); |
| 536 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 537 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 538 | } |
| 539 | dri2_dpy->dri2_major = dri2_query->major_version; |
| 540 | dri2_dpy->dri2_minor = dri2_query->minor_version; |
| 541 | free(dri2_query); |
| 542 | |
| 543 | connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 544 | if (connect == NULL || |
| 545 | connect->driver_name_length + connect->device_name_length == 0) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 546 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 547 | return EGL_FALSE; |
| 548 | } |
| 549 | |
| 550 | dri2_dpy->device_name = |
| 551 | dri2_strndup(xcb_dri2_connect_device_name (connect), |
| 552 | xcb_dri2_connect_device_name_length (connect)); |
| 553 | |
| 554 | dri2_dpy->driver_name = |
| 555 | dri2_strndup(xcb_dri2_connect_driver_name (connect), |
| 556 | xcb_dri2_connect_driver_name_length (connect)); |
| 557 | |
| 558 | if (dri2_dpy->device_name == NULL || dri2_dpy->driver_name == NULL) { |
| 559 | free(dri2_dpy->device_name); |
| 560 | free(dri2_dpy->driver_name); |
| 561 | free(connect); |
| 562 | return EGL_FALSE; |
| 563 | } |
| 564 | free(connect); |
| 565 | |
| 566 | return EGL_TRUE; |
| 567 | } |
| 568 | |
| 569 | static EGLBoolean |
| 570 | dri2_authenticate(struct dri2_egl_display *dri2_dpy) |
| 571 | { |
| 572 | xcb_dri2_authenticate_reply_t *authenticate; |
| 573 | xcb_dri2_authenticate_cookie_t authenticate_cookie; |
| 574 | xcb_screen_iterator_t s; |
| 575 | drm_magic_t magic; |
| 576 | |
| 577 | if (drmGetMagic(dri2_dpy->fd, &magic)) { |
| 578 | _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic"); |
| 579 | return EGL_FALSE; |
| 580 | } |
| 581 | |
| 582 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 583 | authenticate_cookie = |
| 584 | xcb_dri2_authenticate_unchecked(dri2_dpy->conn, s.data->root, magic); |
| 585 | authenticate = |
| 586 | xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); |
| 587 | if (authenticate == NULL || !authenticate->authenticated) { |
| 588 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
| 589 | free(authenticate); |
| 590 | return EGL_FALSE; |
| 591 | } |
| 592 | |
| 593 | free(authenticate); |
| 594 | |
| 595 | return EGL_TRUE; |
| 596 | } |
| 597 | |
| 598 | static EGLBoolean |
| 599 | dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, |
| 600 | _EGLDisplay *disp) |
| 601 | { |
| 602 | xcb_screen_iterator_t s; |
| 603 | xcb_depth_iterator_t d; |
| 604 | xcb_visualtype_t *visuals; |
| 605 | int i, j, id; |
| 606 | |
| 607 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 608 | d = xcb_screen_allowed_depths_iterator(s.data); |
| 609 | id = 1; |
| 610 | while (d.rem > 0) { |
| 611 | EGLBoolean class_added[6] = { 0, }; |
| 612 | |
| 613 | visuals = xcb_depth_visuals(d.data); |
| 614 | for (i = 0; i < xcb_depth_visuals_length(d.data); i++) { |
| 615 | if (class_added[visuals[i]._class]) |
| 616 | continue; |
| 617 | |
| 618 | class_added[visuals[i]._class] = EGL_TRUE; |
| 619 | for (j = 0; dri2_dpy->driver_configs[j]; j++) |
| 620 | dri2_add_config(disp, dri2_dpy->driver_configs[j], |
| 621 | id++, d.data->depth, &visuals[i]); |
| 622 | } |
| 623 | |
| 624 | xcb_depth_next(&d); |
| 625 | } |
| 626 | |
| 627 | if (!disp->NumConfigs) { |
| 628 | _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); |
| 629 | return EGL_FALSE; |
| 630 | } |
| 631 | |
| 632 | return EGL_TRUE; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 637 | */ |
| 638 | static EGLBoolean |
| 639 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, |
| 640 | EGLint *major, EGLint *minor) |
| 641 | { |
| 642 | const __DRIextension **extensions; |
| 643 | struct dri2_egl_display *dri2_dpy; |
| 644 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 645 | unsigned int api_mask; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 646 | |
| 647 | dri2_dpy = malloc(sizeof *dri2_dpy); |
| 648 | if (!dri2_dpy) |
| 649 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 650 | |
| 651 | disp->DriverData = (void *) dri2_dpy; |
| 652 | if (disp->NativeDisplay == NULL) { |
| 653 | dri2_dpy->conn = xcb_connect(0, 0); |
| 654 | if (!dri2_dpy->conn) { |
| 655 | _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); |
| 656 | goto cleanup_dpy; |
| 657 | } |
| 658 | } else { |
| 659 | dri2_dpy->conn = XGetXCBConnection(disp->NativeDisplay); |
| 660 | } |
| 661 | |
| 662 | if (dri2_dpy->conn == NULL) |
| 663 | goto cleanup_conn; |
| 664 | |
| 665 | if (dri2_dpy->conn) { |
| 666 | if (!dri2_connect(dri2_dpy)) |
| 667 | goto cleanup_conn; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | search_paths = NULL; |
| 671 | if (geteuid() == getuid()) { |
| 672 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 673 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 674 | } |
| 675 | if (search_paths == NULL) |
| 676 | search_paths = DEFAULT_DRIVER_DIR; |
| 677 | |
| 678 | dri2_dpy->driver = NULL; |
| 679 | end = search_paths + strlen(search_paths); |
| 680 | for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { |
| 681 | next = strchr(p, ':'); |
| 682 | if (next == NULL) |
| 683 | next = end; |
| 684 | |
| 685 | snprintf(path, sizeof path, |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 686 | dri_driver_format, (int) (next - p), p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 687 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 688 | if (dri2_dpy->driver == NULL) |
| 689 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | if (dri2_dpy->driver == NULL) { |
| 693 | _eglLog(_EGL_FATAL, |
| 694 | "DRI2: failed to open any driver (search paths %s)", |
| 695 | search_paths); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 696 | goto cleanup_conn; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 700 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 701 | if (extensions == NULL) { |
| 702 | _eglLog(_EGL_FATAL, |
| 703 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 704 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 705 | } |
| 706 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 707 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 708 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 709 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 710 | dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 711 | if (dri2_dpy->fd == -1) { |
| 712 | _eglLog(_EGL_FATAL, |
| 713 | "DRI2: could not open %s (%s)", path, strerror(errno)); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 714 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 715 | } |
| 716 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 717 | if (dri2_dpy->conn) { |
| 718 | if (!dri2_authenticate(dri2_dpy)) |
| 719 | goto cleanup_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 720 | } |
| 721 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 722 | if (dri2_dpy->dri2_minor >= 1) { |
| 723 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 724 | dri2_dpy->loader_extension.base.version = 3; |
| 725 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 726 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 727 | dri2_dpy->loader_extension.getBuffersWithFormat = |
| 728 | dri2_get_buffers_with_format; |
| 729 | } else { |
| 730 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 731 | dri2_dpy->loader_extension.base.version = 2; |
| 732 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 733 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 734 | dri2_dpy->loader_extension.getBuffersWithFormat = NULL; |
| 735 | } |
| 736 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 737 | dri2_dpy->image_lookup_extension.base.name = __DRI_IMAGE_LOOKUP; |
| 738 | dri2_dpy->image_lookup_extension.base.version = 1; |
| 739 | dri2_dpy->image_lookup_extension.lookupEGLImage = dri2_lookup_egl_image; |
| 740 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 741 | dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 742 | dri2_dpy->extensions[1] = &dri2_dpy->image_lookup_extension.base; |
| 743 | dri2_dpy->extensions[2] = NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 744 | |
| 745 | dri2_dpy->dri_screen = |
| 746 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 747 | &dri2_dpy->driver_configs, dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 748 | |
| 749 | if (dri2_dpy->dri_screen == NULL) { |
| 750 | _eglLog(_EGL_FATAL, "DRI2: failed to create dri screen"); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 751 | goto cleanup_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 755 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 756 | goto cleanup_dri_screen; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 757 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 758 | if (dri2_dpy->dri2->base.version >= 2) |
| 759 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
| 760 | else |
| 761 | api_mask = __DRI_API_OPENGL; |
| 762 | |
| 763 | disp->ClientAPIsMask = 0; |
| 764 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
| 765 | disp->ClientAPIsMask |= EGL_OPENGL_BIT; |
| 766 | if (api_mask & (1 <<__DRI_API_GLES)) |
| 767 | disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT; |
| 768 | if (api_mask & (1 << __DRI_API_GLES2)) |
| 769 | disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; |
| 770 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 771 | if (dri2_dpy->conn) { |
| 772 | if (!dri2_add_configs_for_visuals(dri2_dpy, disp)) |
| 773 | goto cleanup_configs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 774 | } |
| 775 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 776 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 777 | disp->Extensions.KHR_image_pixmap = EGL_TRUE; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 778 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 3a82c8c | 2010-04-14 16:22:27 -0400 | [diff] [blame] | 779 | disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 780 | |
| 781 | /* we're supporting EGL 1.4 */ |
| 782 | *major = 1; |
| 783 | *minor = 4; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 784 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 785 | return EGL_TRUE; |
| 786 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 787 | cleanup_configs: |
| 788 | _eglCleanupDisplay(disp); |
| 789 | cleanup_dri_screen: |
| 790 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 791 | cleanup_fd: |
| 792 | close(dri2_dpy->fd); |
| 793 | cleanup_driver: |
| 794 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 795 | cleanup_conn: |
| 796 | if (disp->NativeDisplay == NULL) |
| 797 | xcb_disconnect(dri2_dpy->conn); |
| 798 | cleanup_dpy: |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 799 | free(dri2_dpy); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 800 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 801 | return EGL_FALSE; |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * Called via eglTerminate(), drv->API.Terminate(). |
| 806 | */ |
| 807 | static EGLBoolean |
| 808 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 809 | { |
| 810 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 811 | |
| 812 | _eglReleaseDisplayResources(drv, disp); |
| 813 | _eglCleanupDisplay(disp); |
| 814 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 815 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 816 | close(dri2_dpy->fd); |
| 817 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 818 | if (disp->NativeDisplay == NULL) |
| 819 | xcb_disconnect(dri2_dpy->conn); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 820 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 821 | disp->DriverData = NULL; |
| 822 | |
| 823 | return EGL_TRUE; |
| 824 | } |
| 825 | |
| 826 | |
| 827 | /** |
| 828 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 829 | */ |
| 830 | static _EGLContext * |
| 831 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 832 | _EGLContext *share_list, const EGLint *attrib_list) |
| 833 | { |
| 834 | struct dri2_egl_context *dri2_ctx; |
| 835 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 836 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
| 837 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 838 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 839 | |
| 840 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 841 | if (!dri2_ctx) { |
| 842 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 843 | return NULL; |
| 844 | } |
| 845 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 846 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 847 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 848 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame^] | 849 | switch (dri2_ctx->base.ClientAPI) { |
| 850 | case EGL_OPENGL_ES_API: |
| 851 | switch (dri2_ctx->base.ClientVersion) { |
| 852 | case 1: |
| 853 | api = __DRI_API_GLES; |
| 854 | break; |
| 855 | case 2: |
| 856 | api = __DRI_API_GLES2; |
| 857 | break; |
| 858 | default: |
| 859 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 860 | return NULL; |
| 861 | } |
| 862 | break; |
| 863 | case EGL_OPENGL_API: |
| 864 | api = __DRI_API_OPENGL; |
| 865 | break; |
| 866 | default: |
| 867 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 868 | return NULL; |
| 869 | } |
| 870 | |
| 871 | if (dri2_dpy->dri2->base.version >= 2) { |
| 872 | dri2_ctx->dri_context = |
| 873 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 874 | api, |
| 875 | dri2_config->dri_config, |
| 876 | dri2_ctx_shared ? |
| 877 | dri2_ctx_shared->dri_context : NULL, |
| 878 | dri2_ctx); |
| 879 | } else if (api == __DRI_API_OPENGL) { |
| 880 | dri2_ctx->dri_context = |
| 881 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 882 | dri2_config->dri_config, |
| 883 | dri2_ctx_shared ? |
| 884 | dri2_ctx_shared->dri_context : NULL, |
| 885 | dri2_ctx); |
| 886 | } else { |
| 887 | /* fail */ |
| 888 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 889 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 890 | if (!dri2_ctx->dri_context) |
| 891 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 892 | |
| 893 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 894 | |
| 895 | cleanup: |
| 896 | free(dri2_ctx); |
| 897 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static EGLBoolean |
| 901 | dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
| 902 | { |
| 903 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 904 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 905 | |
| 906 | if (_eglIsSurfaceBound(surf)) |
| 907 | return EGL_TRUE; |
| 908 | |
| 909 | (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); |
| 910 | |
| 911 | xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 912 | |
| 913 | if (surf->Type == EGL_PBUFFER_BIT) |
| 914 | xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); |
| 915 | |
| 916 | free(surf); |
| 917 | |
| 918 | return EGL_TRUE; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 923 | */ |
| 924 | static EGLBoolean |
| 925 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 926 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 927 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 928 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 929 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 930 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 931 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 932 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 933 | __DRIdrawable *ddraw, *rdraw; |
| 934 | __DRIcontext *cctx; |
| 935 | |
| 936 | /* bind the new context and return the "orphaned" one */ |
| 937 | if (!_eglBindContext(&ctx, &dsurf, &rsurf)) |
| 938 | return EGL_FALSE; |
| 939 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 940 | /* flush before context switch */ |
| 941 | if (ctx && dri2_drv->glFlush) |
| 942 | dri2_drv->glFlush(); |
| 943 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 944 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 945 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 946 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 947 | |
| 948 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 949 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 950 | if (dsurf && !_eglIsSurfaceLinked(dsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 951 | dri2_destroy_surface(drv, disp, dsurf); |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 952 | if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(dsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 953 | dri2_destroy_surface(drv, disp, rsurf); |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 954 | if (ctx != NULL && !_eglIsContextLinked(ctx)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 955 | dri2_dpy->core->unbindContext(dri2_egl_context(ctx)->dri_context); |
| 956 | |
| 957 | return EGL_TRUE; |
| 958 | } else { |
| 959 | _eglBindContext(&ctx, &dsurf, &rsurf); |
| 960 | |
| 961 | return EGL_FALSE; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 967 | */ |
| 968 | static _EGLSurface * |
| 969 | dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
| 970 | _EGLConfig *conf, EGLNativeWindowType window, |
| 971 | const EGLint *attrib_list) |
| 972 | { |
| 973 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 974 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 975 | struct dri2_egl_surface *dri2_surf; |
| 976 | xcb_get_geometry_cookie_t cookie; |
| 977 | xcb_get_geometry_reply_t *reply; |
| 978 | xcb_screen_iterator_t s; |
| 979 | xcb_generic_error_t *error; |
| 980 | |
| 981 | dri2_surf = malloc(sizeof *dri2_surf); |
| 982 | if (!dri2_surf) { |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 983 | _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 984 | return NULL; |
| 985 | } |
| 986 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 987 | if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) |
| 988 | goto cleanup_surf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 989 | |
| 990 | dri2_surf->region = XCB_NONE; |
| 991 | if (type == EGL_PBUFFER_BIT) { |
| 992 | dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); |
| 993 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 994 | xcb_create_pixmap(dri2_dpy->conn, |
| 995 | _eglGetConfigKey(conf, EGL_BUFFER_SIZE), |
| 996 | dri2_surf->drawable, s.data->root, |
| 997 | dri2_surf->base.Width, dri2_surf->base.Height); |
| 998 | } else { |
| 999 | dri2_surf->drawable = window; |
| 1000 | } |
| 1001 | |
| 1002 | dri2_surf->dri_drawable = |
| 1003 | (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, |
| 1004 | dri2_conf->dri_config, dri2_surf); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1005 | if (dri2_surf->dri_drawable == NULL) { |
| 1006 | _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); |
| 1007 | goto cleanup_pixmap; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 1011 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1012 | if (type != EGL_PBUFFER_BIT) { |
| 1013 | cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); |
| 1014 | reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); |
| 1015 | if (reply == NULL || error != NULL) { |
| 1016 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 1017 | free(error); |
| 1018 | goto cleanup_dri_drawable; |
| 1019 | } |
| 1020 | |
| 1021 | dri2_surf->base.Width = reply->width; |
| 1022 | dri2_surf->base.Height = reply->height; |
| 1023 | free(reply); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1024 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1025 | |
| 1026 | return &dri2_surf->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1027 | |
| 1028 | cleanup_dri_drawable: |
| 1029 | dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); |
| 1030 | cleanup_pixmap: |
| 1031 | if (type == EGL_PBUFFER_BIT) |
| 1032 | xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); |
| 1033 | cleanup_surf: |
| 1034 | free(dri2_surf); |
| 1035 | |
| 1036 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 1041 | */ |
| 1042 | static _EGLSurface * |
| 1043 | dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1044 | _EGLConfig *conf, EGLNativeWindowType window, |
| 1045 | const EGLint *attrib_list) |
| 1046 | { |
| 1047 | return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
| 1048 | window, attrib_list); |
| 1049 | } |
| 1050 | |
| 1051 | static _EGLSurface * |
| 1052 | dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1053 | _EGLConfig *conf, EGLNativePixmapType pixmap, |
| 1054 | const EGLint *attrib_list) |
| 1055 | { |
| 1056 | return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf, |
| 1057 | pixmap, attrib_list); |
| 1058 | } |
| 1059 | |
| 1060 | static _EGLSurface * |
| 1061 | dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1062 | _EGLConfig *conf, const EGLint *attrib_list) |
| 1063 | { |
| 1064 | return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, |
| 1065 | XCB_WINDOW_NONE, attrib_list); |
| 1066 | } |
| 1067 | |
| 1068 | static EGLBoolean |
| 1069 | dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
| 1070 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1071 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1072 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1073 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1074 | _EGLContext *ctx; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1075 | xcb_dri2_copy_region_cookie_t cookie; |
| 1076 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1077 | if (dri2_drv->glFlush) { |
| 1078 | ctx = _eglGetCurrentContext(); |
| 1079 | if (ctx && ctx->DrawSurface == &dri2_surf->base) |
| 1080 | dri2_drv->glFlush(); |
| 1081 | } |
| 1082 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1083 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1084 | |
| 1085 | #if 0 |
| 1086 | /* FIXME: Add support for dri swapbuffers, that'll give us swap |
| 1087 | * interval and page flipping (at least for fullscreen windows) as |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 1088 | * well as the page flip event. Unless surface->SwapBehavior is |
| 1089 | * EGL_BUFFER_PRESERVED. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1090 | #if __DRI2_FLUSH_VERSION >= 2 |
| 1091 | if (pdraw->psc->f) |
| 1092 | (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable); |
| 1093 | #endif |
| 1094 | #endif |
| 1095 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1096 | if (!dri2_surf->have_fake_front) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1097 | return EGL_TRUE; |
| 1098 | |
| 1099 | cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, |
| 1100 | dri2_surf->drawable, |
| 1101 | dri2_surf->region, |
| 1102 | XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1103 | XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1104 | free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); |
| 1105 | |
| 1106 | return EGL_TRUE; |
| 1107 | } |
| 1108 | |
| 1109 | /* |
| 1110 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 1111 | */ |
| 1112 | static _EGLProc |
| 1113 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 1114 | { |
| 1115 | /* FIXME: Do we need to support lookup of EGL symbols too? */ |
| 1116 | |
| 1117 | return (_EGLProc) _glapi_get_proc_address(procname); |
| 1118 | } |
| 1119 | |
| 1120 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1121 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1122 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1123 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1124 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 1125 | |
| 1126 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 1127 | * we need to copy fake to real here.*/ |
| 1128 | |
| 1129 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1130 | |
| 1131 | return EGL_TRUE; |
| 1132 | } |
| 1133 | |
| 1134 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1135 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1136 | { |
| 1137 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 1138 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 1139 | /* glXWaitX(); */ |
| 1140 | |
| 1141 | return EGL_TRUE; |
| 1142 | } |
| 1143 | |
| 1144 | static void |
| 1145 | dri2_unload(_EGLDriver *drv) |
| 1146 | { |
| 1147 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
| 1148 | free(dri2_drv); |
| 1149 | } |
| 1150 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1151 | static EGLBoolean |
| 1152 | dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, |
| 1153 | EGLNativePixmapType target) |
| 1154 | { |
| 1155 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1156 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1157 | xcb_gcontext_t gc; |
| 1158 | |
| 1159 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
| 1160 | |
| 1161 | gc = xcb_generate_id(dri2_dpy->conn); |
| 1162 | xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); |
| 1163 | xcb_copy_area(dri2_dpy->conn, |
| 1164 | dri2_surf->drawable, |
| 1165 | target, |
| 1166 | gc, |
| 1167 | 0, 0, |
| 1168 | 0, 0, |
| 1169 | dri2_surf->base.Width, |
| 1170 | dri2_surf->base.Height); |
| 1171 | xcb_free_gc(dri2_dpy->conn, gc); |
| 1172 | |
| 1173 | return EGL_TRUE; |
| 1174 | } |
| 1175 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1176 | static EGLBoolean |
| 1177 | dri2_bind_tex_image(_EGLDriver *drv, |
| 1178 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1179 | { |
| 1180 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1181 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1182 | struct dri2_egl_context *dri2_ctx; |
| 1183 | _EGLContext *ctx; |
| 1184 | GLint format, target; |
| 1185 | |
| 1186 | ctx = _eglGetCurrentContext(); |
| 1187 | dri2_ctx = dri2_egl_context(ctx); |
| 1188 | |
| 1189 | if (buffer != EGL_BACK_BUFFER) { |
| 1190 | _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); |
| 1191 | return EGL_FALSE; |
| 1192 | } |
| 1193 | |
| 1194 | /* We allow binding pixmaps too... Not conformat, but we can do it |
| 1195 | * for free and it's useful for X compositors. Supposedly there's |
| 1196 | * a EGL_NOKIA_texture_from_pixmap extension that allows that, but |
| 1197 | * I couldn't find it at this time. */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 1198 | if ((dri2_surf->base.Type & (EGL_PBUFFER_BIT | EGL_PIXMAP_BIT)) == 0) { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1199 | _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); |
| 1200 | return EGL_FALSE; |
| 1201 | } |
| 1202 | |
| 1203 | switch (dri2_surf->base.TextureFormat) { |
| 1204 | case EGL_TEXTURE_RGB: |
| 1205 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 1206 | break; |
| 1207 | case EGL_TEXTURE_RGBA: |
| 1208 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 1209 | break; |
| 1210 | default: |
| 1211 | _eglError(EGL_BAD_MATCH, "eglBindTexImage"); |
| 1212 | return EGL_FALSE; |
| 1213 | } |
| 1214 | |
| 1215 | switch (dri2_surf->base.TextureTarget) { |
| 1216 | case EGL_TEXTURE_2D: |
| 1217 | target = GL_TEXTURE_2D; |
| 1218 | break; |
| 1219 | default: |
| 1220 | _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); |
| 1221 | return EGL_FALSE; |
| 1222 | } |
| 1223 | |
| 1224 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 1225 | target, format, |
| 1226 | dri2_surf->dri_drawable); |
| 1227 | |
| 1228 | return dri2_surf->base.BoundToTexture = EGL_TRUE; |
| 1229 | } |
| 1230 | |
| 1231 | static EGLBoolean |
| 1232 | dri2_release_tex_image(_EGLDriver *drv, |
| 1233 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1234 | { |
| 1235 | return EGL_TRUE; |
| 1236 | } |
| 1237 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1238 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1239 | dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, |
| 1240 | EGLClientBuffer buffer, const EGLint *attr_list) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1241 | { |
| 1242 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1243 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1244 | struct dri2_egl_image *dri2_img; |
| 1245 | unsigned int attachments[1]; |
| 1246 | xcb_drawable_t drawable; |
| 1247 | xcb_dri2_get_buffers_cookie_t buffers_cookie; |
| 1248 | xcb_dri2_get_buffers_reply_t *buffers_reply; |
| 1249 | xcb_dri2_dri2_buffer_t *buffers; |
| 1250 | xcb_get_geometry_cookie_t geometry_cookie; |
| 1251 | xcb_get_geometry_reply_t *geometry_reply; |
| 1252 | xcb_generic_error_t *error; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1253 | int stride, format; |
| 1254 | |
| 1255 | drawable = (xcb_drawable_t) buffer; |
| 1256 | xcb_dri2_create_drawable (dri2_dpy->conn, drawable); |
| 1257 | attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; |
| 1258 | buffers_cookie = |
| 1259 | xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 1260 | drawable, 1, 1, attachments); |
| 1261 | geometry_cookie = xcb_get_geometry (dri2_dpy->conn, drawable); |
| 1262 | buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, |
| 1263 | buffers_cookie, NULL); |
| 1264 | buffers = xcb_dri2_get_buffers_buffers (buffers_reply); |
| 1265 | if (buffers == NULL) { |
| 1266 | return NULL; |
| 1267 | } |
| 1268 | |
| 1269 | geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, |
| 1270 | geometry_cookie, &error); |
| 1271 | if (geometry_reply == NULL || error != NULL) { |
| 1272 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 1273 | free(error); |
| 1274 | free(buffers_reply); |
| 1275 | } |
| 1276 | |
| 1277 | switch (geometry_reply->depth) { |
| 1278 | case 16: |
| 1279 | format = __DRI_IMAGE_FORMAT_RGB565; |
| 1280 | break; |
| 1281 | case 24: |
| 1282 | format = __DRI_IMAGE_FORMAT_XRGB8888; |
| 1283 | break; |
| 1284 | case 32: |
| 1285 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1286 | break; |
| 1287 | default: |
| 1288 | _eglError(EGL_BAD_PARAMETER, |
| 1289 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 1290 | free(buffers_reply); |
| 1291 | free(geometry_reply); |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | |
| 1295 | dri2_img = malloc(sizeof *dri2_img); |
| 1296 | if (!dri2_img) { |
| 1297 | free(buffers_reply); |
| 1298 | free(geometry_reply); |
| 1299 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1300 | return EGL_NO_IMAGE_KHR; |
| 1301 | } |
| 1302 | |
| 1303 | if (!_eglInitImage(&dri2_img->base, disp, attr_list)) { |
| 1304 | free(buffers_reply); |
| 1305 | free(geometry_reply); |
| 1306 | return EGL_NO_IMAGE_KHR; |
| 1307 | } |
| 1308 | |
| 1309 | stride = buffers[0].pitch / buffers[0].cpp; |
| 1310 | dri2_img->dri_image = |
| 1311 | dri2_dpy->image->createImageFromName(dri2_ctx->dri_context, |
| 1312 | buffers_reply->width, |
| 1313 | buffers_reply->height, |
| 1314 | format, |
| 1315 | buffers[0].name, |
| 1316 | stride, |
| 1317 | dri2_img); |
| 1318 | |
| 1319 | free(buffers_reply); |
| 1320 | free(geometry_reply); |
| 1321 | |
| 1322 | return &dri2_img->base; |
| 1323 | } |
| 1324 | |
| 1325 | static _EGLImage * |
| 1326 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 1327 | EGLClientBuffer buffer, |
| 1328 | const EGLint *attr_list) |
| 1329 | { |
| 1330 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1331 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1332 | struct dri2_egl_image *dri2_img; |
| 1333 | GLuint renderbuffer = (GLuint) buffer; |
| 1334 | |
| 1335 | if (renderbuffer == 0) { |
| 1336 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1337 | return EGL_NO_IMAGE_KHR; |
| 1338 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1339 | |
| 1340 | dri2_img = malloc(sizeof *dri2_img); |
| 1341 | if (!dri2_img) { |
| 1342 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1343 | return EGL_NO_IMAGE_KHR; |
| 1344 | } |
| 1345 | |
| 1346 | if (!_eglInitImage(&dri2_img->base, disp, attr_list)) |
| 1347 | return EGL_NO_IMAGE_KHR; |
| 1348 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1349 | dri2_img->dri_image = |
| 1350 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
| 1351 | renderbuffer, |
| 1352 | dri2_img); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1353 | |
| 1354 | return &dri2_img->base; |
| 1355 | } |
| 1356 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1357 | static _EGLImage * |
| 1358 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 1359 | _EGLContext *ctx, EGLenum target, |
| 1360 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1361 | { |
| 1362 | switch (target) { |
| 1363 | case EGL_NATIVE_PIXMAP_KHR: |
| 1364 | return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list); |
| 1365 | case EGL_GL_RENDERBUFFER_KHR: |
| 1366 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
| 1367 | default: |
| 1368 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1369 | return EGL_NO_IMAGE_KHR; |
| 1370 | } |
| 1371 | } |
| 1372 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1373 | static EGLBoolean |
| 1374 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1375 | { |
| 1376 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1377 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1378 | |
| 1379 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1380 | free(dri2_img); |
| 1381 | |
| 1382 | return EGL_TRUE; |
| 1383 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1384 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1385 | /** |
| 1386 | * This is the main entrypoint into the driver, called by libEGL. |
| 1387 | * Create a new _EGLDriver object and init its dispatch table. |
| 1388 | */ |
| 1389 | _EGLDriver * |
| 1390 | _eglMain(const char *args) |
| 1391 | { |
| 1392 | struct dri2_egl_driver *dri2_drv; |
| 1393 | |
| 1394 | dri2_drv = malloc(sizeof *dri2_drv); |
| 1395 | if (!dri2_drv) |
| 1396 | return NULL; |
| 1397 | |
| 1398 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1399 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1400 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1401 | dri2_drv->base.API.CreateContext = dri2_create_context; |
| 1402 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
| 1403 | dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; |
| 1404 | dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; |
| 1405 | dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; |
| 1406 | dri2_drv->base.API.DestroySurface = dri2_destroy_surface; |
| 1407 | dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; |
| 1408 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1409 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1410 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1411 | dri2_drv->base.API.CopyBuffers = dri2_copy_buffers; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1412 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1413 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1414 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1415 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1416 | |
| 1417 | dri2_drv->base.Name = "DRI2"; |
| 1418 | dri2_drv->base.Unload = dri2_unload; |
| 1419 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1420 | dri2_drv->glFlush = |
| 1421 | (void (*)(void)) dri2_get_proc_address(&dri2_drv->base, "glFlush"); |
| 1422 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1423 | return &dri2_drv->base; |
| 1424 | } |