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 "intel_batchbuffer.h"
39 #include "swrast/swrast.h"
45 struct intel_context *intel = intel_context(ctx); \
46 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
47 driRenderbuffer *drb = (driRenderbuffer *) rb; \
48 GLuint pitch = drb->pitch; \
49 GLuint height = dPriv->h; \
50 char *buf = (char *) drb->Base.Data + \
51 dPriv->x * drb->cpp + \
56 #define LOCAL_DEPTH_VARS \
57 struct intel_context *intel = intel_context(ctx); \
58 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
59 driRenderbuffer *drb = (driRenderbuffer *) rb; \
60 GLuint pitch = drb->pitch; \
61 GLuint height = dPriv->h; \
62 char *buf = (char *) drb->Base.Data + \
63 dPriv->x * drb->cpp + \
66 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
68 #define INIT_MONO_PIXEL(p,color)\
69 p = INTEL_PACKCOLOR565(color[0],color[1],color[2])
71 #define Y_FLIP(_y) (height - _y - 1)
77 /* 16 bit, 565 rgb color spanline and pixel functions
79 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
80 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
81 (((int)g & 0xfc) << 3) | \
82 (((int)b & 0xf8) >> 3))
83 #define WRITE_PIXEL( _x, _y, p ) \
84 *(GLushort *)(buf + _x*2 + _y*pitch) = p
86 #define READ_RGBA( rgba, _x, _y ) \
88 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
89 rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \
90 rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \
91 rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \
95 #define TAG(x) intel##x##_565
98 /* 15 bit, 555 rgb color spanline and pixel functions
100 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
101 *(GLushort *)(buf + _x*2 + _y*pitch) = (((r & 0xf8) << 7) | \
102 ((g & 0xf8) << 3) | \
105 #define WRITE_PIXEL( _x, _y, p ) \
106 *(GLushort *)(buf + _x*2 + _y*pitch) = p
108 #define READ_RGBA( rgba, _x, _y ) \
110 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
111 rgba[0] = (p >> 7) & 0xf8; \
112 rgba[1] = (p >> 3) & 0xf8; \
113 rgba[2] = (p << 3) & 0xf8; \
117 #define TAG(x) intel##x##_555
120 /* 16 bit depthbuffer functions.
122 #define WRITE_DEPTH( _x, _y, d ) \
123 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
125 #define READ_DEPTH( d, _x, _y ) \
126 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
129 #define TAG(x) intel##x##_z16
130 #include "depthtmp.h"
135 struct intel_context *intel = intel_context(ctx); \
136 __DRIdrawablePrivate *dPriv = intel->driDrawable; \
137 driRenderbuffer *drb = (driRenderbuffer *) rb; \
138 GLuint pitch = drb->pitch; \
139 GLuint height = dPriv->h; \
140 char *buf = (char *)drb->Base.Data + \
141 dPriv->x * drb->cpp + \
146 #undef INIT_MONO_PIXEL
147 #define INIT_MONO_PIXEL(p,color)\
148 p = INTEL_PACKCOLOR8888(color[0],color[1],color[2],color[3])
150 /* 32 bit, 8888 argb color spanline and pixel functions
152 #define WRITE_RGBA(_x, _y, r, g, b, a) \
153 *(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) | \
158 #define WRITE_PIXEL(_x, _y, p) \
159 *(GLuint *)(buf + _x*4 + _y*pitch) = p
162 #define READ_RGBA(rgba, _x, _y) \
164 GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \
165 rgba[0] = (p >> 16) & 0xff; \
166 rgba[1] = (p >> 8) & 0xff; \
167 rgba[2] = (p >> 0) & 0xff; \
168 rgba[3] = (p >> 24) & 0xff; \
171 #define TAG(x) intel##x##_8888
175 /* 24/8 bit interleaved depth/stencil functions
177 #define WRITE_DEPTH( _x, _y, d ) { \
178 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
180 tmp |= (d) & 0xffffff; \
181 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
184 #define READ_DEPTH( d, _x, _y ) \
185 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & 0xffffff;
188 #define TAG(x) intel##x##_z24_s8
189 #include "depthtmp.h"
191 #define WRITE_STENCIL( _x, _y, d ) { \
192 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
195 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
198 #define READ_STENCIL( d, _x, _y ) \
199 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) >> 24;
201 #define TAG(x) intel##x##_z24_s8
202 #include "stenciltmp.h"
205 /* Move locking out to get reasonable span performance.
207 void intelSpanRenderStart( GLcontext
*ctx
)
209 struct intel_context
*intel
= intel_context(ctx
);
211 if (intel
->need_flush
) {
212 LOCK_HARDWARE(intel
);
213 intel
->vtbl
.emit_flush(intel
, 0);
214 intel_batchbuffer_flush(intel
->batch
);
215 intel
->need_flush
= 0;
216 UNLOCK_HARDWARE(intel
);
217 intelFinish(&intel
->ctx
);
221 LOCK_HARDWARE(intel
);
223 /* Just map the framebuffer and all textures. Bufmgr code will
224 * take care of waiting on the necessary fences:
226 intel_region_map(intel
, intel
->front_region
);
227 intel_region_map(intel
, intel
->back_region
);
228 intel_region_map(intel
, intel
->depth_region
);
231 void intelSpanRenderFinish( GLcontext
*ctx
)
233 struct intel_context
*intel
= intel_context( ctx
);
235 _swrast_flush( ctx
);
237 /* Now unmap the framebuffer:
239 intel_region_unmap(intel
, intel
->front_region
);
240 intel_region_unmap(intel
, intel
->back_region
);
241 intel_region_unmap(intel
, intel
->depth_region
);
243 UNLOCK_HARDWARE( intel
);
246 void intelInitSpanFuncs( GLcontext
*ctx
)
248 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
249 swdd
->SpanRenderStart
= intelSpanRenderStart
;
250 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
255 * Plug in the Get/Put routines for the given driRenderbuffer.
258 intelSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
260 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
261 if (vis
->redBits
== 5 && vis
->greenBits
== 5 && vis
->blueBits
== 5) {
262 intelInitPointers_555(&drb
->Base
);
264 else if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
265 intelInitPointers_565(&drb
->Base
);
268 assert(vis
->redBits
== 8);
269 assert(vis
->greenBits
== 8);
270 assert(vis
->blueBits
== 8);
271 intelInitPointers_8888(&drb
->Base
);
274 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
275 intelInitDepthPointers_z16(&drb
->Base
);
277 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
278 intelInitDepthPointers_z24_s8(&drb
->Base
);
280 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
281 intelInitStencilPointers_z24_s8(&drb
->Base
);