d464f6c51897911ab942acba31c798141575bbcc
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_dd.c
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #include "mach64_context.h"
33 #include "mach64_ioctl.h"
34 #include "mach64_dd.h"
35
36 #include "main/context.h"
37
38 #include "utils.h"
39
40 #define DRIVER_DATE "20051019"
41
42 /* Return the current color buffer size.
43 */
44 static void mach64DDGetBufferSize( struct gl_framebuffer *buffer,
45 GLuint *width, GLuint *height )
46 {
47 GET_CURRENT_CONTEXT(ctx);
48 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
49
50 LOCK_HARDWARE( mmesa );
51 *width = mmesa->driDrawable->w;
52 *height = mmesa->driDrawable->h;
53 UNLOCK_HARDWARE( mmesa );
54 }
55
56 /* Return various strings for glGetString().
57 */
58 static const GLubyte *mach64DDGetString( GLcontext *ctx, GLenum name )
59 {
60 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
61 static char buffer[128];
62 unsigned offset;
63 const char * card_name = "Mach64 [Rage Pro]";
64 GLuint agp_mode = mmesa->mach64Screen->IsPCI ? 0 :
65 mmesa->mach64Screen->AGPMode;
66
67 switch ( name ) {
68 case GL_VENDOR:
69 return (GLubyte*)"Gareth Hughes, Leif Delgass, José Fonseca";
70
71 case GL_RENDERER:
72
73 offset = driGetRendererString( buffer, card_name, DRIVER_DATE,
74 agp_mode );
75 return (GLubyte *)buffer;
76
77 default:
78 return NULL;
79 }
80 }
81
82 /* Send all commands to the hardware. If vertex buffers or indirect
83 * buffers are in use, then we need to make sure they are sent to the
84 * hardware. All commands that are normally sent to the ring are
85 * already considered `flushed'.
86 */
87 static void mach64DDFlush( GLcontext *ctx )
88 {
89 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
90
91 LOCK_HARDWARE( mmesa );
92 FLUSH_DMA_LOCKED( mmesa );
93 UNLOCK_HARDWARE( mmesa );
94
95 #if ENABLE_PERF_BOXES
96 if ( mmesa->boxes ) {
97 LOCK_HARDWARE( mmesa );
98 mach64PerformanceBoxesLocked( mmesa );
99 UNLOCK_HARDWARE( mmesa );
100 }
101
102 /* Log the performance counters if necessary */
103 mach64PerformanceCounters( mmesa );
104 #endif
105 }
106
107 /* Make sure all commands have been sent to the hardware and have
108 * completed processing.
109 */
110 static void mach64DDFinish( GLcontext *ctx )
111 {
112 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
113
114 #if ENABLE_PERF_BOXES
115 /* Bump the performance counter */
116 mmesa->c_drawWaits++;
117 #endif
118
119 mach64DDFlush( ctx );
120 mach64WaitForIdle( mmesa );
121 }
122
123 /* Initialize the driver's misc functions.
124 */
125 void mach64InitDriverFuncs( struct dd_function_table *functions )
126 {
127 functions->GetBufferSize = mach64DDGetBufferSize;
128 functions->GetString = mach64DDGetString;
129 functions->Finish = mach64DDFinish;
130 functions->Flush = mach64DDFlush;
131
132 }