Hi,

I thought this would be a good time to summarize the status of the
config-0-0-1-branch. I believe it's ready to get some testing. If
someone is interested in porting other drivers to the new configuration
infrastructure, go ahead. Otherwise I'll do so as time permits. It's
actually quite simple.

The infrastructure is more or less complete. The only thing missing in
the branch is the user-space programme xdriinfo as I havn't found a good
place in the tree to commit it :-/. While the Mese tree reorganization
is still going on that will probably not change. However, the code is
ready and I attached the source and a minimal Makefile. (You may have to
replace glXGetProcAddressARB by glXGetProcAddress in the source.)

The radeon, r200, r128 and mga drivers have been converted to use the
new configuration so far. They will look for configuration files in
/etc/drirc and $HOME/.drirc. The parser for configuration files is very
sloppy. It should parse about any well-formed document. But it reports
lots of warnings if something looks wrong and the LIBGL_DEBUG
environment variable is defined. I also attached a valid configuration
file that contains the default configuration of all drivers for
reference. (The radeon driver has a few more options that are not
working yet, as radeon is my test platform.)

Finally some notes about compiling: You probably need to do a make World
or at least make Everything as some Imakefiles have changed. Furthermore
the DRI tree doesn't have expat (yet?). So you need libexpat and the
headers installed.

To see if it works set LIBGL_DEBUG=something. With no configuration
files present you should see two warnings that the configuration files
were not found. If you install the attached configuration file as
~/.drirc there should be one less warning.

So much for now.

Best regards,
  Felix

------------    __\|/__    ___     ___       -------------------------
 Felix       ___\_e -_/___/ __\___/ __\_____   You can do anything,
   K�hling  (_____\�/____/ /_____/ /________)  just not everything
 [EMAIL PROTECTED]       \___/   \___/   U        at the same time.


#include <GL/glx.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

typedef const char * glXGetScreenDriver_t (Display *dpy, int scrNum);
typedef const char * glXGetDriverConfig_t (const char *driverName);

glXGetScreenDriver_t *GetScreenDriver;
glXGetDriverConfig_t *GetDriverConfig;

enum INFO_FUNC {
    LIST, NSCREENS, DRIVER, OPTIONS
};

void printUsage (void);

void printUsage (void) {
    fprintf (stderr,
"Usage: xdriinfo [-display <dpy>] [command]\n"
"Commands:\n"
"  nscreens               print the number of screens on display\n"
"  driver screen          print the DRI driver name of screen\n"
"  options screen|driver  print configuration information about screen or driver\n"
"If no command is given then the DRI drivers for all screens are listed.\n");
}

int main (int argc, char *argv[]) {
    Display *dpy;
    int nScreens, screenNum, i;
    enum INFO_FUNC func = LIST;
    char *funcArg = NULL;
    char *dpyName = NULL;

    GetScreenDriver = (glXGetScreenDriver_t *)glXGetProcAddressARB ("glXGetScreenDriver");
    GetDriverConfig = (glXGetDriverConfig_t *)glXGetProcAddressARB ("glXGetDriverConfig");
    if (!GetScreenDriver || !GetDriverConfig) {
	fprintf (stderr, "libGL is too old.\n");
	return 1;
    }

  /* parse the command line */
    for (i = 1; i < argc; ++i) {
	char **argPtr = NULL;
	if (!strcmp (argv[i], "-display"))
	    argPtr = &dpyName;
	else if (!strcmp (argv[i], "nscreens"))
	    func = NSCREENS;
	else if (!strcmp (argv[i], "driver")) {
	    func = DRIVER;
	    argPtr = &funcArg;
	} else if (!strcmp (argv[i], "options")) {
	    func = OPTIONS;
	    argPtr = &funcArg;
	} else {
	    printUsage ();
	    return 1;
	}
	if (argPtr) {
	    if (++i == argc) {
		printUsage ();
		return 1;
	    }
	    *argPtr = argv[i];
	}
    }

  /* parse screen number argument */
    if (func == DRIVER || func == OPTIONS) {
	if (sscanf (funcArg, "%i", &screenNum) != 1)
	    screenNum = -1;
	else if (screenNum < 0) {
	    fprintf (stderr, "Negative screen number \"%s\".\n", funcArg);
	    return 1;
	}
    }
  /* if the argument to the options command is a driver name, we can handle
   * it without opening an X connection */
    if (func == OPTIONS && screenNum == -1) {
	const char *options = (*GetDriverConfig) (funcArg);
	if (!options) {
	    fprintf (stderr,
		     "Driver \"%s\" does not exist or does not support configuration.\n",
		     funcArg);
	    return 1;
	}
	printf ("%s", options);
	if (isatty (STDOUT_FILENO))
	    printf ("\n");
	return 0;
    } 
  /* driver command needs a valid screen number */
    else if (func == DRIVER && screenNum == -1) {
	fprintf (stderr, "Invalid screen number \"%s\".\n", funcArg);
	return 1;
    }

  /* open display and count the number of screens */
    if (!(dpy = XOpenDisplay (dpyName))) {
	fprintf (stderr, "Error: Couldn't open display\n");
	return 1;
    }
    nScreens = ScreenCount (dpy);

  /* final check on the screen number argument (if any)*/
    if ((func == DRIVER || func == OPTIONS) && screenNum >= nScreens) {
	fprintf (stderr, "Screen number \"%d\" out of range.\n", screenNum);
	return 1;
    }

    switch (func) {
      case NSCREENS:
	printf ("%d", nScreens);
	if (isatty (STDOUT_FILENO))
	    printf ("\n");
	break;
      case DRIVER: {
	  const char *name = (*GetScreenDriver) (dpy, screenNum);
	  if (!name)
	      return 1;
	  printf ("%s", name);
	  if (isatty (STDOUT_FILENO))
	      printf ("\n");
	  break;
      }
      case OPTIONS: {
	  const char *name = (*GetScreenDriver) (dpy, screenNum), *options;
	  if (!name)
	      return 1;
	  options = (*GetDriverConfig) (name);
	  if (!options)
	      return 1;
	  printf ("%s", options);
	  if (isatty (STDOUT_FILENO))
	      printf ("\n");
	  break;
      }
      case LIST:
	for (i = 0; i < nScreens; ++i) {
	    const char *name = (*GetScreenDriver) (dpy, i);
	    if (name)
		printf ("Screen %d: %s\n", i, name);
	    else
		printf ("Screen %d: not direct rendering capable.\n", i);
	}
    }

    return 0;
}

Attachment: Makefile
Description: Binary data

Attachment: drirc
Description: Binary data

Reply via email to