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