Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / r128 / r128_dd.c
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 * Gareth Hughes <gareth@valinux.com>
31 * Kevin E. Martin <martin@valinux.com>
32 *
33 */
34
35 #include "r128_context.h"
36 #include "r128_ioctl.h"
37 #include "r128_dd.h"
38
39 #include "main/context.h"
40
41 #include "utils.h"
42
43 #define DRIVER_DATE "20051027"
44
45
46 /* Return the width and height of the current color buffer.
47 */
48 static void r128GetBufferSize( struct gl_framebuffer *buffer,
49 GLuint *width, GLuint *height )
50 {
51 GET_CURRENT_CONTEXT(ctx);
52 r128ContextPtr rmesa = R128_CONTEXT(ctx);
53
54 LOCK_HARDWARE( rmesa );
55 *width = rmesa->driDrawable->w;
56 *height = rmesa->driDrawable->h;
57 UNLOCK_HARDWARE( rmesa );
58 }
59
60 /* Return various strings for glGetString().
61 */
62 static const GLubyte *r128GetString( struct gl_context *ctx, GLenum name )
63 {
64 r128ContextPtr rmesa = R128_CONTEXT(ctx);
65 static char buffer[128];
66 unsigned offset;
67 const char * card_name = "Rage 128";
68 GLuint agp_mode = rmesa->r128Screen->IsPCI ? 0 :
69 rmesa->r128Screen->AGPMode;
70
71 switch ( name ) {
72 case GL_VENDOR:
73 return (GLubyte *)"VA Linux Systems, Inc.";
74
75 case GL_RENDERER:
76 /* Select the spefic chipset.
77 */
78 if ( R128_IS_PRO( rmesa ) ) {
79 card_name = "Rage 128 Pro";
80 }
81 else if ( R128_IS_MOBILITY( rmesa ) ) {
82 card_name = "Rage 128 Mobility";
83 }
84
85 offset = driGetRendererString( buffer, card_name, DRIVER_DATE,
86 agp_mode );
87
88 return (GLubyte *)buffer;
89
90 default:
91 return NULL;
92 }
93 }
94
95 /* Send all commands to the hardware. If vertex buffers or indirect
96 * buffers are in use, then we need to make sure they are sent to the
97 * hardware. All commands that are normally sent to the ring are
98 * already considered `flushed'.
99 */
100 static void r128Flush( struct gl_context *ctx )
101 {
102 r128ContextPtr rmesa = R128_CONTEXT(ctx);
103
104 FLUSH_BATCH( rmesa );
105
106 #if ENABLE_PERF_BOXES
107 if ( rmesa->boxes ) {
108 LOCK_HARDWARE( rmesa );
109 r128PerformanceBoxesLocked( rmesa );
110 UNLOCK_HARDWARE( rmesa );
111 }
112
113 /* Log the performance counters if necessary */
114 r128PerformanceCounters( rmesa );
115 #endif
116 }
117
118 /* Make sure all commands have been sent to the hardware and have
119 * completed processing.
120 */
121 static void r128Finish( struct gl_context *ctx )
122 {
123 r128ContextPtr rmesa = R128_CONTEXT(ctx);
124
125 #if ENABLE_PERF_BOXES
126 /* Bump the performance counter */
127 rmesa->c_drawWaits++;
128 #endif
129
130 r128Flush( ctx );
131 r128WaitForIdle( rmesa );
132 }
133
134
135 /* Initialize the driver's misc functions.
136 */
137 void r128InitDriverFuncs( struct dd_function_table *functions )
138 {
139 functions->GetBufferSize = r128GetBufferSize;
140 functions->GetString = r128GetString;
141 functions->Finish = r128Finish;
142 functions->Flush = r128Flush;
143 }