Lots of small updates to GGIMesa, tracking LibGGI internals changes
[mesa.git] / src / mesa / drivers / ggi / default / genkgi_visual.c
1 /* $Id: genkgi_visual.c,v 1.7 2000/06/11 20:11:55 jtaylor Exp $
2 ******************************************************************************
3
4 genkgi_visual.c: visual handling for the generic KGI helper
5
6 Copyright (C) 1999 Jon Taylor [taylorj@ggi-project.org]
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 and/or sell copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the 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 NONINFRINGEMENT. IN NO EVENT SHALL
21 THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 ******************************************************************************
26 */
27
28 #include <ggi/internal/ggi-dl.h>
29 #include <ggi/mesa/ggimesa_int.h>
30 #include <ggi/mesa/display_fbdev.h>
31 #include <ggi/mesa/debug.h>
32 #include "genkgi.h"
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <unistd.h>
40 #include <fcntl.h>
41 #include <sys/stat.h>
42
43 #ifdef HAVE_SYS_VT_H
44 #include <sys/vt.h>
45 #else
46 #include <linux/vt.h>
47 #endif
48 #ifdef HAVE_LINUX_KDEV_T_H
49 #include <linux/kdev_t.h>
50 #endif
51 #include <linux/tty.h>
52
53 #define DEFAULT_FBNUM 0
54
55 static char accel_prefix[] = "tgt-fbdev-kgicon-";
56 #define PREFIX_LEN (sizeof(accel_prefix))
57
58 typedef struct {
59 int async;
60 char *str;
61 } accel_info;
62
63 static accel_info accel_strings[] =
64 {
65 { 0, "d3dim" }, /* Direct3D Immediate Mode */
66 };
67
68 #define NUM_ACCELS (sizeof(accel_strings)/sizeof(accel_info))
69
70 /* FIXME: These should be defined in the makefile system */
71 #define CONF_FILE "/usr/local/etc/ggi/mesa/targets/genkgi.conf"
72 void *_configHandle;
73 char confstub[512] = CONF_FILE;
74 char *conffile = confstub;
75
76 static int changed(ggi_visual_t vis, int whatchanged)
77 {
78 GGIMESADPRINT_CORE("Entered ggimesa_genkgi_changed\n");
79
80 switch (whatchanged)
81 {
82 case GGI_CHG_APILIST:
83 {
84 char api[256];
85 char args[256];
86 int i;
87 const char *fname;
88 ggi_dlhandle *lib;
89
90 for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++)
91 {
92 strcat(api, "-mesa");
93 GGIMESADPRINT_CORE("ggimesa_genkgi_changed: api=%s, i=%d\n", api, i);
94 fname = ggMatchConfig(_configHandle, api, NULL);
95 if (fname == NULL)
96 {
97 /* No special implementation for this sublib */
98 continue;
99 }
100
101 lib = ggiExtensionLoadDL(vis, fname, args, NULL);
102 }
103 }
104 break;
105 }
106 return 0;
107 }
108
109 static int GGIdlinit(ggi_visual *vis, struct ggi_dlhandle *dlh,
110 const char *args, void *argptr, uint32 *dlret)
111 {
112 struct genkgi_priv_mesa *priv;
113 char libname[256], libargs[256];
114 int id, err;
115 struct stat junk;
116 ggifunc_getapi *oldgetapi;
117
118 GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: GGIdlinit start\n");
119
120 GENKGI_PRIV_MESA(vis) = priv = malloc(sizeof(struct genkgi_priv_mesa));
121 if (priv == NULL)
122 {
123 fprintf(stderr, "Failed to allocate genkgi private data\n");
124 return GGI_DL_ERROR;
125 }
126
127 priv->oldpriv = GENKGI_PRIV(vis);
128 #if 0
129 err = ggLoadConfig(conffile, &_configHandle);
130 if (err != GGI_OK)
131 {
132 gl_ggiPrint("display-fbdev-kgicon-mesa: Couldn't open %s\n", conffile);
133 return err;
134 }
135
136 /* Hack city here. We need to probe the KGI driver properly for
137 * suggest-strings to discover the acceleration type(s).
138 */
139 priv->have_accel = 0;
140
141 if (stat("/proc/gfx0", &junk) == 0)
142 {
143 sprintf(priv->accel, "%s%s", accel_prefix, "d3dim");
144 priv->have_accel = 1;
145 GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: Using accel: \"%s\"\n", priv->accel);
146 }
147
148 /* Mode management */
149 vis->opdisplay->getapi = GGIMesa_genkgi_getapi;
150 ggiIndicateChange(vis, GGI_CHG_APILIST);
151
152 /* Give the accel sublibs a chance to set up a driver */
153 if (priv->have_accel == 1)
154 {
155 oldgetapi = vis->opdisplay->getapi;
156 vis->opdisplay->getapi = GGIMesa_genkgi_getapi;
157 changed(vis, GGI_CHG_APILIST);
158 /* If the accel sublibs didn't produce, back up
159 * and keep looking */
160 if ((LIBGGI_MESAEXT(vis)->update_state == NULL) ||
161 (LIBGGI_MESAEXT(vis)->setup_driver == NULL))
162 vis->opdisplay->getapi = oldgetapi;
163 }
164
165 LIBGGI_MESAEXT(vis)->update_state = genkgi_update_state;
166 LIBGGI_MESAEXT(vis)->setup_driver = genkgi_setup_driver;
167 #endif
168 GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: GGIdlinit finished\n");
169
170 *dlret = GGI_DL_OPDRAW;
171 return 0;
172 }
173
174 int MesaGGIdl_fbdev(int func, void **funcptr)
175 {
176 switch (func) {
177 case GGIFUNC_open:
178 *funcptr = GGIopen;
179 return 0;
180 case GGIFUNC_exit:
181 case GGIFUNC_close:
182 *funcptr = NULL;
183 return 0;
184 default:
185 *funcptr = NULL;
186 }
187 return GGI_ENOTFOUND;
188 }
189
190 #include <ggi/internal/ggidlinit.h>