1 /**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27 /*
28 * Author: Keith Whitwell <[email protected]>
29 * Author: Jakob Bornecrantz <[email protected]>
30 */
31
32 #ifndef DRI_SCREEN_H
33 #define DRI_SCREEN_H
34
35 #include "dri_util.h"
36
37 #include "util/compiler.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_state.h"
40 #include "frontend/api.h"
41 #include "frontend/opencl_interop.h"
42 #include "util/u_thread.h"
43 #include "postprocess/filters.h"
44 #include "kopper_interface.h"
45
46 struct dri_context;
47 struct dri_drawable;
48 struct pipe_loader_device;
49
50 struct dri_screen
51 {
52 /* st_api */
53 struct pipe_frontend_screen base;
54
55 /* dri */
56 /* Current screen's number */
57 int myNum;
58
59 void *loaderPrivate;
60
61 int max_gl_core_version;
62 int max_gl_compat_version;
63 int max_gl_es1_version;
64 int max_gl_es2_version;
65
66 enum dri_screen_type type;
67
68 const __DRIswrastLoaderExtension *swrast_loader;
69 const __DRIkopperLoaderExtension *kopper_loader;
70
71 struct {
72 /* Flag to indicate that this is a DRI2 screen. Many of the above
73 * fields will not be valid or initializaed in that case. */
74 const __DRIdri2LoaderExtension *loader;
75 const __DRIimageLookupExtension *image;
76 const __DRIuseInvalidateExtension *useInvalidate;
77 const __DRIbackgroundCallableExtension *backgroundCallable;
78 } dri2;
79
80 struct {
81 const __DRIimageLoaderExtension *loader;
82 } image;
83
84 struct {
85 const __DRImutableRenderBufferLoaderExtension *loader;
86 } mutableRenderBuffer;
87
88 driOptionCache optionInfo;
89 driOptionCache optionCache;
90
91 unsigned int api_mask;
92
93 bool throttle;
94 bool dmabuf_import;
95
96 struct st_config_options options;
97
98 /* Which postprocessing filters are enabled. */
99 unsigned pp_enabled[PP_FILTERS];
100
101 /* drm */
102 int fd;
103 bool can_share_buffer;
104
105 struct pipe_loader_device *dev;
106
107 /* gallium */
108 bool auto_fake_front;
109 bool has_reset_status_query;
110 bool has_protected_context;
111 enum pipe_texture_target target;
112
113 bool swrast_no_present;
114
115 /* DRI exts that vary based on gallium pipe_screen caps. */
116 __DRIimageExtension image_extension;
117 __DRI2bufferDamageExtension buffer_damage_extension;
118
119 /* DRI exts on this screen. Populated at init time based on device caps. */
120 const __DRIextension *screen_extensions[14];
121
122 /* OpenCL interop */
123 mtx_t opencl_func_mutex;
124 opencl_dri_event_add_ref_t opencl_dri_event_add_ref;
125 opencl_dri_event_release_t opencl_dri_event_release;
126 opencl_dri_event_wait_t opencl_dri_event_wait;
127 opencl_dri_event_get_fence_t opencl_dri_event_get_fence;
128
129 /* kopper */
130 bool has_dmabuf;
131 bool is_sw;
132 };
133
134 /** cast wrapper */
135 static inline struct dri_screen *
dri_screen(__DRIscreen * sPriv)136 dri_screen(__DRIscreen * sPriv)
137 {
138 return (struct dri_screen *)sPriv;
139 }
140
141 static inline __DRIscreen *
opaque_dri_screen(struct dri_screen * screen)142 opaque_dri_screen(struct dri_screen *screen)
143 {
144 return (__DRIscreen *)screen;
145 }
146
147 static inline const __DRIkopperLoaderExtension *
dri_screen_get_kopper(struct dri_screen * screen)148 dri_screen_get_kopper(struct dri_screen *screen)
149 {
150 return screen->kopper_loader;
151 }
152
153 struct __DRIimageRec {
154 struct pipe_resource *texture;
155 unsigned level;
156 unsigned layer;
157 uint32_t dri_format;
158 uint32_t dri_fourcc;
159 uint32_t dri_components;
160 /* Provided by eglCreateImageKHR if creating from a
161 * texture or a renderbuffer. 0 otherwise.
162 */
163 uint32_t internal_format;
164 unsigned use;
165 unsigned plane;
166
167 int in_fence_fd;
168
169 void *loader_private;
170
171 bool imported_dmabuf;
172 /**
173 * Provided by EGL_EXT_image_dma_buf_import.
174 */
175 enum __DRIYUVColorSpace yuv_color_space;
176 enum __DRISampleRange sample_range;
177 enum __DRIChromaSiting horizontal_siting;
178 enum __DRIChromaSiting vertical_siting;
179
180 struct dri_screen *screen;
181 };
182
183 static inline bool
dri_with_format(struct dri_screen * screen)184 dri_with_format(struct dri_screen *screen)
185 {
186 const __DRIdri2LoaderExtension *loader = screen->dri2.loader;
187
188 return loader
189 && (loader->base.version >= 3)
190 && (loader->getBuffersWithFormat != NULL);
191 }
192
193 void
194 dri_fill_st_visual(struct st_visual *stvis,
195 const struct dri_screen *screen,
196 const struct gl_config *mode);
197
198 void
199 dri_init_options(struct dri_screen *screen);
200
201 const __DRIconfig **
202 dri_init_screen(struct dri_screen *screen,
203 struct pipe_screen *pscreen,
204 bool has_multibuffer);
205
206 void
207 dri_release_screen(struct dri_screen * screen);
208
209 void
210 dri_destroy_screen(struct dri_screen *screen);
211
212 struct pipe_screen *
213 dri2_init_screen(struct dri_screen *screen, bool driver_name_is_inferred);
214 struct pipe_screen *
215 dri_swrast_kms_init_screen(struct dri_screen *screen, bool driver_name_is_inferred);
216 struct pipe_screen *
217 kopper_init_screen(struct dri_screen *screen, bool driver_name_is_inferred);
218 struct pipe_screen *
219 drisw_init_screen(struct dri_screen *screen, bool driver_name_is_inferred);
220
221 extern const struct __DriverAPIRec dri_swrast_kms_driver_api;
222 extern const __DRIextension *dri_swrast_kms_driver_extensions[];
223 extern const struct __DriverAPIRec galliumdrm_driver_api;
224 extern const __DRIextension *galliumdrm_driver_extensions[];
225 extern const struct __DriverAPIRec galliumsw_driver_api;
226 extern const __DRIextension *galliumsw_driver_extensions[];
227 extern const struct __DriverAPIRec galliumvk_driver_api;
228 extern const __DRIextension *galliumvk_driver_extensions[];
229 extern const __DRIconfigOptionsExtension gallium_config_options;
230
231 #endif
232
233 /* vim: set sw=3 ts=8 sts=3 expandtab: */
234