Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gbm/backends/dri/gbm_driint.h
4561 views
1
/*
2
* Copyright © 2011 Intel Corporation
3
*
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:
10
*
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
13
* Software.
14
*
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.
23
*
24
* Authors:
25
* Benjamin Franzke <[email protected]>
26
*/
27
28
#ifndef _GBM_DRI_INTERNAL_H_
29
#define _GBM_DRI_INTERNAL_H_
30
31
#include <xf86drm.h>
32
#include <string.h>
33
#include <sys/mman.h>
34
#include "gbmint.h"
35
#include "c11/threads.h"
36
37
#include <GL/gl.h> /* dri_interface needs GL types */
38
#include "GL/internal/dri_interface.h"
39
40
struct gbm_dri_surface;
41
struct gbm_dri_bo;
42
43
struct gbm_dri_visual {
44
uint32_t gbm_format;
45
int dri_image_format;
46
struct {
47
int red;
48
int green;
49
int blue;
50
int alpha;
51
} rgba_shifts;
52
struct {
53
unsigned int red;
54
unsigned int green;
55
unsigned int blue;
56
unsigned int alpha;
57
} rgba_sizes;
58
bool is_float;
59
};
60
61
struct gbm_dri_device {
62
struct gbm_device base;
63
64
void *driver;
65
char *driver_name; /* Name of the DRI module, without the _dri suffix */
66
bool software; /* A software driver was loaded */
67
68
__DRIscreen *screen;
69
__DRIcontext *context;
70
mtx_t mutex;
71
72
const __DRIcoreExtension *core;
73
const __DRIdri2Extension *dri2;
74
const __DRI2fenceExtension *fence;
75
const __DRIimageExtension *image;
76
const __DRIswrastExtension *swrast;
77
const __DRI2flushExtension *flush;
78
79
const __DRIconfig **driver_configs;
80
const __DRIextension **loader_extensions;
81
const __DRIextension **driver_extensions;
82
83
__DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data);
84
void *lookup_user_data;
85
86
__DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable,
87
int *width, int *height,
88
unsigned int *attachments, int count,
89
int *out_count, void *data);
90
void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data);
91
__DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable,
92
int *width, int *height,
93
unsigned int *attachments, int count,
94
int *out_count, void *data);
95
int (*image_get_buffers)(__DRIdrawable *driDrawable,
96
unsigned int format,
97
uint32_t *stamp,
98
void *loaderPrivate,
99
uint32_t buffer_mask,
100
struct __DRIimageList *buffers);
101
void (*swrast_put_image2)(__DRIdrawable *driDrawable,
102
int op,
103
int x,
104
int y,
105
int width,
106
int height,
107
int stride,
108
char *data,
109
void *loaderPrivate);
110
void (*swrast_get_image)(__DRIdrawable *driDrawable,
111
int x,
112
int y,
113
int width,
114
int height,
115
char *data,
116
void *loaderPrivate);
117
118
struct wl_drm *wl_drm;
119
120
const struct gbm_dri_visual *visual_table;
121
int num_visuals;
122
};
123
124
struct gbm_dri_bo {
125
struct gbm_bo base;
126
127
__DRIimage *image;
128
129
/* Used for cursors and the swrast front BO */
130
uint32_t handle, size;
131
void *map;
132
};
133
134
struct gbm_dri_surface {
135
struct gbm_surface base;
136
137
void *dri_private;
138
};
139
140
static inline struct gbm_dri_device *
141
gbm_dri_device(struct gbm_device *gbm)
142
{
143
return (struct gbm_dri_device *) gbm;
144
}
145
146
static inline struct gbm_dri_bo *
147
gbm_dri_bo(struct gbm_bo *bo)
148
{
149
return (struct gbm_dri_bo *) bo;
150
}
151
152
static inline struct gbm_dri_surface *
153
gbm_dri_surface(struct gbm_surface *surface)
154
{
155
return (struct gbm_dri_surface *) surface;
156
}
157
158
static inline void *
159
gbm_dri_bo_map_dumb(struct gbm_dri_bo *bo)
160
{
161
struct drm_mode_map_dumb map_arg;
162
int ret;
163
164
if (bo->image != NULL)
165
return NULL;
166
167
if (bo->map != NULL)
168
return bo->map;
169
170
memset(&map_arg, 0, sizeof(map_arg));
171
map_arg.handle = bo->handle;
172
173
ret = drmIoctl(bo->base.gbm->v0.fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
174
if (ret)
175
return NULL;
176
177
bo->map = mmap(0, bo->size, PROT_WRITE,
178
MAP_SHARED, bo->base.gbm->v0.fd, map_arg.offset);
179
if (bo->map == MAP_FAILED) {
180
bo->map = NULL;
181
return NULL;
182
}
183
184
return bo->map;
185
}
186
187
static inline void
188
gbm_dri_bo_unmap_dumb(struct gbm_dri_bo *bo)
189
{
190
munmap(bo->map, bo->size);
191
bo->map = NULL;
192
}
193
194
#endif
195
196