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 PUBLIC
const char __driConfigOptions
[] =
46 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
47 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
48 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
49 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
50 /*DRI_CONF_FORCE_S3TC_ENABLE(false) */
51 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
52 DRI_CONF_SECTION_END DRI_CONF_END
;
54 const uint __driNConfigOptions
= 3;
56 static const __DRItexBufferExtension dri2TexBufferExtension
= {
57 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
62 static const __DRIextension
*dri_screen_extensions
[] = {
63 &driReadDrawableExtension
,
64 &driCopySubBufferExtension
.base
,
65 &driSwapControlExtension
.base
,
66 &driFrameTrackingExtension
.base
,
67 &driMediaStreamCounterExtension
.base
,
68 &dri2TexBufferExtension
.base
,
72 struct dri1_api
*__dri1_api_hooks
= NULL
;
74 static const __DRIconfig
**
75 dri_fill_in_modes(struct dri_screen
*screen
,
78 __DRIconfig
**configs
= NULL
;
80 uint8_t depth_bits_array
[5];
81 uint8_t stencil_bits_array
[5];
82 uint8_t msaa_samples_array
[2];
83 unsigned depth_buffer_factor
;
84 unsigned back_buffer_factor
;
85 unsigned msaa_samples_factor
;
86 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
87 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
88 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
90 static const GLenum back_buffer_modes
[] = {
91 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
94 depth_bits_array
[0] = 0;
95 stencil_bits_array
[0] = 0;
96 depth_buffer_factor
= 1;
98 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
100 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
101 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
103 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
104 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
106 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
107 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
109 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
110 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
112 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
113 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
115 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
116 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_R5G6B5_UNORM
,
118 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
119 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_A8R8G8B8_UNORM
,
121 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
122 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8R8G8B8_UNORM
,
124 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
127 depth_bits_array
[depth_buffer_factor
] = 16;
128 stencil_bits_array
[depth_buffer_factor
++] = 0;
130 if (pf_x8z24
|| pf_z24x8
) {
131 depth_bits_array
[depth_buffer_factor
] = 24;
132 stencil_bits_array
[depth_buffer_factor
++] = 0;
133 screen
->d_depth_bits_last
= pf_x8z24
;
135 if (pf_s8z24
|| pf_z24s8
) {
136 depth_bits_array
[depth_buffer_factor
] = 24;
137 stencil_bits_array
[depth_buffer_factor
++] = 8;
138 screen
->sd_depth_bits_last
= pf_s8z24
;
141 depth_bits_array
[depth_buffer_factor
] = 32;
142 stencil_bits_array
[depth_buffer_factor
++] = 0;
145 msaa_samples_array
[0] = 0;
146 msaa_samples_array
[1] = 4;
147 back_buffer_factor
= 3;
148 msaa_samples_factor
= 2;
151 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
153 if (pixel_bits
== 16 && pf_r5g6b5
) {
154 configs
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
155 depth_bits_array
, stencil_bits_array
,
156 depth_buffer_factor
, back_buffer_modes
,
158 msaa_samples_array
, msaa_samples_factor
);
160 __DRIconfig
**configs_a8r8g8b8
= NULL
;
161 __DRIconfig
**configs_x8r8g8b8
= NULL
;
164 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
171 msaa_samples_factor
);
173 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
180 msaa_samples_factor
);
182 if (configs_a8r8g8b8
&& configs_x8r8g8b8
)
183 configs
= driConcatConfigs(configs_x8r8g8b8
, configs_a8r8g8b8
);
184 else if (configs_a8r8g8b8
)
185 configs
= configs_a8r8g8b8
;
186 else if (configs_x8r8g8b8
)
187 configs
= configs_x8r8g8b8
;
192 if (configs
== NULL
) {
193 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
197 return (const const __DRIconfig
**)configs
;
201 * Get information about previous buffer swaps.
204 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
206 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
213 dri_copy_version(struct dri1_api_version
*dst
,
214 const struct __DRIversionRec
*src
)
216 dst
->major
= src
->major
;
217 dst
->minor
= src
->minor
;
218 dst
->patch_level
= src
->patch
;
221 static const __DRIconfig
**
222 dri_init_screen(__DRIscreen
* sPriv
)
224 struct dri_screen
*screen
;
225 const __DRIconfig
**configs
;
226 struct dri1_create_screen_arg arg
;
228 screen
= CALLOC_STRUCT(dri_screen
);
232 screen
->api
= drm_api_create();
233 screen
->sPriv
= sPriv
;
234 screen
->fd
= sPriv
->fd
;
235 screen
->drmLock
= (drmLock
*) & sPriv
->pSAREA
->lock
;
237 sPriv
->private = (void *)screen
;
238 sPriv
->extensions
= dri_screen_extensions
;
240 arg
.base
.mode
= DRM_CREATE_DRI1
;
242 arg
.ddx_info
= sPriv
->pDevPriv
;
243 arg
.ddx_info_size
= sPriv
->devPrivSize
;
244 arg
.sarea
= sPriv
->pSAREA
;
245 dri_copy_version(&arg
.ddx_version
, &sPriv
->ddx_version
);
246 dri_copy_version(&arg
.dri_version
, &sPriv
->dri_version
);
247 dri_copy_version(&arg
.drm_version
, &sPriv
->drm_version
);
250 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
.base
);
252 if (!screen
->pipe_screen
|| !arg
.api
) {
253 debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__
);
257 __dri1_api_hooks
= arg
.api
;
259 screen
->pipe_screen
->flush_frontbuffer
= dri1_flush_frontbuffer
;
260 driParseOptionInfo(&screen
->optionCache
,
261 __driConfigOptions
, __driNConfigOptions
);
264 * FIXME: If the driver supports format conversion swapbuffer blits, we might
265 * want to support other color bit depths than the server is currently
269 configs
= dri_fill_in_modes(screen
, sPriv
->fbBPP
);
275 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
282 * This is the driver specific part of the createNewScreen entry point.
284 * Returns the __GLcontextModes supported by this driver.
286 static const __DRIconfig
**
287 dri_init_screen2(__DRIscreen
* sPriv
)
289 struct dri_screen
*screen
;
290 struct drm_create_screen_arg arg
;
291 const __DRIdri2LoaderExtension
*dri2_ext
=
294 screen
= CALLOC_STRUCT(dri_screen
);
298 screen
->api
= drm_api_create();
299 screen
->sPriv
= sPriv
;
300 screen
->fd
= sPriv
->fd
;
301 sPriv
->private = (void *)screen
;
302 sPriv
->extensions
= dri_screen_extensions
;
303 arg
.mode
= DRM_CREATE_NORMAL
;
305 screen
->pipe_screen
= screen
->api
->create_screen(screen
->api
, screen
->fd
, &arg
);
306 if (!screen
->pipe_screen
) {
307 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
311 /* We need to hook in here */
312 screen
->pipe_screen
->update_buffer
= dri_update_buffer
;
313 screen
->pipe_screen
->flush_frontbuffer
= dri_flush_frontbuffer
;
315 driParseOptionInfo(&screen
->optionCache
,
316 __driConfigOptions
, __driNConfigOptions
);
318 screen
->auto_fake_front
= dri2_ext
->base
.version
>= 3 &&
319 dri2_ext
->getBuffersWithFormat
!= NULL
;
321 return dri_fill_in_modes(screen
, 32);
327 dri_destroy_screen(__DRIscreen
* sPriv
)
329 struct dri_screen
*screen
= dri_screen(sPriv
);
332 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
334 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
335 FREE(screen
->optionCache
.info
[i
].name
);
336 FREE(screen
->optionCache
.info
[i
].ranges
);
339 FREE(screen
->optionCache
.info
);
340 FREE(screen
->optionCache
.values
);
343 sPriv
->private = NULL
;
346 PUBLIC
const struct __DriverAPIRec driDriverAPI
= {
347 .InitScreen
= dri_init_screen
,
348 .DestroyScreen
= dri_destroy_screen
,
349 .CreateContext
= dri_create_context
,
350 .DestroyContext
= dri_destroy_context
,
351 .CreateBuffer
= dri_create_buffer
,
352 .DestroyBuffer
= dri_destroy_buffer
,
353 .SwapBuffers
= dri_swap_buffers
,
354 .MakeCurrent
= dri_make_current
,
355 .UnbindContext
= dri_unbind_context
,
356 .GetSwapInfo
= dri_get_swap_info
,
357 .GetDrawableMSC
= driDrawableGetMSC32
,
358 .WaitForMSC
= driWaitForMSC32
,
359 .CopySubBuffer
= dri_copy_sub_buffer
,
360 .InitScreen
= dri_init_screen
,
361 .InitScreen2
= dri_init_screen2
,
364 /* This is the table of extensions that the loader will dlsym() for. */
365 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
366 &driCoreExtension
.base
,
367 &driLegacyExtension
.base
,
368 &driDRI2Extension
.base
,
372 /* vim: set sw=3 ts=8 sts=3 expandtab: */