1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
27 #include "nouveau_context.h"
28 //#include "nouveau_state.h"
29 #include "nouveau_lock.h"
30 #include "nouveau_fifo.h"
31 #include "nouveau_driver.h"
32 #include "swrast/swrast.h"
35 #include "framebuffer.h"
40 /* Wrapper for DRM_NOUVEAU_GETPARAM ioctl */
41 GLboolean
nouveauDRMGetParam(nouveauContextPtr nmesa
,
45 struct drm_nouveau_getparam getp
;
48 if (!value
|| drmCommandWriteRead(nmesa
->driFd
, DRM_NOUVEAU_GETPARAM
,
55 /* Wrapper for DRM_NOUVEAU_GETPARAM ioctl */
56 GLboolean
nouveauDRMSetParam(nouveauContextPtr nmesa
,
60 struct drm_nouveau_setparam setp
;
64 if (drmCommandWrite(nmesa
->driFd
, DRM_NOUVEAU_SETPARAM
, &setp
,
70 /* Return the width and height of the current color buffer */
71 static void nouveauGetBufferSize( GLframebuffer
*buffer
,
72 GLuint
*width
, GLuint
*height
)
74 GET_CURRENT_CONTEXT(ctx
);
75 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
77 LOCK_HARDWARE( nmesa
);
78 *width
= nmesa
->driDrawable
->w
;
79 *height
= nmesa
->driDrawable
->h
;
80 UNLOCK_HARDWARE( nmesa
);
84 static const GLubyte
*nouveauGetString( GLcontext
*ctx
, GLenum name
)
86 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
87 static char buffer
[128];
88 const char * card_name
= "Unknown";
93 return (GLubyte
*)DRIVER_AUTHOR
;
96 card_name
=nmesa
->screen
->card
->name
;
98 switch(nmesa
->screen
->bus_type
)
106 agp_mode
=nmesa
->screen
->agp_mode
;
109 driGetRendererString( buffer
, card_name
, DRIVER_DATE
,
111 return (GLubyte
*)buffer
;
118 static void nouveauFlush( GLcontext
*ctx
)
120 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
122 if (ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
)
123 nouveauDoSwapBuffers(nmesa
, nmesa
->driDrawable
);
128 static void nouveauFinish( GLcontext
*ctx
)
130 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
133 nouveauWaitForIdle( nmesa
);
137 static void nouveauClear( GLcontext
*ctx
, GLbitfield mask
)
139 uint32_t clear_value
;
140 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
142 /* FIXME: should we clear front buffer, even if asked to do it? */
143 if (mask
& (BUFFER_BIT_FRONT_LEFT
|BUFFER_BIT_BACK_LEFT
)) {
146 int color_mask
= 0xffffffff;
148 UNCLAMPED_FLOAT_TO_RGBA_CHAN(c
,ctx
->Color
.ClearColor
);
149 clear_value
= PACK_COLOR_8888(c
[3],c
[0],c
[1],c
[2]);
151 if (ctx
->DrawBuffer
) {
152 /* FIXME: find correct color buffer, instead of [0] */
153 if (ctx
->DrawBuffer
->_ColorDrawBuffers
[0]) {
154 color_bits
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->RedBits
;
155 color_bits
+= ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->GreenBits
;
156 color_bits
+= ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->BlueBits
;
157 color_bits
+= ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->AlphaBits
;
162 clear_value
= PACK_COLOR_565(c
[0],c
[1],c
[2]);
166 nouveauClearBuffer(ctx
, nmesa
->color_buffer
,
167 clear_value
, color_mask
);
170 if (mask
& (BUFFER_BIT_DEPTH
)) {
173 if (ctx
->DrawBuffer
) {
174 if (ctx
->DrawBuffer
->_DepthBuffer
) {
175 depth_bits
= ctx
->DrawBuffer
->_DepthBuffer
->DepthBits
;
181 clear_value
= (uint32_t) (ctx
->Depth
.Clear
* 32767.0);
185 clear_value
= ((uint32_t) (ctx
->Depth
.Clear
* 16777215.0)) << 8;
186 depth_mask
= 0xffffff00;
190 nouveauClearBuffer(ctx
, nmesa
->depth_buffer
,
191 clear_value
, depth_mask
);
194 if (mask
& (BUFFER_BIT_STENCIL
)) {
195 int stencil_bits
= 0;
196 if (ctx
->DrawBuffer
) {
197 if (ctx
->DrawBuffer
->_StencilBuffer
) {
198 stencil_bits
= ctx
->DrawBuffer
->_StencilBuffer
->StencilBits
;
202 if (stencil_bits
>0) {
203 nouveauClearBuffer(ctx
, nmesa
->depth_buffer
,
204 ctx
->Stencil
.Clear
, (1<<stencil_bits
)-1);
209 void nouveauDriverInitFunctions( struct dd_function_table
*functions
)
211 functions
->GetBufferSize
= nouveauGetBufferSize
;
212 functions
->ResizeBuffers
= _mesa_resize_framebuffer
;
213 functions
->GetString
= nouveauGetString
;
214 functions
->Flush
= nouveauFlush
;
215 functions
->Finish
= nouveauFinish
;
216 functions
->Clear
= nouveauClear
;