sis: Remove unnecessary headers.
[mesa.git] / src / mesa / drivers / dri / sis / sis_dd.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Sung-Ching Lin <sclin@sis.com.tw>
31 * Eric Anholt <anholt@FreeBSD.org>
32 *
33 */
34
35 #include "sis_context.h"
36 #include "sis_dd.h"
37 #include "sis_lock.h"
38 #include "sis_alloc.h"
39 #include "sis_span.h"
40 #include "sis_state.h"
41 #include "sis_tris.h"
42
43 #include "main/formats.h"
44 #include "main/renderbuffer.h"
45
46 #include "utils.h"
47
48 #define DRIVER_DATE "20060710"
49
50 /* Return the width and height of the given buffer.
51 */
52 static void
53 sisGetBufferSize( GLframebuffer *buffer,
54 GLuint *width, GLuint *height )
55 {
56 GET_CURRENT_CONTEXT(ctx);
57 sisContextPtr smesa = SIS_CONTEXT(ctx);
58
59 LOCK_HARDWARE();
60 *width = smesa->driDrawable->w;
61 *height = smesa->driDrawable->h;
62 UNLOCK_HARDWARE();
63 }
64
65 /* Return various strings for glGetString().
66 */
67 static const GLubyte *
68 sisGetString( GLcontext *ctx, GLenum name )
69 {
70 sisContextPtr smesa = SIS_CONTEXT(ctx);
71 static char buffer[128];
72 unsigned offset;
73 GLuint agp_mode = (smesa->AGPSize > 0);
74
75 switch ( name )
76 {
77 case GL_VENDOR:
78 return (GLubyte *)"Eric Anholt";
79
80 case GL_RENDERER:
81 offset = driGetRendererString( buffer, "SiS", DRIVER_DATE, agp_mode );
82
83 return (GLubyte *)buffer;
84
85 default:
86 return NULL;
87 }
88 }
89
90 /* Send all commands to the hardware.
91 */
92 static void
93 sisFlush( GLcontext *ctx )
94 {
95 sisContextPtr smesa = SIS_CONTEXT(ctx);
96
97 SIS_FIREVERTICES(smesa);
98 }
99
100 /* Make sure all commands have been sent to the hardware and have
101 * completed processing.
102 */
103 static void
104 sisFinish( GLcontext *ctx )
105 {
106 sisContextPtr smesa = SIS_CONTEXT(ctx);
107
108 SIS_FIREVERTICES(smesa);
109 LOCK_HARDWARE();
110 WaitEngIdle( smesa );
111 UNLOCK_HARDWARE();
112 }
113
114 static void
115 sisDeleteRenderbuffer(struct gl_renderbuffer *rb)
116 {
117 /* Don't free() since we're contained in sis_context struct. */
118 }
119
120 static GLboolean
121 sisRenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *rb,
122 GLenum internalFormat, GLuint width, GLuint height)
123 {
124 rb->Width = width;
125 rb->Height = height;
126 rb->InternalFormat = internalFormat;
127 return GL_TRUE;
128 }
129
130 static void
131 sisInitRenderbuffer(struct gl_renderbuffer *rb, GLenum format)
132 {
133 const GLuint name = 0;
134
135 _mesa_init_renderbuffer(rb, name);
136
137 /* Make sure we're using a null-valued GetPointer routine */
138 assert(rb->GetPointer(NULL, rb, 0, 0) == NULL);
139
140 rb->InternalFormat = format;
141
142 if (format == GL_RGBA) {
143 /* Color */
144 rb->Format = MESA_FORMAT_ARGB8888;
145 rb->DataType = GL_UNSIGNED_BYTE;
146 }
147 else if (format == GL_DEPTH_COMPONENT16) {
148 /* Depth */
149 /* we always Get/Put 32-bit Z values */
150 rb->Format = MESA_FORMAT_Z16;
151 rb->DataType = GL_UNSIGNED_INT;
152 }
153 else if (format == GL_DEPTH_COMPONENT24) {
154 /* Depth */
155 /* we always Get/Put 32-bit Z values */
156 rb->Format = MESA_FORMAT_Z32;
157 rb->DataType = GL_UNSIGNED_INT;
158 }
159 else {
160 /* Stencil */
161 ASSERT(format == GL_STENCIL_INDEX8_EXT);
162 rb->Format = MESA_FORMAT_S8;
163 rb->DataType = GL_UNSIGNED_BYTE;
164 }
165
166 rb->Delete = sisDeleteRenderbuffer;
167 rb->AllocStorage = sisRenderbufferStorage;
168 }
169
170 void
171 sisUpdateBufferSize(sisContextPtr smesa)
172 {
173 __GLSiSHardware *current = &smesa->current;
174 __GLSiSHardware *prev = &smesa->prev;
175 struct gl_framebuffer *fb = smesa->glCtx->DrawBuffer;
176
177 if (!smesa->front.Base.InternalFormat) {
178 /* do one-time init for the renderbuffers */
179 sisInitRenderbuffer(&smesa->front.Base, GL_RGBA);
180 sisSetSpanFunctions(&smesa->front, &fb->Visual);
181 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &smesa->front.Base);
182
183 if (fb->Visual.doubleBufferMode) {
184 sisInitRenderbuffer(&smesa->back.Base, GL_RGBA);
185 sisSetSpanFunctions(&smesa->back, &fb->Visual);
186 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &smesa->back.Base);
187 }
188
189 if (smesa->glCtx->Visual.depthBits > 0) {
190 sisInitRenderbuffer(&smesa->depth.Base,
191 (smesa->glCtx->Visual.depthBits == 16
192 ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT24));
193 sisSetSpanFunctions(&smesa->depth, &fb->Visual);
194 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &smesa->depth.Base);
195 }
196
197 if (smesa->glCtx->Visual.stencilBits > 0) {
198 sisInitRenderbuffer(&smesa->stencil.Base, GL_STENCIL_INDEX8_EXT);
199 sisSetSpanFunctions(&smesa->stencil, &fb->Visual);
200 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &smesa->stencil.Base);
201 }
202 }
203
204 /* Make sure initialization did what we think it should */
205 assert(smesa->front.Base.InternalFormat);
206 assert(smesa->front.Base.AllocStorage);
207 if (fb->Visual.doubleBufferMode) {
208 assert(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
209 assert(smesa->front.Base.AllocStorage);
210 }
211 if (fb->Visual.depthBits) {
212 assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
213 assert(smesa->depth.Base.AllocStorage);
214 }
215
216 /* XXX Should get the base offset of the frontbuffer from the X Server */
217 smesa->front.offset = smesa->driDrawable->x * smesa->bytesPerPixel +
218 smesa->driDrawable->y * smesa->front.pitch;
219 smesa->front.map = (char *) smesa->driScreen->pFB + smesa->front.offset;
220
221 if ( smesa->width == smesa->driDrawable->w &&
222 smesa->height == smesa->driDrawable->h )
223 {
224 return;
225 }
226
227 smesa->front.bpp = smesa->bytesPerPixel * 8;
228 /* Front pitch set on context create */
229 smesa->front.size = smesa->front.pitch * smesa->driDrawable->h;
230
231 smesa->width = smesa->driDrawable->w;
232 smesa->height = smesa->driDrawable->h;
233 smesa->bottom = smesa->height - 1;
234
235 if (smesa->back.offset)
236 sisFreeBackbuffer( smesa );
237 if (smesa->depth.offset)
238 sisFreeZStencilBuffer( smesa );
239
240 if ( smesa->glCtx->Visual.depthBits > 0 )
241 sisAllocZStencilBuffer( smesa );
242 if ( smesa->glCtx->Visual.doubleBufferMode )
243 sisAllocBackbuffer( smesa );
244
245 current->hwZ &= ~MASK_ZBufferPitch;
246 current->hwZ |= smesa->depth.pitch >> 2;
247 current->hwOffsetZ = smesa->depth.offset >> 2;
248
249 if ((current->hwOffsetZ != prev->hwOffsetZ) || (current->hwZ != prev->hwZ)) {
250 prev->hwOffsetZ = current->hwOffsetZ;
251 prev->hwZ = current->hwZ;
252 smesa->GlobalFlag |= GFLAG_ZSETTING;
253 }
254
255 sisUpdateClipping( smesa->glCtx );
256 }
257
258 /* Initialize the driver's misc functions.
259 */
260 void
261 sisInitDriverFuncs( struct dd_function_table *functions )
262 {
263 functions->GetBufferSize = sisGetBufferSize;
264 functions->GetString = sisGetString;
265 functions->Finish = sisFinish;
266 functions->Flush = sisFlush;
267 }