PEXSelectVisual - Choose a Visual for Use with PEXlib Applications (Utility) (5.2)


Synopsis

 
   int PEXSelectVisual(
       Display *display,
       int screen,
       int criteria_count,
       PEXUtVisualCriteria *criteria,
       XVisualInfo *vis_info_return,
       XStandardColormap *cmap_info_return,
       PEXColorApproxEntry *capx_info_return,
       int *select_criteria_return,
       unsigned int *unmet_criteria_return,
       Atom *std_prop_atom_return
   )
 

Arguments

display
A pointer to a display structure returned by a successful XOpenDisplay call.

screen
The screen number of the display for which a Visual is to be chosen.

criteria_count
The number of PEXUtVisualCriteria structures in the array pointed to by the criteria argument.

criteria
A pointer to a set of PEXUtVisualCriteria structures in priority order from high to low specifying the criteria to be used in selecting the Visual. See the section entitled "Description" below for a complete description of how to use the data structure.

vis_info_return
A pointer to an XVisualInfo
structure allocated by the client. On successful return, this structure is written with a description of the chosen Visual.

cmap_info_return
A pointer to an XStandardColormap structure allocated by the client. On successful return, this structure is written with a copy of the standard colormap property entry that was used to choose the Visual, if PEXUtStandardColormapProperty was specified in the hard or soft criteria mask and such an entry was found. If no property was found or the criteria masks do not include PEXUtStandardColormapProperty, this structure is written with information derived from the attributes of the Visual.

capx_info_return
A pointer to a PEXColorApproxEntry structure allocated by the client. On a successful return, this structure is written with a color approximation setup that is compatible with the cmap_info_return contents, the Visual, and the color approximation type (if specified as a criterion), and can be used in a PEXSetTableValues call.

select_criteria_return
A pointer to an index into the list of criteria specified indicating the criteria selected, to which the other return arguments correspond. The visual, colormap and color approximation information returned will correspond to the criteria indexed by this return argument. An index value of 0 references the first criteria and index value of criteria_count - 1 references the last criteria.

unmet_criteria_return
A pointer to a mask that describes the criteria that were not satisfied in the selected criteria referenced by select_criteria_return. This return argument is meaningful when the function return value is any of PEXUtSuccess, PEXUtQualifiedSuccess, or PEXUtCriteriaFailure.

std_prop_atom_return
A pointer to an Atom. Upon successful return, this location contains the Atom value for the property whose entry is described in *cmap_info_return, or None if no property entry was used.

Returns

PEXUtSuccess
Indicates that the function was completely successful in finding a Visual that meets all hard and soft criteria of the selected Visual and encountered no errors during X or PEX inquiries.

PEXUtQualifiedSuccess
Indicates that the chosen Visual satisfies all hard criteria but does not meet all soft criteria of the selected criteria. In this case, unmet_criteria_return mask includes the soft criteria that were not satisfied.

PEXUtCriteriaFailure
Indicates that no Visual could be found that meets all the hard criteria. In this case the unmet_criteria_return mask includes the hard and soft criteria that were not satisfied in the first criteria set specified.

PEXUtXFailure
Indicates that an error was encountered during an Xlib function call.

PEXUtPEXFailure
Indicates that an error was encountered during a PEXlib call. One possible cause of this failure is that PEXInitialize has not been called for the display connection.

PEXUtBadAlloc
Indicates that the function ran out of memory.

Description

Invoke PEXSelectVisual as a utility that attempts to select an X Visual on the specified display and screen that meets the criteria of one of the criteria sets specified.

This utility returns a success/failure indicator and if successful, it returns information about the Visual and PEX color support for the Visual in structure storage provided by the caller.

PEXSelectVisual supports a "degradation" sequence of criteria sets: specify the "preferred" Visual in the first element of the criteria array, and progressively weaker or less desirable sets in subsequent elements. If the hard criterion from the first element of the criteria array is not met, then the utility evaluates the next criteria set.

The function returns colormap initialization information and color approximation information in cmap_info_return and capx_info_return. When no color approximation type is specified as a criterion, and no property is available to describe a colormap, then this utility returns a PEXColorRange color approximation entry for GrayScale and StaticGray Visuals, and a PEXColorSpace entry otherwise.

If a standard colormap property was used during Visual selection, then the Atom is returned in std_prop_atom_return. All storage for returned values must be allocated by the caller.

Criteria for Visual selection are specified by two masks inside the criteria structure: (see Mask Bits for the Hard and Soft Criteria.)

