Site hosted by Angelfire.com: Build your free website today!

Hands-on Projects for the Linux Graphics Subsystem

New book from Christos Karayiannis

Available in Amazon Kindle format at:

amazon.com   amazon.co.uk   amazon.de   amazon.es   amazon.fr   amazon.it

Inspecting the X Client-Server handshake using xtrace

The first part of the xtrace output from section 2.4 provides another view of the X client-server initial connection at the X Protocol layer, that was discussed previously in section 1.5 and section 1.6. We again focus at the next figure:

Most important it displays the second part of the second read() info, which as we see in section 1.6, was left undecoded.


000:<: am lsb-first want 11:0 authorising with 'MIT-MAGIC-COOKIE-1' of length 16
000:>: Success, version is 11:0 vendor='The X.Org Foundation' release=10706000 resource-id=0x04000000 
resource-mask=0x001fffff motion-buffer-size=256 max-request-len=65535 image-byte-order=LSBFirst(0x00) 
bitmap-bit-order=LeastSignificant(0x00) scanline-unit=32 scanline-pad=32 min-keycode=0x08 max-keycode=0x00 
pixmap-formats={depth=1 bits/pixel=1 scanline-pad=32},{depth=4 bits/pixel=8 scanline-pad=32},{depth=8 bits/pixel=8 
scanline-pad=32},{depth=15 bits/pixel=16 scanline-pad=32},{depth=16 bits/pixel=16 scanline-pad=32},{depth=24 
bits/pixel=32 scanline-pad=32},{depth=32 bits/pixel=32 scanline-pad=32}; roots={root=0x00000101 
default-colormap=0x00000020 white-pixel=0x00ffffff black-pixel=0x00000000 
input-mask=KeyPress,KeyRelease,EnterWindow,LeaveWindow,Exposure,StructureNotify,
SubstructureNotify,SubstructureRedirect,FocusChange,PropertyChange,ColormapChange
 width[pixel]=1024 height[pixel]=768 width[mm]=302 height[mm]=222 min-installed-maps=1 max-installed-maps=1 
root=0x00000021 backing-stores=Never(0x00) save-unders=false(0x00) root-depth=24 allowed depths={depth=24 
visuals={id=0x00000021 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c2 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c3 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000c4 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c5 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c6 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000c7 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c8 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c9 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000ca class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cb class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cc 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000cd class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ce class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cf 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d0 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d1 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d2 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d3 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d4 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d5 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d6 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d7 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d8 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d9 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000da class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000db 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000dc class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000dd class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000de 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000df class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e0 class=DirectColor(0x05) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e1 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e2 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e3 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e4 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e5 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e6 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e7 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e8 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e9 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ea 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000eb class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ec class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ed 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000ee class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ef class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f0 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f1 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f2 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f3 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f4 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f5 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f6 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f7 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f8 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f9 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000fa class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fb class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fc 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000fd class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fe class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ff 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff};},{depth=1 visuals=;},{depth=4 visuals=;},{depth=8 visuals=;},{depth=15 visuals=;},{depth=16 
visuals=;},{depth=32 visuals={id=0x00000041 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff};};};

xConnClientPrefix

The first line highlighted with yellow color corresponds to the xConnClientPrefix:

000:<: am lsb-first want 11:0 authorising with 'MIT-MAGIC-COOKIE-1' of length 16

As we recall from the previous sections xConnClientPrefix is defined as:

typedef struct {
    CARD8	byteOrder;
    BYTE	pad;
    CARD16	majorVersion B16, minorVersion B16;
    CARD16	nbytesAuthProto B16;	/* Authorization protocol */
    CARD16	nbytesAuthString B16;	/* Authorization string */
    CARD16	pad2 B16;
} xConnClientPrefix;

xConnSetupPrefix

The next part of the xtrace output corresponds to the xConnSetupPrefix field values (linehighlighted in orange color):

000:>: Success, version is 11:0

As we notice the length field is missing. The value for this field was found to be 435 (or 1740 bytes) at section 1.6.

