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