2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_fbo.h"
30 #include "nouveau_texture.h"
31 #include "nv04_driver.h"
32 #include "nv10_driver.h"
33 #include "nv20_driver.h"
35 #include "main/framebuffer.h"
36 #include "main/fbobject.h"
37 #include "main/renderbuffer.h"
38 #include "swrast/s_renderbuffer.h"
40 static const __DRIextension
*nouveau_screen_extensions
[];
43 nouveau_destroy_screen(__DRIscreen
*dri_screen
);
45 static const __DRIconfig
**
46 nouveau_get_configs(void)
48 __DRIconfig
**configs
= NULL
;
51 const uint8_t depth_bits
[] = { 0, 16, 24, 24 };
52 const uint8_t stencil_bits
[] = { 0, 0, 0, 8 };
53 const uint8_t msaa_samples
[] = { 0 };
55 static const mesa_format formats
[3] = {
57 MESA_FORMAT_B8G8R8A8_UNORM
,
58 MESA_FORMAT_B8G8R8X8_UNORM
,
61 const GLenum back_buffer_modes
[] = {
62 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
65 for (i
= 0; i
< Elements(formats
); i
++) {
68 config
= driCreateConfigs(formats
[i
],
69 depth_bits
, stencil_bits
,
72 Elements(back_buffer_modes
),
74 Elements(msaa_samples
),
78 configs
= driConcatConfigs(configs
, config
);
81 return (const __DRIconfig
**)configs
;
84 static const __DRIconfig
**
85 nouveau_init_screen2(__DRIscreen
*dri_screen
)
87 const __DRIconfig
**configs
;
88 struct nouveau_screen
*screen
;
91 /* Allocate the screen. */
92 screen
= CALLOC_STRUCT(nouveau_screen
);
96 /* Open the DRM device. */
97 ret
= nouveau_device_wrap(dri_screen
->fd
, 0, &screen
->device
);
99 nouveau_error("Error opening the DRM device.\n");
103 /* Choose the card specific function pointers. */
104 switch (screen
->device
->chipset
& 0xf0) {
106 screen
->driver
= &nv04_driver
;
109 screen
->driver
= &nv10_driver
;
112 screen
->driver
= &nv20_driver
;
118 /* Compat version validation will occur at context init after
119 * _mesa_compute_version().
121 dri_screen
->max_gl_compat_version
= 15;
123 /* NV10 and NV20 can support OpenGL ES 1.0 only. Older chips
124 * cannot do even that.
126 if ((screen
->device
->chipset
& 0xf0) != 0x00)
127 dri_screen
->max_gl_es1_version
= 10;
129 dri_screen
->driverPrivate
= screen
;
130 dri_screen
->extensions
= nouveau_screen_extensions
;
131 screen
->dri_screen
= dri_screen
;
133 configs
= nouveau_get_configs();
139 nouveau_destroy_screen(dri_screen
);
145 nouveau_destroy_screen(__DRIscreen
*dri_screen
)
147 struct nouveau_screen
*screen
= dri_screen
->driverPrivate
;
152 nouveau_device_del(&screen
->device
);
155 dri_screen
->driverPrivate
= NULL
;
159 nouveau_create_buffer(__DRIscreen
*dri_screen
,
160 __DRIdrawable
*drawable
,
161 const struct gl_config
*visual
,
164 struct gl_renderbuffer
*rb
;
165 struct gl_framebuffer
*fb
;
169 return GL_FALSE
; /* not implemented */
171 if (visual
->redBits
== 5)
172 color_format
= GL_RGB5
;
173 else if (visual
->alphaBits
== 0)
174 color_format
= GL_RGB8
;
176 color_format
= GL_RGBA8
;
178 fb
= nouveau_framebuffer_dri_new(visual
);
183 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
184 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, rb
);
187 if (visual
->doubleBufferMode
) {
188 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
189 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, rb
);
192 /* Depth/stencil buffer. */
193 if (visual
->depthBits
== 24 && visual
->stencilBits
== 8) {
194 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH24_STENCIL8_EXT
, drawable
);
195 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
196 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
198 } else if (visual
->depthBits
== 24) {
199 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT24
, drawable
);
200 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
202 } else if (visual
->depthBits
== 16) {
203 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT16
, drawable
);
204 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
207 /* Software renderbuffers. */
208 _swrast_add_soft_renderbuffers(fb
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
209 visual
->accumRedBits
> 0,
212 drawable
->driverPrivate
= fb
;
218 nouveau_destroy_buffer(__DRIdrawable
*drawable
)
220 _mesa_reference_framebuffer(
221 (struct gl_framebuffer
**)&drawable
->driverPrivate
, NULL
);
225 nouveau_drawable_flush(__DRIdrawable
*draw
)
229 static const struct __DRI2flushExtensionRec nouveau_flush_extension
= {
231 nouveau_drawable_flush
,
232 dri2InvalidateDrawable
,
235 static const struct __DRItexBufferExtensionRec nouveau_texbuffer_extension
= {
236 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
238 nouveau_set_texbuffer
,
241 static const __DRIextension
*nouveau_screen_extensions
[] = {
242 &nouveau_flush_extension
.base
,
243 &nouveau_texbuffer_extension
.base
,
244 &dri2ConfigQueryExtension
.base
,
248 const struct __DriverAPIRec nouveau_driver_api
= {
249 .InitScreen
= nouveau_init_screen2
,
250 .DestroyScreen
= nouveau_destroy_screen
,
251 .CreateBuffer
= nouveau_create_buffer
,
252 .DestroyBuffer
= nouveau_destroy_buffer
,
253 .CreateContext
= nouveau_context_create
,
254 .DestroyContext
= nouveau_context_destroy
,
255 .MakeCurrent
= nouveau_context_make_current
,
256 .UnbindContext
= nouveau_context_unbind
,
259 static const struct __DRIDriverVtableExtensionRec nouveau_vtable
= {
260 .base
= { __DRI_DRIVER_VTABLE
, 1 },
261 .vtable
= &nouveau_driver_api
,
264 /* This is the table of extensions that the loader will dlsym() for. */
265 static const __DRIextension
*nouveau_driver_extensions
[] = {
266 &driCoreExtension
.base
,
267 &driDRI2Extension
.base
,
268 &nouveau_vtable
.base
,
272 PUBLIC
const __DRIextension
**__driDriverGetExtensions_nouveau_vieux(void)
274 globalDriverAPI
= &nouveau_driver_api
;
276 return nouveau_driver_extensions
;