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