typedef struct {
    CARD8          success;
    BYTE           lengthReason; /*num bytes in string following if failure */
    CARD16         majorVersion B16, 
                   minorVersion B16;
    CARD16         length B16;  /* 1/4 additional bytes in setup info */
} xConnSetupPrefix;

xConnSetup e.t.c.

The third and largest part of the xtrace output corresponds to the message received with the second read() call of the X Client. This includes the u union's members values (xConnSetup, vendor, xPixmapFormat, xWindowRoot, xDepth and xVisualType), discussed in section 1.6.

It starts with the vendor value, 'The X.Org Foundation', marked red. This is the value received by the X Client right after the xConnSetup field values, where the rest of the u members are read.

vendor='The X.Org Foundation' 

Probably for usability reasons the xtrace changes the order of the information it displays (vendor before xConnSetup).

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

The next part marked blue shows the values of the xConnSetup fields:

release=10706000 resource-id=0x04000000 resource-mask=0x001fffff motion-buffer-size=256 max-request-len=65535 image-byte-order=LSBFirst(0x00) bitmap-bit-order=LeastSignificant(0x00) scanline-unit=32 scanline-pad=32 min-keycode=0x08 max-keycode=0x00

As we recall from the previous sections xConnSetup is defined as:

typedef struct {
    CARD32         release B32;
    CARD32         ridBase B32, 
                   ridMask B32;
    CARD32         motionBufferSize B32;
    CARD16         nbytesVendor B16;  /* number of bytes in vendor string */
    CARD16         maxRequestSize B16;
    CARD8          numRoots;          /* number of roots structs to follow */
    CARD8          numFormats;        /* number of pixmap formats */
    CARD8          imageByteOrder;        /* LSBFirst, MSBFirst */
    CARD8          bitmapBitOrder;        /* LeastSignificant, MostSign...*/
    CARD8          bitmapScanlineUnit,     /* 8, 16, 32 */
                   bitmapScanlinePad;     /* 8, 16, 32 */
    KeyCode	   minKeyCode, maxKeyCode;
    CARD32	   pad2 B32;
} xConnSetup;

A pointer to xConnSetup (points to an array of xConnSetup) is the first member of union u. The members of u are the ones read by the second read().

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

Seven PixmapFormat values, marked Fuchsia, follows next in the xtrace output:

pixmap-formats={depth=1 bits/pixel=1 scanline-pad=32},{depth=4 bits/pixel=8 scanline-pad=32},{depth=8 bits/pixel=8 
scanline-pad=32},{depth=15 bits/pixel=16 scanline-pad=32},{depth=16 bits/pixel=16 scanline-pad=32},{depth=24 
bits/pixel=32 scanline-pad=32},{depth=32 bits/pixel=32 scanline-pad=32};

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

xPixmapFormat is defined as:

typedef struct {
    CARD8          depth;
    CARD8          bitsPerPixel;
    CARD8          scanLinePad;
    CARD8          pad1;
    CARD32	   pad2 B32;
} xPixmapFormat;

struct xPixmapFormat

Struct xPixmapFormat has three meaningful members (depth, bitsPerPixel, scanLinePad) and two dummies, pad1 and pad2, that are used for padding purposes. Since the xPixmapFormat variables are moved as an array (in union u we have a pointer to xPixmapFormat) they should be aligned to an even 'word' in memory and the purpose of pad1 is to fill the one-byte gap. For padding at the end of structs, in the case of arrays of structs, see Data Structure Alignment and Padding. There is also another padding value, pad2, with a four-byte size at the end of the struct. It may look strange adding this value to the struct, which is already aligned to a 32-bit word, however Xlib runs for both 32-bit and 64-bit systems. This extra value aligns the xPixmapFormat struct in both cases (32-bit words and 64-bit words). For more info on padding for structures shared between 32-bit and 64-bit applications see this IBM link.

