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 __DRIextension
*dri_screen_extensions
[] = {
61 &driReadDrawableExtension
,
62 &driCopySubBufferExtension
.base
,
63 &driSwapControlExtension
.base
,
64 &driFrameTrackingExtension
.base
,
65 &driMediaStreamCounterExtension
.base
,
69 struct dri1_api
*__dri1_api_hooks
= NULL
;
71 static const __DRIconfig
**
72 dri_fill_in_modes(__DRIscreenPrivate
* psp
,
73 unsigned pixel_bits
, unsigned depth_bits
,
74 unsigned stencil_bits
, GLboolean have_back_buffer
)
76 __DRIconfig
**configs
;
79 uint8_t depth_bits_array
[3];
80 uint8_t stencil_bits_array
[3];
81 uint8_t msaa_samples_array
[1];
82 unsigned depth_buffer_factor
;
83 unsigned back_buffer_factor
;
84 unsigned msaa_samples_factor
;
89 static const GLenum back_buffer_modes
[] = {
90 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
93 /* TODO probe the hardware of what is supports */
94 depth_bits_array
[0] = 0;
95 depth_bits_array
[1] = 24;
96 depth_bits_array
[2] = 24;
98 stencil_bits_array
[0] = 0; /* no depth or stencil */
99 stencil_bits_array
[1] = 0; /* z24x8 */
100 stencil_bits_array
[2] = 8; /* z24s8 */
102 msaa_samples_array
[0] = 0;
104 depth_buffer_factor
= 3;
105 back_buffer_factor
= 3;
106 msaa_samples_factor
= 1;
109 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
111 if (pixel_bits
== 16) {
113 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
116 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
119 configs
= driCreateConfigs(fb_format
, fb_type
,
121 stencil_bits_array
, depth_buffer_factor
,
122 back_buffer_modes
, back_buffer_factor
,
123 msaa_samples_array
, msaa_samples_factor
);
124 if (configs
== NULL
) {
125 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
129 for (i
= 0; configs
[i
]; i
++) {
130 m
= &configs
[i
]->modes
;
131 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
132 m
->visualRating
= GLX_SLOW_CONFIG
;
136 return (const const __DRIconfig
**)configs
;
140 * Get information about previous buffer swaps.
143 dri_get_swap_info(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
145 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
152 dri_copy_version(struct dri1_api_version
*dst
,
153 const struct __DRIversionRec
*src
)
155 dst
->major
= src
->major
;
156 dst
->minor
= src
->minor
;
157 dst
->patch_level
= src
->patch
;
160 static const __DRIconfig
**
161 dri_init_screen(__DRIscreenPrivate
* sPriv
)
163 struct dri_screen
*screen
;
164 const __DRIconfig
**configs
;
165 struct dri1_create_screen_arg arg
;
167 dri_init_extensions(NULL
);
169 screen
= CALLOC_STRUCT(dri_screen
);
173 screen
->sPriv
= sPriv
;
174 screen
->fd
= sPriv
->fd
;
175 screen
->drmLock
= (drmLock
*) & sPriv
->pSAREA
->lock
;
177 sPriv
->private = (void *)screen
;
178 sPriv
->extensions
= dri_screen_extensions
;
180 arg
.base
.mode
= DRM_CREATE_DRI1
;
182 arg
.ddx_info
= sPriv
->pDevPriv
;
183 arg
.ddx_info_size
= sPriv
->devPrivSize
;
184 arg
.sarea
= sPriv
->pSAREA
;
185 dri_copy_version(&arg
.ddx_version
, &sPriv
->ddx_version
);
186 dri_copy_version(&arg
.dri_version
, &sPriv
->dri_version
);
187 dri_copy_version(&arg
.drm_version
, &sPriv
->drm_version
);
190 screen
->pipe_screen
= drm_api_hooks
.create_screen(screen
->fd
, &arg
.base
);
192 if (!screen
->pipe_screen
|| !arg
.api
) {
193 debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__
);
197 __dri1_api_hooks
= arg
.api
;
199 screen
->pipe_screen
->flush_frontbuffer
= dri1_flush_frontbuffer
;
200 driParseOptionInfo(&screen
->optionCache
,
201 __driConfigOptions
, __driNConfigOptions
);
203 configs
= dri_fill_in_modes(sPriv
, sPriv
->fbBPP
, 24, 8, 1);
209 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
216 * This is the driver specific part of the createNewScreen entry point.
218 * Returns the __GLcontextModes supported by this driver.
220 static const __DRIconfig
**
221 dri_init_screen2(__DRIscreenPrivate
* sPriv
)
223 struct dri_screen
*screen
;
224 struct drm_create_screen_arg arg
;
226 /* Set up dispatch table to cope with all known extensions */
227 dri_init_extensions(NULL
);
229 screen
= CALLOC_STRUCT(dri_screen
);
233 screen
->sPriv
= sPriv
;
234 screen
->fd
= sPriv
->fd
;
235 sPriv
->private = (void *)screen
;
236 sPriv
->extensions
= dri_screen_extensions
;
237 arg
.mode
= DRM_CREATE_NORMAL
;
239 screen
->pipe_screen
= drm_api_hooks
.create_screen(screen
->fd
, &arg
);
240 if (!screen
->pipe_screen
) {
241 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
245 /* We need to hook in here */
246 screen
->pipe_screen
->flush_frontbuffer
= dri_flush_frontbuffer
;
248 driParseOptionInfo(&screen
->optionCache
,
249 __driConfigOptions
, __driNConfigOptions
);
251 return dri_fill_in_modes(sPriv
, 4 * 8, 24, 8, 1);
257 dri_destroy_screen(__DRIscreenPrivate
* sPriv
)
259 struct dri_screen
*screen
= dri_screen(sPriv
);
261 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
263 sPriv
->private = NULL
;
266 PUBLIC
const struct __DriverAPIRec driDriverAPI
= {
267 .InitScreen
= dri_init_screen
,
268 .DestroyScreen
= dri_destroy_screen
,
269 .CreateContext
= dri_create_context
,
270 .DestroyContext
= dri_destroy_context
,
271 .CreateBuffer
= dri_create_buffer
,
272 .DestroyBuffer
= dri_destroy_buffer
,
273 .SwapBuffers
= dri_swap_buffers
,
274 .MakeCurrent
= dri_make_current
,
275 .UnbindContext
= dri_unbind_context
,
276 .GetSwapInfo
= dri_get_swap_info
,
277 .GetDrawableMSC
= driDrawableGetMSC32
,
278 .WaitForMSC
= driWaitForMSC32
,
279 .CopySubBuffer
= dri_copy_sub_buffer
,
280 .InitScreen
= dri_init_screen
,
281 .InitScreen2
= dri_init_screen2
,
284 /* vim: set sw=3 ts=8 sts=3 expandtab: */