Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / sis / sis_span.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29  * Authors:
30  *   Sung-Ching Lin <sclin@sis.com.tw>
31  *   Eric Anholt <anholt@FreeBSD.org>
32  */
33
34 #include "sis_context.h"
35 #include "sis_span.h"
36 #include "sis_lock.h"
37 #include "sis_tris.h"
38
39 #include "swrast/swrast.h"
40
41 #define DBG 0
42
43 #define LOCAL_VARS                                                      \
44    sisContextPtr smesa = SIS_CONTEXT(ctx);                              \
45    __DRIdrawable *dPriv = smesa->driDrawable;                   \
46    struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb;       \
47    GLuint pitch = srb->pitch;                                           \
48    char *buf = srb->map;                                                \
49    GLuint p;                                                            \
50    (void) buf; (void) p;
51    
52
53 #define LOCAL_DEPTH_VARS                                                \
54    sisContextPtr smesa = SIS_CONTEXT(ctx);                              \
55    __DRIdrawable *dPriv = smesa->driDrawable;                   \
56    struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb;       \
57    char *buf = srb->map;
58
59 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
60
61 #define HW_LOCK() do {} while(0);
62
63 #define HW_UNLOCK() do {} while(0);
64
65 /* RGB565 */
66 #define SPANTMP_PIXEL_FMT GL_RGB
67 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
68
69 #define TAG(x)    sis##x##_RGB565
70 #define TAG2(x,y) sis##x##_RGB565##y
71 #include "spantmp2.h"
72
73
74 /* ARGB8888 */
75 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
76    Was there a reason to do so ? If so that'll won't work with that template... */
77 #define SPANTMP_PIXEL_FMT GL_BGRA
78 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
79
80 #define TAG(x)    sis##x##_ARGB8888
81 #define TAG2(x,y) sis##x##_ARGB8888##y
82 #include "spantmp2.h"
83
84
85 /* 16 bit depthbuffer functions.
86  */
87 #define VALUE_TYPE GLushort
88
89 #define WRITE_DEPTH( _x, _y, d )        \
90    *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch) = d;
91
92 #define READ_DEPTH( d, _x, _y )         \
93    d = *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch);
94
95 #define TAG(x) sis##x##_z16
96 #include "depthtmp.h"
97
98
99 /* 32 bit depthbuffer functions.
100  */
101 #define VALUE_TYPE GLuint
102
103 #define WRITE_DEPTH( _x, _y, d )        \
104    *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = d;
105
106 #define READ_DEPTH( d, _x, _y )         \
107    d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch);
108
109 #define TAG(x) sis##x##_z32
110 #include "depthtmp.h"
111
112
113 /* 8/24 bit interleaved depth/stencil functions
114  */
115 #define VALUE_TYPE GLuint
116
117 #define WRITE_DEPTH( _x, _y, d ) {                              \
118    GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch);    \
119    tmp &= 0xff000000;                                           \
120    tmp |= (d & 0x00ffffff);                                     \
121    *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp;           \
122 }
123
124 #define READ_DEPTH( d, _x, _y ) {                               \
125    d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0x00ffffff; \
126 }
127
128 #define TAG(x) sis##x##_z24_s8
129 #include "depthtmp.h"
130
131 #define WRITE_STENCIL( _x, _y, d ) {                            \
132    GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depth.pitch); \
133    tmp &= 0x00ffffff;                                           \
134    tmp |= (d << 24);                                            \
135    *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp;   \
136 }
137
138 #define READ_STENCIL( d, _x, _y )                       \
139    d = (*(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0xff000000) >> 24;
140
141 #define TAG(x) sis##x##_z24_s8
142 #include "stenciltmp.h"
143
144
145
146 void sisSpanRenderStart( struct gl_context *ctx )
147 {
148    sisContextPtr smesa = SIS_CONTEXT(ctx);
149
150    SIS_FIREVERTICES(smesa);
151    LOCK_HARDWARE();
152    WaitEngIdle( smesa );
153 }
154
155 void sisSpanRenderFinish( struct gl_context *ctx )
156 {
157    sisContextPtr smesa = SIS_CONTEXT(ctx);
158
159    _swrast_flush( ctx );
160    UNLOCK_HARDWARE();
161 }
162
163 void
164 sisDDInitSpanFuncs( struct gl_context *ctx )
165 {
166    struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
167    swdd->SpanRenderStart   = sisSpanRenderStart;
168    swdd->SpanRenderFinish  = sisSpanRenderFinish; 
169 }
170
171
172
173 /**
174  * Plug in the Get/Put routines for the given driRenderbuffer.
175  */
176 void
177 sisSetSpanFunctions(struct sis_renderbuffer *srb, const struct gl_config *vis)
178 {
179    if (srb->Base.Format == MESA_FORMAT_RGB565) {
180       sisInitPointers_RGB565( &srb->Base );
181    }
182    else if (srb->Base.Format == MESA_FORMAT_ARGB8888) {
183       sisInitPointers_ARGB8888( &srb->Base );
184    }
185    else if (srb->Base.Format == MESA_FORMAT_Z16) {
186       sisInitDepthPointers_z16(&srb->Base);
187    }
188    else if (srb->Base.Format == MESA_FORMAT_S8_Z24) {
189       sisInitDepthPointers_z24_s8(&srb->Base);
190    }
191    else if (srb->Base.Format == MESA_FORMAT_Z32) {
192       sisInitDepthPointers_z32(&srb->Base);
193    }
194    else if (srb->Base.Format == MESA_FORMAT_S8) {
195       sisInitStencilPointers_z24_s8(&srb->Base);
196    }
197 }