1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
33 #ifndef __NOT_HAVE_DRM_H
38 #include "dri_screen.h"
39 #include "dri_context.h"
40 #include "dri_drawable.h"
41 #include "dri_st_api.h"
42 #include "dri1_helper.h"
43 #ifndef __NOT_HAVE_DRM_H
50 #include "util/u_inlines.h"
51 #include "pipe/p_screen.h"
52 #include "pipe/p_format.h"
53 #include "state_tracker/drm_api.h"
55 #include "util/u_debug.h"
57 PUBLIC
const char __driConfigOptions
[] =
58 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
59 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
60 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
61 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
62 /* DRI_CONF_FORCE_S3TC_ENABLE(false) */
63 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
64 DRI_CONF_SECTION_END DRI_CONF_END
;
66 const uint __driNConfigOptions
= 3;
69 dri_fill_in_modes(struct dri_screen
*screen
,
72 __DRIconfig
**configs
= NULL
;
73 __DRIconfig
**configs_r5g6b5
= NULL
;
74 __DRIconfig
**configs_a8r8g8b8
= NULL
;
75 __DRIconfig
**configs_x8r8g8b8
= NULL
;
77 uint8_t depth_bits_array
[5];
78 uint8_t stencil_bits_array
[5];
79 uint8_t msaa_samples_array
[2];
80 unsigned depth_buffer_factor
;
81 unsigned back_buffer_factor
;
82 unsigned msaa_samples_factor
;
83 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
84 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
85 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
87 static const GLenum back_buffer_modes
[] = {
88 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
91 depth_bits_array
[0] = 0;
92 stencil_bits_array
[0] = 0;
93 depth_buffer_factor
= 1;
95 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
97 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
98 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
100 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
101 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
103 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
104 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
106 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
107 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8A8_UNORM
,
109 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
110 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8X8_UNORM
,
112 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
113 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B5G6R5_UNORM
,
115 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
117 /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
118 if (dri_with_format(screen
->sPriv
)) {
119 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
121 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
122 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
124 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
131 depth_bits_array
[depth_buffer_factor
] = 16;
132 stencil_bits_array
[depth_buffer_factor
++] = 0;
134 if (pf_x8z24
|| pf_z24x8
) {
135 depth_bits_array
[depth_buffer_factor
] = 24;
136 stencil_bits_array
[depth_buffer_factor
++] = 0;
137 screen
->d_depth_bits_last
= pf_x8z24
;
139 if (pf_s8z24
|| pf_z24s8
) {
140 depth_bits_array
[depth_buffer_factor
] = 24;
141 stencil_bits_array
[depth_buffer_factor
++] = 8;
142 screen
->sd_depth_bits_last
= pf_s8z24
;
145 depth_bits_array
[depth_buffer_factor
] = 32;
146 stencil_bits_array
[depth_buffer_factor
++] = 0;
149 msaa_samples_array
[0] = 0;
150 msaa_samples_array
[1] = 4;
151 back_buffer_factor
= 3;
152 msaa_samples_factor
= 2;
155 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
158 configs_r5g6b5
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
159 depth_bits_array
, stencil_bits_array
,
160 depth_buffer_factor
, back_buffer_modes
,
162 msaa_samples_array
, msaa_samples_factor
,
166 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
177 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
187 if (pixel_bits
== 16) {
188 configs
= configs_r5g6b5
;
189 if (configs_a8r8g8b8
)
190 configs
= configs
? driConcatConfigs(configs
, configs_a8r8g8b8
) : configs_a8r8g8b8
;
191 if (configs_x8r8g8b8
)
192 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
194 configs
= configs_a8r8g8b8
;
195 if (configs_x8r8g8b8
)
196 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
198 configs
= configs
? driConcatConfigs(configs
, configs_r5g6b5
) : configs_r5g6b5
;
201 if (configs
== NULL
) {
202 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
206 return (const __DRIconfig
**)configs
;
210 * Roughly the converse of dri_fill_in_modes.
213 dri_fill_st_visual(struct st_visual
*stvis
, struct dri_screen
*screen
,
214 const __GLcontextModes
*mode
)
216 memset(stvis
, 0, sizeof(*stvis
));
218 stvis
->samples
= mode
->samples
;
219 stvis
->render_buffer
= ST_ATTACHMENT_INVALID
;
221 if (mode
->redBits
== 8) {
222 if (mode
->alphaBits
== 8)
223 stvis
->color_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
225 stvis
->color_format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
227 stvis
->color_format
= PIPE_FORMAT_B5G6R5_UNORM
;
230 switch (mode
->depthBits
) {
233 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
236 stvis
->depth_stencil_format
= PIPE_FORMAT_Z16_UNORM
;
239 if (mode
->stencilBits
== 0) {
240 stvis
->depth_stencil_format
= (screen
->d_depth_bits_last
) ?
241 PIPE_FORMAT_Z24X8_UNORM
:
242 PIPE_FORMAT_X8Z24_UNORM
;
244 stvis
->depth_stencil_format
= (screen
->sd_depth_bits_last
) ?
245 PIPE_FORMAT_Z24S8_UNORM
:
246 PIPE_FORMAT_S8Z24_UNORM
;
250 stvis
->depth_stencil_format
= PIPE_FORMAT_Z32_UNORM
;
254 stvis
->accum_format
= (mode
->haveAccumBuffer
) ?
255 PIPE_FORMAT_R16G16B16A16_SNORM
: PIPE_FORMAT_NONE
;
257 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
258 if (mode
->doubleBufferMode
)
259 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_LEFT_MASK
;
260 if (mode
->stereoMode
) {
261 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_RIGHT_MASK
;
262 if (mode
->doubleBufferMode
)
263 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_RIGHT_MASK
;
266 if (mode
->haveDepthBuffer
|| mode
->haveStencilBuffer
)
267 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
268 /* let the state tracker allocate the accum buffer */
271 #ifndef __NOT_HAVE_DRM_H
274 * Get information about previous buffer swaps.
277 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
279 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
288 dri_destroy_option_cache(struct dri_screen
* screen
)
292 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
293 FREE(screen
->optionCache
.info
[i
].name
);
294 FREE(screen
->optionCache
.info
[i
].ranges
);
297 FREE(screen
->optionCache
.info
);
298 FREE(screen
->optionCache
.values
);
302 dri_destroy_screen(__DRIscreen
* sPriv
)
304 struct dri_screen
*screen
= dri_screen(sPriv
);
306 dri1_destroy_pipe_context(screen
);
309 dri_destroy_st_manager(screen
->smapi
);
311 if (screen
->pipe_screen
)
312 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
314 dri_destroy_option_cache(screen
);
317 sPriv
->private = NULL
;
318 sPriv
->extensions
= NULL
;
321 #ifndef __NOT_HAVE_DRM_H
323 const struct __DriverAPIRec driDriverAPI
= {
324 .DestroyScreen
= dri_destroy_screen
,
325 .CreateContext
= dri_create_context
,
326 .DestroyContext
= dri_destroy_context
,
327 .CreateBuffer
= dri_create_buffer
,
328 .DestroyBuffer
= dri_destroy_buffer
,
329 .MakeCurrent
= dri_make_current
,
330 .UnbindContext
= dri_unbind_context
,
331 .GetSwapInfo
= dri_get_swap_info
,
332 .GetDrawableMSC
= driDrawableGetMSC32
,
333 .WaitForMSC
= driWaitForMSC32
,
334 .InitScreen2
= dri2_init_screen
,
336 .InitScreen
= dri1_init_screen
,
337 .SwapBuffers
= dri1_swap_buffers
,
338 .CopySubBuffer
= dri1_copy_sub_buffer
,
341 /* This is the table of extensions that the loader will dlsym() for. */
342 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
343 &driCoreExtension
.base
,
344 &driLegacyExtension
.base
,
345 &driDRI2Extension
.base
,
351 const struct __DriverAPIRec driDriverAPI
= {
352 .DestroyScreen
= dri_destroy_screen
,
353 .CreateContext
= dri_create_context
,
354 .DestroyContext
= dri_destroy_context
,
355 .CreateBuffer
= dri_create_buffer
,
356 .DestroyBuffer
= dri_destroy_buffer
,
357 .MakeCurrent
= dri_make_current
,
358 .UnbindContext
= dri_unbind_context
,
360 .InitScreen
= drisw_init_screen
,
361 .SwapBuffers
= drisw_swap_buffers
,
364 /* This is the table of extensions that the loader will dlsym() for. */
365 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
366 &driCoreExtension
.base
,
367 &driSWRastExtension
.base
,
373 /* vim: set sw=3 ts=8 sts=3 expandtab: */