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 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
327 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
328 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
330 switch (attachments
[i
]) {
331 case __DRI_BUFFER_BACK_LEFT
:
332 if (get_back_bo(dri2_surf
) < 0) {
333 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
336 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
339 if (get_aux_bo(dri2_surf
, attachments
[i
], attachments
[i
+ 1],
340 &dri2_surf
->buffers
[j
]) < 0) {
341 _eglError(EGL_BAD_ALLOC
, "failed to allocate aux buffer");
352 *width
= dri2_surf
->base
.Width
;
353 *height
= dri2_surf
->base
.Height
;
355 return dri2_surf
->buffers
;
359 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
360 int *width
, int *height
,
361 unsigned int *attachments
, int count
,
362 int *out_count
, void *loaderPrivate
)
364 unsigned int *attachments_with_format
;
366 const unsigned int format
= 32;
368 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
369 if (!attachments_with_format
) {
374 for (int i
= 0; i
< count
; ++i
) {
375 attachments_with_format
[2*i
] = attachments
[i
];
376 attachments_with_format
[2*i
+ 1] = format
;
380 dri2_drm_get_buffers_with_format(driDrawable
,
382 attachments_with_format
, count
,
383 out_count
, loaderPrivate
);
385 free(attachments_with_format
);
391 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
395 uint32_t buffer_mask
,
396 struct __DRIimageList
*buffers
)
398 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
399 struct gbm_dri_bo
*bo
;
401 if (get_back_bo(dri2_surf
) < 0)
404 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
405 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
406 buffers
->back
= bo
->image
;
412 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
415 (void) loaderPrivate
;
419 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
421 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
422 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
424 if (!dri2_dpy
->flush
) {
425 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
429 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
430 if (dri2_surf
->current
)
431 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
432 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
433 if (dri2_surf
->color_buffers
[i
].age
> 0)
434 dri2_surf
->color_buffers
[i
].age
++;
436 /* Make sure we have a back buffer in case we're swapping without
438 if (get_back_bo(dri2_surf
) < 0)
439 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
441 dri2_surf
->current
= dri2_surf
->back
;
442 dri2_surf
->current
->age
= 1;
443 dri2_surf
->back
= NULL
;
446 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
447 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
453 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
454 _EGLDisplay
*disp
, _EGLSurface
*surface
)
456 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
458 if (get_back_bo(dri2_surf
) < 0) {
459 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
463 return dri2_surf
->back
->age
;
467 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
468 EGLClientBuffer buffer
, const EGLint
*attr_list
)
470 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
471 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
472 struct dri2_egl_image
*dri2_img
;
474 dri2_img
= malloc(sizeof *dri2_img
);
476 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
480 _eglInitImage(&dri2_img
->base
, disp
);
482 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
483 if (dri2_img
->dri_image
== NULL
) {
485 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
489 return &dri2_img
->base
;
493 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
494 _EGLContext
*ctx
, EGLenum target
,
495 EGLClientBuffer buffer
, const EGLint
*attr_list
)
500 case EGL_NATIVE_PIXMAP_KHR
:
501 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
503 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
508 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
510 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
512 return drmAuthMagic(dri2_dpy
->fd
, id
);
516 swrast_put_image2(__DRIdrawable
*driDrawable
,
526 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
528 struct gbm_dri_bo
*bo
;
530 int x_bytes
, width_bytes
;
533 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
534 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
537 if (get_swrast_front_bo(dri2_surf
) < 0)
540 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
542 bpp
= gbm_bo_get_bpp(&bo
->base
);
546 x_bytes
= x
* (bpp
>> 3);
547 width_bytes
= width
* (bpp
>> 3);
549 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
552 internal_stride
= bo
->base
.stride
;
554 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
557 for (int i
= 0; i
< height
; i
++) {
558 memcpy(dst
, src
, width_bytes
);
559 dst
+= internal_stride
;
563 gbm_dri_bo_unmap_dumb(bo
);
567 swrast_get_image(__DRIdrawable
*driDrawable
,
575 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
576 int internal_stride
, stride
;
577 struct gbm_dri_bo
*bo
;
579 int x_bytes
, width_bytes
;
582 if (get_swrast_front_bo(dri2_surf
) < 0)
585 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
587 bpp
= gbm_bo_get_bpp(&bo
->base
);
591 x_bytes
= x
* (bpp
>> 3);
592 width_bytes
= width
* (bpp
>> 3);
594 internal_stride
= bo
->base
.stride
;
595 stride
= width_bytes
;
597 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
601 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
603 for (int i
= 0; i
< height
; i
++) {
604 memcpy(dst
, src
, width_bytes
);
606 src
+= internal_stride
;
609 gbm_dri_bo_unmap_dumb(bo
);
613 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
615 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
616 static const struct {
618 unsigned int red_mask
;
619 unsigned int alpha_mask
;
621 { GBM_FORMAT_XRGB2101010
, 0x3ff00000, 0x00000000 },
622 { GBM_FORMAT_ARGB2101010
, 0x3ff00000, 0xc0000000 },
623 { GBM_FORMAT_XRGB8888
, 0x00ff0000, 0x00000000 },
624 { GBM_FORMAT_ARGB8888
, 0x00ff0000, 0xff000000 },
625 { GBM_FORMAT_RGB565
, 0x0000f800, 0x00000000 },
628 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
629 unsigned int config_count
= 0;
631 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
632 unsigned int red
, alpha
;
634 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
635 __DRI_ATTRIB_RED_MASK
, &red
);
636 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
637 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
639 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
640 struct dri2_egl_config
*dri2_conf
;
642 if (visuals
[j
].red_mask
!= red
|| visuals
[j
].alpha_mask
!= alpha
)
645 const EGLint attr_list
[] = {
646 EGL_NATIVE_VISUAL_ID
, visuals
[j
].format
,
650 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
651 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
653 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
660 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
661 if (!format_count
[i
]) {
662 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
667 return (config_count
!= 0);
670 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
671 .authenticate
= dri2_drm_authenticate
,
672 .create_window_surface
= dri2_drm_create_window_surface
,
673 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
674 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
675 .destroy_surface
= dri2_drm_destroy_surface
,
676 .create_image
= dri2_drm_create_image_khr
,
677 .swap_interval
= dri2_fallback_swap_interval
,
678 .swap_buffers
= dri2_drm_swap_buffers
,
679 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
680 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
681 .set_damage_region
= dri2_fallback_set_damage_region
,
682 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
683 .copy_buffers
= dri2_fallback_copy_buffers
,
684 .query_buffer_age
= dri2_drm_query_buffer_age
,
685 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
686 .get_sync_values
= dri2_fallback_get_sync_values
,
687 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
691 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
693 struct dri2_egl_display
*dri2_dpy
;
694 struct gbm_device
*gbm
;
697 loader_set_logger(_eglLog
);
699 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
701 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
704 disp
->DriverData
= (void *) dri2_dpy
;
706 gbm
= disp
->PlatformDisplay
;
709 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
710 if (n
!= -1 && n
< sizeof(buf
))
711 dri2_dpy
->fd
= loader_open_device(buf
);
712 if (dri2_dpy
->fd
< 0)
713 dri2_dpy
->fd
= loader_open_device("/dev/dri/card0");
714 gbm
= gbm_create_device(dri2_dpy
->fd
);
716 err
= "DRI2: failed to create gbm device";
719 dri2_dpy
->own_device
= true;
721 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
722 if (dri2_dpy
->fd
< 0) {
723 err
= "DRI2: failed to fcntl() existing gbm device";
728 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
729 err
= "DRI2: gbm device using incorrect/incompatible backend";
733 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
734 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
736 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
737 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
738 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
739 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
740 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
742 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
743 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
745 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
746 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
747 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
748 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
749 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
750 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
752 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
753 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
754 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
756 if (!dri2_setup_extensions(disp
)) {
757 err
= "DRI2: failed to find required DRI extensions";
761 dri2_setup_screen(disp
);
763 if (!drm_add_configs_for_visuals(drv
, disp
)) {
764 err
= "DRI2: failed to add configs";
768 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
770 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
772 #ifdef HAVE_WAYLAND_PLATFORM
773 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
775 dri2_set_WL_bind_wayland_display(drv
, disp
);
777 /* Fill vtbl last to prevent accidentally calling virtual function during
780 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
785 dri2_display_destroy(disp
);
786 return _eglError(EGL_NOT_INITIALIZED
, err
);