a60d2a689327b7b7ea52ddfc023437bb1c7dcee4
[mesa.git] / src / mesa / drivers / dri / r128 / r128_dd.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_dd.c,v 1.15 2002/10/30 12:51:38 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Gareth Hughes <gareth@valinux.com>
32 * Kevin E. Martin <martin@valinux.com>
33 *
34 */
35
36 #include "r128_context.h"
37 #include "r128_ioctl.h"
38 #include "r128_state.h"
39 #include "r128_dd.h"
40 #include "swrast/swrast.h"
41
42 #include "context.h"
43 #include "framebuffer.h"
44
45 #include "utils.h"
46
47 #define DRIVER_DATE "20051026"
48
49
50 /* Return the width and height of the current color buffer.
51 */
52 static void r128GetBufferSize( GLframebuffer *buffer,
53 GLuint *width, GLuint *height )
54 {
55 GET_CURRENT_CONTEXT(ctx);
56 r128ContextPtr rmesa = R128_CONTEXT(ctx);
57
58 LOCK_HARDWARE( rmesa );
59 *width = rmesa->driDrawable->w;
60 *height = rmesa->driDrawable->h;
61 UNLOCK_HARDWARE( rmesa );
62 }
63
64 /* Return various strings for glGetString().
65 */
66 static const GLubyte *r128GetString( GLcontext *ctx, GLenum name )
67 {
68 r128ContextPtr rmesa = R128_CONTEXT(ctx);
69 static char buffer[128];
70 unsigned offset;
71 const char * card_name = "Rage 128";
72 GLuint agp_mode = rmesa->r128Screen->IsPCI ? 0 :
73 rmesa->r128Screen->AGPMode;
74
75 switch ( name ) {
76 case GL_VENDOR:
77 return (GLubyte *)"VA Linux Systems, Inc.";
78
79 case GL_RENDERER:
80 /* Select the spefic chipset.
81 */
82 if ( R128_IS_PRO( rmesa ) ) {
83 card_name = "Rage 128 Pro";
84 }
85 else if ( R128_IS_MOBILITY( rmesa ) ) {
86 card_name = "Rage 128 Mobility";
87 }
88
89 offset = driGetRendererString( buffer, card_name, DRIVER_DATE,
90 agp_mode );
91
92 return (GLubyte *)buffer;
93
94 default:
95 return NULL;
96 }
97 }
98
99 /* Send all commands to the hardware. If vertex buffers or indirect
100 * buffers are in use, then we need to make sure they are sent to the
101 * hardware. All commands that are normally sent to the ring are
102 * already considered `flushed'.
103 */
104 static void r128Flush( GLcontext *ctx )
105 {
106 r128ContextPtr rmesa = R128_CONTEXT(ctx);
107
108 FLUSH_BATCH( rmesa );
109
110 #if ENABLE_PERF_BOXES
111 if ( rmesa->boxes ) {
112 LOCK_HARDWARE( rmesa );
113 r128PerformanceBoxesLocked( rmesa );
114 UNLOCK_HARDWARE( rmesa );
115 }
116
117 /* Log the performance counters if necessary */
118 r128PerformanceCounters( rmesa );
119 #endif
120 }
121
122 /* Make sure all commands have been sent to the hardware and have
123 * completed processing.
124 */
125 static void r128Finish( GLcontext *ctx )
126 {
127 r128ContextPtr rmesa = R128_CONTEXT(ctx);
128
129 #if ENABLE_PERF_BOXES
130 /* Bump the performance counter */
131 rmesa->c_drawWaits++;
132 #endif
133
134 r128Flush( ctx );
135 r128WaitForIdle( rmesa );
136 }
137
138
139 /* Initialize the driver's misc functions.
140 */
141 void r128InitDriverFuncs( struct dd_function_table *functions )
142 {
143 functions->GetBufferSize = r128GetBufferSize;
144 functions->ResizeBuffers = _mesa_resize_framebuffer;
145 functions->GetString = r128GetString;
146 functions->Finish = r128Finish;
147 functions->Flush = r128Flush;
148 }