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 (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
, false))
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 dri2_egl_surface_free_local_buffers(dri2_surf
);
181 dri2_fini_surface(surf
);
188 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
190 struct dri2_egl_display
*dri2_dpy
=
191 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
192 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
195 if (dri2_surf
->back
== NULL
) {
196 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
197 if (!dri2_surf
->color_buffers
[i
].locked
&&
198 dri2_surf
->color_buffers
[i
].age
>= age
) {
199 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
200 age
= dri2_surf
->color_buffers
[i
].age
;
205 if (dri2_surf
->back
== NULL
)
207 if (dri2_surf
->back
->bo
== NULL
) {
208 if (surf
->base
.modifiers
)
209 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
213 surf
->base
.modifiers
,
216 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
223 if (dri2_surf
->back
->bo
== NULL
)
230 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
232 struct dri2_egl_display
*dri2_dpy
=
233 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
234 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
236 if (dri2_surf
->current
== NULL
) {
237 assert(!dri2_surf
->color_buffers
[0].locked
);
238 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
241 if (dri2_surf
->current
->bo
== NULL
)
242 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
243 surf
->base
.width
, surf
->base
.height
,
244 surf
->base
.format
, surf
->base
.flags
);
245 if (dri2_surf
->current
->bo
== NULL
)
252 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
254 struct dri2_egl_display
*dri2_dpy
=
255 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
256 struct gbm_dri_bo
*bo
;
259 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
261 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
262 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
264 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
266 buffer
->pitch
= pitch
;
272 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
273 int *width
, int *height
,
274 unsigned int *attachments
, int count
,
275 int *out_count
, void *loaderPrivate
)
277 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
280 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
283 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
284 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
286 switch (attachments
[i
]) {
287 case __DRI_BUFFER_BACK_LEFT
:
288 if (get_back_bo(dri2_surf
) < 0) {
289 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
292 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
295 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
299 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
302 dri2_surf
->buffers
[j
] = *local
;
311 *width
= dri2_surf
->base
.Width
;
312 *height
= dri2_surf
->base
.Height
;
314 return dri2_surf
->buffers
;
318 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
319 int *width
, int *height
,
320 unsigned int *attachments
, int count
,
321 int *out_count
, void *loaderPrivate
)
323 unsigned int *attachments_with_format
;
325 const unsigned int format
= 32;
327 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
328 if (!attachments_with_format
) {
333 for (int i
= 0; i
< count
; ++i
) {
334 attachments_with_format
[2*i
] = attachments
[i
];
335 attachments_with_format
[2*i
+ 1] = format
;
339 dri2_drm_get_buffers_with_format(driDrawable
,
341 attachments_with_format
, count
,
342 out_count
, loaderPrivate
);
344 free(attachments_with_format
);
350 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
354 uint32_t buffer_mask
,
355 struct __DRIimageList
*buffers
)
357 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
358 struct gbm_dri_bo
*bo
;
360 if (get_back_bo(dri2_surf
) < 0)
363 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
364 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
365 buffers
->back
= bo
->image
;
371 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
374 (void) loaderPrivate
;
378 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
380 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
381 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
383 if (!dri2_dpy
->flush
) {
384 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
388 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
389 if (dri2_surf
->current
)
390 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
391 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
392 if (dri2_surf
->color_buffers
[i
].age
> 0)
393 dri2_surf
->color_buffers
[i
].age
++;
395 /* Make sure we have a back buffer in case we're swapping without
397 if (get_back_bo(dri2_surf
) < 0)
398 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
400 dri2_surf
->current
= dri2_surf
->back
;
401 dri2_surf
->current
->age
= 1;
402 dri2_surf
->back
= NULL
;
405 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
406 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
412 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
413 _EGLDisplay
*disp
, _EGLSurface
*surface
)
415 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
417 if (get_back_bo(dri2_surf
) < 0) {
418 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
422 return dri2_surf
->back
->age
;
426 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
427 EGLClientBuffer buffer
, const EGLint
*attr_list
)
429 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
430 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
431 struct dri2_egl_image
*dri2_img
;
433 dri2_img
= malloc(sizeof *dri2_img
);
435 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
439 _eglInitImage(&dri2_img
->base
, disp
);
441 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
442 if (dri2_img
->dri_image
== NULL
) {
444 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
448 return &dri2_img
->base
;
452 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
453 _EGLContext
*ctx
, EGLenum target
,
454 EGLClientBuffer buffer
, const EGLint
*attr_list
)
459 case EGL_NATIVE_PIXMAP_KHR
:
460 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
462 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
467 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
469 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
471 return drmAuthMagic(dri2_dpy
->fd
, id
);
475 swrast_put_image2(__DRIdrawable
*driDrawable
,
485 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
487 struct gbm_dri_bo
*bo
;
489 int x_bytes
, width_bytes
;
492 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
493 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
496 if (get_swrast_front_bo(dri2_surf
) < 0)
499 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
501 bpp
= gbm_bo_get_bpp(&bo
->base
);
505 x_bytes
= x
* (bpp
>> 3);
506 width_bytes
= width
* (bpp
>> 3);
508 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
511 internal_stride
= bo
->base
.stride
;
513 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
516 for (int i
= 0; i
< height
; i
++) {
517 memcpy(dst
, src
, width_bytes
);
518 dst
+= internal_stride
;
522 gbm_dri_bo_unmap_dumb(bo
);
526 swrast_get_image(__DRIdrawable
*driDrawable
,
534 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
535 int internal_stride
, stride
;
536 struct gbm_dri_bo
*bo
;
538 int x_bytes
, width_bytes
;
541 if (get_swrast_front_bo(dri2_surf
) < 0)
544 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
546 bpp
= gbm_bo_get_bpp(&bo
->base
);
550 x_bytes
= x
* (bpp
>> 3);
551 width_bytes
= width
* (bpp
>> 3);
553 internal_stride
= bo
->base
.stride
;
554 stride
= width_bytes
;
556 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
560 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
562 for (int i
= 0; i
< height
; i
++) {
563 memcpy(dst
, src
, width_bytes
);
565 src
+= internal_stride
;
568 gbm_dri_bo_unmap_dumb(bo
);
572 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
574 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
575 const struct gbm_dri_visual
*visuals
= dri2_dpy
->gbm_dri
->visual_table
;
576 int num_visuals
= dri2_dpy
->gbm_dri
->num_visuals
;
577 unsigned int format_count
[num_visuals
];
578 unsigned int config_count
= 0;
580 memset(format_count
, 0, num_visuals
* sizeof(unsigned int));
582 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
583 unsigned int red
, green
, blue
, alpha
;
585 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
586 __DRI_ATTRIB_RED_MASK
, &red
);
587 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
588 __DRI_ATTRIB_GREEN_MASK
, &green
);
589 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
590 __DRI_ATTRIB_BLUE_MASK
, &blue
);
591 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
592 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
594 for (unsigned j
= 0; j
< num_visuals
; j
++) {
595 struct dri2_egl_config
*dri2_conf
;
597 if (visuals
[j
].rgba_masks
[0] != red
||
598 visuals
[j
].rgba_masks
[1] != green
||
599 visuals
[j
].rgba_masks
[2] != blue
||
600 visuals
[j
].rgba_masks
[3] != alpha
)
603 const EGLint attr_list
[] = {
604 EGL_NATIVE_VISUAL_ID
, visuals
[j
].gbm_format
,
608 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
609 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
611 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
618 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
619 if (!format_count
[i
]) {
620 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
621 visuals
[i
].gbm_format
);
625 return (config_count
!= 0);
628 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
629 .authenticate
= dri2_drm_authenticate
,
630 .create_window_surface
= dri2_drm_create_window_surface
,
631 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
632 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
633 .destroy_surface
= dri2_drm_destroy_surface
,
634 .create_image
= dri2_drm_create_image_khr
,
635 .swap_buffers
= dri2_drm_swap_buffers
,
636 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
637 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
638 .set_damage_region
= dri2_fallback_set_damage_region
,
639 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
640 .copy_buffers
= dri2_fallback_copy_buffers
,
641 .query_buffer_age
= dri2_drm_query_buffer_age
,
642 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
643 .get_sync_values
= dri2_fallback_get_sync_values
,
644 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
648 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
650 struct dri2_egl_display
*dri2_dpy
;
651 struct gbm_device
*gbm
;
654 /* Not supported yet */
655 if (disp
->Options
.ForceSoftware
)
658 loader_set_logger(_eglLog
);
660 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
662 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
665 disp
->DriverData
= (void *) dri2_dpy
;
667 gbm
= disp
->PlatformDisplay
;
670 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
671 if (n
!= -1 && n
< sizeof(buf
))
672 dri2_dpy
->fd
= loader_open_device(buf
);
673 gbm
= gbm_create_device(dri2_dpy
->fd
);
675 err
= "DRI2: failed to create gbm device";
678 dri2_dpy
->own_device
= true;
680 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
681 if (dri2_dpy
->fd
< 0) {
682 err
= "DRI2: failed to fcntl() existing gbm device";
687 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
688 err
= "DRI2: gbm device using incorrect/incompatible backend";
692 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
693 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
695 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
696 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
697 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
698 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
699 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
701 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
702 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
704 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
705 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
706 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
707 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
708 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
709 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
711 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
712 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
713 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
715 if (!dri2_setup_extensions(disp
)) {
716 err
= "DRI2: failed to find required DRI extensions";
720 dri2_setup_screen(disp
);
722 if (!drm_add_configs_for_visuals(drv
, disp
)) {
723 err
= "DRI2: failed to add configs";
727 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
729 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
731 #ifdef HAVE_WAYLAND_PLATFORM
732 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
734 dri2_set_WL_bind_wayland_display(drv
, disp
);
736 /* Fill vtbl last to prevent accidentally calling virtual function during
739 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
744 dri2_display_destroy(disp
);
745 return _eglError(EGL_NOT_INITIALIZED
, err
);
749 dri2_teardown_drm(struct dri2_egl_display
*dri2_dpy
)
751 if (dri2_dpy
->own_device
)
752 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);