1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "intel_screen.h"
35 #include "intel_span.h"
36 #include "intel_ioctl.h"
37 #include "swrast/swrast.h"
43 intelContextPtr intel = INTEL_CONTEXT(ctx); \
44 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
45 driRenderbuffer *drb = (driRenderbuffer *) rb; \
46 GLuint pitch = drb->pitch; \
47 GLuint height = dPriv->h; \
48 char *buf = (char *) drb->Base.Data + \
49 dPriv->x * drb->cpp + \
54 #define LOCAL_DEPTH_VARS \
55 intelContextPtr intel = INTEL_CONTEXT(ctx); \
56 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
57 driRenderbuffer *drb = (driRenderbuffer *) rb; \
58 GLuint pitch = drb->pitch; \
59 GLuint height = dPriv->h; \
60 char *buf = (char *) drb->Base.Data + \
61 dPriv->x * drb->cpp + \
64 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
66 #define INIT_MONO_PIXEL(p,color)\
67 p = INTEL_PACKCOLOR565(color[0],color[1],color[2])
69 #define Y_FLIP(_y) (height - _y - 1)
75 /* 16 bit, 565 rgb color spanline and pixel functions
77 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
78 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
79 (((int)g & 0xfc) << 3) | \
80 (((int)b & 0xf8) >> 3))
81 #define WRITE_PIXEL( _x, _y, p ) \
82 *(GLushort *)(buf + _x*2 + _y*pitch) = p
84 #define READ_RGBA( rgba, _x, _y ) \
86 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
87 rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \
88 rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \
89 rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \
93 #define TAG(x) intel##x##_565
96 /* 15 bit, 555 rgb color spanline and pixel functions
98 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
99 *(GLushort *)(buf + _x*2 + _y*pitch) = (((r & 0xf8) << 7) | \
100 ((g & 0xf8) << 3) | \
103 #define WRITE_PIXEL( _x, _y, p ) \
104 *(GLushort *)(buf + _x*2 + _y*pitch) = p
106 #define READ_RGBA( rgba, _x, _y ) \
108 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
109 rgba[0] = (p >> 7) & 0xf8; \
110 rgba[1] = (p >> 3) & 0xf8; \
111 rgba[2] = (p << 3) & 0xf8; \
115 #define TAG(x) intel##x##_555
118 /* 16 bit depthbuffer functions.
120 #define WRITE_DEPTH( _x, _y, d ) \
121 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
123 #define READ_DEPTH( d, _x, _y ) \
124 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
127 #define TAG(x) intel##x##_z16
128 #include "depthtmp.h"
133 intelContextPtr intel = INTEL_CONTEXT(ctx); \
134 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
135 driRenderbuffer *drb = (driRenderbuffer *) rb; \
136 GLuint pitch = drb->pitch; \
137 GLuint height = dPriv->h; \
138 char *buf = (char *)drb->Base.Data + \
139 dPriv->x * drb->cpp + \
144 #undef INIT_MONO_PIXEL
145 #define INIT_MONO_PIXEL(p,color)\
146 p = INTEL_PACKCOLOR8888(color[0],color[1],color[2],color[3])
148 /* 32 bit, 8888 argb color spanline and pixel functions
150 #define WRITE_RGBA(_x, _y, r, g, b, a) \
151 *(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) | \
156 #define WRITE_PIXEL(_x, _y, p) \
157 *(GLuint *)(buf + _x*4 + _y*pitch) = p
160 #define READ_RGBA(rgba, _x, _y) \
162 GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \
163 rgba[0] = (p >> 16) & 0xff; \
164 rgba[1] = (p >> 8) & 0xff; \
165 rgba[2] = (p >> 0) & 0xff; \
166 rgba[3] = (p >> 24) & 0xff; \
169 #define TAG(x) intel##x##_8888
173 /* 24/8 bit interleaved depth/stencil functions
175 #define WRITE_DEPTH( _x, _y, d ) { \
176 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
178 tmp |= (d) & 0xffffff; \
179 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
182 #define READ_DEPTH( d, _x, _y ) \
183 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & 0xffffff;
186 #define TAG(x) intel##x##_z24_s8
187 #include "depthtmp.h"
189 #define WRITE_STENCIL( _x, _y, d ) { \
190 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
193 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
196 #define READ_STENCIL( d, _x, _y ) \
197 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) >> 24;
199 #define TAG(x) intel##x##_z24_s8
200 #include "stenciltmp.h"
203 /* Move locking out to get reasonable span performance.
205 void intelSpanRenderStart( GLcontext
*ctx
)
207 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
209 intelFlush(&intel
->ctx
);
210 LOCK_HARDWARE(intel
);
211 intelWaitForIdle(intel
);
214 void intelSpanRenderFinish( GLcontext
*ctx
)
216 intelContextPtr intel
= INTEL_CONTEXT( ctx
);
217 _swrast_flush( ctx
);
218 UNLOCK_HARDWARE( intel
);
221 void intelInitSpanFuncs( GLcontext
*ctx
)
223 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
224 swdd
->SpanRenderStart
= intelSpanRenderStart
;
225 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
230 * Plug in the Get/Put routines for the given driRenderbuffer.
233 intelSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
235 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
236 if (vis
->redBits
== 5 && vis
->greenBits
== 5 && vis
->blueBits
== 5) {
237 intelInitPointers_555(&drb
->Base
);
239 else if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
240 intelInitPointers_565(&drb
->Base
);
243 assert(vis
->redBits
== 8);
244 assert(vis
->greenBits
== 8);
245 assert(vis
->blueBits
== 8);
246 intelInitPointers_8888(&drb
->Base
);
249 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
250 intelInitDepthPointers_z16(&drb
->Base
);
252 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
253 intelInitDepthPointers_z24_s8(&drb
->Base
);
255 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
256 intelInitStencilPointers_z24_s8(&drb
->Base
);