[comp.windows.x] Extension using AllocateGCPrivate

garfinke@hpfcda.HP.COM (Dan Garfinkel) (01/31/90)

This note is for the server implementers and extension writers. All others
may ignore it.

First off, thank you for creating the devPrivates field for screens, windows,
and gcs.  It makes the job of extension writers much easier.  However, I
also need this field for Pixmaps (all drawables) and fonts.  Would you 
consider adding this for R5?

Now for a bug report:

I'm trying to write a complex extension and have run into problems using
AllocateGCPrivate.  The problem is that the extension initialization 
routines are called after InitOutput and InitOutput creates GCs.  When I
try to access my devPrivate for the GCs created by InitOutput, the field isn't
there and bad things happen.  The creating of the GCs should happen after
initializing the extensions, just like the creating of the root windows, 
right?

Is there a workaround for this problem?

-Dan Garfinkel  (garfinke@hpfcda.hp.com)

keith@EXPO.LCS.MIT.EDU (Keith Packard) (02/07/90)

> I'm trying to write a complex extension and have run into problems using
> AllocateGCPrivate.  The problem is that the extension initialization 
> routines are called after InitOutput and InitOutput creates GCs.

Too true.  The GCs are allocated by AddScreen which calls CreateGCPerDepth
on the new screen.  This and the default stipple creation should be delayed
until after the extensions are initialized.  We solved the problem for window
allocation by moving the root window creation from AddScreen to main; to
solve the GC and stipple problem I'd suggest moving them as well.  AddScreen
would then look more like:

    ...
    screenInfo.numScreens++;
    if (!(*pfnInit)(i, pScreen, argc, argv)) {
	FreeScreen (pScreen);
	screenInfo.numScreens--;
	return -1;
    }
    return i;
}

while main would look more like:

        InitOutput(&screenInfo, argc, argv);
        if (screenInfo.numScreens < 1)
            FatalError("no screens found");
        InitExtensions(argc, argv);
        for (i = 0; i < screenInfo.numScreens; i++)
        {
	    if (!CreateGCPerDepth(i))
		FatalError("failed to create scratch GCs");
	    if (!CreateDefaultStipple(i))
		FatalError("failed to create default stipple");
            if (!CreateRootWindow(screenInfo.screens[i]))
                FatalError("failed to create root window");
        }

Caveat:  I have not tested this code (nor even compiled it).

Keith Packard
MIT X Consortium