xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/dri/dri_util.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 /**
27  * \file dri_util.h
28  * DRI utility functions definitions.
29  *
30  * \author Kevin E. Martin <[email protected]>
31  * \author Brian Paul <[email protected]>
32  */
33 
34 #ifndef _DRI_UTIL_H_
35 #define _DRI_UTIL_H_
36 
37 #include <GL/gl.h>
38 #include "mesa_interface.h"
39 #include "kopper_interface.h"
40 #include "main/formats.h"
41 #include "main/glconfig.h"
42 #include "main/menums.h"
43 #include "util/xmlconfig.h"
44 #include "pipe/p_defines.h"
45 #include <stdbool.h>
46 
47 struct pipe_screen;
48 
49 struct dri_screen;
50 
51 #define __DRI_BACKEND_VTABLE "DRI_DriverVtable"
52 
53 struct __DRIconfigRec {
54     struct gl_config modes;
55 };
56 
57 enum dri_screen_type {
58    DRI_SCREEN_DRI3,
59    DRI_SCREEN_KOPPER,
60    DRI_SCREEN_SWRAST,
61    DRI_SCREEN_KMS_SWRAST,
62 };
63 
64 /**
65  * Description of the attributes used to create a config.
66  *
67  * This is passed as the context_config parameter to CreateContext. The idea
68  * with this struct is that it can be extended without having to modify all of
69  * the drivers. The first three members (major/minor_version and flags) are
70  * always valid, but the remaining members are only valid if the corresponding
71  * flag is set for the attribute. If the flag is not set then the default
72  * value should be assumed. That way the driver can quickly check if any
73  * attributes were set that it doesn't understand and report an error.
74  */
75 struct __DriverContextConfig {
76     /* These members are always valid */
77     unsigned major_version;
78     unsigned minor_version;
79     uint32_t flags;
80 
81     /* Flags describing which of the remaining members are valid */
82     uint32_t attribute_mask;
83 
84     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY is set */
85     int reset_strategy;
86 
87     /* Only valid if __DRIVER_CONTEXT_PRIORITY is set */
88     unsigned priority;
89 
90     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR is set */
91     int release_behavior;
92 
93     /* Only valid if __DRIVER_CONTEXT_ATTRIB_NO_ERROR is set */
94     int no_error;
95 
96     /* Only valid if __DRIVER_CONTEXT_ATTRIB_PROTECTED is set */
97     int protected_context;
98 };
99 
100 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY   (1 << 0)
101 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY         (1 << 1)
102 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
103 #define __DRIVER_CONTEXT_ATTRIB_NO_ERROR         (1 << 3)
104 #define __DRIVER_CONTEXT_ATTRIB_PROTECTED        (1 << 4)
105 
106 PUBLIC __DRIscreen *
107 driCreateNewScreen3(int scrn, int fd,
108                     const __DRIextension **loader_extensions,
109                     enum dri_screen_type type,
110                     const __DRIconfig ***driver_configs, bool driver_name_is_inferred,
111                     bool has_multibuffer, void *data);
112 PUBLIC __DRIcontext *
113 driCreateContextAttribs(__DRIscreen *psp, int api,
114                         const __DRIconfig *config,
115                         __DRIcontext *shared,
116                         unsigned num_attribs,
117                         const uint32_t *attribs,
118                         unsigned *error,
119                         void *data);
120 
121 extern uint32_t
122 driImageFormatToSizedInternalGLFormat(uint32_t image_format);
123 PUBLIC unsigned int
124 driGetAPIMask(__DRIscreen *screen);
125 PUBLIC __DRIdrawable *
126 dri_create_drawable(__DRIscreen *psp, const __DRIconfig *config,
127                     bool isPixmap, void *loaderPrivate);
128 extern const __DRIimageDriverExtension driImageDriverExtension;
129 PUBLIC void driDestroyScreen(__DRIscreen *psp);
130 PUBLIC int
131 driGetConfigAttrib(const __DRIconfig *config, unsigned int attrib, unsigned int *value);
132 PUBLIC int
133 driIndexConfigAttrib(const __DRIconfig *config, int index, unsigned int *attrib, unsigned int *value);
134 PUBLIC void
135 driDestroyDrawable(__DRIdrawable *pdp);
136 PUBLIC void
137 driSwapBuffers(__DRIdrawable *pdp);
138 PUBLIC void
139 driSwapBuffersWithDamage(__DRIdrawable *pdp, int nrects, const int *rects);
140 PUBLIC __DRIcontext *
141 driCreateNewContext(__DRIscreen *screen, const __DRIconfig *config, __DRIcontext *shared, void *data);
142 PUBLIC int
143 driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask);
144 PUBLIC void
145 driDestroyContext(__DRIcontext *pcp);
146 PUBLIC int driBindContext(__DRIcontext *pcp, __DRIdrawable *pdp, __DRIdrawable *prp);
147 PUBLIC int driUnbindContext(__DRIcontext *pcp);
148 
149 
150 PUBLIC int64_t
151 kopperSwapBuffers(__DRIdrawable *dPriv, uint32_t flush_flags);
152 PUBLIC int64_t
153 kopperSwapBuffersWithDamage(__DRIdrawable *dPriv, uint32_t flush_flags, int nrects, const int *rects);
154 PUBLIC __DRIdrawable *
155 kopperCreateNewDrawable(__DRIscreen *psp,
156                         const __DRIconfig *config,
157                         void *data,
158                         __DRIkopperDrawableInfo *info);
159 PUBLIC void
160 kopperSetSwapInterval(__DRIdrawable *dPriv, int interval);
161 PUBLIC int
162 kopperQueryBufferAge(__DRIdrawable *dPriv);
163 
164 PUBLIC void
165 driswCopySubBuffer(__DRIdrawable *pdp, int x, int y, int w, int h);
166 
167 PUBLIC void
168 dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
169                     GLint format, __DRIdrawable *dPriv);
170 
171 PUBLIC int
172 dri_query_renderer_string(__DRIscreen *_screen, int param,
173                            const char **value);
174 PUBLIC int
175 dri_query_renderer_integer(__DRIscreen *_screen, int param,
176                             unsigned int *value);
177 
178 PUBLIC void
179 dri_flush_drawable(__DRIdrawable *dPriv);
180 PUBLIC void
181 dri_flush(__DRIcontext *cPriv,
182           __DRIdrawable *dPriv,
183           unsigned flags,
184           enum __DRI2throttleReason reason);
185 PUBLIC void
186 dri_invalidate_drawable(__DRIdrawable *dPriv);
187 
188 PUBLIC int
189 dri2GalliumConfigQueryb(__DRIscreen *sPriv, const char *var,
190                         unsigned char *val);
191 PUBLIC int
192 dri2GalliumConfigQueryi(__DRIscreen *sPriv, const char *var, int *val);
193 PUBLIC int
194 dri2GalliumConfigQueryf(__DRIscreen *sPriv, const char *var, float *val);
195 PUBLIC int
196 dri2GalliumConfigQuerys(__DRIscreen *sPriv, const char *var, char **val);
197 
198 PUBLIC int dri_get_initial_swap_interval(__DRIscreen *driScreen);
199 PUBLIC bool dri_valid_swap_interval(__DRIscreen *driScreen, int interval);
200 
201 PUBLIC void
202 dri_throttle(__DRIcontext *cPriv, __DRIdrawable *dPriv,
203              enum __DRI2throttleReason reason);
204 
205 PUBLIC int
206 dri_interop_query_device_info(__DRIcontext *_ctx,
207                                struct mesa_glinterop_device_info *out);
208 PUBLIC int
209 dri_interop_export_object(__DRIcontext *_ctx,
210                            struct mesa_glinterop_export_in *in,
211                            struct mesa_glinterop_export_out *out);
212 PUBLIC int
213 dri_interop_flush_objects(__DRIcontext *_ctx,
214                            unsigned count, struct mesa_glinterop_export_in *objects,
215                            struct mesa_glinterop_flush_out *out);
216 
217 PUBLIC __DRIimage *
218 dri_create_image_from_renderbuffer(__DRIcontext *context,
219 				     int renderbuffer, void *loaderPrivate,
220                                      unsigned *error);
221 
222 PUBLIC void
223 dri2_destroy_image(__DRIimage *img);
224 
225 PUBLIC __DRIimage *
226 dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
227                          int depth, int level, unsigned *error,
228                          void *loaderPrivate);
229 
230 PUBLIC __DRIimage *
231 dri_create_image(__DRIscreen *_screen,
232                   int width, int height,
233                   int format,
234                   const uint64_t *modifiers,
235                   const unsigned _count,
236                   unsigned int use,
237                   void *loaderPrivate);
238 PUBLIC GLboolean
239 dri2_query_image(__DRIimage *image, int attrib, int *value);
240 PUBLIC __DRIimage *
241 dri2_dup_image(__DRIimage *image, void *loaderPrivate);
242 PUBLIC GLboolean
243 dri2_validate_usage(__DRIimage *image, unsigned int use);
244 PUBLIC __DRIimage *
245 dri2_from_names(__DRIscreen *screen, int width, int height, int fourcc,
246                 int *names, int num_names, int *strides, int *offsets,
247                 void *loaderPrivate);
248 PUBLIC __DRIimage *
249 dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate);
250 PUBLIC __DRIimage *
251 dri2_from_dma_bufs(__DRIscreen *screen,
252                     int width, int height, int fourcc,
253                     uint64_t modifier, int *fds, int num_fds,
254                     int *strides, int *offsets,
255                     enum __DRIYUVColorSpace yuv_color_space,
256                     enum __DRISampleRange sample_range,
257                     enum __DRIChromaSiting horizontal_siting,
258                     enum __DRIChromaSiting vertical_siting,
259                     uint32_t dri_flags,
260                     unsigned *error,
261                     void *loaderPrivate);
262 PUBLIC void
263 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
264                 int dstx0, int dsty0, int dstwidth, int dstheight,
265                 int srcx0, int srcy0, int srcwidth, int srcheight,
266                 int flush_flag);
267 PUBLIC int
268 dri2_get_capabilities(__DRIscreen *_screen);
269 PUBLIC void *
270 dri2_map_image(__DRIcontext *context, __DRIimage *image,
271                 int x0, int y0, int width, int height,
272                 unsigned int flags, int *stride, void **data);
273 PUBLIC void
274 dri2_unmap_image(__DRIcontext *context, __DRIimage *image, void *data);
275 PUBLIC bool
276 dri_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
277                            int *count);
278 PUBLIC bool
279 dri_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
280                              uint64_t *modifiers, unsigned int *external_only,
281                              int *count);
282 PUBLIC bool
283 dri2_query_dma_buf_format_modifier_attribs(__DRIscreen *_screen,
284                                            uint32_t fourcc, uint64_t modifier,
285                                            int attrib, uint64_t *value);
286 PUBLIC __DRIimage *
287 dri_create_image_with_modifiers(__DRIscreen *screen,
288                                  uint32_t width, uint32_t height,
289                                  uint32_t dri_format, uint32_t dri_usage,
290                                  const uint64_t *modifiers,
291                                  unsigned int modifiers_count,
292                                  void *loaderPrivate);
293 PUBLIC int
294 dri_query_compatible_render_only_device_fd(int kms_only_fd);
295 
296 PUBLIC int
297 driSWRastQueryBufferAge(__DRIdrawable *pdp);
298 
299 PUBLIC void
300 dri2_set_in_fence_fd(__DRIimage *img, int fd);
301 
302 PUBLIC bool
303 dri2_query_compression_rates(__DRIscreen *_screen, const __DRIconfig *config, int max,
304                              enum __DRIFixedRateCompression *rates, int *count);
305 PUBLIC bool
306 dri2_query_compression_modifiers(__DRIscreen *_screen, uint32_t fourcc,
307                                  enum __DRIFixedRateCompression rate, int max,
308                                  uint64_t *modifiers, int *count);
309 
310 PUBLIC void
311 dri_set_damage_region(__DRIdrawable *dPriv, unsigned int nrects, int *rects);
312 
313 PUBLIC unsigned
314 dri_fence_get_caps(__DRIscreen *_screen);
315 PUBLIC void *
316 dri_create_fence(__DRIcontext *_ctx);
317 PUBLIC void *
318 dri_create_fence_fd(__DRIcontext *_ctx, int fd);
319 PUBLIC int
320 dri_get_fence_fd(__DRIscreen *_screen, void *_fence);
321 PUBLIC void *
322 dri_get_fence_from_cl_event(__DRIscreen *_screen, intptr_t cl_event);
323 PUBLIC void
324 dri_destroy_fence(__DRIscreen *_screen, void *_fence);
325 PUBLIC GLboolean
326 dri_client_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags,
327                       uint64_t timeout);
328 PUBLIC void
329 dri_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags);
330 
331 PUBLIC void
332 dri_set_blob_cache_funcs(__DRIscreen *sPriv, __DRIblobCacheSet set,
333                          __DRIblobCacheGet get);
334 
335 PUBLIC struct pipe_screen *
336 dri_get_pipe_screen(__DRIscreen *driScreen);
337 PUBLIC int
338 dri_get_screen_param(__DRIscreen *driScreen, enum pipe_cap param);
339 #endif /* _DRI_UTIL_H_ */
340