2 * Copyright © 2011 Intel Corporation
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:
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
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.
25 * Kristian Høgsberg <krh@bitplanet.net>
34 #include <sys/types.h>
40 #include "egl_dri2_fallbacks.h"
43 static struct gbm_bo
*
44 lock_front_buffer(struct gbm_surface
*_surf
)
46 struct gbm_dri_surface
*surf
= (struct gbm_dri_surface
*) _surf
;
47 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
48 struct gbm_dri_device
*device
= (struct gbm_dri_device
*) _surf
->gbm
;
51 if (dri2_surf
->current
== NULL
) {
52 _eglError(EGL_BAD_SURFACE
, "no front buffer");
56 bo
= dri2_surf
->current
->bo
;
59 dri2_surf
->current
->locked
= true;
60 dri2_surf
->current
= NULL
;
67 release_buffer(struct gbm_surface
*_surf
, struct gbm_bo
*bo
)
69 struct gbm_dri_surface
*surf
= (struct gbm_dri_surface
*) _surf
;
70 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
72 for (unsigned 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
= false;
81 has_free_buffers(struct gbm_surface
*_surf
)
83 struct gbm_dri_surface
*surf
= (struct gbm_dri_surface
*) _surf
;
84 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
86 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
87 if (!dri2_surf
->color_buffers
[i
].locked
)
94 dri2_drm_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
95 _EGLConfig
*conf
, void *native_surface
,
96 const EGLint
*attrib_list
)
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
;
101 struct gbm_surface
*surface
= native_surface
;
102 struct gbm_dri_surface
*surf
;
103 const __DRIconfig
*config
;
107 dri2_surf
= calloc(1, sizeof *dri2_surf
);
109 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
113 if (!_eglInitSurface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
))
116 surf
= gbm_dri_surface(surface
);
117 dri2_surf
->gbm_surf
= surf
;
118 dri2_surf
->base
.Width
= surf
->base
.width
;
119 dri2_surf
->base
.Height
= surf
->base
.height
;
120 surf
->dri_private
= dri2_surf
;
122 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
123 dri2_surf
->base
.GLColorspace
);
125 if (dri2_dpy
->dri2
) {
126 dri2_surf
->dri_drawable
=
127 dri2_dpy
->dri2
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
128 dri2_surf
->gbm_surf
);
131 assert(dri2_dpy
->swrast
!= NULL
);
133 dri2_surf
->dri_drawable
=
134 dri2_dpy
->swrast
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
135 dri2_surf
->gbm_surf
);
138 if (dri2_surf
->dri_drawable
== NULL
) {
139 _eglError(EGL_BAD_ALLOC
, "createNewDrawable()");
143 return &dri2_surf
->base
;
152 dri2_drm_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
153 _EGLConfig
*conf
, void *native_window
,
154 const EGLint
*attrib_list
)
156 /* From the EGL_MESA_platform_gbm spec, version 5:
158 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
159 * that belongs to the GBM platform. Any such call fails and generates
162 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
167 dri2_drm_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
169 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
170 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
172 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
174 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
175 if (dri2_surf
->color_buffers
[i
].bo
)
176 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
179 for (unsigned i
= 0; i
< __DRI_BUFFER_COUNT
; i
++) {
180 if (dri2_surf
->dri_buffers
[i
])
181 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
182 dri2_surf
->dri_buffers
[i
]);
191 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
193 struct dri2_egl_display
*dri2_dpy
=
194 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
195 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
198 if (dri2_surf
->back
== NULL
) {
199 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
200 if (!dri2_surf
->color_buffers
[i
].locked
&&
201 dri2_surf
->color_buffers
[i
].age
>= age
) {
202 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
203 age
= dri2_surf
->color_buffers
[i
].age
;
208 if (dri2_surf
->back
== NULL
)
210 if (dri2_surf
->back
->bo
== NULL
) {
211 if (surf
->base
.modifiers
)
212 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
216 surf
->base
.modifiers
,
219 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
226 if (dri2_surf
->back
->bo
== NULL
)
233 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
235 struct dri2_egl_display
*dri2_dpy
=
236 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
237 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
239 if (dri2_surf
->current
== NULL
) {
240 assert(!dri2_surf
->color_buffers
[0].locked
);
241 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
244 if (dri2_surf
->current
->bo
== NULL
)
245 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
246 surf
->base
.width
, surf
->base
.height
,
247 surf
->base
.format
, surf
->base
.flags
);
248 if (dri2_surf
->current
->bo
== NULL
)
255 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
257 struct dri2_egl_display
*dri2_dpy
=
258 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
259 struct gbm_dri_bo
*bo
;
262 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
264 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
265 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
267 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
269 buffer
->pitch
= pitch
;
275 get_aux_bo(struct dri2_egl_surface
*dri2_surf
,
276 unsigned int attachment
, unsigned int format
, __DRIbuffer
*buffer
)
278 struct dri2_egl_display
*dri2_dpy
=
279 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
280 __DRIbuffer
*b
= dri2_surf
->dri_buffers
[attachment
];
283 b
= dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
,
285 dri2_surf
->base
.Width
,
286 dri2_surf
->base
.Height
);
287 dri2_surf
->dri_buffers
[attachment
] = b
;
292 memcpy(buffer
, b
, sizeof *buffer
);
298 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
299 int *width
, int *height
,
300 unsigned int *attachments
, int count
,
301 int *out_count
, void *loaderPrivate
)
303 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
306 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
307 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
308 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
310 switch (attachments
[i
]) {
311 case __DRI_BUFFER_BACK_LEFT
:
312 if (get_back_bo(dri2_surf
) < 0) {
313 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
316 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
319 if (get_aux_bo(dri2_surf
, attachments
[i
], attachments
[i
+ 1],
320 &dri2_surf
->buffers
[j
]) < 0) {
321 _eglError(EGL_BAD_ALLOC
, "failed to allocate aux buffer");
332 *width
= dri2_surf
->base
.Width
;
333 *height
= dri2_surf
->base
.Height
;
335 return dri2_surf
->buffers
;
339 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
340 int *width
, int *height
,
341 unsigned int *attachments
, int count
,
342 int *out_count
, void *loaderPrivate
)
344 unsigned int *attachments_with_format
;
346 const unsigned int format
= 32;
348 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
349 if (!attachments_with_format
) {
354 for (int i
= 0; i
< count
; ++i
) {
355 attachments_with_format
[2*i
] = attachments
[i
];
356 attachments_with_format
[2*i
+ 1] = format
;
360 dri2_drm_get_buffers_with_format(driDrawable
,
362 attachments_with_format
, count
,
363 out_count
, loaderPrivate
);
365 free(attachments_with_format
);
371 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
375 uint32_t buffer_mask
,
376 struct __DRIimageList
*buffers
)
378 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
379 struct gbm_dri_bo
*bo
;
381 if (get_back_bo(dri2_surf
) < 0)
384 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
385 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
386 buffers
->back
= bo
->image
;
392 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
395 (void) loaderPrivate
;
399 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
401 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
402 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
404 if (!dri2_dpy
->flush
) {
405 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
409 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
410 if (dri2_surf
->current
)
411 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
412 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
413 if (dri2_surf
->color_buffers
[i
].age
> 0)
414 dri2_surf
->color_buffers
[i
].age
++;
416 /* Make sure we have a back buffer in case we're swapping without
418 if (get_back_bo(dri2_surf
) < 0)
419 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
421 dri2_surf
->current
= dri2_surf
->back
;
422 dri2_surf
->current
->age
= 1;
423 dri2_surf
->back
= NULL
;
426 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
427 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
433 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
434 _EGLDisplay
*disp
, _EGLSurface
*surface
)
436 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
438 if (get_back_bo(dri2_surf
) < 0) {
439 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
443 return dri2_surf
->back
->age
;
447 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
448 EGLClientBuffer buffer
, const EGLint
*attr_list
)
450 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
451 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
452 struct dri2_egl_image
*dri2_img
;
454 dri2_img
= malloc(sizeof *dri2_img
);
456 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
460 _eglInitImage(&dri2_img
->base
, disp
);
462 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
463 if (dri2_img
->dri_image
== NULL
) {
465 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
469 return &dri2_img
->base
;
473 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
474 _EGLContext
*ctx
, EGLenum target
,
475 EGLClientBuffer buffer
, const EGLint
*attr_list
)
480 case EGL_NATIVE_PIXMAP_KHR
:
481 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
483 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
488 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
490 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
492 return drmAuthMagic(dri2_dpy
->fd
, id
);
496 swrast_put_image2(__DRIdrawable
*driDrawable
,
506 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
508 struct gbm_dri_bo
*bo
;
510 int x_bytes
, width_bytes
;
513 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
514 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
517 if (get_swrast_front_bo(dri2_surf
) < 0)
520 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
522 bpp
= gbm_bo_get_bpp(&bo
->base
);
526 x_bytes
= x
* (bpp
>> 3);
527 width_bytes
= width
* (bpp
>> 3);
529 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
532 internal_stride
= bo
->base
.stride
;
534 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
537 for (int i
= 0; i
< height
; i
++) {
538 memcpy(dst
, src
, width_bytes
);
539 dst
+= internal_stride
;
543 gbm_dri_bo_unmap_dumb(bo
);
547 swrast_get_image(__DRIdrawable
*driDrawable
,
555 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
556 int internal_stride
, stride
;
557 struct gbm_dri_bo
*bo
;
559 int x_bytes
, width_bytes
;
562 if (get_swrast_front_bo(dri2_surf
) < 0)
565 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
567 bpp
= gbm_bo_get_bpp(&bo
->base
);
571 x_bytes
= x
* (bpp
>> 3);
572 width_bytes
= width
* (bpp
>> 3);
574 internal_stride
= bo
->base
.stride
;
575 stride
= width_bytes
;
577 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
581 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
583 for (int i
= 0; i
< height
; i
++) {
584 memcpy(dst
, src
, width_bytes
);
586 src
+= internal_stride
;
589 gbm_dri_bo_unmap_dumb(bo
);
593 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
595 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
596 static const struct {
598 unsigned int red_mask
;
599 unsigned int alpha_mask
;
601 { GBM_FORMAT_XRGB2101010
, 0x3ff00000, 0x00000000 },
602 { GBM_FORMAT_ARGB2101010
, 0x3ff00000, 0xc0000000 },
603 { GBM_FORMAT_XRGB8888
, 0x00ff0000, 0x00000000 },
604 { GBM_FORMAT_ARGB8888
, 0x00ff0000, 0xff000000 },
605 { GBM_FORMAT_RGB565
, 0x0000f800, 0x00000000 },
608 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
609 unsigned int config_count
= 0;
611 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
612 unsigned int red
, alpha
;
614 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
615 __DRI_ATTRIB_RED_MASK
, &red
);
616 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
617 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
619 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
620 struct dri2_egl_config
*dri2_conf
;
622 if (visuals
[j
].red_mask
!= red
|| visuals
[j
].alpha_mask
!= alpha
)
625 const EGLint attr_list
[] = {
626 EGL_NATIVE_VISUAL_ID
, visuals
[j
].format
,
630 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
631 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
633 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
640 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
641 if (!format_count
[i
]) {
642 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
647 return (config_count
!= 0);
650 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
651 .authenticate
= dri2_drm_authenticate
,
652 .create_window_surface
= dri2_drm_create_window_surface
,
653 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
654 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
655 .destroy_surface
= dri2_drm_destroy_surface
,
656 .create_image
= dri2_drm_create_image_khr
,
657 .swap_interval
= dri2_fallback_swap_interval
,
658 .swap_buffers
= dri2_drm_swap_buffers
,
659 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
660 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
661 .set_damage_region
= dri2_fallback_set_damage_region
,
662 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
663 .copy_buffers
= dri2_fallback_copy_buffers
,
664 .query_buffer_age
= dri2_drm_query_buffer_age
,
665 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
666 .get_sync_values
= dri2_fallback_get_sync_values
,
667 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
671 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
673 struct dri2_egl_display
*dri2_dpy
;
674 struct gbm_device
*gbm
;
677 loader_set_logger(_eglLog
);
679 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
681 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
684 disp
->DriverData
= (void *) dri2_dpy
;
686 gbm
= disp
->PlatformDisplay
;
689 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
690 if (n
!= -1 && n
< sizeof(buf
))
691 dri2_dpy
->fd
= loader_open_device(buf
);
692 if (dri2_dpy
->fd
< 0)
693 dri2_dpy
->fd
= loader_open_device("/dev/dri/card0");
694 gbm
= gbm_create_device(dri2_dpy
->fd
);
696 err
= "DRI2: failed to create gbm device";
699 dri2_dpy
->own_device
= true;
701 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
702 if (dri2_dpy
->fd
< 0) {
703 err
= "DRI2: failed to fcntl() existing gbm device";
708 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
709 err
= "DRI2: gbm device using incorrect/incompatible backend";
713 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
714 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
716 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
717 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
718 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
719 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
720 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
722 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
723 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
725 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
726 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
727 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
728 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
729 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
730 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
732 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
733 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
734 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
736 if (!dri2_setup_extensions(disp
)) {
737 err
= "DRI2: failed to find required DRI extensions";
741 dri2_setup_screen(disp
);
743 if (!drm_add_configs_for_visuals(drv
, disp
)) {
744 err
= "DRI2: failed to add configs";
748 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
750 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
752 #ifdef HAVE_WAYLAND_PLATFORM
753 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
755 dri2_set_WL_bind_wayland_display(drv
, disp
);
757 /* Fill vtbl last to prevent accidentally calling virtual function during
760 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
765 dri2_display_destroy(disp
);
766 return _eglError(EGL_NOT_INITIALIZED
, err
);