• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <keithw@vmware.com>
29  * Author: Jakob Bornecrantz <wallbraker@gmail.com>
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    const __DRIextension **extensions;
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 
95    struct st_config_options options;
96 
97    /* Which postprocessing filters are enabled. */
98    unsigned pp_enabled[PP_FILTERS];
99 
100    /* drm */
101    int fd;
102    bool can_share_buffer;
103 
104    struct pipe_loader_device *dev;
105 
106    /* gallium */
107    bool auto_fake_front;
108    bool has_reset_status_query;
109    bool has_protected_context;
110    enum pipe_texture_target target;
111 
112    bool swrast_no_present;
113 
114    /* hooks filled in by dri2 & drisw */
115    __DRIimage * (*lookup_egl_image)(struct dri_screen *ctx, void *handle);
116    bool (*validate_egl_image)(struct dri_screen *ctx, void *handle);
117    __DRIimage * (*lookup_egl_image_validated)(struct dri_screen *ctx, void *handle);
118 
119    /* DRI exts that vary based on gallium pipe_screen caps. */
120    __DRIimageExtension image_extension;
121    __DRI2bufferDamageExtension buffer_damage_extension;
122 
123    /* DRI exts on this screen. Populated at init time based on device caps. */
124    const __DRIextension *screen_extensions[14];
125 
126    /* OpenCL interop */
127    mtx_t opencl_func_mutex;
128    opencl_dri_event_add_ref_t opencl_dri_event_add_ref;
129    opencl_dri_event_release_t opencl_dri_event_release;
130    opencl_dri_event_wait_t opencl_dri_event_wait;
131    opencl_dri_event_get_fence_t opencl_dri_event_get_fence;
132 
133    /* kopper */
134    struct pipe_screen *unwrapped_screen;
135    bool has_dmabuf;
136    bool has_modifiers;
137    bool is_sw;
138 
139    struct dri_drawable *(*create_drawable)(struct dri_screen *screen,
140                                            const struct gl_config *glVis,
141                                            bool pixmapBuffer,
142                                            void *loaderPrivate);
143 
144    __DRIbuffer *(*allocate_buffer)(struct dri_screen *screen,
145                                    unsigned int attachment,
146                                    unsigned int format,
147                                    int width, int height);
148 
149    void (*release_buffer)(__DRIbuffer *buffer);
150 };
151 
152 /** cast wrapper */
153 static inline struct dri_screen *
dri_screen(__DRIscreen * sPriv)154 dri_screen(__DRIscreen * sPriv)
155 {
156    return (struct dri_screen *)sPriv;
157 }
158 
159 static inline __DRIscreen *
opaque_dri_screen(struct dri_screen * screen)160 opaque_dri_screen(struct dri_screen *screen)
161 {
162    return (__DRIscreen *)screen;
163 }
164 
165 static inline const __DRIkopperLoaderExtension *
dri_screen_get_kopper(struct dri_screen * screen)166 dri_screen_get_kopper(struct dri_screen *screen)
167 {
168    return screen->kopper_loader;
169 }
170 
171 struct __DRIimageRec {
172    struct pipe_resource *texture;
173    unsigned level;
174    unsigned layer;
175    uint32_t dri_format;
176    uint32_t dri_fourcc;
177    uint32_t dri_components;
178    /* Provided by eglCreateImageKHR if creating from a
179     * texture or a renderbuffer. 0 otherwise.
180     */
181    uint32_t internal_format;
182    unsigned use;
183    unsigned plane;
184 
185    int in_fence_fd;
186 
187    void *loader_private;
188 
189    bool imported_dmabuf;
190    /**
191     * Provided by EGL_EXT_image_dma_buf_import.
192     */
193    enum __DRIYUVColorSpace yuv_color_space;
194    enum __DRISampleRange sample_range;
195    enum __DRIChromaSiting horizontal_siting;
196    enum __DRIChromaSiting vertical_siting;
197 
198    struct dri_screen *screen;
199 };
200 
201 static inline bool
dri_with_format(struct dri_screen * screen)202 dri_with_format(struct dri_screen *screen)
203 {
204    const __DRIdri2LoaderExtension *loader = screen->dri2.loader;
205 
206    return loader
207        && (loader->base.version >= 3)
208        && (loader->getBuffersWithFormat != NULL);
209 }
210 
211 void
212 dri_fill_st_visual(struct st_visual *stvis,
213                    const struct dri_screen *screen,
214                    const struct gl_config *mode);
215 
216 void
217 dri_init_options(struct dri_screen *screen);
218 
219 const __DRIconfig **
220 dri_init_screen(struct dri_screen *screen,
221                 struct pipe_screen *pscreen);
222 
223 void
224 dri_release_screen(struct dri_screen * screen);
225 
226 void
227 dri_destroy_screen(struct dri_screen *screen);
228 
229 extern const struct __DriverAPIRec dri_swrast_kms_driver_api;
230 extern const __DRIextension *dri_swrast_kms_driver_extensions[];
231 extern const struct __DriverAPIRec galliumdrm_driver_api;
232 extern const __DRIextension *galliumdrm_driver_extensions[];
233 extern const struct __DriverAPIRec galliumsw_driver_api;
234 extern const __DRIextension *galliumsw_driver_extensions[];
235 extern const struct __DriverAPIRec galliumvk_driver_api;
236 extern const __DRIextension *galliumvk_driver_extensions[];
237 extern const __DRIconfigOptionsExtension gallium_config_options;
238 
239 #endif
240 
241 /* vim: set sw=3 ts=8 sts=3 expandtab: */
242