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 "nouveau_drmif.h"
32 #include "nv04_driver.h"
33 #include "nv10_driver.h"
34 #include "nv20_driver.h"
36 #include "main/framebuffer.h"
37 #include "main/renderbuffer.h"
39 static const __DRIextension
*nouveau_screen_extensions
[];
42 nouveau_destroy_screen(__DRIscreen
*dri_screen
);
44 static const __DRIconfig
**
45 nouveau_get_configs(void)
47 __DRIconfig
**configs
= NULL
;
50 const uint8_t depth_bits
[] = { 0, 16, 24, 24 };
51 const uint8_t stencil_bits
[] = { 0, 0, 0, 8 };
52 const uint8_t msaa_samples
[] = { 0 };
58 { GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
},
59 { GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
},
60 { GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
},
63 const GLenum back_buffer_modes
[] = {
64 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
67 for (i
= 0; i
< Elements(fb_formats
); i
++) {
70 config
= driCreateConfigs(fb_formats
[i
].format
,
72 depth_bits
, stencil_bits
,
75 Elements(back_buffer_modes
),
77 Elements(msaa_samples
),
81 configs
= configs
? driConcatConfigs(configs
, config
)
85 return (const __DRIconfig
**)configs
;
88 static const __DRIconfig
**
89 nouveau_init_screen2(__DRIscreen
*dri_screen
)
91 const __DRIconfig
**configs
;
92 struct nouveau_screen
*screen
;
95 /* Allocate the screen. */
96 screen
= CALLOC_STRUCT(nouveau_screen
);
100 dri_screen
->private = screen
;
101 dri_screen
->extensions
= nouveau_screen_extensions
;
102 screen
->dri_screen
= dri_screen
;
104 /* Open the DRM device. */
105 ret
= nouveau_device_open_existing(&screen
->device
, 0, dri_screen
->fd
,
108 nouveau_error("Error opening the DRM device.\n");
112 /* Choose the card specific function pointers. */
113 switch (screen
->device
->chipset
& 0xf0) {
115 screen
->driver
= &nv04_driver
;
118 screen
->driver
= &nv10_driver
;
121 screen
->driver
= &nv20_driver
;
127 configs
= nouveau_get_configs();
133 nouveau_destroy_screen(dri_screen
);
139 nouveau_destroy_screen(__DRIscreen
*dri_screen
)
141 struct nouveau_screen
*screen
= dri_screen
->private;
147 nouveau_device_close(&screen
->device
);
150 dri_screen
->private = NULL
;
154 nouveau_create_buffer(__DRIscreen
*dri_screen
,
155 __DRIdrawable
*drawable
,
156 const __GLcontextModes
*visual
,
159 struct gl_renderbuffer
*rb
;
160 struct gl_framebuffer
*fb
;
164 return GL_FALSE
; /* not implemented */
166 if (visual
->redBits
== 5)
167 color_format
= GL_RGB5
;
168 else if (visual
->alphaBits
== 0)
169 color_format
= GL_RGB8
;
171 color_format
= GL_RGBA8
;
173 fb
= nouveau_framebuffer_dri_new(visual
);
178 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
179 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, rb
);
182 if (visual
->doubleBufferMode
) {
183 rb
= nouveau_renderbuffer_dri_new(color_format
, drawable
);
184 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, rb
);
187 /* Depth/stencil buffer. */
188 if (visual
->depthBits
== 24 && visual
->stencilBits
== 8) {
189 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH24_STENCIL8_EXT
, drawable
);
190 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
191 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, rb
);
193 } else if (visual
->depthBits
== 24) {
194 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT24
, drawable
);
195 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
197 } else if (visual
->depthBits
== 16) {
198 rb
= nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT16
, drawable
);
199 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, rb
);
202 /* Software renderbuffers. */
203 _mesa_add_soft_renderbuffers(fb
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
204 visual
->accumRedBits
> 0,
207 drawable
->driverPrivate
= fb
;
213 nouveau_destroy_buffer(__DRIdrawable
*drawable
)
215 _mesa_reference_framebuffer(
216 (struct gl_framebuffer
**)&drawable
->driverPrivate
, NULL
);
220 nouveau_drawable_flush(__DRIdrawable
*draw
)
224 static const struct __DRI2flushExtensionRec nouveau_flush_extension
= {
225 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
226 nouveau_drawable_flush
,
227 dri2InvalidateDrawable
,
230 static const struct __DRItexBufferExtensionRec nouveau_texbuffer_extension
= {
231 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
233 nouveau_set_texbuffer
,
236 static const __DRIextension
*nouveau_screen_extensions
[] = {
237 &nouveau_flush_extension
.base
,
238 &nouveau_texbuffer_extension
.base
,
239 &dri2ConfigQueryExtension
.base
,
243 const struct __DriverAPIRec driDriverAPI
= {
244 .InitScreen2
= nouveau_init_screen2
,
245 .DestroyScreen
= nouveau_destroy_screen
,
246 .CreateBuffer
= nouveau_create_buffer
,
247 .DestroyBuffer
= nouveau_destroy_buffer
,
248 .CreateContext
= nouveau_context_create
,
249 .DestroyContext
= nouveau_context_destroy
,
250 .MakeCurrent
= nouveau_context_make_current
,
251 .UnbindContext
= nouveau_context_unbind
,
254 /* This is the table of extensions that the loader will dlsym() for. */
255 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
256 &driCoreExtension
.base
,
257 &driDRI2Extension
.base
,