Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 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> |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 29 | #include <stdio.h> |
Benjamin Franzke | 7f881c4 | 2011-05-30 10:49:55 +0200 | [diff] [blame] | 30 | #include <string.h> |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 31 | #include <xf86drm.h> |
Benjamin Franzke | ac3c2c8 | 2011-06-07 22:19:21 +0200 | [diff] [blame] | 32 | #include <dlfcn.h> |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 33 | #include <sys/types.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <unistd.h> |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 37 | |
| 38 | #include "egl_dri2.h" |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 39 | #include "egl_dri2_fallbacks.h" |
Emil Velikov | 8d4357b | 2014-01-11 04:52:48 +0000 | [diff] [blame] | 40 | #include "loader.h" |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 41 | |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 42 | static struct gbm_bo * |
| 43 | lock_front_buffer(struct gbm_surface *_surf) |
| 44 | { |
| 45 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
| 46 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 47 | struct gbm_dri_device *device = (struct gbm_dri_device *) _surf->gbm; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 48 | struct gbm_bo *bo; |
| 49 | |
| 50 | if (dri2_surf->current == NULL) { |
| 51 | _eglError(EGL_BAD_SURFACE, "no front buffer"); |
| 52 | return NULL; |
| 53 | } |
| 54 | |
| 55 | bo = dri2_surf->current->bo; |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 56 | |
| 57 | if (device->dri2) { |
| 58 | dri2_surf->current->locked = 1; |
| 59 | dri2_surf->current = NULL; |
| 60 | } |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 61 | |
| 62 | return bo; |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo) |
| 67 | { |
| 68 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
| 69 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
| 70 | int i; |
| 71 | |
| 72 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 73 | if (dri2_surf->color_buffers[i].bo == bo) { |
| 74 | dri2_surf->color_buffers[i].locked = 0; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static int |
| 80 | has_free_buffers(struct gbm_surface *_surf) |
| 81 | { |
| 82 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
| 83 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
| 84 | int i; |
| 85 | |
| 86 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) |
| 87 | if (!dri2_surf->color_buffers[i].locked) |
| 88 | return 1; |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static _EGLSurface * |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 94 | dri2_drm_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 95 | _EGLConfig *conf, void *native_window, |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 96 | const EGLint *attrib_list) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 97 | { |
| 98 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 99 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 100 | struct dri2_egl_surface *dri2_surf; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 101 | struct gbm_surface *window = native_window; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 102 | struct gbm_dri_surface *surf; |
| 103 | |
| 104 | (void) drv; |
| 105 | |
Matt Turner | 6bda027 | 2012-09-04 23:09:22 -0700 | [diff] [blame] | 106 | dri2_surf = calloc(1, sizeof *dri2_surf); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 107 | if (!dri2_surf) { |
| 108 | _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 112 | if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) |
| 113 | goto cleanup_surf; |
| 114 | |
| 115 | switch (type) { |
| 116 | case EGL_WINDOW_BIT: |
Elvis Lee | cf775c9 | 2012-07-11 11:13:51 +0900 | [diff] [blame] | 117 | if (!window) |
| 118 | return NULL; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 119 | surf = gbm_dri_surface(window); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 120 | dri2_surf->gbm_surf = surf; |
| 121 | dri2_surf->base.Width = surf->base.width; |
| 122 | dri2_surf->base.Height = surf->base.height; |
| 123 | surf->dri_private = dri2_surf; |
| 124 | break; |
| 125 | default: |
| 126 | goto cleanup_surf; |
| 127 | } |
| 128 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 129 | if (dri2_dpy->dri2) { |
| 130 | dri2_surf->dri_drawable = |
| 131 | (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, |
| 132 | dri2_conf->dri_double_config, |
| 133 | dri2_surf->gbm_surf); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 134 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 135 | } else { |
| 136 | assert(dri2_dpy->swrast != NULL); |
| 137 | dri2_surf->dri_drawable = |
| 138 | (*dri2_dpy->swrast->createNewDrawable) (dri2_dpy->dri_screen, |
| 139 | dri2_conf->dri_double_config, |
| 140 | dri2_surf->gbm_surf); |
| 141 | |
| 142 | } |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 143 | if (dri2_surf->dri_drawable == NULL) { |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 144 | _eglError(EGL_BAD_ALLOC, "createNewDrawable()"); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 145 | goto cleanup_surf; |
| 146 | } |
| 147 | |
| 148 | return &dri2_surf->base; |
| 149 | |
| 150 | cleanup_surf: |
| 151 | free(dri2_surf); |
| 152 | |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | static _EGLSurface * |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 157 | dri2_drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 158 | _EGLConfig *conf, void *native_window, |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 159 | const EGLint *attrib_list) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 160 | { |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 161 | return dri2_drm_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 162 | native_window, attrib_list); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Chad Versace | 1787f56 | 2014-02-09 09:13:08 -0800 | [diff] [blame] | 165 | static _EGLSurface * |
| 166 | dri2_drm_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 167 | _EGLConfig *conf, void *native_window, |
| 168 | const EGLint *attrib_list) |
| 169 | { |
| 170 | /* From the EGL_MESA_platform_gbm spec, version 5: |
| 171 | * |
| 172 | * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy> |
| 173 | * that belongs to the GBM platform. Any such call fails and generates |
| 174 | * EGL_BAD_PARAMETER. |
| 175 | */ |
| 176 | _eglError(EGL_BAD_PARAMETER, "cannot create EGL pixmap surfaces on GBM"); |
| 177 | return NULL; |
| 178 | } |
| 179 | |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 180 | static EGLBoolean |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 181 | dri2_drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 182 | { |
| 183 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 184 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 185 | int i; |
| 186 | |
| 187 | if (!_eglPutSurface(surf)) |
| 188 | return EGL_TRUE; |
| 189 | |
| 190 | (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); |
| 191 | |
| 192 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 193 | if (dri2_surf->color_buffers[i].bo) |
| 194 | gbm_bo_destroy(dri2_surf->color_buffers[i].bo); |
| 195 | } |
| 196 | |
| 197 | for (i = 0; i < __DRI_BUFFER_COUNT; i++) { |
| 198 | if (dri2_surf->dri_buffers[i]) |
| 199 | dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen, |
| 200 | dri2_surf->dri_buffers[i]); |
| 201 | } |
| 202 | |
| 203 | free(surf); |
| 204 | |
| 205 | return EGL_TRUE; |
| 206 | } |
| 207 | |
| 208 | static int |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 209 | get_back_bo(struct dri2_egl_surface *dri2_surf) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 210 | { |
| 211 | struct dri2_egl_display *dri2_dpy = |
| 212 | dri2_egl_display(dri2_surf->base.Resource.Display); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 213 | struct gbm_dri_surface *surf = dri2_surf->gbm_surf; |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 214 | int i; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 215 | |
| 216 | if (dri2_surf->back == NULL) { |
| 217 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 218 | if (!dri2_surf->color_buffers[i].locked) { |
| 219 | dri2_surf->back = &dri2_surf->color_buffers[i]; |
| 220 | break; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (dri2_surf->back == NULL) |
| 226 | return -1; |
| 227 | if (dri2_surf->back->bo == NULL) |
| 228 | dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base, |
| 229 | surf->base.width, surf->base.height, |
| 230 | surf->base.format, surf->base.flags); |
| 231 | if (dri2_surf->back->bo == NULL) |
| 232 | return -1; |
| 233 | |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 237 | static int |
| 238 | get_swrast_front_bo(struct dri2_egl_surface *dri2_surf) |
| 239 | { |
| 240 | struct dri2_egl_display *dri2_dpy = |
| 241 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 242 | struct gbm_dri_surface *surf = dri2_surf->gbm_surf; |
| 243 | |
| 244 | if (dri2_surf->current == NULL) { |
| 245 | assert(!dri2_surf->color_buffers[0].locked); |
| 246 | dri2_surf->current = &dri2_surf->color_buffers[0]; |
| 247 | } |
| 248 | |
| 249 | if (dri2_surf->current->bo == NULL) |
| 250 | dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base, |
| 251 | surf->base.width, surf->base.height, |
| 252 | surf->base.format, surf->base.flags); |
| 253 | if (dri2_surf->current->bo == NULL) |
| 254 | return -1; |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 259 | static void |
| 260 | back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer) |
| 261 | { |
| 262 | struct dri2_egl_display *dri2_dpy = |
| 263 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 264 | struct gbm_dri_bo *bo; |
| 265 | int name, pitch; |
| 266 | |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 267 | bo = (struct gbm_dri_bo *) dri2_surf->back->bo; |
| 268 | |
| 269 | dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name); |
| 270 | dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch); |
| 271 | |
| 272 | buffer->attachment = __DRI_BUFFER_BACK_LEFT; |
| 273 | buffer->name = name; |
| 274 | buffer->pitch = pitch; |
| 275 | buffer->cpp = 4; |
| 276 | buffer->flags = 0; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static int |
| 280 | get_aux_bo(struct dri2_egl_surface *dri2_surf, |
| 281 | unsigned int attachment, unsigned int format, __DRIbuffer *buffer) |
| 282 | { |
| 283 | struct dri2_egl_display *dri2_dpy = |
| 284 | dri2_egl_display(dri2_surf->base.Resource.Display); |
Mandeep Singh Baines | 0695cf6 | 2012-04-10 14:48:14 -0700 | [diff] [blame] | 285 | __DRIbuffer *b = dri2_surf->dri_buffers[attachment]; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 286 | |
Mandeep Singh Baines | 0695cf6 | 2012-04-10 14:48:14 -0700 | [diff] [blame] | 287 | if (b == NULL) { |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 288 | b = dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, |
| 289 | attachment, format, |
| 290 | dri2_surf->base.Width, |
| 291 | dri2_surf->base.Height); |
Mandeep Singh Baines | 0695cf6 | 2012-04-10 14:48:14 -0700 | [diff] [blame] | 292 | dri2_surf->dri_buffers[attachment] = b; |
| 293 | } |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 294 | if (b == NULL) |
| 295 | return -1; |
| 296 | |
| 297 | memcpy(buffer, b, sizeof *buffer); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static __DRIbuffer * |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 303 | dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 304 | int *width, int *height, |
| 305 | unsigned int *attachments, int count, |
| 306 | int *out_count, void *loaderPrivate) |
| 307 | { |
| 308 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 309 | int i, j; |
| 310 | |
| 311 | dri2_surf->buffer_count = 0; |
| 312 | for (i = 0, j = 0; i < 2 * count; i += 2, j++) { |
| 313 | assert(attachments[i] < __DRI_BUFFER_COUNT); |
| 314 | assert(dri2_surf->buffer_count < 5); |
| 315 | |
| 316 | switch (attachments[i]) { |
| 317 | case __DRI_BUFFER_BACK_LEFT: |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 318 | if (get_back_bo(dri2_surf) < 0) { |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 319 | _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); |
| 320 | return NULL; |
| 321 | } |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 322 | back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 323 | break; |
| 324 | default: |
| 325 | if (get_aux_bo(dri2_surf, attachments[i], attachments[i + 1], |
| 326 | &dri2_surf->buffers[j]) < 0) { |
| 327 | _eglError(EGL_BAD_ALLOC, "failed to allocate aux buffer"); |
| 328 | return NULL; |
| 329 | } |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | *out_count = j; |
| 335 | if (j == 0) |
| 336 | return NULL; |
| 337 | |
| 338 | *width = dri2_surf->base.Width; |
| 339 | *height = dri2_surf->base.Height; |
| 340 | |
| 341 | return dri2_surf->buffers; |
| 342 | } |
| 343 | |
| 344 | static __DRIbuffer * |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 345 | dri2_drm_get_buffers(__DRIdrawable * driDrawable, |
| 346 | int *width, int *height, |
| 347 | unsigned int *attachments, int count, |
| 348 | int *out_count, void *loaderPrivate) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 349 | { |
| 350 | unsigned int *attachments_with_format; |
| 351 | __DRIbuffer *buffer; |
| 352 | const unsigned int format = 32; |
| 353 | int i; |
| 354 | |
Carl Worth | ecc89e4 | 2014-09-03 14:33:18 -0700 | [diff] [blame] | 355 | attachments_with_format = calloc(count, 2 * sizeof(unsigned int)); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 356 | if (!attachments_with_format) { |
| 357 | *out_count = 0; |
| 358 | return NULL; |
| 359 | } |
| 360 | |
| 361 | for (i = 0; i < count; ++i) { |
| 362 | attachments_with_format[2*i] = attachments[i]; |
| 363 | attachments_with_format[2*i + 1] = format; |
| 364 | } |
| 365 | |
| 366 | buffer = |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 367 | dri2_drm_get_buffers_with_format(driDrawable, |
| 368 | width, height, |
| 369 | attachments_with_format, count, |
| 370 | out_count, loaderPrivate); |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 371 | |
| 372 | free(attachments_with_format); |
| 373 | |
| 374 | return buffer; |
| 375 | } |
| 376 | |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 377 | static int |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 378 | dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, |
| 379 | unsigned int format, |
| 380 | uint32_t *stamp, |
| 381 | void *loaderPrivate, |
| 382 | uint32_t buffer_mask, |
| 383 | struct __DRIimageList *buffers) |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 384 | { |
| 385 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 386 | struct gbm_dri_bo *bo; |
| 387 | |
| 388 | if (get_back_bo(dri2_surf) < 0) |
| 389 | return 0; |
| 390 | |
| 391 | bo = (struct gbm_dri_bo *) dri2_surf->back->bo; |
| 392 | buffers->image_mask = __DRI_IMAGE_BUFFER_BACK; |
| 393 | buffers->back = bo->image; |
| 394 | |
| 395 | return 1; |
| 396 | } |
| 397 | |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 398 | static void |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 399 | dri2_drm_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 400 | { |
| 401 | (void) driDrawable; |
| 402 | (void) loaderPrivate; |
| 403 | } |
| 404 | |
| 405 | static EGLBoolean |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 406 | dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 407 | { |
| 408 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 409 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
Kristian Høgsberg | 4e42e56 | 2012-12-13 23:39:45 -0500 | [diff] [blame] | 410 | int i; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 411 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 412 | if (dri2_dpy->swrast) { |
| 413 | (*dri2_dpy->core->swapBuffers)(dri2_surf->dri_drawable); |
| 414 | } else { |
| 415 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
| 416 | if (dri2_surf->current) |
| 417 | _eglError(EGL_BAD_SURFACE, "dri2_swap_buffers"); |
| 418 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) |
| 419 | if (dri2_surf->color_buffers[i].age > 0) |
| 420 | dri2_surf->color_buffers[i].age++; |
Lionel Landwerlin | d175e7c | 2014-10-14 10:39:47 +0100 | [diff] [blame] | 421 | |
| 422 | /* Make sure we have a back buffer in case we're swapping without |
| 423 | * ever rendering. */ |
| 424 | if (get_back_bo(dri2_surf) < 0) { |
| 425 | _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers"); |
| 426 | return EGL_FALSE; |
| 427 | } |
| 428 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 429 | dri2_surf->current = dri2_surf->back; |
| 430 | dri2_surf->current->age = 1; |
| 431 | dri2_surf->back = NULL; |
| 432 | } |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 433 | |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame^] | 434 | dri2_flush_drawable_for_swapbuffers(disp, draw); |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 435 | (*dri2_dpy->flush->invalidate)(dri2_surf->dri_drawable); |
| 436 | } |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 437 | |
| 438 | return EGL_TRUE; |
| 439 | } |
| 440 | |
Kristian Høgsberg | 4e42e56 | 2012-12-13 23:39:45 -0500 | [diff] [blame] | 441 | static EGLint |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 442 | dri2_drm_query_buffer_age(_EGLDriver *drv, |
| 443 | _EGLDisplay *disp, _EGLSurface *surface) |
Kristian Høgsberg | 4e42e56 | 2012-12-13 23:39:45 -0500 | [diff] [blame] | 444 | { |
| 445 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface); |
Kristian Høgsberg | 4e42e56 | 2012-12-13 23:39:45 -0500 | [diff] [blame] | 446 | |
Kristian Høgsberg | 04e3ef0 | 2013-11-08 22:06:51 -0800 | [diff] [blame] | 447 | if (get_back_bo(dri2_surf) < 0) { |
Kristian Høgsberg | 4e42e56 | 2012-12-13 23:39:45 -0500 | [diff] [blame] | 448 | _eglError(EGL_BAD_ALLOC, "dri2_query_buffer_age"); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | return dri2_surf->back->age; |
| 453 | } |
| 454 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 455 | static _EGLImage * |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 456 | dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, |
| 457 | EGLClientBuffer buffer, const EGLint *attr_list) |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 458 | { |
| 459 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 460 | struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer); |
| 461 | struct dri2_egl_image *dri2_img; |
| 462 | |
| 463 | dri2_img = malloc(sizeof *dri2_img); |
| 464 | if (!dri2_img) { |
| 465 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap"); |
| 466 | return NULL; |
| 467 | } |
| 468 | |
| 469 | if (!_eglInitImage(&dri2_img->base, disp)) { |
| 470 | free(dri2_img); |
| 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | dri2_img->dri_image = dri2_dpy->image->dupImage(dri_bo->image, dri2_img); |
| 475 | if (dri2_img->dri_image == NULL) { |
| 476 | free(dri2_img); |
| 477 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap"); |
| 478 | return NULL; |
| 479 | } |
| 480 | |
| 481 | return &dri2_img->base; |
| 482 | } |
| 483 | |
| 484 | static _EGLImage * |
| 485 | dri2_drm_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 486 | _EGLContext *ctx, EGLenum target, |
| 487 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 488 | { |
| 489 | (void) drv; |
| 490 | |
| 491 | switch (target) { |
| 492 | case EGL_NATIVE_PIXMAP_KHR: |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 493 | return dri2_drm_create_image_khr_pixmap(disp, ctx, buffer, attr_list); |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 494 | default: |
| 495 | return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list); |
| 496 | } |
| 497 | } |
| 498 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 499 | static int |
| 500 | dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id) |
| 501 | { |
| 502 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 503 | |
| 504 | return drmAuthMagic(dri2_dpy->fd, id); |
| 505 | } |
| 506 | |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 507 | static void |
| 508 | swrast_put_image2(__DRIdrawable *driDrawable, |
| 509 | int op, |
| 510 | int x, |
| 511 | int y, |
| 512 | int width, |
| 513 | int height, |
| 514 | int stride, |
| 515 | char *data, |
| 516 | void *loaderPrivate) |
| 517 | { |
| 518 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 519 | int internal_stride, i; |
| 520 | struct gbm_dri_bo *bo; |
| 521 | |
| 522 | if (op != __DRI_SWRAST_IMAGE_OP_DRAW && |
| 523 | op != __DRI_SWRAST_IMAGE_OP_SWAP) |
| 524 | return; |
| 525 | |
| 526 | if (get_swrast_front_bo(dri2_surf) < 0) |
| 527 | return; |
| 528 | |
| 529 | bo = gbm_dri_bo(dri2_surf->current->bo); |
| 530 | if (gbm_dri_bo_map(bo) == NULL) |
| 531 | return; |
| 532 | |
| 533 | internal_stride = bo->base.base.stride; |
| 534 | |
| 535 | for (i = 0; i < height; i++) { |
| 536 | memcpy(bo->map + (x + i) * internal_stride + y, |
| 537 | data + i * stride, stride); |
| 538 | } |
| 539 | |
| 540 | gbm_dri_bo_unmap(bo); |
| 541 | } |
| 542 | |
| 543 | static void |
| 544 | swrast_get_image(__DRIdrawable *driDrawable, |
| 545 | int x, |
| 546 | int y, |
| 547 | int width, |
| 548 | int height, |
| 549 | char *data, |
| 550 | void *loaderPrivate) |
| 551 | { |
| 552 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 553 | int internal_stride, stride, i; |
| 554 | struct gbm_dri_bo *bo; |
| 555 | |
| 556 | if (get_swrast_front_bo(dri2_surf) < 0) |
| 557 | return; |
| 558 | |
| 559 | bo = gbm_dri_bo(dri2_surf->current->bo); |
| 560 | if (gbm_dri_bo_map(bo) == NULL) |
| 561 | return; |
| 562 | |
| 563 | internal_stride = bo->base.base.stride; |
| 564 | stride = width * 4; |
| 565 | |
| 566 | for (i = 0; i < height; i++) { |
| 567 | memcpy(data + i * stride, |
| 568 | bo->map + (x + i) * internal_stride + y, stride); |
| 569 | } |
| 570 | |
| 571 | gbm_dri_bo_unmap(bo); |
| 572 | } |
| 573 | |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 574 | static struct dri2_egl_display_vtbl dri2_drm_display_vtbl = { |
| 575 | .authenticate = dri2_drm_authenticate, |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 576 | .create_window_surface = dri2_drm_create_window_surface, |
Chad Versace | 1787f56 | 2014-02-09 09:13:08 -0800 | [diff] [blame] | 577 | .create_pixmap_surface = dri2_drm_create_pixmap_surface, |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 578 | .create_pbuffer_surface = dri2_fallback_create_pbuffer_surface, |
Chad Versace | 958dd80 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 579 | .destroy_surface = dri2_drm_destroy_surface, |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 580 | .create_image = dri2_drm_create_image_khr, |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 581 | .swap_interval = dri2_fallback_swap_interval, |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 582 | .swap_buffers = dri2_drm_swap_buffers, |
Chad Versace | d03948a | 2014-01-28 16:26:44 -0800 | [diff] [blame] | 583 | .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 584 | .swap_buffers_region = dri2_fallback_swap_buffers_region, |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 585 | .post_sub_buffer = dri2_fallback_post_sub_buffer, |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 586 | .copy_buffers = dri2_fallback_copy_buffers, |
Chad Versace | 3fdfbd2 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 587 | .query_buffer_age = dri2_drm_query_buffer_age, |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 588 | .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image, |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 589 | .get_sync_values = dri2_fallback_get_sync_values, |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 590 | }; |
| 591 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 592 | EGLBoolean |
| 593 | dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) |
| 594 | { |
| 595 | struct dri2_egl_display *dri2_dpy; |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 596 | struct gbm_device *gbm; |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 597 | int fd = -1; |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 598 | int i; |
| 599 | |
Emil Velikov | 8d4357b | 2014-01-11 04:52:48 +0000 | [diff] [blame] | 600 | loader_set_logger(_eglLog); |
| 601 | |
Matt Turner | 6bda027 | 2012-09-04 23:09:22 -0700 | [diff] [blame] | 602 | dri2_dpy = calloc(1, sizeof *dri2_dpy); |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 603 | if (!dri2_dpy) |
| 604 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 605 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 606 | disp->DriverData = (void *) dri2_dpy; |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 607 | |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 608 | gbm = disp->PlatformDisplay; |
| 609 | if (gbm == NULL) { |
Jonathan Gray | c973e44 | 2014-04-03 16:22:26 +1100 | [diff] [blame] | 610 | char buf[64]; |
| 611 | int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0); |
| 612 | if (n != -1 && n < sizeof(buf)) |
| 613 | fd = open(buf, O_RDWR); |
| 614 | if (fd < 0) |
| 615 | fd = open("/dev/dri/card0", O_RDWR); |
Benjamin Franzke | 2a58453 | 2011-12-13 14:43:48 +0100 | [diff] [blame] | 616 | dri2_dpy->own_device = 1; |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 617 | gbm = gbm_create_device(fd); |
| 618 | if (gbm == NULL) |
| 619 | return EGL_FALSE; |
| 620 | } |
| 621 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 622 | if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) { |
| 623 | free(dri2_dpy); |
| 624 | return EGL_FALSE; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 627 | dri2_dpy->gbm_dri = gbm_dri_device(gbm); |
| 628 | if (dri2_dpy->gbm_dri->base.type != GBM_DRM_DRIVER_TYPE_DRI) { |
| 629 | free(dri2_dpy); |
| 630 | return EGL_FALSE; |
| 631 | } |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 632 | |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 633 | if (fd < 0) { |
| 634 | fd = dup(gbm_device_get_fd(gbm)); |
| 635 | if (fd < 0) { |
| 636 | free(dri2_dpy); |
| 637 | return EGL_FALSE; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | dri2_dpy->fd = fd; |
Emil Velikov | 8d4357b | 2014-01-11 04:52:48 +0000 | [diff] [blame] | 642 | dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd); |
Emil Velikov | 5cb1cad | 2014-06-02 12:26:17 +0100 | [diff] [blame] | 643 | dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->base.driver_name); |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 644 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 645 | dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen; |
| 646 | dri2_dpy->core = dri2_dpy->gbm_dri->core; |
| 647 | dri2_dpy->dri2 = dri2_dpy->gbm_dri->dri2; |
| 648 | dri2_dpy->image = dri2_dpy->gbm_dri->image; |
Ander Conselvan de Oliveira | 410aa3e | 2012-01-25 16:24:15 +0200 | [diff] [blame] | 649 | dri2_dpy->flush = dri2_dpy->gbm_dri->flush; |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 650 | dri2_dpy->swrast = dri2_dpy->gbm_dri->swrast; |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 651 | dri2_dpy->driver_configs = dri2_dpy->gbm_dri->driver_configs; |
| 652 | |
| 653 | dri2_dpy->gbm_dri->lookup_image = dri2_lookup_egl_image; |
| 654 | dri2_dpy->gbm_dri->lookup_user_data = disp; |
| 655 | |
Chad Versace | d019cd8 | 2014-01-28 12:47:38 -0800 | [diff] [blame] | 656 | dri2_dpy->gbm_dri->get_buffers = dri2_drm_get_buffers; |
| 657 | dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer; |
| 658 | dri2_dpy->gbm_dri->get_buffers_with_format = dri2_drm_get_buffers_with_format; |
| 659 | dri2_dpy->gbm_dri->image_get_buffers = dri2_drm_image_get_buffers; |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 660 | dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2; |
| 661 | dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image; |
Ander Conselvan de Oliveira | 4a976b6 | 2012-01-25 16:24:17 +0200 | [diff] [blame] | 662 | |
| 663 | dri2_dpy->gbm_dri->base.base.surface_lock_front_buffer = lock_front_buffer; |
| 664 | dri2_dpy->gbm_dri->base.base.surface_release_buffer = release_buffer; |
| 665 | dri2_dpy->gbm_dri->base.base.surface_has_free_buffers = has_free_buffers; |
| 666 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 667 | dri2_setup_screen(disp); |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 668 | |
Kristian Høgsberg | df479cf | 2013-09-25 14:57:22 -0700 | [diff] [blame] | 669 | for (i = 0; dri2_dpy->driver_configs[i]; i++) { |
| 670 | EGLint format, attr_list[3]; |
| 671 | unsigned int mask; |
| 672 | |
| 673 | dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i], |
| 674 | __DRI_ATTRIB_RED_MASK, &mask); |
| 675 | if (mask == 0x3ff00000) |
| 676 | format = GBM_FORMAT_XRGB2101010; |
| 677 | else if (mask == 0x00ff0000) |
| 678 | format = GBM_FORMAT_XRGB8888; |
| 679 | else if (mask == 0xf800) |
| 680 | format = GBM_FORMAT_RGB565; |
| 681 | else |
| 682 | continue; |
| 683 | |
| 684 | attr_list[0] = EGL_NATIVE_VISUAL_ID; |
| 685 | attr_list[1] = format; |
| 686 | attr_list[2] = EGL_NONE; |
| 687 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 688 | dri2_add_config(disp, dri2_dpy->driver_configs[i], |
Kristian Høgsberg | df479cf | 2013-09-25 14:57:22 -0700 | [diff] [blame] | 689 | i + 1, EGL_WINDOW_BIT, attr_list, NULL); |
| 690 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 691 | |
Andreas Pokorny | 53b614b | 2014-09-03 22:43:41 +0200 | [diff] [blame] | 692 | disp->Extensions.KHR_image_pixmap = EGL_TRUE; |
Giovanni Campagna | 8430af5 | 2014-06-15 13:49:49 +0200 | [diff] [blame] | 693 | if (dri2_dpy->dri2) |
| 694 | disp->Extensions.EXT_buffer_age = EGL_TRUE; |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 695 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 696 | #ifdef HAVE_WAYLAND_PLATFORM |
Giovanni Campagna | e57ad3d | 2014-07-23 19:28:52 +0100 | [diff] [blame] | 697 | if (dri2_dpy->image) { |
| 698 | if (dri2_dpy->image->base.version >= 10 && |
| 699 | dri2_dpy->image->getCapabilities != NULL) { |
| 700 | int capabilities; |
| 701 | |
| 702 | capabilities = |
| 703 | dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen); |
| 704 | disp->Extensions.WL_bind_wayland_display = |
| 705 | (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; |
| 706 | } else |
| 707 | disp->Extensions.WL_bind_wayland_display = EGL_TRUE; |
| 708 | } |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 709 | #endif |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 710 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 711 | /* we're supporting EGL 1.4 */ |
| 712 | disp->VersionMajor = 1; |
| 713 | disp->VersionMinor = 4; |
| 714 | |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 715 | /* Fill vtbl last to prevent accidentally calling virtual function during |
| 716 | * initialization. |
| 717 | */ |
| 718 | dri2_dpy->vtbl = &dri2_drm_display_vtbl; |
| 719 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 720 | return EGL_TRUE; |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 721 | } |