Next Prev Up

5.1 Introduction

Clients of the X Window System specify the visual attributes of graphical output primitives by using graphics contexts. A graphics context is a set of graphical attribute values such as foreground color, font, line style, and so forth. Like a window, a graphics context is another kind of X server resource which is created and maintained at the request of a client program. The client program, which may use several different graphics contexts at different times, is responsible for specifying a graphics context to use with each graphical output function.

CLX represents a graphics context by an object of type gcontext and defines functions to create, modify, and manipulate gcontext objects. By default, CLX also records the contents of graphics contexts in a cache associated with each display. This local caching of graphics contexts has two important advantages:

  1. Communication efficiency -- Changes to attribute values in a gcontext are first made only in the local cache. Just before a gcontext is actually used, CLX automatically sends any changes to the X server, batching all changes into a single request.
  2. Inquiring gcontext contents -- Accessor functions can be used to return the value of any individual gcontext component by reading the copy of the gcontext from the cache. This kind of inquiry is not supported by the basic X protocol. There is no way for a client program to request an X server to return the contents of a gcontext .

Caching graphics contexts can result in a synchronization problem if more than one client program modifies a graphics context. However, this problem is unusual. Sharing a graphics context among several clients, while possible, is not expected to be useful and is not very easy to do. At any rate, a client program can choose to not cache a gcontext when it is created.

Each client program must determine its own policy for creating and using graphics contexts. Depending on the display hardware and the server implementation, creating a new graphics context can be more or less expensive than modifying an existing one. In general, some amount of graphics context information can be cached in the display hardware, in which case modifying the hardware cache is faster than replacing it. Typical display hardware can cache only a small number of graphics contexts. Graphics output is fastest when only a few graphics contexts are used without heavy modifications.

This section explains the CLX functions used to:

Next Prev Up
© 1988, 1989 Texas Instruments Incorporated
Conversion to HTML made by Gilbert Baumann.
Last build: Tue Dec 16 23:30:42 1997