Path: blob/21.2-virgl/src/egl/drivers/dri2/platform_drm.c
4570 views
/*1* Copyright © 2011 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT18* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,19* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Authors:24* Kristian Høgsberg <[email protected]>25*/2627#include <stdint.h>28#include <stdlib.h>29#include <stdio.h>30#include <string.h>31#include <xf86drm.h>32#include <dlfcn.h>33#include <sys/types.h>34#include <sys/stat.h>35#include <fcntl.h>36#include <unistd.h>3738#include "util/os_file.h"3940#include "egl_dri2.h"41#include "loader.h"4243static struct gbm_bo *44lock_front_buffer(struct gbm_surface *_surf)45{46struct gbm_dri_surface *surf = gbm_dri_surface(_surf);47struct dri2_egl_surface *dri2_surf = surf->dri_private;48struct gbm_dri_device *device = gbm_dri_device(_surf->gbm);49struct gbm_bo *bo;5051if (dri2_surf->current == NULL) {52_eglError(EGL_BAD_SURFACE, "no front buffer");53return NULL;54}5556bo = dri2_surf->current->bo;5758if (device->dri2) {59dri2_surf->current->locked = true;60dri2_surf->current = NULL;61}6263return bo;64}6566static void67release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo)68{69struct gbm_dri_surface *surf = gbm_dri_surface(_surf);70struct dri2_egl_surface *dri2_surf = surf->dri_private;7172for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {73if (dri2_surf->color_buffers[i].bo == bo) {74dri2_surf->color_buffers[i].locked = false;75break;76}77}78}7980static int81has_free_buffers(struct gbm_surface *_surf)82{83struct gbm_dri_surface *surf = gbm_dri_surface(_surf);84struct dri2_egl_surface *dri2_surf = surf->dri_private;8586for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)87if (!dri2_surf->color_buffers[i].locked)88return 1;8990return 0;91}9293static bool94dri2_drm_config_is_compatible(struct dri2_egl_display *dri2_dpy,95const __DRIconfig *config,96struct gbm_surface *surface)97{98const struct gbm_dri_visual *visual = NULL;99int shifts[4];100unsigned int sizes[4];101bool is_float;102int i;103104/* Check that the EGLConfig being used to render to the surface is105* compatible with the surface format. Since mixing ARGB and XRGB of106* otherwise-compatible formats is relatively common, explicitly allow107* this.108*/109dri2_get_shifts_and_sizes(dri2_dpy->core, config, shifts, sizes);110111dri2_get_render_type_float(dri2_dpy->core, config, &is_float);112113for (i = 0; i < dri2_dpy->gbm_dri->num_visuals; i++) {114visual = &dri2_dpy->gbm_dri->visual_table[i];115if (visual->gbm_format == surface->v0.format)116break;117}118119if (i == dri2_dpy->gbm_dri->num_visuals)120return false;121122if (shifts[0] != visual->rgba_shifts.red ||123shifts[1] != visual->rgba_shifts.green ||124shifts[2] != visual->rgba_shifts.blue ||125(shifts[3] > -1 && visual->rgba_shifts.alpha > -1 &&126shifts[3] != visual->rgba_shifts.alpha) ||127sizes[0] != visual->rgba_sizes.red ||128sizes[1] != visual->rgba_sizes.green ||129sizes[2] != visual->rgba_sizes.blue ||130(sizes[3] > 0 && visual->rgba_sizes.alpha > 0 &&131sizes[3] != visual->rgba_sizes.alpha) ||132is_float != visual->is_float) {133return false;134}135136return true;137}138139static _EGLSurface *140dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,141void *native_surface, const EGLint *attrib_list)142{143struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);144struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);145struct dri2_egl_surface *dri2_surf;146struct gbm_surface *surface = native_surface;147struct gbm_dri_surface *surf;148const __DRIconfig *config;149150dri2_surf = calloc(1, sizeof *dri2_surf);151if (!dri2_surf) {152_eglError(EGL_BAD_ALLOC, "dri2_create_surface");153return NULL;154}155156if (!dri2_init_surface(&dri2_surf->base, disp, EGL_WINDOW_BIT, conf,157attrib_list, false, native_surface))158goto cleanup_surf;159160config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,161dri2_surf->base.GLColorspace);162163if (!config) {164_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");165goto cleanup_surf;166}167168if (!dri2_drm_config_is_compatible(dri2_dpy, config, surface)) {169_eglError(EGL_BAD_MATCH, "EGL config not compatible with GBM format");170goto cleanup_surf;171}172173surf = gbm_dri_surface(surface);174dri2_surf->gbm_surf = surf;175dri2_surf->base.Width = surf->base.v0.width;176dri2_surf->base.Height = surf->base.v0.height;177surf->dri_private = dri2_surf;178179if (!dri2_create_drawable(dri2_dpy, config, dri2_surf, dri2_surf->gbm_surf))180goto cleanup_surf;181182return &dri2_surf->base;183184cleanup_surf:185free(dri2_surf);186187return NULL;188}189190static _EGLSurface *191dri2_drm_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,192void *native_window, const EGLint *attrib_list)193{194/* From the EGL_MESA_platform_gbm spec, version 5:195*196* It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>197* that belongs to the GBM platform. Any such call fails and generates198* EGL_BAD_PARAMETER.199*/200_eglError(EGL_BAD_PARAMETER, "cannot create EGL pixmap surfaces on GBM");201return NULL;202}203204static EGLBoolean205dri2_drm_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)206{207struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);208struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);209210dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);211212for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {213if (dri2_surf->color_buffers[i].bo)214gbm_bo_destroy(dri2_surf->color_buffers[i].bo);215}216217dri2_egl_surface_free_local_buffers(dri2_surf);218219dri2_fini_surface(surf);220free(surf);221222return EGL_TRUE;223}224225static int226get_back_bo(struct dri2_egl_surface *dri2_surf)227{228struct dri2_egl_display *dri2_dpy =229dri2_egl_display(dri2_surf->base.Resource.Display);230struct gbm_dri_surface *surf = dri2_surf->gbm_surf;231int age = 0;232233if (dri2_surf->back == NULL) {234for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {235if (!dri2_surf->color_buffers[i].locked &&236dri2_surf->color_buffers[i].age >= age) {237dri2_surf->back = &dri2_surf->color_buffers[i];238age = dri2_surf->color_buffers[i].age;239}240}241}242243if (dri2_surf->back == NULL)244return -1;245if (dri2_surf->back->bo == NULL) {246if (surf->base.v0.modifiers)247dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base,248surf->base.v0.width,249surf->base.v0.height,250surf->base.v0.format,251surf->base.v0.modifiers,252surf->base.v0.count);253else {254unsigned flags = surf->base.v0.flags;255if (dri2_surf->base.ProtectedContent)256flags |= GBM_BO_USE_PROTECTED;257dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,258surf->base.v0.width,259surf->base.v0.height,260surf->base.v0.format,261flags);262}263264}265if (dri2_surf->back->bo == NULL)266return -1;267268return 0;269}270271static int272get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)273{274struct dri2_egl_display *dri2_dpy =275dri2_egl_display(dri2_surf->base.Resource.Display);276struct gbm_dri_surface *surf = dri2_surf->gbm_surf;277278if (dri2_surf->current == NULL) {279assert(!dri2_surf->color_buffers[0].locked);280dri2_surf->current = &dri2_surf->color_buffers[0];281}282283if (dri2_surf->current->bo == NULL)284dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,285surf->base.v0.width,286surf->base.v0.height,287surf->base.v0.format,288surf->base.v0.flags);289if (dri2_surf->current->bo == NULL)290return -1;291292return 0;293}294295static void296back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)297{298struct dri2_egl_display *dri2_dpy =299dri2_egl_display(dri2_surf->base.Resource.Display);300struct gbm_dri_bo *bo;301int name, pitch;302303bo = gbm_dri_bo(dri2_surf->back->bo);304305dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);306dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch);307308buffer->attachment = __DRI_BUFFER_BACK_LEFT;309buffer->name = name;310buffer->pitch = pitch;311buffer->cpp = 4;312buffer->flags = 0;313}314315static __DRIbuffer *316dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,317int *width, int *height,318unsigned int *attachments, int count,319int *out_count, void *loaderPrivate)320{321struct dri2_egl_surface *dri2_surf = loaderPrivate;322int i, j;323324for (i = 0, j = 0; i < 2 * count; i += 2, j++) {325__DRIbuffer *local;326327assert(attachments[i] < __DRI_BUFFER_COUNT);328assert(j < ARRAY_SIZE(dri2_surf->buffers));329330switch (attachments[i]) {331case __DRI_BUFFER_BACK_LEFT:332if (get_back_bo(dri2_surf) < 0) {333_eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");334return NULL;335}336back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]);337break;338default:339local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],340attachments[i + 1]);341342if (!local) {343_eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");344return NULL;345}346dri2_surf->buffers[j] = *local;347break;348}349}350351*out_count = j;352if (j == 0)353return NULL;354355*width = dri2_surf->base.Width;356*height = dri2_surf->base.Height;357358return dri2_surf->buffers;359}360361static __DRIbuffer *362dri2_drm_get_buffers(__DRIdrawable * driDrawable,363int *width, int *height,364unsigned int *attachments, int count,365int *out_count, void *loaderPrivate)366{367unsigned int *attachments_with_format;368__DRIbuffer *buffer;369const unsigned int format = 32;370371attachments_with_format = calloc(count, 2 * sizeof(unsigned int));372if (!attachments_with_format) {373*out_count = 0;374return NULL;375}376377for (int i = 0; i < count; ++i) {378attachments_with_format[2*i] = attachments[i];379attachments_with_format[2*i + 1] = format;380}381382buffer =383dri2_drm_get_buffers_with_format(driDrawable,384width, height,385attachments_with_format, count,386out_count, loaderPrivate);387388free(attachments_with_format);389390return buffer;391}392393static int394dri2_drm_image_get_buffers(__DRIdrawable *driDrawable,395unsigned int format,396uint32_t *stamp,397void *loaderPrivate,398uint32_t buffer_mask,399struct __DRIimageList *buffers)400{401struct dri2_egl_surface *dri2_surf = loaderPrivate;402struct gbm_dri_bo *bo;403404if (get_back_bo(dri2_surf) < 0)405return 0;406407bo = gbm_dri_bo(dri2_surf->back->bo);408buffers->image_mask = __DRI_IMAGE_BUFFER_BACK;409buffers->back = bo->image;410411return 1;412}413414static void415dri2_drm_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)416{417(void) driDrawable;418(void) loaderPrivate;419}420421static EGLBoolean422dri2_drm_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)423{424struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);425struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);426427if (!dri2_dpy->flush) {428dri2_dpy->core->swapBuffers(dri2_surf->dri_drawable);429return EGL_TRUE;430}431432if (dri2_surf->current)433_eglError(EGL_BAD_SURFACE, "dri2_swap_buffers");434for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)435if (dri2_surf->color_buffers[i].age > 0)436dri2_surf->color_buffers[i].age++;437438/* Make sure we have a back buffer in case we're swapping without439* ever rendering. */440if (get_back_bo(dri2_surf) < 0)441return _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");442443dri2_surf->current = dri2_surf->back;444dri2_surf->current->age = 1;445dri2_surf->back = NULL;446447dri2_flush_drawable_for_swapbuffers(disp, draw);448dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);449450return EGL_TRUE;451}452453static EGLint454dri2_drm_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surface)455{456struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface);457458if (get_back_bo(dri2_surf) < 0) {459_eglError(EGL_BAD_ALLOC, "dri2_query_buffer_age");460return -1;461}462463return dri2_surf->back->age;464}465466static _EGLImage *467dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,468EGLClientBuffer buffer, const EGLint *attr_list)469{470struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);471struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer);472struct dri2_egl_image *dri2_img;473474dri2_img = malloc(sizeof *dri2_img);475if (!dri2_img) {476_eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap");477return NULL;478}479480_eglInitImage(&dri2_img->base, disp);481482dri2_img->dri_image = dri2_dpy->image->dupImage(dri_bo->image, dri2_img);483if (dri2_img->dri_image == NULL) {484free(dri2_img);485_eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap");486return NULL;487}488489return &dri2_img->base;490}491492static _EGLImage *493dri2_drm_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,494EGLClientBuffer buffer, const EGLint *attr_list)495{496switch (target) {497case EGL_NATIVE_PIXMAP_KHR:498return dri2_drm_create_image_khr_pixmap(disp, ctx, buffer, attr_list);499default:500return dri2_create_image_khr(disp, ctx, target, buffer, attr_list);501}502}503504static int505dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)506{507struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);508509return drmAuthMagic(dri2_dpy->fd, id);510}511512static void513swrast_put_image2(__DRIdrawable *driDrawable,514int op,515int x,516int y,517int width,518int height,519int stride,520char *data,521void *loaderPrivate)522{523struct dri2_egl_surface *dri2_surf = loaderPrivate;524int internal_stride;525struct gbm_dri_bo *bo;526uint32_t bpp;527int x_bytes, width_bytes;528char *src, *dst;529530if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&531op != __DRI_SWRAST_IMAGE_OP_SWAP)532return;533534if (get_swrast_front_bo(dri2_surf) < 0)535return;536537bo = gbm_dri_bo(dri2_surf->current->bo);538539bpp = gbm_bo_get_bpp(&bo->base);540if (bpp == 0)541return;542543x_bytes = x * (bpp >> 3);544width_bytes = width * (bpp >> 3);545546if (gbm_dri_bo_map_dumb(bo) == NULL)547return;548549internal_stride = bo->base.v0.stride;550551dst = bo->map + x_bytes + (y * internal_stride);552src = data;553554for (int i = 0; i < height; i++) {555memcpy(dst, src, width_bytes);556dst += internal_stride;557src += stride;558}559560gbm_dri_bo_unmap_dumb(bo);561}562563static void564swrast_get_image(__DRIdrawable *driDrawable,565int x,566int y,567int width,568int height,569char *data,570void *loaderPrivate)571{572struct dri2_egl_surface *dri2_surf = loaderPrivate;573int internal_stride, stride;574struct gbm_dri_bo *bo;575uint32_t bpp;576int x_bytes, width_bytes;577char *src, *dst;578579if (get_swrast_front_bo(dri2_surf) < 0)580return;581582bo = gbm_dri_bo(dri2_surf->current->bo);583584bpp = gbm_bo_get_bpp(&bo->base);585if (bpp == 0)586return;587588x_bytes = x * (bpp >> 3);589width_bytes = width * (bpp >> 3);590591internal_stride = bo->base.v0.stride;592stride = width_bytes;593594if (gbm_dri_bo_map_dumb(bo) == NULL)595return;596597dst = data;598src = bo->map + x_bytes + (y * internal_stride);599600for (int i = 0; i < height; i++) {601memcpy(dst, src, width_bytes);602dst += stride;603src += internal_stride;604}605606gbm_dri_bo_unmap_dumb(bo);607}608609static EGLBoolean610drm_add_configs_for_visuals(_EGLDisplay *disp)611{612struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);613const struct gbm_dri_visual *visuals = dri2_dpy->gbm_dri->visual_table;614int num_visuals = dri2_dpy->gbm_dri->num_visuals;615unsigned int format_count[num_visuals];616unsigned int config_count = 0;617618memset(format_count, 0, num_visuals * sizeof(unsigned int));619620for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) {621const __DRIconfig *config = dri2_dpy->driver_configs[i];622int shifts[4];623unsigned int sizes[4];624bool is_float;625626dri2_get_shifts_and_sizes(dri2_dpy->core, config, shifts, sizes);627628dri2_get_render_type_float(dri2_dpy->core, config, &is_float);629630for (unsigned j = 0; j < num_visuals; j++) {631struct dri2_egl_config *dri2_conf;632633if (visuals[j].rgba_shifts.red != shifts[0] ||634visuals[j].rgba_shifts.green != shifts[1] ||635visuals[j].rgba_shifts.blue != shifts[2] ||636visuals[j].rgba_shifts.alpha != shifts[3] ||637visuals[j].rgba_sizes.red != sizes[0] ||638visuals[j].rgba_sizes.green != sizes[1] ||639visuals[j].rgba_sizes.blue != sizes[2] ||640visuals[j].rgba_sizes.alpha != sizes[3] ||641visuals[j].is_float != is_float)642continue;643644const EGLint attr_list[] = {645EGL_NATIVE_VISUAL_ID, visuals[j].gbm_format,646EGL_NONE,647};648649dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],650config_count + 1, EGL_WINDOW_BIT, attr_list, NULL, NULL);651if (dri2_conf) {652if (dri2_conf->base.ConfigID == config_count + 1)653config_count++;654format_count[j]++;655}656}657}658659for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {660if (!format_count[i]) {661struct gbm_format_name_desc desc;662_eglLog(_EGL_DEBUG, "No DRI config supports native format %s",663gbm_format_get_name(visuals[i].gbm_format, &desc));664}665}666667return (config_count != 0);668}669670static 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.destroy_surface = dri2_drm_destroy_surface,675.create_image = dri2_drm_create_image_khr,676.swap_buffers = dri2_drm_swap_buffers,677.query_buffer_age = dri2_drm_query_buffer_age,678.get_dri_drawable = dri2_surface_get_dri_drawable,679};680681EGLBoolean682dri2_initialize_drm(_EGLDisplay *disp)683{684_EGLDevice *dev;685struct dri2_egl_display *dri2_dpy;686struct gbm_device *gbm;687const char *err;688689dri2_dpy = calloc(1, sizeof *dri2_dpy);690if (!dri2_dpy)691return _eglError(EGL_BAD_ALLOC, "eglInitialize");692693dri2_dpy->fd = -1;694disp->DriverData = (void *) dri2_dpy;695696gbm = disp->PlatformDisplay;697if (gbm == NULL) {698char buf[64];699int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);700if (n != -1 && n < sizeof(buf))701dri2_dpy->fd = loader_open_device(buf);702gbm = gbm_create_device(dri2_dpy->fd);703if (gbm == NULL) {704err = "DRI2: failed to create gbm device";705goto cleanup;706}707dri2_dpy->own_device = true;708} else {709dri2_dpy->fd = os_dupfd_cloexec(gbm_device_get_fd(gbm));710if (dri2_dpy->fd < 0) {711err = "DRI2: failed to fcntl() existing gbm device";712goto cleanup;713}714}715dri2_dpy->gbm_dri = gbm_dri_device(gbm);716717if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) {718err = "DRI2: gbm device using incorrect/incompatible backend";719goto cleanup;720}721722dev = _eglAddDevice(dri2_dpy->fd, dri2_dpy->gbm_dri->software);723if (!dev) {724err = "DRI2: failed to find EGLDevice";725goto cleanup;726}727728disp->Device = dev;729730dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name);731dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER;732733/* render nodes cannot use Gem names, and thus do not support734* the __DRI_DRI2_LOADER extension */735if (!dri2_dpy->is_render_node) {736if (!dri2_load_driver(disp)) {737err = "DRI2: failed to load driver";738goto cleanup;739}740} else {741if (!dri2_load_driver_dri3(disp)) {742err = "DRI3: failed to load driver";743goto cleanup;744}745}746747dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen;748dri2_dpy->core = dri2_dpy->gbm_dri->core;749dri2_dpy->dri2 = dri2_dpy->gbm_dri->dri2;750dri2_dpy->swrast = dri2_dpy->gbm_dri->swrast;751dri2_dpy->driver_configs = dri2_dpy->gbm_dri->driver_configs;752753dri2_dpy->gbm_dri->lookup_image = dri2_lookup_egl_image;754dri2_dpy->gbm_dri->lookup_user_data = disp;755756dri2_dpy->gbm_dri->get_buffers = dri2_drm_get_buffers;757dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer;758dri2_dpy->gbm_dri->get_buffers_with_format = dri2_drm_get_buffers_with_format;759dri2_dpy->gbm_dri->image_get_buffers = dri2_drm_image_get_buffers;760dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2;761dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image;762763dri2_dpy->gbm_dri->base.v0.surface_lock_front_buffer = lock_front_buffer;764dri2_dpy->gbm_dri->base.v0.surface_release_buffer = release_buffer;765dri2_dpy->gbm_dri->base.v0.surface_has_free_buffers = has_free_buffers;766767if (!dri2_setup_extensions(disp)) {768err = "DRI2: failed to find required DRI extensions";769goto cleanup;770}771772dri2_setup_screen(disp);773774if (!drm_add_configs_for_visuals(disp)) {775err = "DRI2: failed to add configs";776goto cleanup;777}778779disp->Extensions.KHR_image_pixmap = EGL_TRUE;780if (dri2_dpy->dri2)781disp->Extensions.EXT_buffer_age = EGL_TRUE;782783#ifdef HAVE_WAYLAND_PLATFORM784dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);785#endif786dri2_set_WL_bind_wayland_display(disp);787788/* Fill vtbl last to prevent accidentally calling virtual function during789* initialization.790*/791dri2_dpy->vtbl = &dri2_drm_display_vtbl;792793return EGL_TRUE;794795cleanup:796dri2_display_destroy(disp);797return _eglError(EGL_NOT_INITIALIZED, err);798}799800void801dri2_teardown_drm(struct dri2_egl_display *dri2_dpy)802{803if (dri2_dpy->own_device)804gbm_device_destroy(&dri2_dpy->gbm_dri->base);805}806807808