gbm: Fix the alpha masks in the GBM format table.
[mesa.git] / src / gbm / backends / dri / gbm_driint.h
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 <benjaminfranzke@googlemail.com>
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 uint32_t rgba_masks[4];
47 };
48
49 struct gbm_dri_device {
50 struct gbm_device base;
51
52 void *driver;
53 char *driver_name; /* Name of the DRI module, without the _dri suffix */
54
55 __DRIscreen *screen;
56 __DRIcontext *context;
57 mtx_t mutex;
58
59 const __DRIcoreExtension *core;
60 const __DRIdri2Extension *dri2;
61 const __DRI2fenceExtension *fence;
62 const __DRIimageExtension *image;
63 const __DRIswrastExtension *swrast;
64 const __DRI2flushExtension *flush;
65
66 const __DRIconfig **driver_configs;
67 const __DRIextension **loader_extensions;
68 const __DRIextension **driver_extensions;
69
70 __DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data);
71 void *lookup_user_data;
72
73 __DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable,
74 int *width, int *height,
75 unsigned int *attachments, int count,
76 int *out_count, void *data);
77 void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data);
78 __DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable,
79 int *width, int *height,
80 unsigned int *attachments, int count,
81 int *out_count, void *data);
82 int (*image_get_buffers)(__DRIdrawable *driDrawable,
83 unsigned int format,
84 uint32_t *stamp,
85 void *loaderPrivate,
86 uint32_t buffer_mask,
87 struct __DRIimageList *buffers);
88 void (*swrast_put_image2)(__DRIdrawable *driDrawable,
89 int op,
90 int x,
91 int y,
92 int width,
93 int height,
94 int stride,
95 char *data,
96 void *loaderPrivate);
97 void (*swrast_get_image)(__DRIdrawable *driDrawable,
98 int x,
99 int y,
100 int width,
101 int height,
102 char *data,
103 void *loaderPrivate);
104
105 struct wl_drm *wl_drm;
106
107 const struct gbm_dri_visual *visual_table;
108 int num_visuals;
109 };
110
111 struct gbm_dri_bo {
112 struct gbm_bo base;
113
114 __DRIimage *image;
115
116 /* Used for cursors and the swrast front BO */
117 uint32_t handle, size;
118 void *map;
119 };
120
121 struct gbm_dri_surface {
122 struct gbm_surface base;
123
124 void *dri_private;
125 };
126
127 static inline struct gbm_dri_device *
128 gbm_dri_device(struct gbm_device *gbm)
129 {
130 return (struct gbm_dri_device *) gbm;
131 }
132
133 static inline struct gbm_dri_bo *
134 gbm_dri_bo(struct gbm_bo *bo)
135 {
136 return (struct gbm_dri_bo *) bo;
137 }
138
139 static inline struct gbm_dri_surface *
140 gbm_dri_surface(struct gbm_surface *surface)
141 {
142 return (struct gbm_dri_surface *) surface;
143 }
144
145 static inline void *
146 gbm_dri_bo_map_dumb(struct gbm_dri_bo *bo)
147 {
148 struct drm_mode_map_dumb map_arg;
149 int ret;
150
151 if (bo->image != NULL)
152 return NULL;
153
154 if (bo->map != NULL)
155 return bo->map;
156
157 memset(&map_arg, 0, sizeof(map_arg));
158 map_arg.handle = bo->handle;
159
160 ret = drmIoctl(bo->base.gbm->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
161 if (ret)
162 return NULL;
163
164 bo->map = mmap(0, bo->size, PROT_WRITE,
165 MAP_SHARED, bo->base.gbm->fd, map_arg.offset);
166 if (bo->map == MAP_FAILED) {
167 bo->map = NULL;
168 return NULL;
169 }
170
171 return bo->map;
172 }
173
174 static inline void
175 gbm_dri_bo_unmap_dumb(struct gbm_dri_bo *bo)
176 {
177 munmap(bo->map, bo->size);
178 bo->map = NULL;
179 }
180
181 #endif