Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / i810 / i810context.h
1 /*
2  * GLX Hardware Device Driver for Intel i810
3  * Copyright (C) 1999 Keith Whitwell
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, sublicense,
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 shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
21  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24
25 #ifndef I810CONTEXT_INC
26 #define I810CONTEXT_INC
27
28 typedef struct i810_context_t i810Context;
29 typedef struct i810_context_t *i810ContextPtr;
30 typedef struct i810_texture_object_t *i810TextureObjectPtr;
31
32 #include "drm.h"
33 #include "main/mtypes.h"
34 #include "main/mm.h"
35
36 #include "i810screen.h"
37 #include "i810tex.h"
38
39
40 /* Reasons to disable hardware rasterization. 
41  */
42 #define I810_FALLBACK_TEXTURE        0x1
43 #define I810_FALLBACK_DRAW_BUFFER    0x2
44 #define I810_FALLBACK_READ_BUFFER    0x4
45 #define I810_FALLBACK_COLORMASK      0x8  
46 #define I810_FALLBACK_SPECULAR       0x20 
47 #define I810_FALLBACK_LOGICOP        0x40
48 #define I810_FALLBACK_RENDERMODE     0x80
49 #define I810_FALLBACK_STENCIL        0x100
50 #define I810_FALLBACK_BLEND_EQ       0x200
51 #define I810_FALLBACK_BLEND_FUNC     0x400
52
53
54 #ifndef PCI_CHIP_I810                            
55 #define PCI_CHIP_I810              0x7121
56 #define PCI_CHIP_I810_DC100        0x7123
57 #define PCI_CHIP_I810_E            0x7125 
58 #define PCI_CHIP_I815              0x1132 
59 #endif
60
61 #define IS_I810(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I810 || \
62                         imesa->i810Screen->deviceID == PCI_CHIP_I810_DC100 || \
63                         imesa->i810Screen->deviceID == PCI_CHIP_I810_E)
64 #define IS_I815(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I815)
65
66
67 #define I810_UPLOAD_TEX(i) (I810_UPLOAD_TEX0<<(i))
68
69 /* Use the templated vertex formats:
70  */
71 #define TAG(x) i810##x
72 #include "tnl_dd/t_dd_vertex.h"
73 #undef TAG
74
75 typedef void (*i810_tri_func)( i810ContextPtr, i810Vertex *, i810Vertex *,
76                                i810Vertex * );
77 typedef void (*i810_line_func)( i810ContextPtr, i810Vertex *, i810Vertex * );
78 typedef void (*i810_point_func)( i810ContextPtr, i810Vertex * );
79
80 struct i810_context_t {
81    GLint refcount;   
82    struct gl_context *glCtx;
83
84    /* Texture object bookkeeping
85     */
86    unsigned              nr_heaps;
87    driTexHeap          * texture_heaps[1];
88    driTextureObject      swapped;
89
90    struct i810_texture_object_t *CurrentTexObj[2];
91
92
93    /* Bit flag to keep track of fallbacks.
94     */
95    GLuint Fallback;
96
97    /* State for i810vb.c and i810tris.c.
98     */
99    GLuint new_state;            /* _NEW_* flags */
100    GLuint SetupNewInputs;
101    GLuint SetupIndex;
102    GLuint RenderIndex;
103    GLmatrix ViewportMatrix;
104    GLenum render_primitive;
105    GLenum reduced_primitive;
106    GLuint hw_primitive;
107    GLubyte *verts;
108
109    drmBufPtr  vertex_buffer;
110    char *vertex_addr;
111    GLuint vertex_low;
112    GLuint vertex_high;
113    GLuint vertex_last_prim;
114    
115    GLboolean upload_cliprects;
116
117
118    /* Fallback rasterization functions 
119     */
120    i810_point_func draw_point;
121    i810_line_func draw_line;
122    i810_tri_func draw_tri;
123
124    /* Hardware state 
125     */
126    GLuint dirty;                /* I810_UPLOAD_* */
127    GLuint Setup[I810_CTX_SETUP_SIZE];
128    GLuint BufferSetup[I810_DEST_SETUP_SIZE];
129    int vertex_size;
130    int vertex_stride_shift;
131    unsigned int lastStamp;
132    GLboolean stipple_in_hw;
133
134    GLenum TexEnvImageFmt[2];
135
136    /* State which can't be computed completely on the fly:
137     */
138    GLuint LcsCullMode;
139    GLuint LcsLineWidth;
140    GLuint LcsPointSize;
141
142    /* Funny mesa mirrors
143     */
144    GLushort ClearColor;
145
146    /* DRI stuff
147     */
148    GLuint needClip;
149    struct gl_framebuffer *glBuffer;
150    GLboolean doPageFlip;
151
152    /* These refer to the current draw (front vs. back) buffer:
153     */
154    int drawX;                   /* origin of drawable in draw buffer */
155    int drawY;
156    GLuint numClipRects;         /* cliprects for that buffer */
157    drm_clip_rect_t *pClipRects;
158
159    int lastSwap;
160    int texAge;
161    int ctxAge;
162    int dirtyAge;
163   
164  
165    GLboolean scissor;
166    drm_clip_rect_t draw_rect;
167    drm_clip_rect_t scissor_rect;
168
169    drm_context_t hHWContext;
170    drm_hw_lock_t *driHwLock;
171    int driFd;
172
173    __DRIdrawable *driDrawable;
174    __DRIscreen *driScreen;
175    i810ScreenPrivate *i810Screen; 
176    I810SAREAPtr sarea;
177 };
178
179
180 #define I810_CONTEXT(ctx)    ((i810ContextPtr)(ctx->DriverCtx))
181
182 #define GET_DISPATCH_AGE( imesa ) imesa->sarea->last_dispatch
183 #define GET_ENQUEUE_AGE( imesa ) imesa->sarea->last_enqueue
184
185
186 /* Lock the hardware and validate our state.  
187  */
188 #define LOCK_HARDWARE( imesa )                          \
189   do {                                                  \
190     char __ret=0;                                       \
191     DRM_CAS(imesa->driHwLock, imesa->hHWContext,        \
192             (DRM_LOCK_HELD|imesa->hHWContext), __ret);  \
193     if (__ret)                                          \
194         i810GetLock( imesa, 0 );                        \
195   } while (0)
196
197
198
199 /* Release the kernel lock.
200  */
201 #define UNLOCK_HARDWARE(imesa)                                  \
202     DRM_UNLOCK(imesa->driFd, imesa->driHwLock, imesa->hHWContext);      
203
204
205 /* This is the wrong way to do it, I'm sure.  Otherwise the drm
206  * bitches that I've already got the heavyweight lock.  At worst,
207  * this is 3 ioctls.  The best solution probably only gets me down 
208  * to 2 ioctls in the worst case.
209  */
210 #define LOCK_HARDWARE_QUIESCENT( imesa ) do {   \
211    LOCK_HARDWARE( imesa );                      \
212    i810RegetLockQuiescent( imesa );             \
213 } while(0)
214
215
216 extern void i810GetLock( i810ContextPtr imesa, GLuint flags );
217 extern void i810EmitHwStateLocked( i810ContextPtr imesa );
218 extern void i810EmitScissorValues( i810ContextPtr imesa, int box_nr, int emit );
219 extern void i810EmitDrawingRectangle( i810ContextPtr imesa );
220 extern void i810XMesaSetBackClipRects( i810ContextPtr imesa );
221 extern void i810XMesaSetFrontClipRects( i810ContextPtr imesa );
222
223 #define SUBPIXEL_X -.5
224 #define SUBPIXEL_Y -.5
225
226 /* ================================================================
227  * Debugging:
228  */
229 #define DO_DEBUG                1
230 #if DO_DEBUG
231 extern int I810_DEBUG;
232 #else
233 #define I810_DEBUG              0
234 #endif
235
236 #define DEBUG_TEXTURE   0x1
237 #define DEBUG_STATE     0x2
238 #define DEBUG_IOCTL     0x4
239 #define DEBUG_PRIMS     0x8
240 #define DEBUG_VERTS     0x10
241 #define DEBUG_FALLBACKS 0x20
242 #define DEBUG_VERBOSE   0x40
243 #define DEBUG_DRI       0x80
244 #define DEBUG_DMA       0x100
245 #define DEBUG_SANITY    0x200
246 #define DEBUG_SYNC      0x400
247 #define DEBUG_SLEEP     0x800
248
249 #endif