hard_criteria_mask -
indicates what fields in the criteria structure contain valid values to be considered absolute ("hard") criteria during Visual selection.

soft_criteria_mask -
contains bits for criteria that are desirable but not absolutely required for success.

If a bit for a particular criterion is present in both masks then it is treated as a hard criterion.

For each bit that is set in a criteria mask, a corresponding field in the PEXUtVisualCriteria structure is expected to be set to appropriate values:

  PEXUtDepth          depth
  PEXUtMinColors          min_colors
  PEXUtMinRed          min_red
  PEXUtMinGreen          min_green
  PEXUtMinBlue          min_blue
  PEXUtVisualClass          visual_class
  PEXUtStandardColormapProperty     standard_colormap_property
  PEXUtDynamicVisual          dynamic_visual
  PEXUtDBCapability          double_buffering_capability
  PEXUtColorApproxType          color_approx_type
  PEXUtZBufferDepth          z_buffer_depth
  PEXUtAlphaBufferDepth          alpha_buffer_depth
  PEXUtAccumBufferDepth          accum_buffer_depth
  PEXUtAccumBufferMinRed          accum_buffer_min_red
  PEXUtAccumBufferMinGreen          accum_buffer_min_green
  PEXUtAccumBufferMinBlue          accum_buffer_min_blue

The depth, min_colors, and (min_red,min_green,min_blue) criteria fields interact with one another, and typically only some subset of these should be specified. Depth refers to the depth of the Visual, and may be combined with visual_class if the application must have a specific Visual type (e.g., depth 8 PseudoColor). The depth field may have any valid depth (number of planes) as a value; the value of the visual_class field must be one of the standard X Visual classes (PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray). Min_colors specifies a minimum number of total colors (i.e., cells in a PseudoColor Visual, or combinations in a DirectColor Visual). Min_red, min_green, and min_blue can be used to indicate more specific requirements of a DirectColor or TrueColor visual, or of a color space sampling specified in a standard colormap property. Allowed values for all these fields are positive integers.

When the standard_colormap_property criterion is specified (allowed values are True and False), the procedure searches for defined standard colormap properties in a predefined order: first RGB_BEST_MAP, then RGB_DEFAULT_MAP. It is recommended that standard_colormap_property be specified as a "soft" criterion, since some PEX servers do not define standard colormap properties.

This utility may choose a Visual with more than the requested number of colors unless some other criterion prevents it from doing so.

You can use the dynamic_visual criterion as a hard criterion to enforce selection of a Visual that you can write to, or as a soft criterion to indicate a preference. Conflict is possible between this criterion and the visual_class field. Allowed values are True and False.

The double_buffering_capability criterion may be important to many interactive graphics applications. Allowed values are True and False.

Color_approx_type is mainly useful to applications that need PEXColorRange color approximation. If not specified, then this utility assumes that PEXColorSpace is acceptable, since this is the most common and natural method for most PEX applications. If it is set to PEXColorRange, the returned color approximation entry is initialized for an appropriate gray ramp.

Use the Z buffer depth criterion to specify a minimum depth criterion in terms of bits. If you intend to read the contents of a Z buffer, the function PEXGetAncillaryBufferInfo is useful for determining the format and range of the Z buffer values.

Specify alpha buffer depth as a criterion if you expect to use alpha blending functions that utilize a destination alpha buffer or intend to use alpha buffer transparency.

Specify some combination of the four accumulation buffer criteria if you intend to use accumulation buffers for multi-pass rendering.

For good application portability and interoperability, the following recommendation is made: always specify standard_colormap_property as a soft criterion. If the application has a need for a certain amount of color resolution, specify either min_colors or (min_red,min_green,min_blue) but not both. Double_buffering_capability may be specified as hard or soft criteria depending on the application. Other criteria should be specified as soft criteria unless particular application needs cause them to be absolute requirements.

The ability of this procedure to verify that criteria are met depends on information available from the PEX server, including its support for various interoperability conventions. In general, if a hard criterion cannot be determined to have been satisfied or not, it is considered to have not been met; if a soft criterion cannot be verified, then the utility acts as though it had been met but still returns the corresponding bit in unmet_criteria_return.

If two or more visuals meet all the hard criteria, then the visual that meets the largest number of soft criteria is selected. If there is more than one visual that meets the same number of soft criteria, then the visual with the highest color resolution is chosen. In the event that the visuals are equivalent in these three respects, a static visual is preferred over a dynamic one. The final criterion is that preference is given to visuals in the order that they are listed by the server.

Errors

See function return values.

See Also

For an overview, see PEXlib Access and Information Functions.