Small optimization for big-endian (e.g., PowerPC) systems.
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_dd.c
1 /* $XFree86$ */ /* -*- 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_state.h"
35 #include "mach64_vb.h"
36 #include "mach64_dd.h"
37
38 #include "context.h"
39 #include "utils.h"
40
41 #define DRIVER_DATE "20030502"
42
43 /* Return the current color buffer size.
44 */
45 static void mach64DDGetBufferSize( GLframebuffer *buffer,
46 GLuint *width, GLuint *height )
47 {
48 GET_CURRENT_CONTEXT(ctx);
49 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
50
51 LOCK_HARDWARE( mmesa );
52 *width = mmesa->driDrawable->w;
53 *height = mmesa->driDrawable->h;
54 UNLOCK_HARDWARE( mmesa );
55 }
56
57 /* Return various strings for glGetString().
58 */
59 static const GLubyte *mach64DDGetString( GLcontext *ctx, GLenum name )
60 {
61 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
62 static char buffer[128];
63 unsigned offset;
64 const char * card_name = "Mach64 [Rage Pro]";
65 GLuint agp_mode = mmesa->mach64Screen->IsPCI ? 0 :
66 mmesa->mach64Screen->AGPMode;
67
68 switch ( name ) {
69 case GL_VENDOR:
70 return (GLubyte*)"Gareth Hughes, Leif Delgass, José Fonseca";
71
72 case GL_RENDERER:
73
74 offset = driGetRendererString( buffer, card_name, DRIVER_DATE,
75 agp_mode );
76 return (GLubyte *)buffer;
77
78 default:
79 return NULL;
80 }
81 }
82
83 /* Send all commands to the hardware. If vertex buffers or indirect
84 * buffers are in use, then we need to make sure they are sent to the
85 * hardware. All commands that are normally sent to the ring are
86 * already considered `flushed'.
87 */
88 static void mach64DDFlush( GLcontext *ctx )
89 {
90 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
91
92 LOCK_HARDWARE( mmesa );
93 FLUSH_DMA_LOCKED( mmesa );
94 UNLOCK_HARDWARE( mmesa );
95
96 #if ENABLE_PERF_BOXES
97 if ( mmesa->boxes ) {
98 LOCK_HARDWARE( mmesa );
99 mach64PerformanceBoxesLocked( mmesa );
100 UNLOCK_HARDWARE( mmesa );
101 }
102
103 /* Log the performance counters if necessary */
104 mach64PerformanceCounters( mmesa );
105 #endif
106 }
107
108 /* Make sure all commands have been sent to the hardware and have
109 * completed processing.
110 */
111 static void mach64DDFinish( GLcontext *ctx )
112 {
113 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
114
115 #if ENABLE_PERF_BOXES
116 /* Bump the performance counter */
117 mmesa->c_drawWaits++;
118 #endif
119
120 mach64DDFlush( ctx );
121 mach64WaitForIdle( mmesa );
122 }
123
124 /* Initialize the driver's misc functions.
125 */
126 void mach64InitDriverFuncs( struct dd_function_table *functions )
127 {
128 functions->GetBufferSize = mach64DDGetBufferSize;
129 functions->ResizeBuffers = _swrast_alloc_buffers;
130 functions->GetString = mach64DDGetString;
131 functions->Finish = mach64DDFinish;
132 functions->Flush = mach64DDFlush;
133
134 }