13464ebd5Sriastradh/* 23464ebd5Sriastradh * Copyright © 2011 Intel Corporation 33464ebd5Sriastradh * 43464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a 53464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"), 63464ebd5Sriastradh * to deal in the Software without restriction, including without limitation 73464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 83464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the 93464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions: 103464ebd5Sriastradh * 113464ebd5Sriastradh * The above copyright notice and this permission notice (including the next 123464ebd5Sriastradh * paragraph) shall be included in all copies or substantial portions of the 133464ebd5Sriastradh * Software. 143464ebd5Sriastradh * 153464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 163464ebd5Sriastradh * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 173464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 183464ebd5Sriastradh * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 193464ebd5Sriastradh * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 203464ebd5Sriastradh * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 213464ebd5Sriastradh * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 223464ebd5Sriastradh * DEALINGS IN THE SOFTWARE. 233464ebd5Sriastradh * 243464ebd5Sriastradh * Authors: 253464ebd5Sriastradh * Benjamin Franzke <benjaminfranzke@googlemail.com> 263464ebd5Sriastradh */ 273464ebd5Sriastradh 283464ebd5Sriastradh#ifndef _GBM_DRI_INTERNAL_H_ 293464ebd5Sriastradh#define _GBM_DRI_INTERNAL_H_ 303464ebd5Sriastradh 3101e04c3fSmrg#include <xf86drm.h> 3201e04c3fSmrg#include <string.h> 33af69d88dSmrg#include <sys/mman.h> 343464ebd5Sriastradh#include "gbmint.h" 3501e04c3fSmrg#include "c11/threads.h" 363464ebd5Sriastradh 373464ebd5Sriastradh#include <GL/gl.h> /* dri_interface needs GL types */ 383464ebd5Sriastradh#include "GL/internal/dri_interface.h" 393464ebd5Sriastradh 40af69d88dSmrgstruct gbm_dri_surface; 41af69d88dSmrgstruct gbm_dri_bo; 42af69d88dSmrg 4301e04c3fSmrgstruct gbm_dri_visual { 4401e04c3fSmrg uint32_t gbm_format; 4501e04c3fSmrg int dri_image_format; 4601e04c3fSmrg struct { 477ec681f3Smrg int red; 487ec681f3Smrg int green; 497ec681f3Smrg int blue; 507ec681f3Smrg int alpha; 517ec681f3Smrg } rgba_shifts; 527ec681f3Smrg struct { 537ec681f3Smrg unsigned int red; 547ec681f3Smrg unsigned int green; 557ec681f3Smrg unsigned int blue; 567ec681f3Smrg unsigned int alpha; 577ec681f3Smrg } rgba_sizes; 587ec681f3Smrg bool is_float; 5901e04c3fSmrg}; 6001e04c3fSmrg 613464ebd5Sriastradhstruct gbm_dri_device { 6201e04c3fSmrg struct gbm_device base; 633464ebd5Sriastradh 643464ebd5Sriastradh void *driver; 6501e04c3fSmrg char *driver_name; /* Name of the DRI module, without the _dri suffix */ 667ec681f3Smrg bool software; /* A software driver was loaded */ 673464ebd5Sriastradh 683464ebd5Sriastradh __DRIscreen *screen; 6901e04c3fSmrg __DRIcontext *context; 7001e04c3fSmrg mtx_t mutex; 713464ebd5Sriastradh 72af69d88dSmrg const __DRIcoreExtension *core; 73af69d88dSmrg const __DRIdri2Extension *dri2; 7401e04c3fSmrg const __DRI2fenceExtension *fence; 75af69d88dSmrg const __DRIimageExtension *image; 76af69d88dSmrg const __DRIswrastExtension *swrast; 77af69d88dSmrg const __DRI2flushExtension *flush; 783464ebd5Sriastradh 793464ebd5Sriastradh const __DRIconfig **driver_configs; 8001e04c3fSmrg const __DRIextension **loader_extensions; 81af69d88dSmrg const __DRIextension **driver_extensions; 823464ebd5Sriastradh 833464ebd5Sriastradh __DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data); 847ec681f3Smrg GLboolean (*validate_image)(void *image, void *data); 857ec681f3Smrg __DRIimage *(*lookup_image_validated)(void *image, void *data); 863464ebd5Sriastradh void *lookup_user_data; 87af69d88dSmrg 88af69d88dSmrg __DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable, 89af69d88dSmrg int *width, int *height, 90af69d88dSmrg unsigned int *attachments, int count, 91af69d88dSmrg int *out_count, void *data); 92af69d88dSmrg void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data); 93af69d88dSmrg __DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable, 94af69d88dSmrg int *width, int *height, 95af69d88dSmrg unsigned int *attachments, int count, 96af69d88dSmrg int *out_count, void *data); 97af69d88dSmrg int (*image_get_buffers)(__DRIdrawable *driDrawable, 98af69d88dSmrg unsigned int format, 99af69d88dSmrg uint32_t *stamp, 100af69d88dSmrg void *loaderPrivate, 101af69d88dSmrg uint32_t buffer_mask, 102af69d88dSmrg struct __DRIimageList *buffers); 103af69d88dSmrg void (*swrast_put_image2)(__DRIdrawable *driDrawable, 104af69d88dSmrg int op, 105af69d88dSmrg int x, 106af69d88dSmrg int y, 107af69d88dSmrg int width, 108af69d88dSmrg int height, 109af69d88dSmrg int stride, 110af69d88dSmrg char *data, 111af69d88dSmrg void *loaderPrivate); 112af69d88dSmrg void (*swrast_get_image)(__DRIdrawable *driDrawable, 113af69d88dSmrg int x, 114af69d88dSmrg int y, 115af69d88dSmrg int width, 116af69d88dSmrg int height, 117af69d88dSmrg char *data, 118af69d88dSmrg void *loaderPrivate); 119af69d88dSmrg 120af69d88dSmrg struct wl_drm *wl_drm; 12101e04c3fSmrg 12201e04c3fSmrg const struct gbm_dri_visual *visual_table; 12301e04c3fSmrg int num_visuals; 1243464ebd5Sriastradh}; 1253464ebd5Sriastradh 1263464ebd5Sriastradhstruct gbm_dri_bo { 12701e04c3fSmrg struct gbm_bo base; 1283464ebd5Sriastradh 1293464ebd5Sriastradh __DRIimage *image; 130af69d88dSmrg 131af69d88dSmrg /* Used for cursors and the swrast front BO */ 132af69d88dSmrg uint32_t handle, size; 133af69d88dSmrg void *map; 134af69d88dSmrg}; 135af69d88dSmrg 136af69d88dSmrgstruct gbm_dri_surface { 137af69d88dSmrg struct gbm_surface base; 138af69d88dSmrg 139af69d88dSmrg void *dri_private; 1403464ebd5Sriastradh}; 1413464ebd5Sriastradh 1423464ebd5Sriastradhstatic inline struct gbm_dri_device * 1433464ebd5Sriastradhgbm_dri_device(struct gbm_device *gbm) 1443464ebd5Sriastradh{ 1453464ebd5Sriastradh return (struct gbm_dri_device *) gbm; 1463464ebd5Sriastradh} 1473464ebd5Sriastradh 1483464ebd5Sriastradhstatic inline struct gbm_dri_bo * 1493464ebd5Sriastradhgbm_dri_bo(struct gbm_bo *bo) 1503464ebd5Sriastradh{ 1513464ebd5Sriastradh return (struct gbm_dri_bo *) bo; 1523464ebd5Sriastradh} 1533464ebd5Sriastradh 154af69d88dSmrgstatic inline struct gbm_dri_surface * 155af69d88dSmrggbm_dri_surface(struct gbm_surface *surface) 156af69d88dSmrg{ 157af69d88dSmrg return (struct gbm_dri_surface *) surface; 158af69d88dSmrg} 159af69d88dSmrg 160af69d88dSmrgstatic inline void * 16101e04c3fSmrggbm_dri_bo_map_dumb(struct gbm_dri_bo *bo) 162af69d88dSmrg{ 163af69d88dSmrg struct drm_mode_map_dumb map_arg; 164af69d88dSmrg int ret; 165af69d88dSmrg 166af69d88dSmrg if (bo->image != NULL) 167af69d88dSmrg return NULL; 168af69d88dSmrg 169af69d88dSmrg if (bo->map != NULL) 170af69d88dSmrg return bo->map; 171af69d88dSmrg 172af69d88dSmrg memset(&map_arg, 0, sizeof(map_arg)); 173af69d88dSmrg map_arg.handle = bo->handle; 174af69d88dSmrg 1757ec681f3Smrg ret = drmIoctl(bo->base.gbm->v0.fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg); 176af69d88dSmrg if (ret) 177af69d88dSmrg return NULL; 178af69d88dSmrg 179af69d88dSmrg bo->map = mmap(0, bo->size, PROT_WRITE, 1807ec681f3Smrg MAP_SHARED, bo->base.gbm->v0.fd, map_arg.offset); 181af69d88dSmrg if (bo->map == MAP_FAILED) { 182af69d88dSmrg bo->map = NULL; 183af69d88dSmrg return NULL; 184af69d88dSmrg } 185af69d88dSmrg 186af69d88dSmrg return bo->map; 187af69d88dSmrg} 188af69d88dSmrg 189af69d88dSmrgstatic inline void 19001e04c3fSmrggbm_dri_bo_unmap_dumb(struct gbm_dri_bo *bo) 191af69d88dSmrg{ 192af69d88dSmrg munmap(bo->map, bo->size); 193af69d88dSmrg bo->map = NULL; 194af69d88dSmrg} 1953464ebd5Sriastradh 1963464ebd5Sriastradh#endif 197