2
* Copyright 2000-2001 VA Linux Systems, Inc.
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* on the rights to use, copy, modify, merge, publish, distribute, sub
9
* license, and/or sell copies of the Software, and to permit persons to whom
10
* the Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE.
25
* Keith Whitwell <keith@tungstengraphics.com>
27
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgaspan.c,v 1.11 2002/10/30 12:51:36 alanh Exp $ */
31
#include "mgacontext.h"
34
#include "swrast/swrast.h"
40
__DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
41
mgaScreenPrivate *mgaScreen = mmesa->mgaScreen; \
42
__DRIscreenPrivate *sPriv = mmesa->driScreen; \
43
GLuint pitch = mgaScreen->frontPitch; \
44
GLuint height = dPriv->h; \
45
char *read_buf = (char *)(sPriv->pFB + \
47
dPriv->x * mgaScreen->cpp + \
49
char *buf = (char *)(sPriv->pFB + \
51
dPriv->x * mgaScreen->cpp + \
54
(void) read_buf; (void) buf; (void) p
58
#define LOCAL_DEPTH_VARS \
59
__DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
60
mgaScreenPrivate *mgaScreen = mmesa->mgaScreen; \
61
__DRIscreenPrivate *sPriv = mmesa->driScreen; \
62
GLuint pitch = mgaScreen->frontPitch; \
63
GLuint height = dPriv->h; \
64
char *buf = (char *)(sPriv->pFB + \
65
mgaScreen->depthOffset + \
66
dPriv->x * mgaScreen->cpp + \
69
#define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
71
#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
72
_y >= miny && _y < maxy)
74
#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
75
if ( _y < miny || _y >= maxy ) { \
80
if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
81
if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
86
mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
88
LOCK_HARDWARE_QUIESCENT(mmesa);
91
#define HW_CLIPLOOP() \
93
int _nc = mmesa->numClipRects; \
95
int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
96
int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
97
int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
98
int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
100
#define HW_ENDCLIPLOOP() \
104
#define HW_UNLOCK() \
105
UNLOCK_HARDWARE(mmesa);
113
/* 16 bit, 565 rgb color spanline and pixel functions
115
#define Y_FLIP(_y) (height - _y - 1)
117
#undef INIT_MONO_PIXEL
118
#define INIT_MONO_PIXEL(p, color) \
119
p = MGAPACKCOLOR565( color[0], color[1], color[2] )
122
#define WRITE_RGBA( _x, _y, r, g, b, a ) \
123
*(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
124
(((int)g & 0xfc) << 3) | \
125
(((int)b & 0xf8) >> 3))
127
#define WRITE_PIXEL( _x, _y, p ) \
128
*(GLushort *)(buf + _x*2 + _y*pitch) = p
130
#define READ_RGBA( rgba, _x, _y ) \
132
GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch); \
133
rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \
134
rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \
135
rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \
139
#define TAG(x) mga##x##_565
146
/* 32 bit, 8888 argb color spanline and pixel functions
149
#undef INIT_MONO_PIXEL
150
#define INIT_MONO_PIXEL(p, color) \
151
p = MGAPACKCOLOR8888( color[0], color[1], color[2], color[3] )
154
#define WRITE_RGBA(_x, _y, r, g, b, a) \
155
*(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) | \
160
#define WRITE_PIXEL(_x, _y, p) \
161
*(GLuint *)(buf + _x*4 + _y*pitch) = p
163
#define READ_RGBA(rgba, _x, _y) \
165
GLuint p = *(GLuint *)(read_buf + _x*4 + _y*pitch); \
166
rgba[0] = (p >> 16) & 0xff; \
167
rgba[1] = (p >> 8) & 0xff; \
168
rgba[2] = (p >> 0) & 0xff; \
172
#define TAG(x) mga##x##_8888
178
/* 16 bit depthbuffer functions.
180
#define WRITE_DEPTH( _x, _y, d ) \
181
*(GLushort *)(buf + _x*2 + _y*pitch) = d;
183
#define READ_DEPTH( d, _x, _y ) \
184
d = *(GLushort *)(buf + _x*2 + _y*pitch);
186
#define TAG(x) mga##x##_16
187
#include "depthtmp.h"
192
/* 32 bit depthbuffer functions.
194
#define WRITE_DEPTH( _x, _y, d ) \
195
*(GLuint *)(buf + _x*4 + _y*pitch) = d;
197
#define READ_DEPTH( d, _x, _y ) \
198
d = *(GLuint *)(buf + _x*4 + _y*pitch);
200
#define TAG(x) mga##x##_32
201
#include "depthtmp.h"
205
/* 24/8 bit interleaved depth/stencil functions
207
#define WRITE_DEPTH( _x, _y, d ) { \
208
GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
211
*(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
214
#define READ_DEPTH( d, _x, _y ) { \
215
d = (*(GLuint *)(buf + _x*4 + _y*pitch) & ~0xff) >> 8; \
218
#define TAG(x) mga##x##_24_8
219
#include "depthtmp.h"
221
#define WRITE_STENCIL( _x, _y, d ) { \
222
GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
225
*(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
228
#define READ_STENCIL( d, _x, _y ) \
229
d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
231
#define TAG(x) mga##x##_24_8
232
#include "stenciltmp.h"
236
static void mgaDDSetReadBuffer(GLcontext *ctx, GLframebuffer *buffer,
239
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
241
if (mode == GL_FRONT_LEFT)
243
mmesa->readOffset = mmesa->mgaScreen->frontOffset;
244
mmesa->read_buffer = MGA_FRONT;
248
mmesa->readOffset = mmesa->mgaScreen->backOffset;
249
mmesa->read_buffer = MGA_BACK;
253
void mgaDDInitSpanFuncs( GLcontext *ctx )
255
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
256
struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
258
swdd->SetReadBuffer = mgaDDSetReadBuffer;
260
switch (mmesa->mgaScreen->cpp) {
262
swdd->WriteRGBASpan = mgaWriteRGBASpan_565;
263
swdd->WriteRGBSpan = mgaWriteRGBSpan_565;
264
swdd->WriteMonoRGBASpan = mgaWriteMonoRGBASpan_565;
265
swdd->WriteRGBAPixels = mgaWriteRGBAPixels_565;
266
swdd->WriteMonoRGBAPixels = mgaWriteMonoRGBAPixels_565;
267
swdd->ReadRGBASpan = mgaReadRGBASpan_565;
268
swdd->ReadRGBAPixels = mgaReadRGBAPixels_565;
270
swdd->ReadDepthSpan = mgaReadDepthSpan_16;
271
swdd->WriteDepthSpan = mgaWriteDepthSpan_16;
272
swdd->ReadDepthPixels = mgaReadDepthPixels_16;
273
swdd->WriteDepthPixels = mgaWriteDepthPixels_16;
277
swdd->WriteRGBASpan = mgaWriteRGBASpan_8888;
278
swdd->WriteRGBSpan = mgaWriteRGBSpan_8888;
279
swdd->WriteMonoRGBASpan = mgaWriteMonoRGBASpan_8888;
280
swdd->WriteRGBAPixels = mgaWriteRGBAPixels_8888;
281
swdd->WriteMonoRGBAPixels = mgaWriteMonoRGBAPixels_8888;
282
swdd->ReadRGBASpan = mgaReadRGBASpan_8888;
283
swdd->ReadRGBAPixels = mgaReadRGBAPixels_8888;
285
if (!mmesa->hw_stencil) {
286
swdd->ReadDepthSpan = mgaReadDepthSpan_32;
287
swdd->WriteDepthSpan = mgaWriteDepthSpan_32;
288
swdd->ReadDepthPixels = mgaReadDepthPixels_32;
289
swdd->WriteDepthPixels = mgaWriteDepthPixels_32;
291
swdd->ReadDepthSpan = mgaReadDepthSpan_24_8;
292
swdd->WriteDepthSpan = mgaWriteDepthSpan_24_8;
293
swdd->ReadDepthPixels = mgaReadDepthPixels_24_8;
294
swdd->WriteDepthPixels = mgaWriteDepthPixels_24_8;
296
swdd->ReadStencilSpan = mgaReadStencilSpan_24_8;
297
swdd->WriteStencilSpan = mgaWriteStencilSpan_24_8;
298
swdd->ReadStencilPixels = mgaReadStencilPixels_24_8;
299
swdd->WriteStencilPixels = mgaWriteStencilPixels_24_8;