Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_span.c
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * Jos�Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #include "mach64_context.h"
33 #include "mach64_ioctl.h"
34 #include "mach64_span.h"
35
36 #include "swrast/swrast.h"
37
38 #define DBG 0
39
40 #define LOCAL_VARS \
41 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
42 __DRIscreen *sPriv = mmesa->driScreen; \
43 __DRIdrawable *dPriv = mmesa->driDrawable; \
44 driRenderbuffer *drb = (driRenderbuffer *) rb; \
45 GLuint height = dPriv->h; \
46 GLushort p; \
47 (void) p;
48
49 #define LOCAL_DEPTH_VARS \
50 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
51 __DRIdrawable *dPriv = mmesa->driDrawable; \
52 __DRIscreen *driScreen = mmesa->driScreen; \
53 driRenderbuffer *drb = (driRenderbuffer *) rb; \
54 GLuint height = dPriv->h; \
55 char *buf = (char *)(driScreen->pFB + drb->offset + \
56 (dPriv->x + dPriv->y * drb->pitch) * 2)
57
58 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
59
60 #define Y_FLIP( _y ) (height - _y - 1)
61
62 #define HW_LOCK()
63
64 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
65 #define HW_CLIPLOOP() \
66 do { \
67 int _nc = mmesa->numClipRects; \
68 \
69 while ( _nc-- ) { \
70 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
71 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
72 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
73 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
74
75 #define HW_ENDCLIPLOOP() \
76 } \
77 } while (0)
78
79 #define HW_UNLOCK()
80
81
82
83 /* ================================================================
84 * Color buffer
85 */
86
87 /* 16 bit, RGB565 color spanline and pixel functions
88 */
89 #define SPANTMP_PIXEL_FMT GL_RGB
90 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
91
92 #define TAG(x) mach64##x##_RGB565
93 #define TAG2(x,y) mach64##x##_RGB565##y
94 #define GET_PTR(X,Y) (sPriv->pFB + drb->offset \
95 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
96 #include "spantmp2.h"
97
98
99 /* 32 bit, ARGB8888 color spanline and pixel functions
100 */
101 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
102 Was there a reason to do so ? If so that'll won't work with that template... */
103 #define SPANTMP_PIXEL_FMT GL_BGRA
104 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
105
106 #define TAG(x) mach64##x##_ARGB8888
107 #define TAG2(x,y) mach64##x##_ARGB8888##y
108 #define GET_PTR(X,Y) (sPriv->pFB + drb->offset \
109 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
110 #include "spantmp2.h"
111
112
113 /* ================================================================
114 * Depth buffer
115 */
116
117 /* 16 bit depthbuffer functions.
118 */
119 #define VALUE_TYPE GLushort
120
121 #define WRITE_DEPTH( _x, _y, d ) \
122 *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2) = d;
123
124 #define READ_DEPTH( d, _x, _y ) \
125 d = *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2);
126
127 #define TAG(x) mach64##x##_z16
128 #include "depthtmp.h"
129
130
131 static void mach64SpanRenderStart( GLcontext *ctx )
132 {
133 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
134 LOCK_HARDWARE( mmesa );
135 FINISH_DMA_LOCKED( mmesa );
136 }
137
138 static void mach64SpanRenderFinish( GLcontext *ctx )
139 {
140 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
141 _swrast_flush( ctx );
142 UNLOCK_HARDWARE( mmesa );
143 }
144
145 void mach64DDInitSpanFuncs( GLcontext *ctx )
146 {
147 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
148 swdd->SpanRenderStart = mach64SpanRenderStart;
149 swdd->SpanRenderFinish = mach64SpanRenderFinish;
150 }
151
152
153 /**
154 * Plug in the Get/Put routines for the given driRenderbuffer.
155 */
156 void
157 mach64SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
158 {
159 if (drb->Base.Format == MESA_FORMAT_RGB565) {
160 mach64InitPointers_RGB565(&drb->Base);
161 }
162 else if (drb->Base.Format == MESA_FORMAT_ARGB8888) {
163 mach64InitPointers_ARGB8888(&drb->Base);
164 }
165 else if (drb->Base.Format == MESA_FORMAT_Z16) {
166 mach64InitDepthPointers_z16(&drb->Base);
167 }
168 }