Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / r128 / r128_context.h
1 /**************************************************************************
2
3 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
4                                                Cedar Park, Texas.
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 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS 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  *   Kevin E. Martin <martin@valinux.com>
31  *   Gareth Hughes <gareth@valinux.com>
32  *
33  */
34
35 #ifndef __R128_CONTEXT_H__
36 #define __R128_CONTEXT_H__
37
38 #include "dri_util.h"
39 #include "drm.h"
40 #include "r128_drm.h"
41
42 #include "main/mtypes.h"
43 #include "tnl/t_vertex.h"
44
45 #include "r128_reg.h"
46
47 #include "texmem.h"
48
49 struct r128_context;
50 typedef struct r128_context r128ContextRec;
51 typedef struct r128_context *r128ContextPtr;
52
53 #include "r128_lock.h"
54 #include "r128_texobj.h"
55 #include "r128_screen.h"
56
57 /* Flags for what context state needs to be updated:
58  */
59 #define R128_NEW_ALPHA          0x0001
60 #define R128_NEW_DEPTH          0x0002
61 #define R128_NEW_FOG            0x0004
62 #define R128_NEW_CLIP           0x0008
63 #define R128_NEW_CULL           0x0010
64 #define R128_NEW_MASKS          0x0020
65 #define R128_NEW_RENDER_NOT     0x0040
66 #define R128_NEW_WINDOW         0x0080
67 #define R128_NEW_CONTEXT        0x0100
68 #define R128_NEW_ALL            0x01ff
69
70 /* Flags for software fallback cases:
71  */
72 #define R128_FALLBACK_TEXTURE           0x0001
73 #define R128_FALLBACK_DRAW_BUFFER       0x0002
74 #define R128_FALLBACK_READ_BUFFER       0x0004
75 #define R128_FALLBACK_STENCIL           0x0008
76 #define R128_FALLBACK_RENDER_MODE       0x0010
77 #define R128_FALLBACK_LOGICOP           0x0020
78 #define R128_FALLBACK_SEP_SPECULAR      0x0040
79 #define R128_FALLBACK_BLEND_EQ          0x0080
80 #define R128_FALLBACK_BLEND_FUNC        0x0100
81 #define R128_FALLBACK_PROJTEX           0x0200
82 #define R128_FALLBACK_DISABLE           0x0400
83
84
85 /* Use the templated vertex format:
86  */
87 #define TAG(x) r128##x
88 #include "tnl_dd/t_dd_vertex.h"
89 #undef TAG
90
91 /* Reasons why the GL_BLEND fallback mightn't work:
92  */
93 #define R128_BLEND_ENV_COLOR    0x1
94 #define R128_BLEND_MULTITEX     0x2
95
96 /* Subpixel offsets for window coordinates (triangles):
97  */
98 #define SUBPIXEL_X  (0.0F)
99 #define SUBPIXEL_Y  (0.125F)
100
101
102 typedef void (*r128_tri_func)( r128ContextPtr, 
103                                  r128Vertex *,
104                                  r128Vertex *,
105                                  r128Vertex * );
106
107 typedef void (*r128_line_func)( r128ContextPtr, 
108                                   r128Vertex *,
109                                   r128Vertex * );
110
111 typedef void (*r128_point_func)( r128ContextPtr,
112                                    r128Vertex * );
113
114
115 struct r128_context {
116    struct gl_context *glCtx;                    /* Mesa context */
117
118    /* Driver and hardware state management
119     */
120    GLuint new_state;
121    GLuint dirty;                        /* Hardware state to be updated */
122    drm_r128_context_regs_t setup;
123
124    /* Vertex state */
125    GLuint vertex_size;
126    GLuint vertex_format;
127    struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
128    GLuint vertex_attr_count;
129    char *verts;                 /* points to tnl->clipspace.vertex_buf */
130    GLuint num_verts;
131    int coloroffset, specoffset;
132    DECLARE_RENDERINPUTS(tnl_state_bitset);      /* tnl->render_inputs for this _tnl_install_attrs */
133
134    GLuint NewGLState;
135    GLuint Fallback;
136    GLuint RenderIndex;
137    GLfloat hw_viewport[16];
138    GLfloat depth_scale;
139
140    uint32_t ClearColor;                 /* Color used to clear color buffer */
141    uint32_t ClearDepth;                 /* Value used to clear depth buffer */
142    uint32_t ClearStencil;               /* Value used to clear stencil */
143
144    /* Map GL texture units onto hardware
145     */
146    GLint multitex;
147    GLint tmu_source[2];
148    GLuint tex_combine[2];
149    GLuint blend_flags;
150    GLuint env_color;
151
152    /* Texture object bookkeeping
153     */
154    unsigned              nr_heaps;
155    driTexHeap          * texture_heaps[ R128_NR_TEX_HEAPS ];
156    driTextureObject      swapped;
157
158    r128TexObjPtr CurrentTexObj[2];
159
160    int texture_depth;
161  
162    /* Fallback rasterization functions 
163     */
164    r128_point_func draw_point;
165    r128_line_func draw_line;
166    r128_tri_func draw_tri;
167
168    /* Vertex buffers
169     */
170    drmBufPtr vert_buf;
171
172    GLuint hw_primitive;
173    GLenum render_primitive;
174
175    /* Page flipping
176     */
177    GLuint doPageFlip;
178
179    /* Cliprect and scissor information
180     */
181    GLuint numClipRects;                 /* Cliprects for the draw buffer */
182    drm_clip_rect_t *pClipRects;
183
184    GLuint scissor;
185    drm_clip_rect_t ScissorRect; /* Current software scissor */
186
187    /* Mirrors of some DRI state
188     */
189    __DRIcontext *driContext;    /* DRI context */
190    __DRIscreen  *driScreen;     /* DRI screen */
191    __DRIdrawable        *driDrawable;   /* DRI drawable bound to this ctx */
192
193    unsigned int lastStamp;              /* mirror driDrawable->lastStamp */
194
195    drm_context_t hHWContext;
196    drm_hw_lock_t *driHwLock;
197    int driFd;
198
199    r128ScreenPtr r128Screen;            /* Screen private DRI data */
200    drm_r128_sarea_t *sarea;             /* Private SAREA data */
201
202    /* Performance counters
203     */
204    GLuint boxes;                        /* Draw performance boxes */
205    GLuint hardwareWentIdle;
206    GLuint c_clears;
207    GLuint c_drawWaits;
208    GLuint c_textureSwaps;
209    GLuint c_textureBytes;
210    GLuint c_vertexBuffers;
211
212    /* Configuration cache
213     */
214    driOptionCache optionCache;
215 };
216
217 #define R128_CONTEXT(ctx)               ((r128ContextPtr)(ctx->DriverCtx))
218
219 #define R128_IS_PLAIN( rmesa ) \
220                 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128)
221 #define R128_IS_PRO( rmesa ) \
222                 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_PRO)
223 #define R128_IS_MOBILITY( rmesa ) \
224                 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)
225
226
227 extern GLboolean r128CreateContext( gl_api api,
228                                     const struct gl_config *glVisual,
229                                     __DRIcontext *driContextPriv,
230                                     void *sharedContextPrivate );
231
232 extern void r128DestroyContext( __DRIcontext * );
233
234 extern GLboolean r128MakeCurrent( __DRIcontext *driContextPriv,
235                                   __DRIdrawable *driDrawPriv,
236                                   __DRIdrawable *driReadPriv );
237
238 extern GLboolean r128UnbindContext( __DRIcontext *driContextPriv );
239
240 /* ================================================================
241  * Debugging:
242  */
243 #define DO_DEBUG                1
244 #define ENABLE_PERF_BOXES       0
245
246 #if DO_DEBUG
247 extern int R128_DEBUG;
248 #else
249 #define R128_DEBUG              0
250 #endif
251
252 #define DEBUG_ALWAYS_SYNC       0x01
253 #define DEBUG_VERBOSE_API       0x02
254 #define DEBUG_VERBOSE_MSG       0x04
255 #define DEBUG_VERBOSE_LRU       0x08
256 #define DEBUG_VERBOSE_DRI       0x10
257 #define DEBUG_VERBOSE_IOCTL     0x20
258 #define DEBUG_VERBOSE_2D        0x40
259 #define DEBUG_VERBOSE_FALL      0x80
260
261 #endif /* __R128_CONTEXT_H__ */