Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / i810 / i810span.c
1 #include "main/glheader.h"
2 #include "main/macros.h"
3 #include "main/mtypes.h"
4 #include "main/colormac.h"
5 #include "swrast/swrast.h"
6
7 #include "i810screen.h"
8 #include "i810_dri.h"
9
10 #include "i810span.h"
11 #include "i810ioctl.h"
12
13
14 #define DBG 0
15
16 #define LOCAL_VARS \
17 i810ContextPtr imesa = I810_CONTEXT(ctx); \
18 __DRIdrawable *dPriv = imesa->driDrawable; \
19 driRenderbuffer *drb = (driRenderbuffer *) rb; \
20 GLuint pitch = drb->pitch; \
21 GLuint height = dPriv->h; \
22 GLushort p; \
23 char *buf = (char *)(drb->flippedData + \
24 dPriv->x * 2 + \
25 dPriv->y * pitch); \
26 (void) buf; (void) p
27
28 #define LOCAL_DEPTH_VARS \
29 i810ContextPtr imesa = I810_CONTEXT(ctx); \
30 __DRIdrawable *dPriv = imesa->driDrawable; \
31 driRenderbuffer *drb = (driRenderbuffer *) rb; \
32 GLuint pitch = drb->pitch; \
33 GLuint height = dPriv->h; \
34 char *buf = (char *)(drb->Base.Data + \
35 dPriv->x * 2 + \
36 dPriv->y * pitch)
37
38 #define INIT_MONO_PIXEL(p, color) \
39 p = PACK_COLOR_565( color[0], color[1], color[2] )
40
41 #define Y_FLIP(_y) (height - _y - 1)
42
43 #define HW_LOCK()
44
45 #define HW_UNLOCK()
46
47 /* 16 bit, 565 rgb color spanline and pixel functions
48 */
49 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
50 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
51 (((int)g & 0xfc) << 3) | \
52 (((int)b & 0xf8) >> 3))
53 #define WRITE_PIXEL( _x, _y, p ) \
54 *(GLushort *)(buf + _x*2 + _y*pitch) = p
55
56 #define READ_RGBA( rgba, _x, _y ) \
57 do { \
58 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
59 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
60 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
61 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
62 rgba[3] = 255; \
63 } while(0)
64
65 #define TAG(x) i810##x##_565
66 #include "spantmp.h"
67
68 /* 16 bit depthbuffer functions.
69 */
70 #define VALUE_TYPE GLushort
71
72 #define WRITE_DEPTH( _x, _y, d ) \
73 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
74
75 #define READ_DEPTH( d, _x, _y ) \
76 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
77
78 #define TAG(x) i810##x##_z16
79 #include "depthtmp.h"
80
81
82 /* Move locking out to get reasonable span performance.
83 */
84 void i810SpanRenderStart( GLcontext *ctx )
85 {
86 i810ContextPtr imesa = I810_CONTEXT(ctx);
87 I810_FIREVERTICES(imesa);
88 LOCK_HARDWARE(imesa);
89 i810RegetLockQuiescent( imesa );
90 }
91
92 void i810SpanRenderFinish( GLcontext *ctx )
93 {
94 i810ContextPtr imesa = I810_CONTEXT( ctx );
95 _swrast_flush( ctx );
96 UNLOCK_HARDWARE( imesa );
97 }
98
99 void i810InitSpanFuncs( GLcontext *ctx )
100 {
101 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
102 swdd->SpanRenderStart = i810SpanRenderStart;
103 swdd->SpanRenderFinish = i810SpanRenderFinish;
104 }
105
106
107
108 /**
109 * Plug in the Get/Put routines for the given driRenderbuffer.
110 */
111 void
112 i810SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
113 {
114 if (drb->Base.InternalFormat == GL_RGBA) {
115 /* always 565 RGB */
116 i810InitPointers_565(&drb->Base);
117 }
118 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
119 i810InitDepthPointers_z16(&drb->Base);
120 }
121 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
122 /* should never get here */
123 drb->Base.GetRow = NULL;
124 drb->Base.GetValues = NULL;
125 drb->Base.PutRow = NULL;
126 drb->Base.PutMonoRow = NULL;
127 drb->Base.PutValues = NULL;
128 drb->Base.PutMonoValues = NULL;
129 }
130 else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
131 drb->Base.GetRow = NULL;
132 drb->Base.GetValues = NULL;
133 drb->Base.PutRow = NULL;
134 drb->Base.PutMonoRow = NULL;
135 drb->Base.PutValues = NULL;
136 drb->Base.PutMonoValues = NULL;
137 }
138 }