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