Path: blob/21.2-virgl/src/gbm/backends/dri/gbm_driint.h
4561 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* Benjamin Franzke <[email protected]>25*/2627#ifndef _GBM_DRI_INTERNAL_H_28#define _GBM_DRI_INTERNAL_H_2930#include <xf86drm.h>31#include <string.h>32#include <sys/mman.h>33#include "gbmint.h"34#include "c11/threads.h"3536#include <GL/gl.h> /* dri_interface needs GL types */37#include "GL/internal/dri_interface.h"3839struct gbm_dri_surface;40struct gbm_dri_bo;4142struct gbm_dri_visual {43uint32_t gbm_format;44int dri_image_format;45struct {46int red;47int green;48int blue;49int alpha;50} rgba_shifts;51struct {52unsigned int red;53unsigned int green;54unsigned int blue;55unsigned int alpha;56} rgba_sizes;57bool is_float;58};5960struct gbm_dri_device {61struct gbm_device base;6263void *driver;64char *driver_name; /* Name of the DRI module, without the _dri suffix */65bool software; /* A software driver was loaded */6667__DRIscreen *screen;68__DRIcontext *context;69mtx_t mutex;7071const __DRIcoreExtension *core;72const __DRIdri2Extension *dri2;73const __DRI2fenceExtension *fence;74const __DRIimageExtension *image;75const __DRIswrastExtension *swrast;76const __DRI2flushExtension *flush;7778const __DRIconfig **driver_configs;79const __DRIextension **loader_extensions;80const __DRIextension **driver_extensions;8182__DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data);83void *lookup_user_data;8485__DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable,86int *width, int *height,87unsigned int *attachments, int count,88int *out_count, void *data);89void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data);90__DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable,91int *width, int *height,92unsigned int *attachments, int count,93int *out_count, void *data);94int (*image_get_buffers)(__DRIdrawable *driDrawable,95unsigned int format,96uint32_t *stamp,97void *loaderPrivate,98uint32_t buffer_mask,99struct __DRIimageList *buffers);100void (*swrast_put_image2)(__DRIdrawable *driDrawable,101int op,102int x,103int y,104int width,105int height,106int stride,107char *data,108void *loaderPrivate);109void (*swrast_get_image)(__DRIdrawable *driDrawable,110int x,111int y,112int width,113int height,114char *data,115void *loaderPrivate);116117struct wl_drm *wl_drm;118119const struct gbm_dri_visual *visual_table;120int num_visuals;121};122123struct gbm_dri_bo {124struct gbm_bo base;125126__DRIimage *image;127128/* Used for cursors and the swrast front BO */129uint32_t handle, size;130void *map;131};132133struct gbm_dri_surface {134struct gbm_surface base;135136void *dri_private;137};138139static inline struct gbm_dri_device *140gbm_dri_device(struct gbm_device *gbm)141{142return (struct gbm_dri_device *) gbm;143}144145static inline struct gbm_dri_bo *146gbm_dri_bo(struct gbm_bo *bo)147{148return (struct gbm_dri_bo *) bo;149}150151static inline struct gbm_dri_surface *152gbm_dri_surface(struct gbm_surface *surface)153{154return (struct gbm_dri_surface *) surface;155}156157static inline void *158gbm_dri_bo_map_dumb(struct gbm_dri_bo *bo)159{160struct drm_mode_map_dumb map_arg;161int ret;162163if (bo->image != NULL)164return NULL;165166if (bo->map != NULL)167return bo->map;168169memset(&map_arg, 0, sizeof(map_arg));170map_arg.handle = bo->handle;171172ret = drmIoctl(bo->base.gbm->v0.fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);173if (ret)174return NULL;175176bo->map = mmap(0, bo->size, PROT_WRITE,177MAP_SHARED, bo->base.gbm->v0.fd, map_arg.offset);178if (bo->map == MAP_FAILED) {179bo->map = NULL;180return NULL;181}182183return bo->map;184}185186static inline void187gbm_dri_bo_unmap_dumb(struct gbm_dri_bo *bo)188{189munmap(bo->map, bo->size);190bo->map = NULL;191}192193#endif194195196