4e64c17b3d3eac0a3cff48f69bdf23a77e62e550
[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 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 *
34 */
35
36 #include "sis_context.h"
37 #include "sis_dd.h"
38 #include "sis_lock.h"
39 #include "sis_alloc.h"
40 #include "sis_state.h"
41 #include "sis_tris.h"
42
43 #include "swrast/swrast.h"
44 #include "framebuffer.h"
45
46 #include "utils.h"
47
48 #define DRIVER_DATE "20041008"
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 void
115 sisUpdateBufferSize( sisContextPtr smesa )
116 {
117 __GLSiSHardware *current = &smesa->current;
118 __GLSiSHardware *prev = &smesa->prev;
119 GLuint z_depth;
120
121 /* XXX Should get the base offset of the frontbuffer from the X Server */
122 smesa->frontOffset = smesa->driDrawable->x * smesa->bytesPerPixel +
123 smesa->driDrawable->y * smesa->frontPitch;
124
125 if ( smesa->width == smesa->driDrawable->w &&
126 smesa->height == smesa->driDrawable->h )
127 {
128 return;
129 }
130
131 smesa->width = smesa->driDrawable->w;
132 smesa->height = smesa->driDrawable->h;
133 smesa->bottom = smesa->height - 1;
134
135 if ( smesa->backbuffer )
136 sisFreeBackbuffer( smesa );
137 if ( smesa->depthbuffer )
138 sisFreeZStencilBuffer( smesa );
139
140 if ( smesa->glCtx->Visual.depthBits > 0 )
141 sisAllocZStencilBuffer( smesa );
142 if ( smesa->glCtx->Visual.doubleBufferMode )
143 sisAllocBackbuffer( smesa );
144
145 switch (smesa->zFormat)
146 {
147 case SiS_ZFORMAT_Z16:
148 z_depth = 2;
149 break;
150 case SiS_ZFORMAT_Z32:
151 case SiS_ZFORMAT_S8Z24:
152 z_depth = 4;
153 break;
154 default:
155 sis_fatal_error("Bad Z format\n");
156 }
157
158 current->hwZ &= ~MASK_ZBufferPitch;
159 current->hwZ |= smesa->width * z_depth >> 2;
160 current->hwOffsetZ = smesa->depthOffset >> 2;
161
162 if ((current->hwOffsetZ != prev->hwOffsetZ) || (current->hwZ != prev->hwZ)) {
163 prev->hwOffsetZ = current->hwOffsetZ;
164 prev->hwZ = current->hwZ;
165 smesa->GlobalFlag |= GFLAG_ZSETTING;
166 }
167
168 sisUpdateClipping( smesa->glCtx );
169 }
170
171 /* Initialize the driver's misc functions.
172 */
173 void
174 sisInitDriverFuncs( struct dd_function_table *functions )
175 {
176 functions->GetBufferSize = sisGetBufferSize;
177 functions->ResizeBuffers = _mesa_resize_framebuffer;
178 functions->GetString = sisGetString;
179 functions->Finish = sisFinish;
180 functions->Flush = sisFlush;
181 }