1 /*
2  * Copyright © 2013 Keith Packard
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22 
23 #ifndef _DRI3_H_
24 #define _DRI3_H_
25 
26 #ifdef DRI3
27 
28 #include <X11/extensions/dri3proto.h>
29 #include <randrstr.h>
30 
31 #define DRI3_SCREEN_INFO_VERSION        2
32 
33 typedef int (*dri3_open_proc)(ScreenPtr screen,
34                               RRProviderPtr provider,
35                               int *fd);
36 
37 typedef int (*dri3_open_client_proc)(ClientPtr client,
38                                      ScreenPtr screen,
39                                      RRProviderPtr provider,
40                                      int *fd);
41 
42 typedef PixmapPtr (*dri3_pixmap_from_fd_proc) (ScreenPtr screen,
43                                                int fd,
44                                                CARD16 width,
45                                                CARD16 height,
46                                                CARD16 stride,
47                                                CARD8 depth,
48                                                CARD8 bpp);
49 
50 typedef PixmapPtr (*dri3_pixmap_from_fds_proc) (ScreenPtr screen,
51                                                 CARD8 num_fds,
52                                                 const int *fds,
53                                                 CARD16 width,
54                                                 CARD16 height,
55                                                 const CARD32 *strides,
56                                                 const CARD32 *offsets,
57                                                 CARD8 depth,
58                                                 CARD8 bpp,
59                                                 CARD64 modifier);
60 
61 typedef int (*dri3_fd_from_pixmap_proc) (ScreenPtr screen,
62                                          PixmapPtr pixmap,
63                                          CARD16 *stride,
64                                          CARD32 *size);
65 
66 typedef int (*dri3_fds_from_pixmap_proc) (ScreenPtr screen,
67                                           PixmapPtr pixmap,
68                                           int *fds,
69                                           uint32_t *strides,
70                                           uint32_t *offsets,
71                                           uint64_t *modifier);
72 
73 typedef int (*dri3_get_formats_proc) (ScreenPtr screen,
74                                       CARD32 *num_formats,
75                                       CARD32 **formats);
76 
77 typedef int (*dri3_get_modifiers_proc) (ScreenPtr screen,
78                                         uint32_t format,
79                                         uint32_t *num_modifiers,
80                                         uint64_t **modifiers);
81 
82 typedef int (*dri3_get_drawable_modifiers_proc) (DrawablePtr draw,
83                                                  uint32_t format,
84                                                  uint32_t *num_modifiers,
85                                                  uint64_t **modifiers);
86 
87 typedef struct dri3_screen_info {
88     uint32_t                    version;
89 
90     dri3_open_proc              open;
91     dri3_pixmap_from_fd_proc    pixmap_from_fd;
92     dri3_fd_from_pixmap_proc    fd_from_pixmap;
93 
94     /* Version 1 */
95     dri3_open_client_proc       open_client;
96 
97     /* Version 2 */
98     dri3_pixmap_from_fds_proc   pixmap_from_fds;
99     dri3_fds_from_pixmap_proc   fds_from_pixmap;
100     dri3_get_formats_proc       get_formats;
101     dri3_get_modifiers_proc     get_modifiers;
102     dri3_get_drawable_modifiers_proc get_drawable_modifiers;
103 
104 } dri3_screen_info_rec, *dri3_screen_info_ptr;
105 
106 extern _X_EXPORT Bool
107 dri3_screen_init(ScreenPtr screen, const dri3_screen_info_rec *info);
108 
109 extern _X_EXPORT int
110 dri3_send_open_reply(ClientPtr client, int fd);
111 
112 extern _X_EXPORT uint32_t
113 drm_format_for_depth(uint32_t depth, uint32_t bpp);
114 
115 #endif
116 
117 #endif /* _DRI3_H_ */
118