• 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 #include "utils.h"
33 
34 #include "dri_screen.h"
35 #include "dri_context.h"
36 #include "dri_helpers.h"
37 
38 #include "util/u_inlines.h"
39 #include "pipe/p_screen.h"
40 #include "pipe/p_format.h"
41 #include "pipe-loader/pipe_loader.h"
42 #include "state_tracker/st_gl_api.h" /* for st_gl_api_create */
43 #include "frontend/drm_driver.h"
44 
45 #include "util/u_debug.h"
46 #include "util/format/u_format_s3tc.h"
47 
48 #define MSAA_VISUAL_MAX_SAMPLES 32
49 
50 #undef false
51 
52 const __DRIconfigOptionsExtension gallium_config_options = {
53    .base = { __DRI_CONFIG_OPTIONS, 2 },
54    .getXml = pipe_loader_get_driinfo_xml
55 };
56 
57 #define false 0
58 
59 static void
dri_fill_st_options(struct dri_screen * screen)60 dri_fill_st_options(struct dri_screen *screen)
61 {
62    struct st_config_options *options = &screen->options;
63    const struct driOptionCache *optionCache = &screen->dev->option_cache;
64 
65    options->disable_blend_func_extended =
66       driQueryOptionb(optionCache, "disable_blend_func_extended");
67    options->disable_arb_gpu_shader5 =
68       driQueryOptionb(optionCache, "disable_arb_gpu_shader5");
69    options->disable_glsl_line_continuations =
70       driQueryOptionb(optionCache, "disable_glsl_line_continuations");
71    options->force_glsl_extensions_warn =
72       driQueryOptionb(optionCache, "force_glsl_extensions_warn");
73    options->force_glsl_version =
74       driQueryOptioni(optionCache, "force_glsl_version");
75    options->allow_extra_pp_tokens =
76       driQueryOptionb(optionCache, "allow_extra_pp_tokens");
77    options->allow_glsl_extension_directive_midshader =
78       driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader");
79    options->allow_glsl_120_subset_in_110 =
80       driQueryOptionb(optionCache, "allow_glsl_120_subset_in_110");
81    options->allow_glsl_builtin_const_expression =
82       driQueryOptionb(optionCache, "allow_glsl_builtin_const_expression");
83    options->allow_glsl_relaxed_es =
84       driQueryOptionb(optionCache, "allow_glsl_relaxed_es");
85    options->allow_glsl_builtin_variable_redeclaration =
86       driQueryOptionb(optionCache, "allow_glsl_builtin_variable_redeclaration");
87    options->allow_higher_compat_version =
88       driQueryOptionb(optionCache, "allow_higher_compat_version");
89    options->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");
90    options->force_integer_tex_nearest =
91       driQueryOptionb(optionCache, "force_integer_tex_nearest");
92    options->vs_position_always_invariant =
93       driQueryOptionb(optionCache, "vs_position_always_invariant");
94    options->force_glsl_abs_sqrt =
95       driQueryOptionb(optionCache, "force_glsl_abs_sqrt");
96    options->allow_glsl_cross_stage_interpolation_mismatch =
97       driQueryOptionb(optionCache, "allow_glsl_cross_stage_interpolation_mismatch");
98    options->allow_draw_out_of_order =
99       driQueryOptionb(optionCache, "allow_draw_out_of_order");
100    options->force_gl_names_reuse =
101       driQueryOptionb(optionCache, "force_gl_names_reuse");
102 
103    char *vendor_str = driQueryOptionstr(optionCache, "force_gl_vendor");
104    /* not an empty string */
105    if (*vendor_str)
106       options->force_gl_vendor = strdup(vendor_str);
107 
108    driComputeOptionsSha1(optionCache, options->config_options_sha1);
109 }
110 
111 static unsigned
dri_loader_get_cap(struct dri_screen * screen,enum dri_loader_cap cap)112 dri_loader_get_cap(struct dri_screen *screen, enum dri_loader_cap cap)
113 {
114    const __DRIdri2LoaderExtension *dri2_loader = screen->sPriv->dri2.loader;
115    const __DRIimageLoaderExtension *image_loader = screen->sPriv->image.loader;
116 
117    if (dri2_loader && dri2_loader->base.version >= 4 &&
118        dri2_loader->getCapability)
119       return dri2_loader->getCapability(screen->sPriv->loaderPrivate, cap);
120 
121    if (image_loader && image_loader->base.version >= 2 &&
122        image_loader->getCapability)
123       return image_loader->getCapability(screen->sPriv->loaderPrivate, cap);
124 
125    return 0;
126 }
127 
128 static const __DRIconfig **
dri_fill_in_modes(struct dri_screen * screen)129 dri_fill_in_modes(struct dri_screen *screen)
130 {
131    static const mesa_format mesa_formats[] = {
132       MESA_FORMAT_B10G10R10A2_UNORM,
133       MESA_FORMAT_B10G10R10X2_UNORM,
134       MESA_FORMAT_R10G10B10A2_UNORM,
135       MESA_FORMAT_R10G10B10X2_UNORM,
136       MESA_FORMAT_B8G8R8A8_UNORM,
137       MESA_FORMAT_B8G8R8X8_UNORM,
138       MESA_FORMAT_B8G8R8A8_SRGB,
139       MESA_FORMAT_B8G8R8X8_SRGB,
140       MESA_FORMAT_B5G6R5_UNORM,
141       MESA_FORMAT_RGBA_FLOAT16,
142       MESA_FORMAT_RGBX_FLOAT16,
143 
144       /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
145        * Likewise for RGBX and BGRX.  Otherwise, the GLX client and the GLX
146        * server may disagree on which format the GLXFBConfig represents,
147        * resulting in swapped color channels.
148        *
149        * The problem, as of 2017-05-30:
150        * When matching a GLXFBConfig to a __DRIconfig, GLX ignores the channel
151        * order and chooses the first __DRIconfig with the expected channel
152        * sizes. Specifically, GLX compares the GLXFBConfig's and __DRIconfig's
153        * __DRI_ATTRIB_{CHANNEL}_SIZE but ignores __DRI_ATTRIB_{CHANNEL}_MASK.
154        *
155        * EGL does not suffer from this problem. It correctly compares the
156        * channel masks when matching EGLConfig to __DRIconfig.
157        */
158 
159       /* Required by Android, for HAL_PIXEL_FORMAT_RGBA_8888. */
160       MESA_FORMAT_R8G8B8A8_UNORM,
161 
162       /* Required by Android, for HAL_PIXEL_FORMAT_RGBX_8888. */
163       MESA_FORMAT_R8G8B8X8_UNORM,
164    };
165    static const enum pipe_format pipe_formats[] = {
166       PIPE_FORMAT_B10G10R10A2_UNORM,
167       PIPE_FORMAT_B10G10R10X2_UNORM,
168       PIPE_FORMAT_R10G10B10A2_UNORM,
169       PIPE_FORMAT_R10G10B10X2_UNORM,
170       PIPE_FORMAT_BGRA8888_UNORM,
171       PIPE_FORMAT_BGRX8888_UNORM,
172       PIPE_FORMAT_BGRA8888_SRGB,
173       PIPE_FORMAT_BGRX8888_SRGB,
174       PIPE_FORMAT_B5G6R5_UNORM,
175       PIPE_FORMAT_R16G16B16A16_FLOAT,
176       PIPE_FORMAT_R16G16B16X16_FLOAT,
177       PIPE_FORMAT_RGBA8888_UNORM,
178       PIPE_FORMAT_RGBX8888_UNORM,
179    };
180    mesa_format format;
181    __DRIconfig **configs = NULL;
182    uint8_t depth_bits_array[5];
183    uint8_t stencil_bits_array[5];
184    unsigned depth_buffer_factor;
185    unsigned msaa_samples_max;
186    unsigned i;
187    struct pipe_screen *p_screen = screen->base.screen;
188    bool pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32;
189    bool mixed_color_depth;
190    bool allow_rgba_ordering;
191    bool allow_rgb10;
192    bool allow_fp16;
193 
194    static const GLenum back_buffer_modes[] = {
195       __DRI_ATTRIB_SWAP_NONE, __DRI_ATTRIB_SWAP_UNDEFINED,
196       __DRI_ATTRIB_SWAP_COPY
197    };
198 
199    if (driQueryOptionb(&screen->dev->option_cache, "always_have_depth_buffer")) {
200       /* all visuals will have a depth buffer */
201       depth_buffer_factor = 0;
202    }
203    else {
204       depth_bits_array[0] = 0;
205       stencil_bits_array[0] = 0;
206       depth_buffer_factor = 1;
207    }
208 
209    allow_rgba_ordering = dri_loader_get_cap(screen, DRI_LOADER_CAP_RGBA_ORDERING);
210    allow_rgb10 = driQueryOptionb(&screen->dev->option_cache, "allow_rgb10_configs");
211    allow_fp16 = driQueryOptionb(&screen->dev->option_cache, "allow_fp16_configs");
212    allow_fp16 &= dri_loader_get_cap(screen, DRI_LOADER_CAP_FP16);
213 
214    msaa_samples_max = (screen->st_api->feature_mask & ST_API_FEATURE_MS_VISUALS_MASK)
215       ? MSAA_VISUAL_MAX_SAMPLES : 1;
216 
217    pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM,
218 					    PIPE_TEXTURE_2D, 0, 0,
219                                             PIPE_BIND_DEPTH_STENCIL);
220    pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM,
221 					    PIPE_TEXTURE_2D, 0, 0,
222                                             PIPE_BIND_DEPTH_STENCIL);
223    pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24_UNORM_S8_UINT,
224 					    PIPE_TEXTURE_2D, 0, 0,
225                                             PIPE_BIND_DEPTH_STENCIL);
226    pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8_UINT_Z24_UNORM,
227 					    PIPE_TEXTURE_2D, 0, 0,
228                                             PIPE_BIND_DEPTH_STENCIL);
229    pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM,
230                                           PIPE_TEXTURE_2D, 0, 0,
231                                           PIPE_BIND_DEPTH_STENCIL);
232    pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM,
233                                           PIPE_TEXTURE_2D, 0, 0,
234                                           PIPE_BIND_DEPTH_STENCIL);
235 
236    if (pf_z16) {
237       depth_bits_array[depth_buffer_factor] = 16;
238       stencil_bits_array[depth_buffer_factor++] = 0;
239    }
240    if (pf_x8z24 || pf_z24x8) {
241       depth_bits_array[depth_buffer_factor] = 24;
242       stencil_bits_array[depth_buffer_factor++] = 0;
243       screen->d_depth_bits_last = pf_x8z24;
244    }
245    if (pf_s8z24 || pf_z24s8) {
246       depth_bits_array[depth_buffer_factor] = 24;
247       stencil_bits_array[depth_buffer_factor++] = 8;
248       screen->sd_depth_bits_last = pf_s8z24;
249    }
250    if (pf_z32) {
251       depth_bits_array[depth_buffer_factor] = 32;
252       stencil_bits_array[depth_buffer_factor++] = 0;
253    }
254 
255    mixed_color_depth =
256       p_screen->get_param(p_screen, PIPE_CAP_MIXED_COLOR_DEPTH_BITS);
257 
258    assert(ARRAY_SIZE(mesa_formats) == ARRAY_SIZE(pipe_formats));
259 
260    /* Add configs. */
261    for (format = 0; format < ARRAY_SIZE(mesa_formats); format++) {
262       __DRIconfig **new_configs = NULL;
263       unsigned num_msaa_modes = 0; /* includes a single-sample mode */
264       uint8_t msaa_modes[MSAA_VISUAL_MAX_SAMPLES];
265 
266       /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
267       if (!allow_rgba_ordering &&
268           (mesa_formats[format] == MESA_FORMAT_R8G8B8A8_UNORM ||
269            mesa_formats[format] == MESA_FORMAT_R8G8B8X8_UNORM))
270          continue;
271 
272       if (!allow_rgb10 &&
273           (mesa_formats[format] == MESA_FORMAT_B10G10R10A2_UNORM ||
274            mesa_formats[format] == MESA_FORMAT_B10G10R10X2_UNORM ||
275            mesa_formats[format] == MESA_FORMAT_R10G10B10A2_UNORM ||
276            mesa_formats[format] == MESA_FORMAT_R10G10B10X2_UNORM))
277          continue;
278 
279       if (!allow_fp16 &&
280           (mesa_formats[format] == MESA_FORMAT_RGBA_FLOAT16 ||
281            mesa_formats[format] == MESA_FORMAT_RGBX_FLOAT16))
282          continue;
283 
284       if (!p_screen->is_format_supported(p_screen, pipe_formats[format],
285                                          PIPE_TEXTURE_2D, 0, 0,
286                                          PIPE_BIND_RENDER_TARGET |
287                                          PIPE_BIND_DISPLAY_TARGET))
288          continue;
289 
290       for (i = 1; i <= msaa_samples_max; i++) {
291          int samples = i > 1 ? i : 0;
292 
293          if (p_screen->is_format_supported(p_screen, pipe_formats[format],
294                                            PIPE_TEXTURE_2D, samples, samples,
295                                            PIPE_BIND_RENDER_TARGET)) {
296             msaa_modes[num_msaa_modes++] = samples;
297          }
298       }
299 
300       if (num_msaa_modes) {
301          /* Single-sample configs with an accumulation buffer. */
302          new_configs = driCreateConfigs(mesa_formats[format],
303                                         depth_bits_array, stencil_bits_array,
304                                         depth_buffer_factor, back_buffer_modes,
305                                         ARRAY_SIZE(back_buffer_modes),
306                                         msaa_modes, 1,
307                                         GL_TRUE, !mixed_color_depth, GL_FALSE);
308          configs = driConcatConfigs(configs, new_configs);
309 
310          /* Multi-sample configs without an accumulation buffer. */
311          if (num_msaa_modes > 1) {
312             new_configs = driCreateConfigs(mesa_formats[format],
313                                            depth_bits_array, stencil_bits_array,
314                                            depth_buffer_factor, back_buffer_modes,
315                                            ARRAY_SIZE(back_buffer_modes),
316                                            msaa_modes+1, num_msaa_modes-1,
317                                            GL_FALSE, !mixed_color_depth, GL_FALSE);
318             configs = driConcatConfigs(configs, new_configs);
319          }
320       }
321    }
322 
323    if (configs == NULL) {
324       debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__);
325       return NULL;
326    }
327 
328    return (const __DRIconfig **)configs;
329 }
330 
331 /**
332  * Roughly the converse of dri_fill_in_modes.
333  */
334 void
dri_fill_st_visual(struct st_visual * stvis,const struct dri_screen * screen,const struct gl_config * mode)335 dri_fill_st_visual(struct st_visual *stvis,
336                    const struct dri_screen *screen,
337                    const struct gl_config *mode)
338 {
339    memset(stvis, 0, sizeof(*stvis));
340 
341    if (!mode) {
342       stvis->no_config = true;
343       return;
344    }
345 
346    /* Deduce the color format. */
347    switch (mode->redMask) {
348    case 0:
349       /* Formats > 32 bpp */
350       assert(mode->floatMode);
351       if (mode->alphaShift > -1) {
352          assert(mode->alphaShift == 48);
353          stvis->color_format = PIPE_FORMAT_R16G16B16A16_FLOAT;
354       } else {
355          stvis->color_format = PIPE_FORMAT_R16G16B16X16_FLOAT;
356       }
357       break;
358 
359    case 0x3FF00000:
360       if (mode->alphaMask) {
361          assert(mode->alphaMask == 0xC0000000);
362          stvis->color_format = PIPE_FORMAT_B10G10R10A2_UNORM;
363       } else {
364          stvis->color_format = PIPE_FORMAT_B10G10R10X2_UNORM;
365       }
366       break;
367 
368    case 0x000003FF:
369       if (mode->alphaMask) {
370          assert(mode->alphaMask == 0xC0000000);
371          stvis->color_format = PIPE_FORMAT_R10G10B10A2_UNORM;
372       } else {
373          stvis->color_format = PIPE_FORMAT_R10G10B10X2_UNORM;
374       }
375       break;
376 
377    case 0x00FF0000:
378       if (mode->alphaMask) {
379          assert(mode->alphaMask == 0xFF000000);
380          stvis->color_format = mode->sRGBCapable ?
381                                   PIPE_FORMAT_BGRA8888_SRGB :
382                                   PIPE_FORMAT_BGRA8888_UNORM;
383       } else {
384          stvis->color_format = mode->sRGBCapable ?
385                                   PIPE_FORMAT_BGRX8888_SRGB :
386                                   PIPE_FORMAT_BGRX8888_UNORM;
387       }
388       break;
389 
390    case 0x000000FF:
391       if (mode->alphaMask) {
392          assert(mode->alphaMask == 0xFF000000);
393          stvis->color_format = mode->sRGBCapable ?
394                                   PIPE_FORMAT_RGBA8888_SRGB :
395                                   PIPE_FORMAT_RGBA8888_UNORM;
396       } else {
397          stvis->color_format = mode->sRGBCapable ?
398                                   PIPE_FORMAT_RGBX8888_SRGB :
399                                   PIPE_FORMAT_RGBX8888_UNORM;
400       }
401       break;
402 
403    case 0x0000F800:
404       stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM;
405       break;
406 
407    default:
408       assert(!"unsupported visual: invalid red mask");
409       return;
410    }
411 
412    if (mode->sampleBuffers) {
413       stvis->samples = mode->samples;
414    }
415 
416    switch (mode->depthBits) {
417    default:
418    case 0:
419       stvis->depth_stencil_format = PIPE_FORMAT_NONE;
420       break;
421    case 16:
422       stvis->depth_stencil_format = PIPE_FORMAT_Z16_UNORM;
423       break;
424    case 24:
425       if (mode->stencilBits == 0) {
426 	 stvis->depth_stencil_format = (screen->d_depth_bits_last) ?
427                                           PIPE_FORMAT_Z24X8_UNORM:
428                                           PIPE_FORMAT_X8Z24_UNORM;
429       } else {
430 	 stvis->depth_stencil_format = (screen->sd_depth_bits_last) ?
431                                           PIPE_FORMAT_Z24_UNORM_S8_UINT:
432                                           PIPE_FORMAT_S8_UINT_Z24_UNORM;
433       }
434       break;
435    case 32:
436       stvis->depth_stencil_format = PIPE_FORMAT_Z32_UNORM;
437       break;
438    }
439 
440    stvis->accum_format = (mode->accumRedBits > 0) ?
441       PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE;
442 
443    stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK;
444    stvis->render_buffer = ST_ATTACHMENT_FRONT_LEFT;
445    if (mode->doubleBufferMode) {
446       stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
447       stvis->render_buffer = ST_ATTACHMENT_BACK_LEFT;
448    }
449    if (mode->stereoMode) {
450       stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
451       if (mode->doubleBufferMode)
452          stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
453    }
454 
455    if (mode->depthBits > 0 || mode->stencilBits > 0)
456       stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK;
457    /* let the gallium frontend allocate the accum buffer */
458 }
459 
460 static bool
dri_get_egl_image(struct st_manager * smapi,void * egl_image,struct st_egl_image * stimg)461 dri_get_egl_image(struct st_manager *smapi,
462                   void *egl_image,
463                   struct st_egl_image *stimg)
464 {
465    struct dri_screen *screen = (struct dri_screen *)smapi;
466    __DRIimage *img = NULL;
467    const struct dri2_format_mapping *map;
468 
469    if (screen->lookup_egl_image) {
470       img = screen->lookup_egl_image(screen, egl_image);
471    }
472 
473    if (!img)
474       return FALSE;
475 
476    stimg->texture = NULL;
477    pipe_resource_reference(&stimg->texture, img->texture);
478    map = dri2_get_mapping_by_fourcc(img->dri_fourcc);
479    stimg->format = map ? map->pipe_format : img->texture->format;
480    stimg->level = img->level;
481    stimg->layer = img->layer;
482 
483    if (img->imported_dmabuf && map) {
484       /* Guess sized internal format for dma-bufs. Could be used
485        * by EXT_EGL_image_storage.
486        */
487       mesa_format mesa_format = driImageFormatToGLFormat(map->dri_format);
488       stimg->internalformat = driGLFormatToSizedInternalGLFormat(mesa_format);
489    }
490 
491    return TRUE;
492 }
493 
494 static int
dri_get_param(struct st_manager * smapi,enum st_manager_param param)495 dri_get_param(struct st_manager *smapi,
496               enum st_manager_param param)
497 {
498    struct dri_screen *screen = (struct dri_screen *)smapi;
499 
500    switch(param) {
501    case ST_MANAGER_BROKEN_INVALIDATE:
502       return screen->broken_invalidate;
503    default:
504       return 0;
505    }
506 }
507 
508 void
dri_destroy_screen_helper(struct dri_screen * screen)509 dri_destroy_screen_helper(struct dri_screen * screen)
510 {
511    if (screen->base.destroy)
512       screen->base.destroy(&screen->base);
513 
514    if (screen->st_api && screen->st_api->destroy)
515       screen->st_api->destroy(screen->st_api);
516 
517    if (screen->base.screen)
518       screen->base.screen->destroy(screen->base.screen);
519 
520    mtx_destroy(&screen->opencl_func_mutex);
521 }
522 
523 void
dri_destroy_screen(__DRIscreen * sPriv)524 dri_destroy_screen(__DRIscreen * sPriv)
525 {
526    struct dri_screen *screen = dri_screen(sPriv);
527 
528    dri_destroy_screen_helper(screen);
529 
530    pipe_loader_release(&screen->dev, 1);
531 
532    free(screen->options.force_gl_vendor);
533 
534    /* The caller in dri_util preserves the fd ownership */
535    free(screen);
536    sPriv->driverPrivate = NULL;
537    sPriv->extensions = NULL;
538 }
539 
540 static void
dri_postprocessing_init(struct dri_screen * screen)541 dri_postprocessing_init(struct dri_screen *screen)
542 {
543    unsigned i;
544 
545    for (i = 0; i < PP_FILTERS; i++) {
546       screen->pp_enabled[i] = driQueryOptioni(&screen->dev->option_cache,
547                                               pp_filters[i].name);
548    }
549 }
550 
551 static void
dri_set_background_context(struct st_context_iface * st,struct util_queue_monitoring * queue_info)552 dri_set_background_context(struct st_context_iface *st,
553                            struct util_queue_monitoring *queue_info)
554 {
555    struct dri_context *ctx = (struct dri_context *)st->st_manager_private;
556    const __DRIbackgroundCallableExtension *backgroundCallable =
557       ctx->sPriv->dri2.backgroundCallable;
558 
559    /* Note: Mesa will only call this function if GL multithreading is enabled
560     * We only do that if the loader exposed the __DRI_BACKGROUND_CALLABLE
561     * extension. So we know that backgroundCallable is not NULL.
562     */
563    assert(backgroundCallable);
564    backgroundCallable->setBackgroundContext(ctx->cPriv->loaderPrivate);
565 
566    if (ctx->hud)
567       hud_add_queue_for_monitoring(ctx->hud, queue_info);
568 }
569 
570 void
dri_init_options(struct dri_screen * screen)571 dri_init_options(struct dri_screen *screen)
572 {
573    pipe_loader_load_options(screen->dev);
574 
575    dri_fill_st_options(screen);
576 }
577 
578 const __DRIconfig **
dri_init_screen_helper(struct dri_screen * screen,struct pipe_screen * pscreen)579 dri_init_screen_helper(struct dri_screen *screen,
580                        struct pipe_screen *pscreen)
581 {
582    screen->base.screen = pscreen;
583    screen->base.get_egl_image = dri_get_egl_image;
584    screen->base.get_param = dri_get_param;
585    screen->base.set_background_context = dri_set_background_context;
586 
587    screen->st_api = st_gl_api_create();
588    if (!screen->st_api)
589       return NULL;
590 
591    if(pscreen->get_param(pscreen, PIPE_CAP_NPOT_TEXTURES))
592       screen->target = PIPE_TEXTURE_2D;
593    else
594       screen->target = PIPE_TEXTURE_RECT;
595 
596    dri_postprocessing_init(screen);
597 
598    screen->st_api->query_versions(screen->st_api, &screen->base,
599                                   &screen->options,
600                                   &screen->sPriv->max_gl_core_version,
601                                   &screen->sPriv->max_gl_compat_version,
602                                   &screen->sPriv->max_gl_es1_version,
603                                   &screen->sPriv->max_gl_es2_version);
604 
605    return dri_fill_in_modes(screen);
606 }
607 
608 /* vim: set sw=3 ts=8 sts=3 expandtab: */
609