As we read in X.Org Manual pages "The screenInfo's pixmap format's depth, bits per pixel and scanline padding is also initialized at this stage." The stage referred here is InitOutput(), called by main(). This info is send to the X Client on client's connection as we see in the previous sections.

Depth (Color Depth) is the number of bit planes in the pixmap. From this GTK+ link we read:
"Alternatively, you can think of a display like this as a stack of bit planes, or two-dimensional arrays of bits. If all the planes are parallel to one another, a pixel is a perpendicular line passing through the same coordinates on each plane, taking a single bit from each one. This is the origin of the term depth, since the number of bits per pixel is equal to the depth of the stack of bit planes."

The following figure from Display Graphics shows (a) Display memory (b) The contents of two sample bit planes (c) The resulting display:

bitsPerPixel is the number of consecutive bits used to encode a single pixel. Also from the GTK+ link we read:
"In the X Window System, pixels represent entries in a color lookup table. A color is a red, green, blue (RGB) value---monitors mix red, green, and blue light in some ratio to display each pixel. Take an eight bit display, for example: eight bits are not enough to encode a color in-place; only a few arbitrary RGB values would be possible. Instead, the bits are interpreted as an integer and used to index an array of RGB color values. This table of colors is called the colormap; it can sometimes be modified to contain the colors you plan to use, though this is hardware-dependent---some colormaps are read-only."

The following figure from Display Graphics shows 8-bits per pixel and this value is mapped to a color value:

Notice that this is the simple case, where 'Indexed Color' is used (see Wikipedia). The other more powerful solution is 'Direct color'.

xPixmapFormat has two members depth and bitsPerPixel, that are treated as identical by most web articles. For instance Wikipedia makes no distinction between depth and bits per pixel:
"In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel (bpp)."
As we notice from the previous xtrace output the pairs of depth and bitsPerPixel returned are not always the same, with the depth to be less than or equals to bitsPerPixel:
depth   bits/pixel
   1        1
   4        8
   8        8
  15       16
  16       16
  24       32
  32       32
The explanation comes from the fbFinishScreenInit() comment at section 3.2.2.12
     * By default, a 24bpp screen will use 32bpp images, this avoids
     * problems with many applications which just can't handle packed
     * pixels.  If you want real 24bit images, include a 24bpp
     * format in the pixmap formats
Therefore depth represents the bits required for the color and bitsPerPixel the bits required to align the 'depth' bits in a power of 2. For instance the bits of the 15-bit depth occupy to 16-bit memory and 24-bit depth bits occupy to 32-bit memory areas. However as the previous comment denotes this is not the only option and 24-bits can also be packed to 24-bit memory spaces. This saves memory but is a less efficient way to use the CPU. It is referred as 'Packed pixel'. As we read from Pixel Packing:
"To save memory, you could resort to pixel packing; instead of storing one 4-bit pixel per byte, you could store two 4-bit pixels per byte". "The size of memory required to hold the 4-bit, 4096-pixel image drops from 4096 bytes to 2048 bytes, only half the memory that was required before."

As we see in the precious xtrace output 16 bitsPerPixel can store color depth of either 15 or 16. A value of 15 in the RGB (Red Green Blue) system allows 5 bits for each color and 16 allows the same values for RB and 6 bits for G.
As we read from RGB pixel formats: "As an aside, most display drivers handle both RGB 5:5:5 and 5:6:5 formats but several video codecs get confused when asked to decompress to a 5:6:5 desktop so using 5:5:5 as the default is generally safer."

scanLinePad, according to RFC 1013 "Each scanline is padded to a multiple of bits as given by bitmap-format-scanline-pad." As we read from Wikipedia "A scan line or scanline is one line, or row, in a raster scanning pattern, such as a video line on a cathode ray tube (CRT) display of a television or computer.", "The term is used, by analogy, for a single row of pixels in a raster graphics image."

