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_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint type
,
95 _EGLConfig
*conf
, void *native_window
,
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
*window
= native_window
;
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
, type
, conf
, attrib_list
))
119 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_create_surface");
123 surf
= gbm_dri_surface(window
);
124 dri2_surf
->gbm_surf
= surf
;
125 dri2_surf
->base
.Width
= surf
->base
.width
;
126 dri2_surf
->base
.Height
= surf
->base
.height
;
127 surf
->dri_private
= dri2_surf
;
133 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
134 dri2_surf
->base
.GLColorspace
);
136 if (dri2_dpy
->dri2
) {
137 dri2_surf
->dri_drawable
=
138 dri2_dpy
->dri2
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
139 dri2_surf
->gbm_surf
);
142 assert(dri2_dpy
->swrast
!= NULL
);
144 dri2_surf
->dri_drawable
=
145 dri2_dpy
->swrast
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
146 dri2_surf
->gbm_surf
);
149 if (dri2_surf
->dri_drawable
== NULL
) {
150 _eglError(EGL_BAD_ALLOC
, "createNewDrawable()");
154 return &dri2_surf
->base
;
163 dri2_drm_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
164 _EGLConfig
*conf
, void *native_window
,
165 const EGLint
*attrib_list
)
167 return dri2_drm_create_surface(drv
, disp
, EGL_WINDOW_BIT
, conf
,
168 native_window
, attrib_list
);
172 dri2_drm_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
173 _EGLConfig
*conf
, void *native_window
,
174 const EGLint
*attrib_list
)
176 /* From the EGL_MESA_platform_gbm spec, version 5:
178 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
179 * that belongs to the GBM platform. Any such call fails and generates
182 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
187 dri2_drm_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
189 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
190 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
192 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
194 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
195 if (dri2_surf
->color_buffers
[i
].bo
)
196 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
199 for (unsigned i
= 0; i
< __DRI_BUFFER_COUNT
; i
++) {
200 if (dri2_surf
->dri_buffers
[i
])
201 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
202 dri2_surf
->dri_buffers
[i
]);
211 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
213 struct dri2_egl_display
*dri2_dpy
=
214 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
215 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
218 if (dri2_surf
->back
== NULL
) {
219 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
220 if (!dri2_surf
->color_buffers
[i
].locked
&&
221 dri2_surf
->color_buffers
[i
].age
>= age
) {
222 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
223 age
= dri2_surf
->color_buffers
[i
].age
;
228 if (dri2_surf
->back
== NULL
)
230 if (dri2_surf
->back
->bo
== NULL
) {
231 if (surf
->base
.modifiers
)
232 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
236 surf
->base
.modifiers
,
239 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
246 if (dri2_surf
->back
->bo
== NULL
)
253 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
255 struct dri2_egl_display
*dri2_dpy
=
256 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
257 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
259 if (dri2_surf
->current
== NULL
) {
260 assert(!dri2_surf
->color_buffers
[0].locked
);
261 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
264 if (dri2_surf
->current
->bo
== NULL
)
265 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
266 surf
->base
.width
, surf
->base
.height
,
267 surf
->base
.format
, surf
->base
.flags
);
268 if (dri2_surf
->current
->bo
== NULL
)
275 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
277 struct dri2_egl_display
*dri2_dpy
=
278 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
279 struct gbm_dri_bo
*bo
;
282 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
284 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
285 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
287 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
289 buffer
->pitch
= pitch
;
295 get_aux_bo(struct dri2_egl_surface
*dri2_surf
,
296 unsigned int attachment
, unsigned int format
, __DRIbuffer
*buffer
)
298 struct dri2_egl_display
*dri2_dpy
=
299 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
300 __DRIbuffer
*b
= dri2_surf
->dri_buffers
[attachment
];
303 b
= dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
,
305 dri2_surf
->base
.Width
,
306 dri2_surf
->base
.Height
);
307 dri2_surf
->dri_buffers
[attachment
] = b
;
312 memcpy(buffer
, b
, sizeof *buffer
);
318 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
319 int *width
, int *height
,
320 unsigned int *attachments
, int count
,
321 int *out_count
, void *loaderPrivate
)
323 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
326 dri2_surf
->buffer_count
= 0;
327 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
328 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
329 assert(dri2_surf
->buffer_count
< 5);
331 switch (attachments
[i
]) {
332 case __DRI_BUFFER_BACK_LEFT
:
333 if (get_back_bo(dri2_surf
) < 0) {
334 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
337 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
340 if (get_aux_bo(dri2_surf
, attachments
[i
], attachments
[i
+ 1],
341 &dri2_surf
->buffers
[j
]) < 0) {
342 _eglError(EGL_BAD_ALLOC
, "failed to allocate aux buffer");
353 *width
= dri2_surf
->base
.Width
;
354 *height
= dri2_surf
->base
.Height
;
356 return dri2_surf
->buffers
;
360 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
361 int *width
, int *height
,
362 unsigned int *attachments
, int count
,
363 int *out_count
, void *loaderPrivate
)
365 unsigned int *attachments_with_format
;
367 const unsigned int format
= 32;
369 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
370 if (!attachments_with_format
) {
375 for (int i
= 0; i
< count
; ++i
) {
376 attachments_with_format
[2*i
] = attachments
[i
];
377 attachments_with_format
[2*i
+ 1] = format
;
381 dri2_drm_get_buffers_with_format(driDrawable
,
383 attachments_with_format
, count
,
384 out_count
, loaderPrivate
);
386 free(attachments_with_format
);
392 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
396 uint32_t buffer_mask
,
397 struct __DRIimageList
*buffers
)
399 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
400 struct gbm_dri_bo
*bo
;
402 if (get_back_bo(dri2_surf
) < 0)
405 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
406 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
407 buffers
->back
= bo
->image
;
413 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
416 (void) loaderPrivate
;
420 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
422 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
423 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
425 if (!dri2_dpy
->flush
) {
426 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
430 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
431 if (dri2_surf
->current
)
432 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
433 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
434 if (dri2_surf
->color_buffers
[i
].age
> 0)
435 dri2_surf
->color_buffers
[i
].age
++;
437 /* Make sure we have a back buffer in case we're swapping without
439 if (get_back_bo(dri2_surf
) < 0)
440 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
442 dri2_surf
->current
= dri2_surf
->back
;
443 dri2_surf
->current
->age
= 1;
444 dri2_surf
->back
= NULL
;
447 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
448 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
454 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
455 _EGLDisplay
*disp
, _EGLSurface
*surface
)
457 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
459 if (get_back_bo(dri2_surf
) < 0) {
460 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
464 return dri2_surf
->back
->age
;
468 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
469 EGLClientBuffer buffer
, const EGLint
*attr_list
)
471 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
472 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
473 struct dri2_egl_image
*dri2_img
;
475 dri2_img
= malloc(sizeof *dri2_img
);
477 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
481 _eglInitImage(&dri2_img
->base
, disp
);
483 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
484 if (dri2_img
->dri_image
== NULL
) {
486 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
490 return &dri2_img
->base
;
494 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
495 _EGLContext
*ctx
, EGLenum target
,
496 EGLClientBuffer buffer
, const EGLint
*attr_list
)
501 case EGL_NATIVE_PIXMAP_KHR
:
502 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
504 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
509 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
511 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
513 return drmAuthMagic(dri2_dpy
->fd
, id
);
517 swrast_put_image2(__DRIdrawable
*driDrawable
,
527 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
529 struct gbm_dri_bo
*bo
;
531 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
532 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
535 if (get_swrast_front_bo(dri2_surf
) < 0)
538 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
539 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
542 internal_stride
= bo
->base
.stride
;
544 for (int i
= 0; i
< height
; i
++) {
545 memcpy(bo
->map
+ (x
+ i
) * internal_stride
+ y
,
546 data
+ i
* stride
, stride
);
549 gbm_dri_bo_unmap_dumb(bo
);
553 swrast_get_image(__DRIdrawable
*driDrawable
,
561 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
562 int internal_stride
, stride
;
563 struct gbm_dri_bo
*bo
;
565 if (get_swrast_front_bo(dri2_surf
) < 0)
568 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
569 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
572 internal_stride
= bo
->base
.stride
;
575 for (int i
= 0; i
< height
; i
++) {
576 memcpy(data
+ i
* stride
,
577 bo
->map
+ (x
+ i
) * internal_stride
+ y
, stride
);
580 gbm_dri_bo_unmap_dumb(bo
);
584 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
586 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
587 static const struct {
589 unsigned int red_mask
;
590 unsigned int alpha_mask
;
592 { GBM_FORMAT_XRGB2101010
, 0x3ff00000, 0x00000000 },
593 { GBM_FORMAT_ARGB2101010
, 0x3ff00000, 0xc0000000 },
594 { GBM_FORMAT_XRGB8888
, 0x00ff0000, 0x00000000 },
595 { GBM_FORMAT_ARGB8888
, 0x00ff0000, 0xff000000 },
596 { GBM_FORMAT_RGB565
, 0x0000f800, 0x00000000 },
599 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
600 unsigned int config_count
= 0;
602 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
603 unsigned int red
, alpha
;
605 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
606 __DRI_ATTRIB_RED_MASK
, &red
);
607 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
608 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
610 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
611 struct dri2_egl_config
*dri2_conf
;
613 if (visuals
[j
].red_mask
!= red
|| visuals
[j
].alpha_mask
!= alpha
)
616 const EGLint attr_list
[] = {
617 EGL_NATIVE_VISUAL_ID
, visuals
[j
].format
,
621 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
622 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
624 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
631 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
632 if (!format_count
[i
]) {
633 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
638 return (config_count
!= 0);
641 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
642 .authenticate
= dri2_drm_authenticate
,
643 .create_window_surface
= dri2_drm_create_window_surface
,
644 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
645 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
646 .destroy_surface
= dri2_drm_destroy_surface
,
647 .create_image
= dri2_drm_create_image_khr
,
648 .swap_interval
= dri2_fallback_swap_interval
,
649 .swap_buffers
= dri2_drm_swap_buffers
,
650 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
651 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
652 .set_damage_region
= dri2_fallback_set_damage_region
,
653 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
654 .copy_buffers
= dri2_fallback_copy_buffers
,
655 .query_buffer_age
= dri2_drm_query_buffer_age
,
656 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
657 .get_sync_values
= dri2_fallback_get_sync_values
,
658 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
662 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
664 struct dri2_egl_display
*dri2_dpy
;
665 struct gbm_device
*gbm
;
668 loader_set_logger(_eglLog
);
670 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
672 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
675 disp
->DriverData
= (void *) dri2_dpy
;
677 gbm
= disp
->PlatformDisplay
;
680 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
681 if (n
!= -1 && n
< sizeof(buf
))
682 dri2_dpy
->fd
= loader_open_device(buf
);
683 if (dri2_dpy
->fd
< 0)
684 dri2_dpy
->fd
= loader_open_device("/dev/dri/card0");
685 gbm
= gbm_create_device(dri2_dpy
->fd
);
687 err
= "DRI2: failed to create gbm device";
690 dri2_dpy
->own_device
= true;
692 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
693 if (dri2_dpy
->fd
< 0) {
694 err
= "DRI2: failed to fcntl() existing gbm device";
699 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
700 err
= "DRI2: gbm device using incorrect/incompatible backend";
704 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
705 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
707 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
708 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
709 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
710 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
711 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
713 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
714 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
716 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
717 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
718 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
719 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
720 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
721 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
723 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
724 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
725 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
727 if (!dri2_setup_extensions(disp
)) {
728 err
= "DRI2: failed to find required DRI extensions";
732 dri2_setup_screen(disp
);
734 if (!drm_add_configs_for_visuals(drv
, disp
)) {
735 err
= "DRI2: failed to add configs";
739 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
741 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
743 #ifdef HAVE_WAYLAND_PLATFORM
744 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
746 dri2_set_WL_bind_wayland_display(drv
, disp
);
748 /* Fill vtbl last to prevent accidentally calling virtual function during
751 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
756 dri2_display_destroy(disp
);
757 return _eglError(EGL_NOT_INITIALIZED
, err
);