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