new Makefiles
[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
42 #include "swrast/swrast.h"
43
44 #include "utils.h"
45
46 #define DRIVER_DATE "20030810"
47
48 /* Return the width and height of the given buffer.
49 */
50 static void
51 sisDDGetBufferSize( GLframebuffer *buffer,
52 GLuint *width, GLuint *height )
53 {
54 GET_CURRENT_CONTEXT(ctx);
55 sisContextPtr smesa = SIS_CONTEXT(ctx);
56
57 LOCK_HARDWARE();
58 *width = smesa->driDrawable->w;
59 *height = smesa->driDrawable->h;
60 UNLOCK_HARDWARE();
61 }
62
63 /* Return various strings for glGetString().
64 */
65 static const GLubyte *
66 sisDDGetString( GLcontext *ctx, GLenum name )
67 {
68 sisContextPtr smesa = SIS_CONTEXT(ctx);
69 static char buffer[128];
70 unsigned offset;
71 GLuint agp_mode = (smesa->AGPSize > 0);
72
73 switch ( name )
74 {
75 case GL_VENDOR:
76 return (GLubyte *)"Eric Anholt";
77
78 case GL_RENDERER:
79 offset = driGetRendererString( buffer, "SiS", DRIVER_DATE, agp_mode );
80
81 return (GLubyte *)buffer;
82
83 default:
84 return NULL;
85 }
86 }
87
88 /* Send all commands to the hardware. No-op, due to mmio.
89 */
90 static void
91 sisDDFlush( GLcontext *ctx )
92 {
93 /* Do nothing */
94 }
95
96 /* Make sure all commands have been sent to the hardware and have
97 * completed processing.
98 */
99 static void
100 sisDDFinish( GLcontext *ctx )
101 {
102 sisContextPtr smesa = SIS_CONTEXT(ctx);
103
104 sisDDFlush( ctx );
105 WaitEngIdle( smesa );
106 }
107
108 void
109 sisUpdateBufferSize( sisContextPtr smesa )
110 {
111 __GLSiSHardware *current = &smesa->current;
112 __GLSiSHardware *prev = &smesa->prev;
113 GLuint z_depth;
114
115 /* XXX Should get the base offset of the frontbuffer from the X Server */
116 smesa->frontOffset = smesa->driDrawable->x * smesa->bytesPerPixel +
117 smesa->driDrawable->y * smesa->frontPitch;
118
119 if ( smesa->width == smesa->driDrawable->w &&
120 smesa->height == smesa->driDrawable->h )
121 {
122 return;
123 }
124
125 smesa->width = smesa->driDrawable->w;
126 smesa->height = smesa->driDrawable->h;
127 smesa->bottom = smesa->height - 1;
128
129 if ( smesa->backbuffer )
130 sisFreeBackbuffer( smesa );
131 if ( smesa->depthbuffer )
132 sisFreeZStencilBuffer( smesa );
133
134 if ( smesa->glCtx->Visual.depthBits > 0 )
135 sisAllocZStencilBuffer( smesa );
136 if ( smesa->glCtx->Visual.doubleBufferMode )
137 sisAllocBackbuffer( smesa );
138
139 switch (smesa->zFormat)
140 {
141 case SiS_ZFORMAT_Z16:
142 z_depth = 2;
143 break;
144 case SiS_ZFORMAT_Z32:
145 case SiS_ZFORMAT_S8Z24:
146 z_depth = 4;
147 break;
148 default:
149 assert( 0 );
150 }
151
152 current->hwZ &= ~MASK_ZBufferPitch;
153 current->hwZ |= smesa->width * z_depth >> 2;
154 current->hwOffsetZ = smesa->depthOffset >> 2;
155
156 if ((current->hwOffsetZ != prev->hwOffsetZ) || (current->hwZ != prev->hwZ)) {
157 prev->hwOffsetZ = current->hwOffsetZ;
158 prev->hwZ = current->hwZ;
159 smesa->GlobalFlag |= GFLAG_ZSETTING;
160 }
161
162 sisUpdateClipping( smesa->glCtx );
163 }
164
165 /* Initialize the driver's misc functions.
166 */
167 void
168 sisDDInitDriverFuncs( GLcontext *ctx )
169 {
170 ctx->Driver.GetBufferSize = sisDDGetBufferSize;
171 ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
172 ctx->Driver.GetString = sisDDGetString;
173 ctx->Driver.Finish = sisDDFinish;
174 ctx->Driver.Flush = sisDDFlush;
175 ctx->Driver.Error = NULL;
176 }