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"
34 #include "intel_regions.h"
35 #include "intel_span.h"
36 #include "intel_ioctl.h"
37 #include "intel_tex.h"
38 #include "swrast/swrast.h"
44 struct intel_context *intel = intel_context(ctx); \
45 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
46 driRenderbuffer *drb = (driRenderbuffer *) rb; \
47 GLuint pitch = drb->pitch; \
48 GLuint height = dPriv->h; \
49 char *buf = (char *) drb->Base.Data + \
50 dPriv->x * drb->cpp + \
55 #define LOCAL_DEPTH_VARS \
56 struct intel_context *intel = intel_context(ctx); \
57 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
58 driRenderbuffer *drb = (driRenderbuffer *) rb; \
59 GLuint pitch = drb->pitch; \
60 GLuint height = dPriv->h; \
61 char *buf = (char *) drb->Base.Data + \
62 dPriv->x * drb->cpp + \
65 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
67 #define INIT_MONO_PIXEL(p,color)\
68 p = INTEL_PACKCOLOR565(color[0],color[1],color[2])
70 #define Y_FLIP(_y) (height - _y - 1)
76 /* 16 bit, 565 rgb color spanline and pixel functions
78 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
79 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
80 (((int)g & 0xfc) << 3) | \
81 (((int)b & 0xf8) >> 3))
82 #define WRITE_PIXEL( _x, _y, p ) \
83 *(GLushort *)(buf + _x*2 + _y*pitch) = p
85 #define READ_RGBA( rgba, _x, _y ) \
87 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
88 rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \
89 rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \
90 rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \
94 #define TAG(x) intel##x##_565
97 /* 15 bit, 555 rgb color spanline and pixel functions
99 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
100 *(GLushort *)(buf + _x*2 + _y*pitch) = (((r & 0xf8) << 7) | \
101 ((g & 0xf8) << 3) | \
104 #define WRITE_PIXEL( _x, _y, p ) \
105 *(GLushort *)(buf + _x*2 + _y*pitch) = p
107 #define READ_RGBA( rgba, _x, _y ) \
109 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
110 rgba[0] = (p >> 7) & 0xf8; \
111 rgba[1] = (p >> 3) & 0xf8; \
112 rgba[2] = (p << 3) & 0xf8; \
116 #define TAG(x) intel##x##_555
119 /* 16 bit depthbuffer functions.
121 #define WRITE_DEPTH( _x, _y, d ) \
122 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
124 #define READ_DEPTH( d, _x, _y ) \
125 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
128 #define TAG(x) intel##x##_z16
129 #include "depthtmp.h"
134 struct intel_context *intel = intel_context(ctx); \
135 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
136 driRenderbuffer *drb = (driRenderbuffer *) rb; \
137 GLuint pitch = drb->pitch; \
138 GLuint height = dPriv->h; \
139 char *buf = (char *)drb->Base.Data + \
140 dPriv->x * drb->cpp + \
145 #undef INIT_MONO_PIXEL
146 #define INIT_MONO_PIXEL(p,color)\
147 p = INTEL_PACKCOLOR8888(color[0],color[1],color[2],color[3])
149 /* 32 bit, 8888 argb color spanline and pixel functions
151 #define WRITE_RGBA(_x, _y, r, g, b, a) \
152 *(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) | \
157 #define WRITE_PIXEL(_x, _y, p) \
158 *(GLuint *)(buf + _x*4 + _y*pitch) = p
161 #define READ_RGBA(rgba, _x, _y) \
163 GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \
164 rgba[0] = (p >> 16) & 0xff; \
165 rgba[1] = (p >> 8) & 0xff; \
166 rgba[2] = (p >> 0) & 0xff; \
167 rgba[3] = (p >> 24) & 0xff; \
170 #define TAG(x) intel##x##_8888
174 /* 24/8 bit interleaved depth/stencil functions
176 #define WRITE_DEPTH( _x, _y, d ) { \
177 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
179 tmp |= (d) & 0xffffff; \
180 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
183 #define READ_DEPTH( d, _x, _y ) \
184 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & 0xffffff;
187 #define TAG(x) intel##x##_z24_s8
188 #include "depthtmp.h"
190 #define WRITE_STENCIL( _x, _y, d ) { \
191 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
194 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
197 #define READ_STENCIL( d, _x, _y ) \
198 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) >> 24;
200 #define TAG(x) intel##x##_z24_s8
201 #include "stenciltmp.h"
204 /* Move locking out to get reasonable span performance.
206 void intelSpanRenderStart( GLcontext
*ctx
)
208 struct intel_context
*intel
= intel_context(ctx
);
210 if (intel
->need_flush
) {
211 LOCK_HARDWARE(intel
);
212 intel
->vtbl
.emit_flush(intel
, 0);
213 intel_batchbuffer_flush(intel
->batch
);
214 intel
->need_flush
= 0;
215 UNLOCK_HARDWARE(intel
);
220 LOCK_HARDWARE(intel
);
222 /* Just map the framebuffer and all textures. Bufmgr code will
223 * take care of waiting on the necessary fences:
225 intel_region_map(intel
, intel
->front_region
);
226 intel_region_map(intel
, intel
->back_region
);
227 intel_region_map(intel
, intel
->depth_region
);
230 void intelSpanRenderFinish( GLcontext
*ctx
)
232 struct intel_context
*intel
= intel_context( ctx
);
234 _swrast_flush( ctx
);
236 /* Now unmap the framebuffer:
238 intel_region_unmap(intel
, intel
->front_region
);
239 intel_region_unmap(intel
, intel
->back_region
);
240 intel_region_unmap(intel
, intel
->depth_region
);
242 UNLOCK_HARDWARE( intel
);
245 void intelInitSpanFuncs( GLcontext
*ctx
)
247 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
248 swdd
->SpanRenderStart
= intelSpanRenderStart
;
249 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
254 * Plug in the Get/Put routines for the given driRenderbuffer.
257 intelSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
259 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
260 if (vis
->redBits
== 5 && vis
->greenBits
== 5 && vis
->blueBits
== 5) {
261 intelInitPointers_555(&drb
->Base
);
263 else if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
264 intelInitPointers_565(&drb
->Base
);
267 assert(vis
->redBits
== 8);
268 assert(vis
->greenBits
== 8);
269 assert(vis
->blueBits
== 8);
270 intelInitPointers_8888(&drb
->Base
);
273 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
274 intelInitDepthPointers_z16(&drb
->Base
);
276 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
277 intelInitDepthPointers_z24_s8(&drb
->Base
);
279 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
280 intelInitStencilPointers_z24_s8(&drb
->Base
);