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>
36 #include "dri_screen.h"
37 #include "dri_context.h"
38 #include "dri_drawable.h"
40 #include "pipe/p_screen.h"
41 #include "pipe/p_format.h"
42 #include "state_tracker/drm_api.h"
43 #include "state_tracker/dri1_api.h"
45 #include "util/u_debug.h"
47 PUBLIC
const char __driConfigOptions
[] =
48 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
49 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
50 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
51 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
52 /*DRI_CONF_FORCE_S3TC_ENABLE(false) */
53 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
54 DRI_CONF_SECTION_END DRI_CONF_END
;
56 const uint __driNConfigOptions
= 3;
58 static const __DRItexBufferExtension dri2TexBufferExtension
= {
59 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
65 dri2_flush_drawable(__DRIdrawable
*draw
)
69 static const __DRI2flushExtension dri2FlushExtension
= {
70 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
72 dri2InvalidateDrawable
,
75 static const __DRIextension
*dri_screen_extensions
[] = {
76 &driReadDrawableExtension
,
77 &driCopySubBufferExtension
.base
,
78 &driSwapControlExtension
.base
,
79 &driFrameTrackingExtension
.base
,
80 &driMediaStreamCounterExtension
.base
,
81 &dri2TexBufferExtension
.base
,
82 &dri2FlushExtension
.base
,
86 struct dri1_api
*__dri1_api_hooks
= NULL
;
88 static const __DRIconfig
**
89 dri_fill_in_modes(struct dri_screen
*screen
,
92 __DRIconfig
**configs
= NULL
;
93 __DRIconfig
**configs_r5g6b5
= NULL
;
94 __DRIconfig
**configs_a8r8g8b8
= NULL
;
95 __DRIconfig
**configs_x8r8g8b8
= NULL
;
97 uint8_t depth_bits_array
[5];
98 uint8_t stencil_bits_array
[5];
99 uint8_t msaa_samples_array
[2];
100 unsigned depth_buffer_factor
;
101 unsigned back_buffer_factor
;
102 unsigned msaa_samples_factor
;
103 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
104 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
105 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
107 static const GLenum back_buffer_modes
[] = {
108 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
111 depth_bits_array
[0] = 0;
112 stencil_bits_array
[0] = 0;
113 depth_buffer_factor
= 1;
115 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
117 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
118 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
120 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
121 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
123 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
124 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
126 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
127 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8A8_UNORM
,
129 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
130 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8X8_UNORM
,
132 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
133 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B5G6R5_UNORM
,
135 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
137 /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
138 if (screen
->sPriv
->dri2
.loader
&&
139 (screen
->sPriv
->dri2
.loader
->base
.version
> 2) &&
140 (screen
->sPriv
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
141 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
143 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
144 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
146 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
153 depth_bits_array
[depth_buffer_factor
] = 16;
154 stencil_bits_array
[depth_buffer_factor
++] = 0;
156 if (pf_x8z24
|| pf_z24x8
) {
157 depth_bits_array
[depth_buffer_factor
] = 24;
158 stencil_bits_array
[depth_buffer_factor
++] = 0;
159 screen
->d_depth_bits_last
= pf_x8z24
;
161 if (pf_s8z24
|| pf_z24s8
) {
162 depth_bits_array
[depth_buffer_factor
] = 24;
163 stencil_bits_array
[depth_buffer_factor
++] = 8;
164 screen
->sd_depth_bits_last
= pf_s8z24
;
167 depth_bits_array
[depth_buffer_factor
] = 32;
168 stencil_bits_array
[depth_buffer_factor
++] = 0;
171 msaa_samples_array
[0] = 0;
172 msaa_samples_array
[1] = 4;
173 back_buffer_factor
= 3;
174 msaa_samples_factor
= 2;
177 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
180 configs_r5g6b5
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
181 depth_bits_array
, stencil_bits_array
,
182 depth_buffer_factor
, back_buffer_modes
,
184 msaa_samples_array
, msaa_samples_factor
,
188 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
199 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
209 if (pixel_bits
== 16) {
210 configs
= configs_r5g6b5
;
211 if (configs_a8r8g8b8
)
212 configs
= configs
? driConcatConfigs(configs
, configs_a8r8g8b8
) : configs_a8r8g8b8
;
213 if (configs_x8r8g8b8
)
214 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
216 configs
= configs_a8r8g8b8
;
217 if (configs_x8r8g8b8
)
218 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
220 configs
= configs
? driConcatConfigs(configs
, configs_r5g6b5
) : configs_r5g6b5
;
223 if (configs
== NULL
) {
224 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
228 return (const __DRIconfig
**)configs
;
232 * Get information about previous buffer swaps.
235 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
237 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
244 dri_copy_version(struct dri1_api_version
*dst
,
245 const struct __DRIversionRec
*src
)
247 dst
->major
= src
->major
;
248 dst
->minor
= src
->minor
;
249 dst
->patch_level
= src
->patch
;
252 static const __DRIconfig
**
253 dri_init_screen(__DRIscreen
* sPriv
)
255 struct dri_screen
*screen
;
256 const __DRIconfig
**configs
;
257 struct dri1_create_screen_arg arg
;
259 screen
= CALLOC_STRUCT(dri_screen
);
263 screen
->api
= drm_api_create();
264 screen
->sPriv
= sPriv
;
265 screen
->fd
= sPriv
->fd
;
266 screen
->drmLock
= (drmLock
*) & sPriv
->pSAREA
->lock
;
268 sPriv
->private = (void *)screen
;
269 sPriv
->extensions
= dri_screen_extensions
;
271 arg
.base
.mode
= DRM_CREATE_DRI1
;
273 arg
.ddx_info
= sPriv
->pDevPriv
;
274 arg
.ddx_info_size
= sPriv
->devPrivSize
;
275 arg
.sarea
= sPriv
->pSAREA
;
276 dri_copy_version(&arg
.ddx_version
, &sPriv
->ddx_version
);
277 dri_copy_version(&arg
.dri_version
, &sPriv
->dri_version
);
278 dri_copy_version(&arg
.drm_version
, &sPriv
->drm_version
);
281 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
.base
);
283 if (!screen
->pipe_screen
|| !arg
.api
) {
284 debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__
);
288 __dri1_api_hooks
= arg
.api
;
290 screen
->pipe_screen
->flush_frontbuffer
= dri1_flush_frontbuffer
;
291 driParseOptionInfo(&screen
->optionCache
,
292 __driConfigOptions
, __driNConfigOptions
);
295 * FIXME: If the driver supports format conversion swapbuffer blits, we might
296 * want to support other color bit depths than the server is currently
300 configs
= dri_fill_in_modes(screen
, sPriv
->fbBPP
);
306 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
313 * This is the driver specific part of the createNewScreen entry point.
315 * Returns the __GLcontextModes supported by this driver.
317 static const __DRIconfig
**
318 dri_init_screen2(__DRIscreen
* sPriv
)
320 struct dri_screen
*screen
;
321 struct drm_create_screen_arg arg
;
322 const __DRIdri2LoaderExtension
*dri2_ext
=
325 screen
= CALLOC_STRUCT(dri_screen
);
329 screen
->api
= drm_api_create();
330 screen
->sPriv
= sPriv
;
331 screen
->fd
= sPriv
->fd
;
332 sPriv
->private = (void *)screen
;
333 sPriv
->extensions
= dri_screen_extensions
;
334 arg
.mode
= DRM_CREATE_NORMAL
;
336 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
);
337 if (!screen
->pipe_screen
) {
338 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
342 /* We need to hook in here */
343 screen
->pipe_screen
->update_buffer
= dri_update_buffer
;
344 screen
->pipe_screen
->flush_frontbuffer
= dri_flush_frontbuffer
;
346 driParseOptionInfo(&screen
->optionCache
,
347 __driConfigOptions
, __driNConfigOptions
);
349 screen
->auto_fake_front
= dri2_ext
->base
.version
>= 3 &&
350 dri2_ext
->getBuffersWithFormat
!= NULL
;
352 return dri_fill_in_modes(screen
, 32);
358 dri_destroy_screen(__DRIscreen
* sPriv
)
360 struct dri_screen
*screen
= dri_screen(sPriv
);
363 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
365 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
366 FREE(screen
->optionCache
.info
[i
].name
);
367 FREE(screen
->optionCache
.info
[i
].ranges
);
370 FREE(screen
->optionCache
.info
);
371 FREE(screen
->optionCache
.values
);
374 sPriv
->private = NULL
;
377 PUBLIC
const struct __DriverAPIRec driDriverAPI
= {
378 .InitScreen
= dri_init_screen
,
379 .DestroyScreen
= dri_destroy_screen
,
380 .CreateContext
= dri_create_context
,
381 .DestroyContext
= dri_destroy_context
,
382 .CreateBuffer
= dri_create_buffer
,
383 .DestroyBuffer
= dri_destroy_buffer
,
384 .SwapBuffers
= dri_swap_buffers
,
385 .MakeCurrent
= dri_make_current
,
386 .UnbindContext
= dri_unbind_context
,
387 .GetSwapInfo
= dri_get_swap_info
,
388 .GetDrawableMSC
= driDrawableGetMSC32
,
389 .WaitForMSC
= driWaitForMSC32
,
390 .CopySubBuffer
= dri_copy_sub_buffer
,
391 .InitScreen
= dri_init_screen
,
392 .InitScreen2
= dri_init_screen2
,
395 /* This is the table of extensions that the loader will dlsym() for. */
396 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
397 &driCoreExtension
.base
,
398 &driLegacyExtension
.base
,
399 &driDRI2Extension
.base
,
403 /* vim: set sw=3 ts=8 sts=3 expandtab: */