Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / unichrome / via_span.c
1 /*
2  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sub license,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "main/glheader.h"
26 #include "main/formats.h"
27 #include "main/macros.h"
28 #include "main/mtypes.h"
29 #include "main/colormac.h"
30 #include "via_context.h"
31 #include "via_span.h"
32 #include "via_ioctl.h"
33 #include "swrast/swrast.h"
34
35 #define DBG 0
36
37 #define Y_FLIP(_y) (height - _y - 1)
38
39 #define HW_LOCK() 
40
41 #define HW_UNLOCK()
42
43 #undef LOCAL_VARS
44 #define LOCAL_VARS                                                      \
45     struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb;      \
46     __DRIdrawable *dPriv = vrb->dPriv;                           \
47     GLuint pitch = vrb->pitch;                                          \
48     GLuint height = dPriv->h;                                           \
49     GLint p = 0;                                                        \
50     char *buf = (char *)(vrb->origMap);                                 \
51     (void) p;
52
53 /* ================================================================
54  * Color buffer
55  */
56
57 /* 16 bit, RGB565 color spanline and pixel functions
58  */
59 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
60 #define SPANTMP_PIXEL_FMT GL_RGB
61 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
62
63 #define TAG(x)    via##x##_565
64 #define TAG2(x,y) via##x##_565##y
65 #include "spantmp2.h"
66
67
68 /* 32 bit, ARGB8888 color spanline and pixel functions
69  */
70 #define GET_PTR(_x, _y) (buf + (_x) * 4 + (_y) * pitch)
71 #define SPANTMP_PIXEL_FMT GL_BGRA
72 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
73
74 #define TAG(x)    via##x##_8888
75 #define TAG2(x,y) via##x##_8888##y
76 #include "spantmp2.h"
77
78
79 /* 16 bit depthbuffer functions.
80  */
81 #define LOCAL_DEPTH_VARS                                            \
82     struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb;  \
83     __DRIdrawable *dPriv = vrb->dPriv;                       \
84     GLuint depth_pitch = vrb->pitch;                                \
85     GLuint height = dPriv->h;                                       \
86     char *buf = (char *)(vrb->map)
87
88 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
89
90 #define VALUE_TYPE GLushort
91
92 #define WRITE_DEPTH(_x, _y, d)                      \
93     *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
94
95 #define READ_DEPTH(d, _x, _y)                       \
96     d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
97
98 #define TAG(x) via##x##_z16
99 #include "depthtmp.h"
100
101 /* 32 bit depthbuffer functions.
102  */
103 #define VALUE_TYPE GLuint
104
105 #define WRITE_DEPTH(_x, _y, d)                      \
106     *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
107
108 #define READ_DEPTH(d, _x, _y)                       \
109     d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
110
111 #define TAG(x) via##x##_z32
112 #include "depthtmp.h"
113
114
115
116 /* 24/8 bit interleaved depth/stencil functions
117  */
118 #define VALUE_TYPE GLuint
119
120 #define WRITE_DEPTH( _x, _y, d ) {                      \
121    GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch);   \
122    tmp &= 0x000000ff;                                   \
123    tmp |= ((d)<<8);                             \
124    *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp;          \
125 }
126
127 #define READ_DEPTH( d, _x, _y )         \
128    d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
129
130
131 #define TAG(x) via##x##_z24_s8
132 #include "depthtmp.h"
133
134 #define WRITE_STENCIL( _x, _y, d ) {                    \
135    GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch);   \
136    tmp &= 0xffffff00;                                   \
137    tmp |= (d);                                  \
138    *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp;          \
139 }
140
141 #define READ_STENCIL( d, _x, _y )                       \
142    d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
143
144 #define TAG(x) via##x##_z24_s8
145 #include "stenciltmp.h"
146
147
148
149
150 /* Move locking out to get reasonable span performance.
151  */
152 void viaSpanRenderStart( struct gl_context *ctx )
153 {
154    struct via_context *vmesa = VIA_CONTEXT(ctx);     
155    viaWaitIdle(vmesa, GL_FALSE);
156    LOCK_HARDWARE(vmesa);
157 }
158
159 void viaSpanRenderFinish( struct gl_context *ctx )
160 {
161    struct via_context *vmesa = VIA_CONTEXT(ctx);
162    _swrast_flush( ctx );
163    UNLOCK_HARDWARE( vmesa );
164 }
165
166 void viaInitSpanFuncs(struct gl_context *ctx)
167 {
168     struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
169     swdd->SpanRenderStart = viaSpanRenderStart;
170     swdd->SpanRenderFinish = viaSpanRenderFinish; 
171 }
172
173
174
175 /**
176  * Plug in the Get/Put routines for the given driRenderbuffer.
177  */
178 void
179 viaSetSpanFunctions(struct via_renderbuffer *vrb, const struct gl_config *vis)
180 {
181    if (vrb->Base.Format == MESA_FORMAT_RGB565) {
182       viaInitPointers_565(&vrb->Base);
183    }
184    else if (vrb->Base.Format == MESA_FORMAT_ARGB8888) {
185       viaInitPointers_8888(&vrb->Base);
186    }
187    else if (vrb->Base.Format == MESA_FORMAT_Z16) {
188       viaInitDepthPointers_z16(&vrb->Base);
189    }
190    else if (vrb->Base.Format == MESA_FORMAT_Z24_S8) {
191       viaInitDepthPointers_z24_s8(&vrb->Base);
192    }
193    else if (vrb->Base.Format == MESA_FORMAT_Z32) {
194       viaInitDepthPointers_z32(&vrb->Base);
195    }
196    else if (vrb->Base.Format == MESA_FORMAT_S8) {
197       viaInitStencilPointers_z24_s8(&vrb->Base);
198    }
199 }