gallium: fix refcount bug introduced in eb20e2984
[mesa.git] / src / mesa / drivers / dri / sis / sis_span.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 #include "sis_context.h"
35 #include "sis_span.h"
36 #include "sis_lock.h"
37 #include "sis_tris.h"
38
39 #include "swrast/swrast.h"
40
41 #define DBG 0
42
43 #define LOCAL_VARS \
44 sisContextPtr smesa = SIS_CONTEXT(ctx); \
45 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
46 struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb; \
47 GLuint pitch = srb->pitch; \
48 char *buf = srb->map; \
49 GLuint p; \
50 (void) buf; (void) p;
51
52
53 #define LOCAL_DEPTH_VARS \
54 sisContextPtr smesa = SIS_CONTEXT(ctx); \
55 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
56 struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb; \
57 char *buf = srb->map;
58
59 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
60
61 #define HW_LOCK() do {} while(0);
62
63 #define HW_UNLOCK() do {} while(0);
64
65 /* RGB565 */
66 #define SPANTMP_PIXEL_FMT GL_RGB
67 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
68
69 #define TAG(x) sis##x##_RGB565
70 #define TAG2(x,y) sis##x##_RGB565##y
71 #include "spantmp2.h"
72
73
74 /* ARGB8888 */
75 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
76 Was there a reason to do so ? If so that'll won't work with that template... */
77 #define SPANTMP_PIXEL_FMT GL_BGRA
78 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
79
80 #define TAG(x) sis##x##_ARGB8888
81 #define TAG2(x,y) sis##x##_ARGB8888##y
82 #include "spantmp2.h"
83
84
85 /* 16 bit depthbuffer functions.
86 */
87 #define WRITE_DEPTH( _x, _y, d ) \
88 *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch) = d;
89
90 #define READ_DEPTH( d, _x, _y ) \
91 d = *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch);
92
93 #define TAG(x) sis##x##_z16
94 #include "depthtmp.h"
95
96
97 /* 32 bit depthbuffer functions.
98 */
99 #define WRITE_DEPTH( _x, _y, d ) \
100 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = d;
101
102 #define READ_DEPTH( d, _x, _y ) \
103 d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch);
104
105 #define TAG(x) sis##x##_z32
106 #include "depthtmp.h"
107
108
109 /* 8/24 bit interleaved depth/stencil functions
110 */
111 #define WRITE_DEPTH( _x, _y, d ) { \
112 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch); \
113 tmp &= 0xff000000; \
114 tmp |= (d & 0x00ffffff); \
115 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp; \
116 }
117
118 #define READ_DEPTH( d, _x, _y ) { \
119 d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0x00ffffff; \
120 }
121
122 #define TAG(x) sis##x##_z24_s8
123 #include "depthtmp.h"
124
125 #define WRITE_STENCIL( _x, _y, d ) { \
126 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depth.pitch); \
127 tmp &= 0x00ffffff; \
128 tmp |= (d << 24); \
129 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp; \
130 }
131
132 #define READ_STENCIL( d, _x, _y ) \
133 d = (*(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0xff000000) >> 24;
134
135 #define TAG(x) sis##x##_z24_s8
136 #include "stenciltmp.h"
137
138
139
140 void sisSpanRenderStart( GLcontext *ctx )
141 {
142 sisContextPtr smesa = SIS_CONTEXT(ctx);
143
144 SIS_FIREVERTICES(smesa);
145 LOCK_HARDWARE();
146 WaitEngIdle( smesa );
147 }
148
149 void sisSpanRenderFinish( GLcontext *ctx )
150 {
151 sisContextPtr smesa = SIS_CONTEXT(ctx);
152
153 _swrast_flush( ctx );
154 UNLOCK_HARDWARE();
155 }
156
157 void
158 sisDDInitSpanFuncs( GLcontext *ctx )
159 {
160 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
161 swdd->SpanRenderStart = sisSpanRenderStart;
162 swdd->SpanRenderFinish = sisSpanRenderFinish;
163 }
164
165
166
167 /**
168 * Plug in the Get/Put routines for the given driRenderbuffer.
169 */
170 void
171 sisSetSpanFunctions(struct sis_renderbuffer *srb, const GLvisual *vis)
172 {
173 if (srb->Base.InternalFormat == GL_RGBA) {
174 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
175 sisInitPointers_RGB565( &srb->Base );
176 }
177 else {
178 sisInitPointers_ARGB8888( &srb->Base );
179 }
180 }
181 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
182 sisInitDepthPointers_z16(&srb->Base);
183 }
184 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
185 sisInitDepthPointers_z24_s8(&srb->Base);
186 }
187 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
188 sisInitDepthPointers_z32(&srb->Base);
189 }
190 else if (srb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
191 sisInitStencilPointers_z24_s8(&srb->Base);
192 }
193 }