• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <kevin@precisioninsight.com>
31  * \author Brian Paul <brian@precisioninsight.com>
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 struct dri_screen;
49 struct mesa_glinterop_device_info;
50 struct mesa_glinterop_export_in;
51 struct mesa_glinterop_export_out;
52 struct mesa_glinterop_flush_out;
53 
54 #define __DRI_BACKEND_VTABLE "DRI_DriverVtable"
55 
56 struct dri_config {
57     struct gl_config modes;
58 };
59 
60 enum dri_screen_type {
61    DRI_SCREEN_DRI3,
62    DRI_SCREEN_KOPPER,
63    DRI_SCREEN_SWRAST,
64    DRI_SCREEN_KMS_SWRAST,
65 };
66 
67 /**
68  * Description of the attributes used to create a config.
69  *
70  * This is passed as the context_config parameter to CreateContext. The idea
71  * with this struct is that it can be extended without having to modify all of
72  * the drivers. The first three members (major/minor_version and flags) are
73  * always valid, but the remaining members are only valid if the corresponding
74  * flag is set for the attribute. If the flag is not set then the default
75  * value should be assumed. That way the driver can quickly check if any
76  * attributes were set that it doesn't understand and report an error.
77  */
78 struct __DriverContextConfig {
79     /* These members are always valid */
80     unsigned major_version;
81     unsigned minor_version;
82     uint32_t flags;
83 
84     /* Flags describing which of the remaining members are valid */
85     uint32_t attribute_mask;
86 
87     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY is set */
88     int reset_strategy;
89 
90     /* Only valid if __DRIVER_CONTEXT_PRIORITY is set */
91     unsigned priority;
92 
93     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR is set */
94     int release_behavior;
95 
96     /* Only valid if __DRIVER_CONTEXT_ATTRIB_NO_ERROR is set */
97     int no_error;
98 
99     /* Only valid if __DRIVER_CONTEXT_ATTRIB_PROTECTED is set */
100     int protected_context;
101 };
102 
103 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY   (1 << 0)
104 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY         (1 << 1)
105 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
106 #define __DRIVER_CONTEXT_ATTRIB_NO_ERROR         (1 << 3)
107 #define __DRIVER_CONTEXT_ATTRIB_PROTECTED        (1 << 4)
108 
109 PUBLIC struct dri_screen *
110 driCreateNewScreen3(int scrn, int fd,
111                     const __DRIextension **loader_extensions,
112                     enum dri_screen_type type,
113                     const struct dri_config ***driver_configs, bool driver_name_is_inferred,
114                     bool has_multibuffer, void *data);
115 PUBLIC struct dri_context *
116 driCreateContextAttribs(struct dri_screen *psp, int api,
117                         const struct dri_config *config,
118                         struct dri_context *shared,
119                         unsigned num_attribs,
120                         const uint32_t *attribs,
121                         unsigned *error,
122                         void *data);
123 
124 extern uint32_t
125 driImageFormatToSizedInternalGLFormat(uint32_t image_format);
126 PUBLIC unsigned int
127 driGetAPIMask(struct dri_screen *screen);
128 PUBLIC struct dri_drawable *
129 dri_create_drawable(struct dri_screen *psp, const struct dri_config *config,
130                     bool isPixmap, void *loaderPrivate);
131 extern const __DRIimageDriverExtension driImageDriverExtension;
132 PUBLIC void driDestroyScreen(struct dri_screen *psp);
133 PUBLIC int
134 driGetConfigAttrib(const struct dri_config *config, unsigned int attrib, unsigned int *value);
135 PUBLIC int
136 driIndexConfigAttrib(const struct dri_config *config, int index, unsigned int *attrib, unsigned int *value);
137 PUBLIC void
138 driDestroyDrawable(struct dri_drawable *drawable);
139 PUBLIC void
140 driSwapBuffers(struct dri_drawable *drawable);
141 PUBLIC void
142 driSwapBuffersWithDamage(struct dri_drawable *drawable, int nrects, const int *rects);
143 PUBLIC struct dri_context *
144 driCreateNewContext(struct dri_screen *screen, const struct dri_config *config, struct dri_context *shared, void *data);
145 PUBLIC int
146 driCopyContext(struct dri_context *dest, struct dri_context *src, unsigned long mask);
147 PUBLIC void
148 driDestroyContext(struct dri_context *ctx);
149 PUBLIC int driBindContext(struct dri_context *ctx, struct dri_drawable *draw, struct dri_drawable *read);
150 PUBLIC int driUnbindContext(struct dri_context *ctx);
151 
152 
153 PUBLIC int64_t
154 kopperSwapBuffers(struct dri_drawable *dPriv, uint32_t flush_flags);
155 PUBLIC int64_t
156 kopperSwapBuffersWithDamage(struct dri_drawable *drawable, uint32_t flush_flags, int nrects, const int *rects);
157 PUBLIC struct dri_drawable *
158 kopperCreateNewDrawable(struct dri_screen *psp,
159                         const struct dri_config *config,
160                         void *data,
161                         __DRIkopperDrawableInfo *info);
162 PUBLIC void
163 kopperSetSwapInterval(struct dri_drawable *drawable, int interval);
164 PUBLIC int
165 kopperQueryBufferAge(struct dri_drawable *drawable);
166 
167 PUBLIC void
168 driswCopySubBuffer(struct dri_drawable *drawable, int x, int y, int w, int h);
169 
170 PUBLIC void
171 dri_set_tex_buffer2(struct dri_context *ctx, GLint target,
172                     GLint format, struct dri_drawable *drawable);
173 
174 PUBLIC int
175 dri_query_renderer_string(struct dri_screen *_screen, int param,
176                            const char **value);
177 PUBLIC int
178 dri_query_renderer_integer(struct dri_screen *_screen, int param,
179                             unsigned int *value);
180 
181 PUBLIC void
182 dri_flush_drawable(struct dri_drawable *dPriv);
183 PUBLIC void
184 dri_flush(struct dri_context *cPriv,
185           struct dri_drawable *dPriv,
186           unsigned flags,
187           enum __DRI2throttleReason reason);
188 PUBLIC void
189 dri_invalidate_drawable(struct dri_drawable *drawable);
190 
191 PUBLIC int
192 dri2GalliumConfigQueryb(struct dri_screen *sPriv, const char *var,
193                         unsigned char *val);
194 PUBLIC int
195 dri2GalliumConfigQueryi(struct dri_screen *sPriv, const char *var, int *val);
196 PUBLIC int
197 dri2GalliumConfigQueryf(struct dri_screen *sPriv, const char *var, float *val);
198 PUBLIC int
199 dri2GalliumConfigQuerys(struct dri_screen *sPriv, const char *var, char **val);
200 
201 PUBLIC int dri_get_initial_swap_interval(struct dri_screen *driScreen);
202 PUBLIC bool dri_valid_swap_interval(struct dri_screen *driScreen, int interval);
203 
204 PUBLIC void
205 dri_throttle(struct dri_context *cPriv, struct dri_drawable *dPriv,
206              enum __DRI2throttleReason reason);
207 
208 PUBLIC int
209 dri_interop_query_device_info(struct dri_context *ctx,
210                               struct mesa_glinterop_device_info *out);
211 PUBLIC int
212 dri_interop_export_object(struct dri_context *ctx,
213                           struct mesa_glinterop_export_in *in,
214                           struct mesa_glinterop_export_out *out);
215 PUBLIC int
216 dri_interop_flush_objects(struct dri_context *_ctx,
217                            unsigned count, struct mesa_glinterop_export_in *objects,
218                            struct mesa_glinterop_flush_out *out);
219 
220 PUBLIC struct dri_image *
221 dri_create_image_from_renderbuffer(struct dri_context *dri_ctx,
222                                    int renderbuffer, void *loaderPrivate,
223                                    unsigned *error);
224 
225 PUBLIC void
226 dri2_destroy_image(struct dri_image *img);
227 
228 PUBLIC struct dri_image *
229 dri2_create_from_texture(struct dri_context *dri_ctx, int target, unsigned texture,
230                          int depth, int level, unsigned *error,
231                          void *loaderPrivate);
232 
233 PUBLIC struct dri_image *
234 dri_create_image(struct dri_screen *screen,
235                  int width, int height,
236                  int format,
237                  const uint64_t *modifiers,
238                  const unsigned _count,
239                  unsigned int use,
240                  void *loaderPrivate);
241 PUBLIC GLboolean
242 dri2_query_image(struct dri_image *image, int attrib, int *value);
243 PUBLIC struct dri_image *
244 dri2_dup_image(struct dri_image *image, void *loaderPrivate);
245 PUBLIC GLboolean
246 dri2_validate_usage(struct dri_image *image, unsigned int use);
247 PUBLIC struct dri_image *
248 dri2_from_names(struct dri_screen *screen, int width, int height, int fourcc,
249                 int *names, int num_names, int *strides, int *offsets,
250                 void *loaderPrivate);
251 PUBLIC struct dri_image *
252 dri2_from_planar(struct dri_image *image, int plane, void *loaderPrivate);
253 PUBLIC struct dri_image *
254 dri2_from_dma_bufs(struct dri_screen *screen,
255                     int width, int height, int fourcc,
256                     uint64_t modifier, int *fds, int num_fds,
257                     int *strides, int *offsets,
258                     enum __DRIYUVColorSpace yuv_color_space,
259                     enum __DRISampleRange sample_range,
260                     enum __DRIChromaSiting horizontal_siting,
261                     enum __DRIChromaSiting vertical_siting,
262                     uint32_t dri_flags,
263                     unsigned *error,
264                     void *loaderPrivate);
265 PUBLIC void
266 dri2_blit_image(struct dri_context *ctx, struct dri_image *dst, struct dri_image *src,
267                 int dstx0, int dsty0, int dstwidth, int dstheight,
268                 int srcx0, int srcy0, int srcwidth, int srcheight,
269                 int flush_flag);
270 PUBLIC int
271 dri2_get_capabilities(struct dri_screen *_screen);
272 PUBLIC void *
273 dri2_map_image(struct dri_context *ctx, struct dri_image *image,
274                int x0, int y0, int width, int height,
275                unsigned int flags, int *stride, void **data);
276 PUBLIC void
277 dri2_unmap_image(struct dri_context *ctx, struct dri_image *image, void *data);
278 PUBLIC bool
279 dri_query_dma_buf_formats(struct dri_screen *_screen, int max, int *formats,
280                            int *count);
281 PUBLIC bool
282 dri_query_dma_buf_modifiers(struct dri_screen *_screen, int fourcc, int max,
283                              uint64_t *modifiers, unsigned int *external_only,
284                              int *count);
285 PUBLIC bool
286 dri2_query_dma_buf_format_modifier_attribs(struct dri_screen *_screen,
287                                            uint32_t fourcc, uint64_t modifier,
288                                            int attrib, uint64_t *value);
289 PUBLIC struct dri_image *
290 dri_create_image_with_modifiers(struct dri_screen *screen,
291                                  uint32_t width, uint32_t height,
292                                  uint32_t dri_format, uint32_t dri_usage,
293                                  const uint64_t *modifiers,
294                                  unsigned int modifiers_count,
295                                  void *loaderPrivate);
296 PUBLIC int
297 dri_query_compatible_render_only_device_fd(int kms_only_fd);
298 
299 PUBLIC int
300 driSWRastQueryBufferAge(struct dri_drawable *drawable);
301 
302 PUBLIC void
303 dri2_set_in_fence_fd(struct dri_image *img, int fd);
304 
305 PUBLIC bool
306 dri2_query_compression_rates(struct dri_screen *_screen, const struct dri_config *config, int max,
307                              enum __DRIFixedRateCompression *rates, int *count);
308 PUBLIC bool
309 dri2_query_compression_modifiers(struct dri_screen *_screen, uint32_t fourcc,
310                                  enum __DRIFixedRateCompression rate, int max,
311                                  uint64_t *modifiers, int *count);
312 
313 PUBLIC void
314 dri_set_damage_region(struct dri_drawable *drawable, unsigned int nrects, int *rects);
315 
316 PUBLIC unsigned
317 dri_fence_get_caps(struct dri_screen *screen);
318 PUBLIC void *
319 dri_create_fence(struct dri_context *ctx);
320 PUBLIC void *
321 dri_create_fence_fd(struct dri_context *_ctx, int fd);
322 PUBLIC int
323 dri_get_fence_fd(struct dri_screen *driscreen, void *_fence);
324 PUBLIC void *
325 dri_get_fence_from_cl_event(struct dri_screen *driscreen, intptr_t cl_event);
326 PUBLIC void
327 dri_destroy_fence(struct dri_screen *driscreen, void *_fence);
328 PUBLIC GLboolean
329 dri_client_wait_sync(struct dri_context *_ctx, void *_fence, unsigned flags,
330                       uint64_t timeout);
331 PUBLIC void
332 dri_server_wait_sync(struct dri_context *ctx, void *_fence, unsigned flags);
333 
334 PUBLIC void
335 dri_set_blob_cache_funcs(struct dri_screen *screen, __DRIblobCacheSet set,
336                          __DRIblobCacheGet get);
337 
338 PUBLIC struct pipe_screen *
339 dri_get_pipe_screen(struct dri_screen *driScreen);
340 #endif /* _DRI_UTIL_H_ */
341