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
))
118 surf
= gbm_dri_surface(window
);
119 dri2_surf
->gbm_surf
= surf
;
120 dri2_surf
->base
.Width
= surf
->base
.width
;
121 dri2_surf
->base
.Height
= surf
->base
.height
;
122 surf
->dri_private
= dri2_surf
;
128 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
129 dri2_surf
->base
.GLColorspace
);
131 if (dri2_dpy
->dri2
) {
132 dri2_surf
->dri_drawable
=
133 dri2_dpy
->dri2
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
134 dri2_surf
->gbm_surf
);
137 assert(dri2_dpy
->swrast
!= NULL
);
139 dri2_surf
->dri_drawable
=
140 dri2_dpy
->swrast
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
141 dri2_surf
->gbm_surf
);
144 if (dri2_surf
->dri_drawable
== NULL
) {
145 _eglError(EGL_BAD_ALLOC
, "createNewDrawable()");
149 return &dri2_surf
->base
;
158 dri2_drm_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
159 _EGLConfig
*conf
, void *native_window
,
160 const EGLint
*attrib_list
)
162 return dri2_drm_create_surface(drv
, disp
, EGL_WINDOW_BIT
, conf
,
163 native_window
, attrib_list
);
167 dri2_drm_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
168 _EGLConfig
*conf
, void *native_window
,
169 const EGLint
*attrib_list
)
171 /* From the EGL_MESA_platform_gbm spec, version 5:
173 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
174 * that belongs to the GBM platform. Any such call fails and generates
177 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
182 dri2_drm_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
184 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
185 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
187 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
189 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
190 if (dri2_surf
->color_buffers
[i
].bo
)
191 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
194 for (unsigned i
= 0; i
< __DRI_BUFFER_COUNT
; i
++) {
195 if (dri2_surf
->dri_buffers
[i
])
196 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
197 dri2_surf
->dri_buffers
[i
]);
206 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
208 struct dri2_egl_display
*dri2_dpy
=
209 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
210 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
213 if (dri2_surf
->back
== NULL
) {
214 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
215 if (!dri2_surf
->color_buffers
[i
].locked
&&
216 dri2_surf
->color_buffers
[i
].age
>= age
) {
217 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
218 age
= dri2_surf
->color_buffers
[i
].age
;
223 if (dri2_surf
->back
== NULL
)
225 if (dri2_surf
->back
->bo
== NULL
) {
226 if (surf
->base
.modifiers
)
227 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
231 surf
->base
.modifiers
,
234 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
241 if (dri2_surf
->back
->bo
== NULL
)
248 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
250 struct dri2_egl_display
*dri2_dpy
=
251 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
252 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
254 if (dri2_surf
->current
== NULL
) {
255 assert(!dri2_surf
->color_buffers
[0].locked
);
256 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
259 if (dri2_surf
->current
->bo
== NULL
)
260 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
261 surf
->base
.width
, surf
->base
.height
,
262 surf
->base
.format
, surf
->base
.flags
);
263 if (dri2_surf
->current
->bo
== NULL
)
270 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
272 struct dri2_egl_display
*dri2_dpy
=
273 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
274 struct gbm_dri_bo
*bo
;
277 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
279 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
280 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
282 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
284 buffer
->pitch
= pitch
;
290 get_aux_bo(struct dri2_egl_surface
*dri2_surf
,
291 unsigned int attachment
, unsigned int format
, __DRIbuffer
*buffer
)
293 struct dri2_egl_display
*dri2_dpy
=
294 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
295 __DRIbuffer
*b
= dri2_surf
->dri_buffers
[attachment
];
298 b
= dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
,
300 dri2_surf
->base
.Width
,
301 dri2_surf
->base
.Height
);
302 dri2_surf
->dri_buffers
[attachment
] = b
;
307 memcpy(buffer
, b
, sizeof *buffer
);
313 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
314 int *width
, int *height
,
315 unsigned int *attachments
, int count
,
316 int *out_count
, void *loaderPrivate
)
318 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
321 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
322 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
323 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
325 switch (attachments
[i
]) {
326 case __DRI_BUFFER_BACK_LEFT
:
327 if (get_back_bo(dri2_surf
) < 0) {
328 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
331 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
334 if (get_aux_bo(dri2_surf
, attachments
[i
], attachments
[i
+ 1],
335 &dri2_surf
->buffers
[j
]) < 0) {
336 _eglError(EGL_BAD_ALLOC
, "failed to allocate aux buffer");
347 *width
= dri2_surf
->base
.Width
;
348 *height
= dri2_surf
->base
.Height
;
350 return dri2_surf
->buffers
;
354 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
355 int *width
, int *height
,
356 unsigned int *attachments
, int count
,
357 int *out_count
, void *loaderPrivate
)
359 unsigned int *attachments_with_format
;
361 const unsigned int format
= 32;
363 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
364 if (!attachments_with_format
) {
369 for (int i
= 0; i
< count
; ++i
) {
370 attachments_with_format
[2*i
] = attachments
[i
];
371 attachments_with_format
[2*i
+ 1] = format
;
375 dri2_drm_get_buffers_with_format(driDrawable
,
377 attachments_with_format
, count
,
378 out_count
, loaderPrivate
);
380 free(attachments_with_format
);
386 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
390 uint32_t buffer_mask
,
391 struct __DRIimageList
*buffers
)
393 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
394 struct gbm_dri_bo
*bo
;
396 if (get_back_bo(dri2_surf
) < 0)
399 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
400 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
401 buffers
->back
= bo
->image
;
407 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
410 (void) loaderPrivate
;
414 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
416 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
417 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
419 if (!dri2_dpy
->flush
) {
420 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
424 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
425 if (dri2_surf
->current
)
426 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
427 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
428 if (dri2_surf
->color_buffers
[i
].age
> 0)
429 dri2_surf
->color_buffers
[i
].age
++;
431 /* Make sure we have a back buffer in case we're swapping without
433 if (get_back_bo(dri2_surf
) < 0)
434 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
436 dri2_surf
->current
= dri2_surf
->back
;
437 dri2_surf
->current
->age
= 1;
438 dri2_surf
->back
= NULL
;
441 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
442 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
448 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
449 _EGLDisplay
*disp
, _EGLSurface
*surface
)
451 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
453 if (get_back_bo(dri2_surf
) < 0) {
454 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
458 return dri2_surf
->back
->age
;
462 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
463 EGLClientBuffer buffer
, const EGLint
*attr_list
)
465 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
466 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
467 struct dri2_egl_image
*dri2_img
;
469 dri2_img
= malloc(sizeof *dri2_img
);
471 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
475 _eglInitImage(&dri2_img
->base
, disp
);
477 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
478 if (dri2_img
->dri_image
== NULL
) {
480 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
484 return &dri2_img
->base
;
488 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
489 _EGLContext
*ctx
, EGLenum target
,
490 EGLClientBuffer buffer
, const EGLint
*attr_list
)
495 case EGL_NATIVE_PIXMAP_KHR
:
496 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
498 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
503 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
505 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
507 return drmAuthMagic(dri2_dpy
->fd
, id
);
511 swrast_put_image2(__DRIdrawable
*driDrawable
,
521 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
523 struct gbm_dri_bo
*bo
;
525 int x_bytes
, width_bytes
;
528 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
529 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
532 if (get_swrast_front_bo(dri2_surf
) < 0)
535 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
537 bpp
= gbm_bo_get_bpp(&bo
->base
);
541 x_bytes
= x
* (bpp
>> 3);
542 width_bytes
= width
* (bpp
>> 3);
544 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
547 internal_stride
= bo
->base
.stride
;
549 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
552 for (int i
= 0; i
< height
; i
++) {
553 memcpy(dst
, src
, width_bytes
);
554 dst
+= internal_stride
;
558 gbm_dri_bo_unmap_dumb(bo
);
562 swrast_get_image(__DRIdrawable
*driDrawable
,
570 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
571 int internal_stride
, stride
;
572 struct gbm_dri_bo
*bo
;
574 int x_bytes
, width_bytes
;
577 if (get_swrast_front_bo(dri2_surf
) < 0)
580 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
582 bpp
= gbm_bo_get_bpp(&bo
->base
);
586 x_bytes
= x
* (bpp
>> 3);
587 width_bytes
= width
* (bpp
>> 3);
589 internal_stride
= bo
->base
.stride
;
590 stride
= width_bytes
;
592 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
596 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
598 for (int i
= 0; i
< height
; i
++) {
599 memcpy(dst
, src
, width_bytes
);
601 src
+= internal_stride
;
604 gbm_dri_bo_unmap_dumb(bo
);
608 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
610 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
611 static const struct {
613 unsigned int red_mask
;
614 unsigned int alpha_mask
;
616 { GBM_FORMAT_XRGB2101010
, 0x3ff00000, 0x00000000 },
617 { GBM_FORMAT_ARGB2101010
, 0x3ff00000, 0xc0000000 },
618 { GBM_FORMAT_XRGB8888
, 0x00ff0000, 0x00000000 },
619 { GBM_FORMAT_ARGB8888
, 0x00ff0000, 0xff000000 },
620 { GBM_FORMAT_RGB565
, 0x0000f800, 0x00000000 },
623 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
624 unsigned int config_count
= 0;
626 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
627 unsigned int red
, alpha
;
629 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
630 __DRI_ATTRIB_RED_MASK
, &red
);
631 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
632 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
634 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
635 struct dri2_egl_config
*dri2_conf
;
637 if (visuals
[j
].red_mask
!= red
|| visuals
[j
].alpha_mask
!= alpha
)
640 const EGLint attr_list
[] = {
641 EGL_NATIVE_VISUAL_ID
, visuals
[j
].format
,
645 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
646 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
648 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
655 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
656 if (!format_count
[i
]) {
657 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
662 return (config_count
!= 0);
665 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
666 .authenticate
= dri2_drm_authenticate
,
667 .create_window_surface
= dri2_drm_create_window_surface
,
668 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
669 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
670 .destroy_surface
= dri2_drm_destroy_surface
,
671 .create_image
= dri2_drm_create_image_khr
,
672 .swap_interval
= dri2_fallback_swap_interval
,
673 .swap_buffers
= dri2_drm_swap_buffers
,
674 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
675 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
676 .set_damage_region
= dri2_fallback_set_damage_region
,
677 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
678 .copy_buffers
= dri2_fallback_copy_buffers
,
679 .query_buffer_age
= dri2_drm_query_buffer_age
,
680 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
681 .get_sync_values
= dri2_fallback_get_sync_values
,
682 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
686 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
688 struct dri2_egl_display
*dri2_dpy
;
689 struct gbm_device
*gbm
;
692 loader_set_logger(_eglLog
);
694 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
696 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
699 disp
->DriverData
= (void *) dri2_dpy
;
701 gbm
= disp
->PlatformDisplay
;
704 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
705 if (n
!= -1 && n
< sizeof(buf
))
706 dri2_dpy
->fd
= loader_open_device(buf
);
707 if (dri2_dpy
->fd
< 0)
708 dri2_dpy
->fd
= loader_open_device("/dev/dri/card0");
709 gbm
= gbm_create_device(dri2_dpy
->fd
);
711 err
= "DRI2: failed to create gbm device";
714 dri2_dpy
->own_device
= true;
716 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
717 if (dri2_dpy
->fd
< 0) {
718 err
= "DRI2: failed to fcntl() existing gbm device";
723 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
724 err
= "DRI2: gbm device using incorrect/incompatible backend";
728 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
729 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
731 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
732 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
733 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
734 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
735 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
737 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
738 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
740 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
741 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
742 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
743 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
744 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
745 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
747 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
748 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
749 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
751 if (!dri2_setup_extensions(disp
)) {
752 err
= "DRI2: failed to find required DRI extensions";
756 dri2_setup_screen(disp
);
758 if (!drm_add_configs_for_visuals(drv
, disp
)) {
759 err
= "DRI2: failed to add configs";
763 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
765 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
767 #ifdef HAVE_WAYLAND_PLATFORM
768 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
770 dri2_set_WL_bind_wayland_display(drv
, disp
);
772 /* Fill vtbl last to prevent accidentally calling virtual function during
775 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
780 dri2_display_destroy(disp
);
781 return _eglError(EGL_NOT_INITIALIZED
, err
);