remove common macros used in the span functions of most drivers from the individual...
[mesa.git] / src / mesa / drivers / dri / i810 / i810span.c
1 #include "glheader.h"
2 #include "macros.h"
3 #include "mtypes.h"
4 #include "colormac.h"
5
6 #include "i810screen.h"
7 #include "i810_dri.h"
8
9 #include "i810span.h"
10 #include "i810ioctl.h"
11 #include "swrast/swrast.h"
12
13
14 #define DBG 0
15
16 #define LOCAL_VARS \
17 i810ContextPtr imesa = I810_CONTEXT(ctx); \
18 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
19 i810ScreenPrivate *i810Screen = imesa->i810Screen; \
20 GLuint pitch = i810Screen->backPitch; \
21 GLuint height = dPriv->h; \
22 GLushort p; \
23 char *buf = (char *)(imesa->drawMap + \
24 dPriv->x * 2 + \
25 dPriv->y * pitch); \
26 char *read_buf = (char *)(imesa->readMap + \
27 dPriv->x * 2 + \
28 dPriv->y * pitch); \
29 (void) read_buf; (void) buf; (void) p
30
31 #define LOCAL_DEPTH_VARS \
32 i810ContextPtr imesa = I810_CONTEXT(ctx); \
33 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
34 i810ScreenPrivate *i810Screen = imesa->i810Screen; \
35 GLuint pitch = i810Screen->backPitch; \
36 GLuint height = dPriv->h; \
37 char *buf = (char *)(i810Screen->depth.map + \
38 dPriv->x * 2 + \
39 dPriv->y * pitch)
40
41 #define INIT_MONO_PIXEL(p, color) \
42 p = PACK_COLOR_565( color[0], color[1], color[2] )
43
44 #define Y_FLIP(_y) (height - _y - 1)
45
46 #define HW_LOCK()
47
48 #define HW_UNLOCK()
49
50 /* 16 bit, 565 rgb color spanline and pixel functions
51 */
52 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
53 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
54 (((int)g & 0xfc) << 3) | \
55 (((int)b & 0xf8) >> 3))
56 #define WRITE_PIXEL( _x, _y, p ) \
57 *(GLushort *)(buf + _x*2 + _y*pitch) = p
58
59 #define READ_RGBA( rgba, _x, _y ) \
60 do { \
61 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch); \
62 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
63 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
64 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
65 rgba[3] = 255; \
66 } while(0)
67
68 #define TAG(x) i810##x##_565
69 #include "spantmp.h"
70
71 /* 16 bit depthbuffer functions.
72 */
73 #define WRITE_DEPTH( _x, _y, d ) \
74 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
75
76 #define READ_DEPTH( d, _x, _y ) \
77 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
78
79 #define TAG(x) i810##x##_16
80 #include "depthtmp.h"
81
82
83 /*
84 * This function is called to specify which buffer to read and write
85 * for software rasterization (swrast) fallbacks. This doesn't necessarily
86 * correspond to glDrawBuffer() or glReadBuffer() calls.
87 */
88 static void i810SetBuffer(GLcontext *ctx, GLframebuffer *buffer,
89 GLuint bufferBit )
90 {
91 i810ContextPtr imesa = I810_CONTEXT(ctx);
92 (void) buffer;
93
94 switch(bufferBit) {
95 case BUFFER_BIT_FRONT_LEFT:
96 if ( imesa->sarea->pf_current_page == 1)
97 imesa->readMap = imesa->i810Screen->back.map;
98 else
99 imesa->readMap = (char*)imesa->driScreen->pFB;
100 break;
101 case BUFFER_BIT_BACK_LEFT:
102 if ( imesa->sarea->pf_current_page == 1)
103 imesa->readMap = (char*)imesa->driScreen->pFB;
104 else
105 imesa->readMap = imesa->i810Screen->back.map;
106 break;
107 default:
108 ASSERT(0);
109 break;
110 }
111 imesa->drawMap = imesa->readMap;
112 }
113
114 /* Move locking out to get reasonable span performance.
115 */
116 void i810SpanRenderStart( GLcontext *ctx )
117 {
118 i810ContextPtr imesa = I810_CONTEXT(ctx);
119 I810_FIREVERTICES(imesa);
120 LOCK_HARDWARE(imesa);
121 i810RegetLockQuiescent( imesa );
122 }
123
124 void i810SpanRenderFinish( GLcontext *ctx )
125 {
126 i810ContextPtr imesa = I810_CONTEXT( ctx );
127 _swrast_flush( ctx );
128 UNLOCK_HARDWARE( imesa );
129 }
130
131 void i810InitSpanFuncs( GLcontext *ctx )
132 {
133 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
134
135 swdd->SetBuffer = i810SetBuffer;
136
137 #if 0
138 swdd->WriteRGBASpan = i810WriteRGBASpan_565;
139 swdd->WriteRGBSpan = i810WriteRGBSpan_565;
140 swdd->WriteMonoRGBASpan = i810WriteMonoRGBASpan_565;
141 swdd->WriteRGBAPixels = i810WriteRGBAPixels_565;
142 swdd->WriteMonoRGBAPixels = i810WriteMonoRGBAPixels_565;
143 swdd->ReadRGBASpan = i810ReadRGBASpan_565;
144 swdd->ReadRGBAPixels = i810ReadRGBAPixels_565;
145 #endif
146
147 #if 0
148 swdd->ReadDepthSpan = i810ReadDepthSpan_16;
149 swdd->WriteDepthSpan = i810WriteDepthSpan_16;
150 swdd->ReadDepthPixels = i810ReadDepthPixels_16;
151 swdd->WriteDepthPixels = i810WriteDepthPixels_16;
152 #endif
153
154 swdd->SpanRenderStart = i810SpanRenderStart;
155 swdd->SpanRenderFinish = i810SpanRenderFinish;
156 }
157
158
159
160 /**
161 * Plug in the Get/Put routines for the given driRenderbuffer.
162 */
163 void
164 i810SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
165 {
166 if (drb->Base.InternalFormat == GL_RGBA) {
167 /* always 565 RGB */
168 drb->Base.GetRow = i810ReadRGBASpan_565;
169 drb->Base.GetValues = i810ReadRGBAPixels_565;
170 drb->Base.PutRow = i810WriteRGBASpan_565;
171 drb->Base.PutRowRGB = i810WriteRGBSpan_565;
172 drb->Base.PutMonoRow = i810WriteMonoRGBASpan_565;
173 drb->Base.PutValues = i810WriteRGBAPixels_565;
174 drb->Base.PutMonoValues = i810WriteMonoRGBAPixels_565;
175 }
176 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
177 drb->Base.GetRow = i810ReadDepthSpan_16;
178 drb->Base.GetValues = i810ReadDepthPixels_16;
179 drb->Base.PutRow = i810WriteDepthSpan_16;
180 drb->Base.PutMonoRow = i810WriteMonoDepthSpan_16;
181 drb->Base.PutValues = i810WriteDepthPixels_16;
182 drb->Base.PutMonoValues = NULL;
183 }
184 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
185 /* should never get here */
186 drb->Base.GetRow = NULL;
187 drb->Base.GetValues = NULL;
188 drb->Base.PutRow = NULL;
189 drb->Base.PutMonoRow = NULL;
190 drb->Base.PutValues = NULL;
191 drb->Base.PutMonoValues = NULL;
192 }
193 else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
194 drb->Base.GetRow = NULL;
195 drb->Base.GetValues = NULL;
196 drb->Base.PutRow = NULL;
197 drb->Base.PutMonoRow = NULL;
198 drb->Base.PutValues = NULL;
199 drb->Base.PutMonoValues = NULL;
200 }
201 }