gallium: fix refcount bug introduced in eb20e2984
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_context.h
1 /*
2 * Copyright 2001 by Alan Hourihane.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
13 *
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
23 *
24 */
25
26 #ifndef _GAMMA_CONTEXT_H_
27 #define _GAMMA_CONTEXT_H_
28
29 #include "dri_util.h"
30 #include "drm.h"
31 #include "drm_sarea.h"
32 #include "colormac.h"
33 #include "gamma_regs.h"
34 #include "gamma_macros.h"
35 #include "gamma_screen.h"
36 #include "macros.h"
37 #include "mtypes.h"
38 #include "glint_dri.h"
39 #include "mm.h"
40
41 typedef union {
42 unsigned int i;
43 float f;
44 } dmaBufRec, *dmaBuf;
45
46 /* Flags for context */
47 #define GAMMA_FRONT_BUFFER 0x00000001
48 #define GAMMA_BACK_BUFFER 0x00000002
49 #define GAMMA_DEPTH_BUFFER 0x00000004
50 #define GAMMA_STENCIL_BUFFER 0x00000008
51 #define GAMMA_ACCUM_BUFFER 0x00000010
52
53 #define GAMMA_MAX_TEXTURE_SIZE 2048
54
55 /* These are the minimum requirements and should probably be increased */
56 #define MAX_MODELVIEW_STACK 16
57 #define MAX_PROJECTION_STACK 2
58 #define MAX_TEXTURE_STACK 2
59
60 extern void gammaDDUpdateHWState(GLcontext *ctx);
61 extern gammaScreenPtr gammaCreateScreen(__DRIscreenPrivate *sPriv);
62 extern void gammaDestroyScreen(__DRIscreenPrivate *sPriv);
63 extern GLboolean gammaCreateContext( const __GLcontextModes *glVisual,
64 __DRIcontextPrivate *driContextPriv,
65 void *sharedContextPrivate);
66
67 #define GAMMA_UPLOAD_ALL 0xffffffff
68 #define GAMMA_UPLOAD_CLIPRECTS 0x00000002
69 #define GAMMA_UPLOAD_ALPHA 0x00000004
70 #define GAMMA_UPLOAD_BLEND 0x00000008
71 #define GAMMA_UPLOAD_DEPTH 0x00000010
72 #define GAMMA_UPLOAD_VIEWPORT 0x00000020
73 #define GAMMA_UPLOAD_SHADE 0x00000040
74 #define GAMMA_UPLOAD_CLIP 0x00000080
75 #define GAMMA_UPLOAD_MASKS 0x00000100
76 #define GAMMA_UPLOAD_WINDOW 0x00000200 /* defunct */
77 #define GAMMA_UPLOAD_GEOMETRY 0x00000400
78 #define GAMMA_UPLOAD_POLYGON 0x00000800
79 #define GAMMA_UPLOAD_DITHER 0x00001000
80 #define GAMMA_UPLOAD_LOGICOP 0x00002000
81 #define GAMMA_UPLOAD_FOG 0x00004000
82 #define GAMMA_UPLOAD_LIGHT 0x00008000
83 #define GAMMA_UPLOAD_CONTEXT 0x00010000
84 #define GAMMA_UPLOAD_TEX0 0x00020000
85 #define GAMMA_UPLOAD_STIPPLE 0x00040000
86 #define GAMMA_UPLOAD_TRANSFORM 0x00080000
87 #define GAMMA_UPLOAD_LINEMODE 0x00100000
88 #define GAMMA_UPLOAD_POINTMODE 0x00200000
89 #define GAMMA_UPLOAD_TRIMODE 0x00400000
90
91 #define GAMMA_NEW_CLIP 0x00000001
92 #define GAMMA_NEW_WINDOW 0x00000002
93 #define GAMMA_NEW_CONTEXT 0x00000004
94 #define GAMMA_NEW_TEXTURE 0x00000008 /* defunct */
95 #define GAMMA_NEW_ALPHA 0x00000010
96 #define GAMMA_NEW_DEPTH 0x00000020
97 #define GAMMA_NEW_MASKS 0x00000040
98 #define GAMMA_NEW_POLYGON 0x00000080
99 #define GAMMA_NEW_CULL 0x00000100
100 #define GAMMA_NEW_LOGICOP 0x00000200
101 #define GAMMA_NEW_FOG 0x00000400
102 #define GAMMA_NEW_LIGHT 0x00000800
103 #define GAMMA_NEW_STIPPLE 0x00001000
104 #define GAMMA_NEW_ALL 0xffffffff
105
106 #define GAMMA_FALLBACK_TRI 0x00000001
107 #define GAMMA_FALLBACK_TEXTURE 0x00000002
108
109 #define FLUSH_BATCH(gmesa) do { \
110 /*FLUSH_DMA_BUFFER(gmesa);*/ \
111 } while(0)
112
113 struct gamma_context;
114 typedef struct gamma_context gammaContextRec;
115 typedef struct gamma_context *gammaContextPtr;
116 typedef struct gamma_texture_object_t *gammaTextureObjectPtr;
117
118 #define VALID_GAMMA_TEXTURE_OBJECT(tobj) (tobj)
119
120 #define GAMMA_TEX_MAXLEVELS 12 /* 2K x 2K */
121
122 /* For shared texture space managment, these texture objects may also
123 * be used as proxies for regions of texture memory containing other
124 * client's textures. Such proxy textures (not to be confused with GL
125 * proxy textures) are subject to the same LRU aging we use for our
126 * own private textures, and thus we have a mechanism where we can
127 * fairly decide between kicking out our own textures and those of
128 * other clients.
129 *
130 * Non-local texture objects have a valid MemBlock to describe the
131 * region managed by the other client, and can be identified by
132 * 't->globj == 0'
133 */
134 struct gamma_texture_object_t {
135 struct gamma_texture_object_t *next, *prev;
136
137 GLuint age;
138 struct gl_texture_object *globj;
139
140 int Pitch;
141 int Height;
142 int texelBytes;
143 int totalSize;
144 int bound;
145
146 struct mem_block *MemBlock;
147 char * BufAddr;
148
149 GLuint min_level;
150 GLuint max_level;
151 GLuint dirty_images;
152
153 GLint firstLevel, lastLevel; /* upload tObj->Image[0][first .. lastLevel] */
154
155 struct {
156 const struct gl_texture_image *image;
157 int offset; /* into BufAddr */
158 int height;
159 int internalFormat;
160 } image[GAMMA_TEX_MAXLEVELS];
161
162 uint32_t TextureBaseAddr[GAMMA_TEX_MAXLEVELS];
163 uint32_t TextureAddressMode;
164 uint32_t TextureColorMode;
165 uint32_t TextureFilterMode;
166 uint32_t TextureFormat;
167 uint32_t TextureReadMode;
168 uint32_t TextureBorderColor;
169 };
170
171 #define GAMMA_NO_PALETTE 0x0
172 #define GAMMA_USE_PALETTE 0x1
173 #define GAMMA_UPDATE_PALETTE 0x2
174 #define GAMMA_FALLBACK_PALETTE 0x4
175
176 void gammaUpdateTextureState( GLcontext *ctx );
177
178 void gammaDestroyTexObj( gammaContextPtr gmesa, gammaTextureObjectPtr t );
179 void gammaSwapOutTexObj( gammaContextPtr gmesa, gammaTextureObjectPtr t );
180 void gammaUploadTexImages( gammaContextPtr gmesa, gammaTextureObjectPtr t );
181
182 void gammaResetGlobalLRU( gammaContextPtr gmesa );
183 void gammaUpdateTexLRU( gammaContextPtr gmesa, gammaTextureObjectPtr t );
184 void gammaTexturesGone( gammaContextPtr gmesa,
185 GLuint start, GLuint end,
186 GLuint in_use );
187
188 void gammaEmitHwState( gammaContextPtr gmesa );
189 void gammaDDInitExtensions( GLcontext *ctx );
190 void gammaDDInitDriverFuncs( GLcontext *ctx );
191 void gammaDDInitSpanFuncs( GLcontext *ctx );
192 void gammaDDInitState( gammaContextPtr gmesa );
193 void gammaInitHW( gammaContextPtr gmesa );
194 void gammaDDInitStateFuncs( GLcontext *ctx );
195 void gammaDDInitTextureFuncs( struct dd_function_table *table );
196 void gammaInitTextureObjects( GLcontext *ctx );
197 void gammaDDInitTriFuncs( GLcontext *ctx );
198
199 void gammaUpdateWindow( GLcontext *ctx );
200 void gammaUpdateViewportOffset( GLcontext *ctx );
201
202 void gammaPrintLocalLRU( gammaContextPtr gmesa );
203 void gammaPrintGlobalLRU( gammaContextPtr gmesa );
204
205 extern void gammaFallback( gammaContextPtr gmesa, GLuint bit, GLboolean mode );
206 #define FALLBACK( imesa, bit, mode ) gammaFallback( imesa, bit, mode )
207
208 /* Use the templated vertex formats. Only one of these is used in gamma.
209 */
210 #define TAG(x) gamma##x
211 #include "tnl_dd/t_dd_vertex.h"
212 #undef TAG
213
214 typedef void (*gamma_quad_func)( gammaContextPtr,
215 const gammaVertex *,
216 const gammaVertex *,
217 const gammaVertex *,
218 const gammaVertex * );
219 typedef void (*gamma_tri_func)( gammaContextPtr,
220 const gammaVertex *,
221 const gammaVertex *,
222 const gammaVertex * );
223 typedef void (*gamma_line_func)( gammaContextPtr,
224 const gammaVertex *,
225 const gammaVertex * );
226 typedef void (*gamma_point_func)( gammaContextPtr,
227 const gammaVertex * );
228
229
230 struct gamma_context {
231 GLcontext *glCtx; /* Mesa context */
232
233 __DRIcontextPrivate *driContext;
234 __DRIscreenPrivate *driScreen;
235 __DRIdrawablePrivate *driDrawable;
236
237 GLuint new_gl_state;
238 GLuint new_state;
239 GLuint dirty;
240
241 GLINTSAREADRIPtr sarea;
242
243 /* Mirrors of some DRI state
244 */
245 drm_context_t hHWContext;
246 drm_hw_lock_t *driHwLock;
247 int driFd;
248
249 GLuint numClipRects; /* Cliprects for the draw buffer */
250 drm_clip_rect_t *pClipRects;
251
252 dmaBuf buf; /* DMA buffer for regular cmds */
253 int bufIndex;
254 int bufSize;
255 int bufCount;
256
257 dmaBuf WCbuf; /* DMA buffer for window changed cmds */
258 int WCbufIndex;
259 int WCbufSize;
260 int WCbufCount;
261
262 gammaScreenPtr gammaScreen; /* Screen private DRI data */
263
264 int drawOffset;
265 int readOffset;
266
267 gamma_point_func draw_point;
268 gamma_line_func draw_line;
269 gamma_tri_func draw_tri;
270 gamma_quad_func draw_quad;
271
272 GLuint Fallback;
273 GLuint RenderIndex;
274 GLuint SetupNewInputs;
275 GLuint SetupIndex;
276
277 GLuint vertex_format;
278 GLuint vertex_size;
279 GLuint vertex_stride_shift;
280 GLubyte *verts;
281
282 GLfloat hw_viewport[16];
283 GLuint hw_primitive;
284 GLenum render_primitive;
285
286 GLfloat depth_scale;
287
288 gammaTextureObjectPtr CurrentTexObj[2];
289 struct gamma_texture_object_t TexObjList;
290 struct gamma_texture_object_t SwappedOut;
291 GLenum TexEnvImageFmt[2];
292
293 struct mem_block *texHeap;
294
295 unsigned int lastSwap;
296 int texAge;
297 int ctxAge;
298 int dirtyAge;
299 unsigned int lastStamp;
300
301
302 uint32_t ClearColor;
303 uint32_t Color;
304 uint32_t DitherMode;
305 uint32_t ClearDepth;
306 uint32_t FogMode;
307 uint32_t AreaStippleMode;
308 uint32_t LBReadFormat;
309 uint32_t LBWriteFormat;
310 uint32_t LineMode;
311 uint32_t PointMode;
312 uint32_t TriangleMode;
313 uint32_t AntialiasMode;
314 GLfloat ViewportScaleX;
315 GLfloat ViewportScaleY;
316 GLfloat ViewportScaleZ;
317 GLfloat ViewportOffsetX;
318 GLfloat ViewportOffsetY;
319 GLfloat ViewportOffsetZ;
320 int MatrixMode;
321 int DepthMode;
322 int TransformMode;
323 int LBReadMode;
324 int FBReadMode;
325 int FBWindowBase;
326 int LBWindowBase;
327 int ColorDDAMode;
328 int GeometryMode;
329 int AlphaTestMode;
330 int AlphaBlendMode;
331 int AB_FBReadMode;
332 int AB_FBReadMode_Save;
333 int DeltaMode;
334 int ColorMaterialMode;
335 int FBHardwareWriteMask;
336 int MaterialMode;
337 int NormalizeMode;
338 int LightingMode;
339 int Light0Mode;
340 int Light1Mode;
341 int Light2Mode;
342 int Light3Mode;
343 int Light4Mode;
344 int Light5Mode;
345 int Light6Mode;
346 int Light7Mode;
347 int Light8Mode;
348 int Light9Mode;
349 int Light10Mode;
350 int Light11Mode;
351 int Light12Mode;
352 int Light13Mode;
353 int Light14Mode;
354 int Light15Mode;
355 int LogicalOpMode;
356 int ScissorMode;
357 int ScissorMaxXY;
358 int ScissorMinXY;
359 int Window; /* GID part probably should be in draw priv */
360 int WindowOrigin;
361 int x, y, w, h; /* Probably should be in drawable priv */
362 int FrameCount; /* Probably should be in drawable priv */
363 int NotClipped; /* Probably should be in drawable priv */
364 int WindowChanged; /* Probably should be in drawabl... */
365 int Flags;
366 int EnabledFlags;
367 int DepthSize;
368 int Begin;
369 GLenum ErrorValue;
370 int Texture1DEnabled;
371 int Texture2DEnabled;
372
373 float ModelView[16];
374 float Proj[16];
375 float ModelViewProj[16];
376 float Texture[16];
377
378 float ModelViewStack[(MAX_MODELVIEW_STACK-1)*16];
379 int ModelViewCount;
380 float ProjStack[(MAX_PROJECTION_STACK-1)*16];
381 int ProjCount;
382 float TextureStack[(MAX_TEXTURE_STACK-1)*16];
383 int TextureCount;
384 };
385
386 static __inline GLuint gammaPackColor( GLuint cpp,
387 GLubyte r, GLubyte g,
388 GLubyte b, GLubyte a )
389 {
390 switch ( cpp ) {
391 case 2:
392 return PACK_COLOR_565( r, g, b );
393 case 4:
394 return PACK_COLOR_8888( a, r, g, b );
395 default:
396 return 0;
397 }
398 }
399
400 #define GAMMA_CONTEXT(ctx) ((gammaContextPtr)(ctx->DriverCtx))
401
402 #endif /* _GAMMA_CONTEXT_H_ */