The next part of info send by the X Server is a xWindowRoot struct:

 roots={root=0x00000101 
default-colormap=0x00000020 white-pixel=0x00ffffff black-pixel=0x00000000 
input-mask=KeyPress,KeyRelease,EnterWindow,LeaveWindow,Exposure,StructureNotify,
SubstructureNotify,SubstructureRedirect,FocusChange,PropertyChange,ColormapChange
 width[pixel]=1024 height[pixel]=768 width[mm]=302 height[mm]=222 min-installed-maps=1 max-installed-maps=1 
root=0x00000021 backing-stores=Never(0x00) save-unders=false(0x00) root-depth=24 allowed depths=

A pointer to xWindowRoot is also a member of union u:

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

xWindowRoot is defined as:

typedef struct {
    Window         windowId B32;
    Colormap       defaultColormap B32;
    CARD32         whitePixel B32, blackPixel B32;
    CARD32         currentInputMask B32;   
    CARD16         pixWidth B16, pixHeight B16;
    CARD16         mmWidth B16, mmHeight B16;
    CARD16         minInstalledMaps B16, maxInstalledMaps B16;
    VisualID       rootVisualID B32;
    CARD8          backingStore;
    BOOL           saveUnders;
    CARD8          rootDepth;
    CARD8          nDepths;  /* number of xDepth structures following */
} xWindowRoot;

struct xWindowRoot

Struct xWindowRoot returns to the X client info about the root window. For the root window we read from Wikipedia:
"In the X Window System, every window is contained within another window, called its parent. This makes the windows form a hierarchy. The root window is the root of this hierarchy. It is as large as the screen, and all other windows are either children or descendants of it."

windowId: is the window ID of the root window.

currentInputMask: is the event mask of the root window.

For the other xWindowRoot fields we read from RFC 1013:

defaultColormap:

   The default-colormap is the one initially associated with the root
   window.  Clients with minimal color requirements creating windows of
   the same depth as the root may want to allocate from this map by
   default.
whitePixel and blackPixel:
   Black-pixel and white-pixel can be used in implementing a
   "monochrome" application.  These pixel values are for permanently
   allocated entries in the default-colormap; the actual RGB values may
   be settable on some screens.
rootDepth and rootVisualID:
   Root-depth and root-visual specify the depth and visual type of the
   root window.
pixWidth and pixHeight:
 
Width-in-pixels and height-in-pixels specify the size
   of the root window (which cannot be changed).
mmWidth and mmHeight:
 
   Width-in-millimeters and
   height-in-millimeters can be used to determine the physical size and
   the aspect ratio.
minInstalledMaps and maxInstalledMaps:
   Min-installed-maps specifies the number of maps that can be
   guaranteed to installed simultaneously (with InstallColormap),
   regardless of the number of entries allocated in each map.
   Max-installed-maps specifies the maximum number of maps that might
   possibly be installed simultaneously, depending on their
   allocations. For the typical case of a single hardware colormap,
   both values will be one.
backingStore:
   Backing-stores indicates when the server supports backing stores for
   this screen, although it may be storage limited in the number of
   windows it can support at once.
saveUnders:
   If save-unders is True, then the a
   server can support the save-under mode in CreateWindow and
   ChangeWindowAttributes, although again it may be storage limited.

It follows then the xDepth info:

{depth=24 
visuals={

A pointer to xDepth is also a member of u:

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

xDepth is defined as:

typedef struct {
    CARD8 	depth;
    CARD8 	pad1;
    CARD16	nVisuals B16;  /* number of xVisualType structures following */
    CARD32	pad2 B32;
    } xDepth;

xtrace instead of printing the number of xVisualType structures following, as we read in the comment, it displays all xVisualType the X Server supports.

This number for the current case study is 64:

{id=0x00000021 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c2 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c3 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000c4 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c5 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c6 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000c7 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c8 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000c9 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000ca class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cb class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cc 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000cd class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ce class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000cf 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d0 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d1 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d2 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d3 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d4 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d5 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d6 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d7 class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000d8 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000d9 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000da class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000db 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000dc class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000dd class=TrueColor(0x04) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000de 
class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000df class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 
green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e0 class=DirectColor(0x05) bits/rgb-value=8 
colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e1 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e2 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e3 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e4 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e5 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e6 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e7 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000e8 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000e9 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ea 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000eb class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ec class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ed 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000ee class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ef class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f0 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f1 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f2 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f3 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f4 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f5 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f6 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000f7 class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f8 class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000f9 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000fa class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fb class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fc 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff},{id=0x000000fd class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000fe class=DirectColor(0x05) 
bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff},{id=0x000000ff 
class=DirectColor(0x05) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 
blue-mask=0x000000ff};},{depth=1 visuals=;},{depth=4 visuals=;},{depth=8 visuals=;},{depth=15 visuals=;},{depth=16 
visuals=;},{depth=32 visuals={id=0x00000041 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 
red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff}

A pointer to xVisualType (actually an arrray of xVisualType) is the next member of u:

	union {
		xConnSetup *setup;
		char *failure;
		char *vendor;
		xPixmapFormat *sf;
		xWindowRoot *rp;
		xDepth *dp;
		xVisualType *vp;
	} u;	

xVisualType is defined as:

typedef struct {
    VisualID visualID B32;
#if defined(__cplusplus) || defined(c_plusplus)
    CARD8 c_class;
#else
    CARD8 class;
#endif
    CARD8 bitsPerRGB;
    CARD16 colormapEntries B16;
    CARD32 redMask B32, greenMask B32, blueMask B32;
    CARD32 pad B32;
    } xVisualType;

struct xVisualType

Struct xVisualType represents visual types. It has the following fields:

class

From Writing GNOME Applications we read:

"To simplify and categorize the various color-mapping situations, X11 divides them into six major groups, called visuals. Each visual represents a different style for handling color maps. A visual is a conceptual abstraction that allows us to describe complex color-mapping arrangements in clear, simple language.

The six common visuals in X are StaticGray, GrayScale, StaticColor, PseudoColor, TrueColor, and DirectColor. These visuals have many interesting relationships with each other (see Figure 10.2). Their two primary characteristics are color depth and read/write access. Visuals can use a monochrome color map (StaticGray and GrayScale), or use an RGB color map as we discussed in the previous section (StaticColor and PseudoColor), or write colors directly to the frame buffer for full-color displays (TrueColor and DirectColor)."

As we see from the xtrace output the visual class supported by the X Server is TrueColor. For the visual classes read also the Basic X Concepts.

From the Data Types page we read about the other xVisualType fields:

bits-per-rgb

Specifies the log base 2 of the approximate number of distinct color values ( individually) of red, green, and blue. Actual RGB values are unsigned 16-bit numbers.

colormap-entries

Defines the number of available colormap entries in a newly created colormap. For :direct-color and :true-color , this is the size of an individual pixel subfield.

red-mask, green-mask, blue-mask

The red-mask, green-mask, and blue-mask elements are only meaningful for the :direct-color and :true-color classes. Each mask has one contiguous set of bits with no intersections.

xdpyinfo (X Display Info) and xwininfo

With xdpyinfo we verify some of the previous xtrace results concerning the display info of the X Server. As we read from the man page:

       Xdpyinfo is a utility for displaying information about an X server.  It
       is  used to examine the capabilities of a server, the predefined values
       for various parameters used in communicating between  clients  and  the
       server,  and the different types of screens and visuals that are avail-
       able.
From the command line we run xdpyinfo as:
xdpyinfo
or because it returns an enormous output as:
xdpyinfo | more
To find the details about the xPixmapFormat struct fields we enter in the command line:
xdpyinfo | grep scanline
The result is illustrated in the following image:

xdpyinfo returns also info about the xWindowRoot struct:

Some of the previous info is also returned by the xwininfo utility when it runs with the -root argument:

Reading the xdpyinfo output we get info about the array of xVisualType structs (as we did with xtrace in the first part). The next figure shows the info about the first xVisualType struct:

Also if we continue with the xdpyinfo output we read the rest of the xVisualType structs info.