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_context.h"
41 #include "pipe/p_screen.h"
42 #include "pipe/p_inlines.h"
43 #include "pipe/p_format.h"
44 #include "state_tracker/drm_api.h"
45 #include "state_tracker/dri1_api.h"
46 #include "state_tracker/st_public.h"
47 #include "state_tracker/st_cb_fbo.h"
49 PUBLIC
const char __driConfigOptions
[] =
50 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
51 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
52 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
53 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
54 /*DRI_CONF_FORCE_S3TC_ENABLE(false) */
55 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
56 DRI_CONF_SECTION_END DRI_CONF_END
;
58 const uint __driNConfigOptions
= 3;
60 static const __DRItexBufferExtension dri2TexBufferExtension
= {
61 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
66 static const __DRIextension
*dri_screen_extensions
[] = {
67 &driReadDrawableExtension
,
68 &driCopySubBufferExtension
.base
,
69 &driSwapControlExtension
.base
,
70 &driFrameTrackingExtension
.base
,
71 &driMediaStreamCounterExtension
.base
,
72 &dri2TexBufferExtension
.base
,
76 struct dri1_api
*__dri1_api_hooks
= NULL
;
78 static const __DRIconfig
**
79 dri_fill_in_modes(struct dri_screen
*screen
,
82 __DRIconfig
**configs
= NULL
;
84 uint8_t depth_bits_array
[5];
85 uint8_t stencil_bits_array
[5];
86 uint8_t msaa_samples_array
[2];
87 unsigned depth_buffer_factor
;
88 unsigned back_buffer_factor
;
89 unsigned msaa_samples_factor
;
90 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
91 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
92 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
94 static const GLenum back_buffer_modes
[] = {
95 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
98 depth_bits_array
[0] = 0;
99 stencil_bits_array
[0] = 0;
100 depth_buffer_factor
= 1;
102 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
104 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
105 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
107 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
108 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
110 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
111 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
113 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
114 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
116 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
117 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
119 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
120 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_R5G6B5_UNORM
,
122 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
123 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_A8R8G8B8_UNORM
,
125 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
126 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8R8G8B8_UNORM
,
128 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 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;
157 if (pixel_bits
== 16 && pf_r5g6b5
) {
158 configs
= 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
);
164 __DRIconfig
**configs_a8r8g8b8
= NULL
;
165 __DRIconfig
**configs_x8r8g8b8
= NULL
;
168 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
175 msaa_samples_factor
);
177 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
184 msaa_samples_factor
);
186 if (configs_a8r8g8b8
&& configs_x8r8g8b8
)
187 configs
= driConcatConfigs(configs_x8r8g8b8
, configs_a8r8g8b8
);
188 else if (configs_a8r8g8b8
)
189 configs
= configs_a8r8g8b8
;
190 else if (configs_x8r8g8b8
)
191 configs
= configs_x8r8g8b8
;
196 if (configs
== NULL
) {
197 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
201 return (const const __DRIconfig
**)configs
;
205 * Get information about previous buffer swaps.
208 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
210 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
217 dri_copy_version(struct dri1_api_version
*dst
,
218 const struct __DRIversionRec
*src
)
220 dst
->major
= src
->major
;
221 dst
->minor
= src
->minor
;
222 dst
->patch_level
= src
->patch
;
225 static const __DRIconfig
**
226 dri_init_screen(__DRIscreen
* sPriv
)
228 struct dri_screen
*screen
;
229 const __DRIconfig
**configs
;
230 struct dri1_create_screen_arg arg
;
232 screen
= CALLOC_STRUCT(dri_screen
);
236 screen
->api
= drm_api_create();
237 screen
->sPriv
= sPriv
;
238 screen
->fd
= sPriv
->fd
;
239 screen
->drmLock
= (drmLock
*) & sPriv
->pSAREA
->lock
;
241 sPriv
->private = (void *)screen
;
242 sPriv
->extensions
= dri_screen_extensions
;
244 arg
.base
.mode
= DRM_CREATE_DRI1
;
246 arg
.ddx_info
= sPriv
->pDevPriv
;
247 arg
.ddx_info_size
= sPriv
->devPrivSize
;
248 arg
.sarea
= sPriv
->pSAREA
;
249 dri_copy_version(&arg
.ddx_version
, &sPriv
->ddx_version
);
250 dri_copy_version(&arg
.dri_version
, &sPriv
->dri_version
);
251 dri_copy_version(&arg
.drm_version
, &sPriv
->drm_version
);
254 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
.base
);
256 if (!screen
->pipe_screen
|| !arg
.api
) {
257 debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__
);
261 __dri1_api_hooks
= arg
.api
;
263 screen
->pipe_screen
->flush_frontbuffer
= dri1_flush_frontbuffer
;
264 driParseOptionInfo(&screen
->optionCache
,
265 __driConfigOptions
, __driNConfigOptions
);
268 * FIXME: If the driver supports format conversion swapbuffer blits, we might
269 * want to support other color bit depths than the server is currently
273 configs
= dri_fill_in_modes(screen
, sPriv
->fbBPP
);
279 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
286 * This is the driver specific part of the createNewScreen entry point.
288 * Returns the __GLcontextModes supported by this driver.
290 static const __DRIconfig
**
291 dri_init_screen2(__DRIscreen
* sPriv
)
293 struct dri_screen
*screen
;
294 struct drm_create_screen_arg arg
;
295 const __DRIdri2LoaderExtension
*dri2_ext
=
298 screen
= CALLOC_STRUCT(dri_screen
);
302 screen
->api
= drm_api_create();
303 screen
->sPriv
= sPriv
;
304 screen
->fd
= sPriv
->fd
;
305 sPriv
->private = (void *)screen
;
306 sPriv
->extensions
= dri_screen_extensions
;
307 arg
.mode
= DRM_CREATE_NORMAL
;
309 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
);
310 if (!screen
->pipe_screen
) {
311 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
315 /* We need to hook in here */
316 screen
->pipe_screen
->update_buffer
= dri_update_buffer
;
317 screen
->pipe_screen
->flush_frontbuffer
= dri_flush_frontbuffer
;
319 driParseOptionInfo(&screen
->optionCache
,
320 __driConfigOptions
, __driNConfigOptions
);
322 screen
->auto_fake_front
= dri2_ext
->base
.version
>= 3 &&
323 dri2_ext
->getBuffersWithFormat
!= NULL
;
325 return dri_fill_in_modes(screen
, 32);
331 dri_destroy_screen(__DRIscreen
* sPriv
)
333 struct dri_screen
*screen
= dri_screen(sPriv
);
336 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
338 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
339 FREE(screen
->optionCache
.info
[i
].name
);
340 FREE(screen
->optionCache
.info
[i
].ranges
);
343 FREE(screen
->optionCache
.info
);
344 FREE(screen
->optionCache
.values
);
347 sPriv
->private = NULL
;
350 PUBLIC
const struct __DriverAPIRec driDriverAPI
= {
351 .InitScreen
= dri_init_screen
,
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 .SwapBuffers
= dri_swap_buffers
,
358 .MakeCurrent
= dri_make_current
,
359 .UnbindContext
= dri_unbind_context
,
360 .GetSwapInfo
= dri_get_swap_info
,
361 .GetDrawableMSC
= driDrawableGetMSC32
,
362 .WaitForMSC
= driWaitForMSC32
,
363 .CopySubBuffer
= dri_copy_sub_buffer
,
364 .InitScreen
= dri_init_screen
,
365 .InitScreen2
= dri_init_screen2
,
368 /* This is the table of extensions that the loader will dlsym() for. */
369 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
370 &driCoreExtension
.base
,
371 &driLegacyExtension
.base
,
372 &driDRI2Extension
.base
,
376 /* vim: set sw=3 ts=8 sts=3 expandtab: */